diff options
-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): |