diff options
author | Jason Dunsmore <jasondunsmore@gmail.com> | 2014-07-15 11:52:46 -0500 |
---|---|---|
committer | Jason Dunsmore <jasondunsmore@gmail.com> | 2014-07-15 11:54:23 -0500 |
commit | bd4ed52b78dc20759b0780e2fcece409c423f1d4 (patch) | |
tree | 483daf1538bbc796143a9edfc98cfb39af475a4a | |
parent | b534ff5271e1221fdd4258d56dc15d76a498f008 (diff) | |
download | heat-bd4ed52b78dc20759b0780e2fcece409c423f1d4.tar.gz |
Move novaclient exceptions to heat.tests.v1_1.fakes
Applying novaclient exceptions fix from commit:
9850832da563c1113e121b99d38feb21af9daa8d
"Raising nova exceptions has been moved to
heat.tests.v1_1.fakes.fake_exception since it is actually impossible
to directly create a nova exception object which works on both
novaclient 2.17 and (yet to be released) 2.18.
nova.exceptions.from_response is stable across novaclient releases
so all test exceptions are now raised using from_response."
Change-Id: I0c5e58ffdd3eb13b9a87df22f1c5e06cec972913
Closes-Bug: #1322098
-rw-r--r-- | heat/tests/test_nova_utils.py | 11 | ||||
-rw-r--r-- | heat/tests/test_security_group.py | 12 | ||||
-rw-r--r-- | heat/tests/v1_1/fakes.py | 10 |
3 files changed, 17 insertions, 16 deletions
diff --git a/heat/tests/test_nova_utils.py b/heat/tests/test_nova_utils.py index 3e382ba91..a4d881fcc 100644 --- a/heat/tests/test_nova_utils.py +++ b/heat/tests/test_nova_utils.py @@ -20,6 +20,7 @@ from heat.common import exception from heat.engine import clients from heat.engine.resources import nova_utils from heat.tests.common import HeatTestCase +from heat.tests.v1_1 import fakes class NovaUtilsTests(HeatTestCase): @@ -126,10 +127,7 @@ class NovaUtilsRefreshServerTests(HeatTestCase): def test_500_error(self): server = self.m.CreateMockAnything() - msg = ("ClientException: The server has either erred or is " - "incapable of performing the requested operation.") - server.get().AndRaise( - clients.novaclient.exceptions.ClientException(500, msg)) + server.get().AndRaise(fakes.fake_exception(500)) self.m.ReplayAll() self.assertIsNone(nova_utils.refresh_server(server)) @@ -137,10 +135,7 @@ class NovaUtilsRefreshServerTests(HeatTestCase): def test_503_error(self): server = self.m.CreateMockAnything() - msg = ("ClientException: The server has either erred or is " - "incapable of performing the requested operation.") - server.get().AndRaise( - clients.novaclient.exceptions.ClientException(503, msg)) + server.get().AndRaise(fakes.fake_exception(503)) self.m.ReplayAll() self.assertIsNone(nova_utils.refresh_server(server)) diff --git a/heat/tests/test_security_group.py b/heat/tests/test_security_group.py index b5794205a..09ab32041 100644 --- a/heat/tests/test_security_group.py +++ b/heat/tests/test_security_group.py @@ -361,20 +361,16 @@ Resources: clients.OpenStackClients.nova('compute').AndReturn(self.fc) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '22', '22', '0.0.0.0/0', None).AndRaise( - clients.novaclient.exceptions.BadRequest( - 400, 'Rule already exists')) + fakes.fake_exception(400, 'Rule already exists')) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', '80', '80', '0.0.0.0/0', None).AndReturn( - clients.novaclient.exceptions.BadRequest( - 400, 'Rule already exists')) + fakes.fake_exception(400, 'Rule already exists')) nova_sgr.SecurityGroupRuleManager.create( 2, 'tcp', None, None, None, 1).AndReturn( - clients.novaclient.exceptions.BadRequest( - 400, 'Rule already exists')) + fakes.fake_exception(400, 'Rule already exists')) nova_sgr.SecurityGroupRuleManager.create( 2, 'icmp', None, None, None, '1').AndReturn( - clients.novaclient.exceptions.BadRequest( - 400, 'Rule already exists')) + fakes.fake_exception(400, 'Rule already exists')) # delete script clients.OpenStackClients.nova('compute').AndReturn(self.fc) diff --git a/heat/tests/v1_1/fakes.py b/heat/tests/v1_1/fakes.py index cd20a4d10..04e95154b 100644 --- a/heat/tests/v1_1/fakes.py +++ b/heat/tests/v1_1/fakes.py @@ -14,14 +14,24 @@ # limitations under the License. import httplib2 +import mock from novaclient import client as base_client +from novaclient import exceptions as nova_exceptions from novaclient.v1_1 import client from heat.openstack.common.py3kcompat import urlutils from heat.tests import fakes +def fake_exception(status_code=404, message=None, details=None): + resp = mock.Mock() + resp.status_code = status_code + resp.headers = None + body = {'error': {'message': message, 'details': details}} + return nova_exceptions.from_response(resp, body, None) + + class FakeClient(fakes.FakeClient, client.Client): def __init__(self, *args, **kwargs): |