def test_cached_service_instace_dffierent_host(self): mock_si = MagicMock() mock_si_stub = MagicMock() mock_disconnect = MagicMock() mock_get_si = MagicMock(return_value=mock_si) mock_si._GetStub = mock_si_stub with patch('salt.utils.vmware.GetSi', mock_get_si): with patch('salt.utils.vmware.Disconnect', mock_disconnect): salt.utils.vmware.get_service_instance( host='fake_host', username='******', password='******', protocol='fake_protocol', port=1, mechanism='fake_mechanism', principal='fake_principal', domain='fake_domain') self.assertEqual(mock_get_si.call_count, 1) self.assertEqual(mock_si_stub.call_count, 1) self.assertEqual(mock_disconnect.call_count, 1)
def test_cached_service_instace_same_host_on_proxy(self): mock_si = MagicMock() mock_si_stub_value = MagicMock() mock_si_get_connection = MagicMock() mock_si_stub = MagicMock(return_value=mock_si_stub_value) mock_get_si = MagicMock(return_value=mock_si) mock_si._GetStub = mock_si_stub mock_si_stub_value.host = 'fake_host:1' mock_si_stub_value.GetConnection = mock_si_get_connection with patch('salt.utils.vmware.GetSi', mock_get_si): salt.utils.vmware.get_service_instance(host='fake_host', username='******', password='******', protocol='fake_protocol', port=1, mechanism='fake_mechanism', principal='fake_principal', domain='fake_domain') self.assertEqual(mock_get_si.call_count, 1) self.assertEqual(mock_si_stub.call_count, 2) self.assertEqual(mock_si_get_connection.call_count, 1)