def test_neutron(self): fake_neutron = fakes.FakeNeutronClient() mock_neutron = mock.MagicMock() mock_neutron.client.Client.return_value = fake_neutron self.assertNotIn("neutron", self.clients.cache) with mock.patch.dict("sys.modules", {"neutronclient.neutron": mock_neutron}): client = self.clients.neutron() self.assertEqual(fake_neutron, client) kw = { "token": self.fake_keystone.auth_token, "endpoint_url": self.service_catalog.url_for.return_value, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": self.credential.insecure, "ca_cert": self.credential.cacert, "username": self.credential.username, "password": self.credential.password, "tenant_name": self.credential.tenant_name, "auth_url": self.credential.auth_url } self.service_catalog.url_for.assert_called_once_with( service_type="network", endpoint_type=consts.EndpointType.PUBLIC, region_name=self.credential.region_name) mock_neutron.client.Client.assert_called_once_with("2.0", **kw) self.assertEqual(fake_neutron, self.clients.cache["neutron"])
def test_neutron(self, mock_neutron__get_endpoint): fake_neutron = fakes.FakeNeutronClient() mock_neutron__get_endpoint.return_value = "http://fake.to:2/fake" mock_neutron = mock.MagicMock() mock_keystoneauth1 = mock.MagicMock() mock_neutron.client.Client.return_value = fake_neutron self.assertNotIn("neutron", self.clients.cache) with mock.patch.dict("sys.modules", {"neutronclient.neutron": mock_neutron, "keystoneauth1": mock_keystoneauth1}): client = self.clients.neutron() self.assertEqual(fake_neutron, client) kw = { "session": mock_keystoneauth1.session.Session(), "endpoint_override": mock_neutron__get_endpoint.return_value} mock_neutron.client.Client.assert_called_once_with("2.0", **kw) self.assertEqual(fake_neutron, self.clients.cache["neutron"])
def test_neutron(self, mock_neutron): fake_neutron = fakes.FakeNeutronClient() mock_neutron.Client = mock.MagicMock(return_value=fake_neutron) self.assertTrue("neutron" not in self.clients.cache) client = self.clients.neutron() self.assertEqual(client, fake_neutron) kw = { "token": self.fake_keystone.auth_token, "endpoint_url": self.service_catalog.url_for.return_value, "timeout": cfg.CONF.openstack_client_http_timeout, "insecure": cfg.CONF.https_insecure, "ca_cert": cfg.CONF.https_cacert } self.service_catalog.url_for.assert_called_once_with( service_type='network', endpoint_type=consts.EndpointType.PUBLIC, region_name=self.endpoint.region_name) mock_neutron.Client.assert_called_once_with("2.0", **kw) self.assertEqual(self.clients.cache["neutron"], fake_neutron)