From a280d2e88c7a732630a5ae00c2c452c6db34cc8b Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Sun, 31 Jul 2016 18:34:57 -0400 Subject: [PATCH] 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 --- nova/network/neutronv2/api.py | 2 +- nova/tests/unit/network/test_neutronv2.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index 0bfa4ce7f1..e1b714c68b 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -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 diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 9005f2f6aa..f8894c9e9a 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -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