Straddle python-neutronclient 5.0 for testing

python-neutronclient 5.0 has deprecated the usage of
tenant_id/tenant_name in place of project_id/project_name
for keystone v3 usage. It does this using debtcollector
decorators on the methods with those kwargs. This is fine
at runtime but doesn't work with mox since mox stubs the
methods off the Client class, but doesn't pick up and stub
any decorators on those methods. So when our unit tests
pass tenant_id kwargs they fail on the moxed_client.

To make the tests work for both neutronclient>5 and <5 we
simply pass the project_id as an arg rather than kwarg
to the show_quota method.

Change-Id: I86bbac3e24bef27396297dfc79eb24c61dbcb6ac
Closes-Bug: #1608258
This commit is contained in:
Matt Riedemann 2016-07-31 18:34:57 -04:00
parent 32b7526b3c
commit a280d2e88c
2 changed files with 10 additions and 10 deletions

View File

@ -1535,7 +1535,7 @@ class API(base_api.NetworkAPI):
# from the hypervisor. So we just check the quota and return
# how many of the requested number of instances can be created
if ports_needed_per_instance:
quotas = neutron.show_quota(tenant_id=context.project_id)['quota']
quotas = neutron.show_quota(context.project_id)['quota']
if quotas.get('port', -1) == -1:
# Unlimited Port Quota
return num_instances

View File

@ -1675,7 +1675,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets2})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 50}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -1692,7 +1692,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets2})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {}})
self.mox.ReplayAll()
api = neutronapi.API()
@ -1704,7 +1704,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(['my_netid1'])).AndReturn(
{'networks': self.nets1})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 50}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -1744,7 +1744,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets1})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 50}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -1938,7 +1938,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets2})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 2}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -1964,7 +1964,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets1})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 5}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -2002,7 +2002,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets2})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': 5}})
self.moxed_client.list_ports(
tenant_id=uuids.my_tenant, fields=['id']).AndReturn(
@ -2025,7 +2025,7 @@ class TestNeutronv2(TestNeutronv2Base):
id=mox.SameElementsAs(ids)).AndReturn(
{'networks': self.nets2})
self.moxed_client.show_quota(
tenant_id=uuids.my_tenant).AndReturn(
uuids.my_tenant).AndReturn(
{'quota': {'port': -1}})
self.mox.ReplayAll()
api = neutronapi.API()
@ -3196,7 +3196,7 @@ class TestNeutronv2WithMock(test.TestCase):
self.assertEqual(len(list_port_values),
len(list_ports_mock.call_args_list))
list_networks_mock.assert_called_once_with(id=ids)
show_quota_mock.assert_called_once_with(tenant_id='fake-project')
show_quota_mock.assert_called_once_with('fake-project')
def test_validate_networks_over_limit_quota(self):
"""Test validates that a relevant exception is being raised when