From 980c76266629ea66bc23fddb02f5be61c51d873c Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 3 Jul 2012 22:15:12 -0400 Subject: Fix some hacking violations in the quantum tests. This patch fixes some import sorting and HACKING violations in the quantum tests. Quantum client raises Exception which is discouraged by HACKING. To avoid some of the HACKING violations we set a constant equal to Exception and use it for the assertions in the tests. This avoids the HACKING violations until we can make quantum client throw a custom exception class instead. Change-Id: Ie52d0049dda2d18ad06c5137ca8c316c5531b56a --- nova/network/quantumv2/__init__.py | 2 +- nova/network/quantumv2/api.py | 2 +- nova/tests/network/test_quantumv2.py | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nova/network/quantumv2/__init__.py b/nova/network/quantumv2/__init__.py index ff140fd72..af114a80c 100644 --- a/nova/network/quantumv2/__init__.py +++ b/nova/network/quantumv2/__init__.py @@ -17,8 +17,8 @@ from nova import exception from nova import flags -from nova.openstack.common import log as logging from nova.openstack.common import excutils +from nova.openstack.common import log as logging from quantumclient import client from quantumclient.v2_0 import client as clientv20 diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 1e796a308..1cac12f8e 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -18,12 +18,12 @@ from nova.db import base from nova import exception from nova import flags -from nova.openstack.common import log as logging from nova.network.api import refresh_cache from nova.network import model as network_model from nova.network import quantumv2 from nova.openstack.common import cfg from nova.openstack.common import excutils +from nova.openstack.common import log as logging quantum_opts = [ cfg.StrOpt('quantum_url', diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index f24c60e69..7a12914cb 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -19,8 +19,8 @@ import mox from nova import context from nova import exception -from nova.network import quantumv2 from nova.network import model +from nova.network import quantumv2 from nova.network.quantumv2 import api as quantumapi from nova.openstack.common import cfg from nova import test @@ -28,6 +28,11 @@ from nova import utils from quantumclient.v2_0 import client FLAGS = cfg.CONF +#NOTE: Quantum client raises Exception which is discouraged by HACKING. +# We set this variable here and use it for assertions below to avoid +# the hacking checks until we can make quantum client throw a custom +# exception class instead. +QUANTUM_CLIENT_EXCEPTION = Exception class MyComparator(mox.Comparator): @@ -99,7 +104,7 @@ class TestQuantumClient(test.TestCase): self.flags(quantum_auth_strategy='keystone') self.flags(quantum_url='http://anyhost/') my_context = context.RequestContext('userid', 'my_tenantid') - self.assertRaises(Exception, + self.assertRaises(QUANTUM_CLIENT_EXCEPTION, quantumv2.get_client, my_context) @@ -308,7 +313,7 @@ class TestQuantumv2(test.TestCase): index += 1 self.moxed_client.delete_port('portid_' + self.nets2[0]['id']) self.mox.ReplayAll() - self.assertRaises(Exception, api.allocate_for_instance, + self.assertRaises(QUANTUM_CLIENT_EXCEPTION, api.allocate_for_instance, self.context, self.instance) def test_allocate_for_instance_ex2(self): @@ -334,7 +339,7 @@ class TestQuantumv2(test.TestCase): MyComparator(port_req_body)).AndRaise( Exception("fail to create port")) self.mox.ReplayAll() - self.assertRaises(Exception, api.allocate_for_instance, + self.assertRaises(QUANTUM_CLIENT_EXCEPTION, api.allocate_for_instance, self.context, self.instance) def _deallocate_for_instance(self, number): -- cgit