Explicitly pass endpoint type to Neutron client

Adds unit test to exercise branch.

Change-Id: I2c5fb7c58031916497e8eedd9eef5d8866e52393
Closes-Bug: 1655728
This commit is contained in:
Carlos L. Torres 2017-01-11 12:52:17 -06:00
parent 2b66c63054
commit ba97c9b172
No known key found for this signature in database
GPG Key ID: E03C5855B93A1F91
2 changed files with 27 additions and 1 deletions

View File

@ -354,9 +354,14 @@ class Neutron(OSClient):
"""Return neutron client."""
from neutronclient.neutron import client as neutron
kw_args = {}
if self.credential.endpoint_type:
kw_args["endpoint_type"] = self.credential.endpoint_type
client = neutron.Client(self.choose_version(version),
session=self.keystone.get_session()[0],
endpoint_url=self._get_endpoint(service_type))
endpoint_url=self._get_endpoint(service_type),
**kw_args)
return client

View File

@ -369,6 +369,27 @@ class OSClientsTestCase(test.TestCase):
mock_neutron.client.Client.assert_called_once_with("2.0", **kw)
self.assertEqual(fake_neutron, self.clients.cache["neutron"])
@mock.patch("rally.osclients.Neutron._get_endpoint")
def test_neutron_endpoint_type(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)
self.credential.endpoint_type = "internal"
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_url": mock_neutron__get_endpoint.return_value,
"endpoint_type": "internal"}
mock_neutron.client.Client.assert_called_once_with("2.0", **kw)
self.assertEqual(fake_neutron, self.clients.cache["neutron"])
@mock.patch("rally.osclients.Glance._get_endpoint")
def test_glance(self, mock_glance__get_endpoint):
fake_glance = fakes.FakeGlanceClient()