From 33b1cefe66e4a936c5cfa90bbba5dd8daa73e618 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Wed, 30 Jul 2014 18:35:28 +0800 Subject: [PATCH] Use Constraint stubs in common.py Migrate to use functions: stub_KeypairConstraint_validate() and stub_ImageConstraint_validate() in tests/common.py which defined in patch I23dc126e621f3cfa7ca86b3a1c27dd949d3f5093. Change-Id: I63d578a9291d0fe08815d6a33323324432ae21cb --- heat/tests/test_instance.py | 6 +++--- heat/tests/test_metadata_refresh.py | 26 ++++++-------------------- heat/tests/test_neutron_autoscaling.py | 5 +---- heat/tests/test_server.py | 19 ++++++++----------- heat/tests/test_volume.py | 5 ++--- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index 731236061..39844852b 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -878,9 +878,7 @@ class InstancesTest(HeatTestCase): instance = self._create_test_instance(return_server, 'in_update2') - self.m.StubOutWithMock(glance.ImageConstraint, "validate") - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() self.m.ReplayAll() update_template = copy.deepcopy(instance.t) @@ -888,6 +886,8 @@ class InstancesTest(HeatTestCase): updater = scheduler.TaskRunner(instance.update, update_template) self.assertRaises(resource.UpdateReplace, updater) + self.m.VerifyAll() + def test_instance_status_build(self): return_server = self.fc.servers.list()[0] instance = self._setup_test_instance(return_server, diff --git a/heat/tests/test_metadata_refresh.py b/heat/tests/test_metadata_refresh.py index ff4cd10af..da3088855 100644 --- a/heat/tests/test_metadata_refresh.py +++ b/heat/tests/test_metadata_refresh.py @@ -17,11 +17,9 @@ from oslo.config import cfg from heat.common import identifier from heat.common import template_format -from heat.engine.clients.os import glance from heat.engine import environment from heat.engine import parser from heat.engine.resources import instance -from heat.engine.resources import nova_keypair from heat.engine.resources import server from heat.engine.resources import wait_condition as wc from heat.engine import scheduler @@ -164,12 +162,8 @@ class MetadataRefreshTest(HeatTestCase): self.stack_id = stack.store() - self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate') - nova_keypair.KeypairConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) - self.m.StubOutWithMock(glance.ImageConstraint, 'validate') - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() + self.stub_KeypairConstraint_validate() self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') @@ -231,12 +225,8 @@ class WaitCondMetadataUpdateTest(HeatTestCase): self.stack_id = stack.store() - self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate') - nova_keypair.KeypairConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) - self.m.StubOutWithMock(glance.ImageConstraint, 'validate') - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() + self.stub_KeypairConstraint_validate() self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') @@ -327,12 +317,8 @@ class MetadataRefreshTestServer(HeatTestCase): self.stack_id = stack.store() - self.m.StubOutWithMock(nova_keypair.KeypairConstraint, 'validate') - nova_keypair.KeypairConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) - self.m.StubOutWithMock(glance.ImageConstraint, 'validate') - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() + self.stub_KeypairConstraint_validate() self.m.StubOutWithMock(server.Server, 'handle_create') self.m.StubOutWithMock(server.Server, 'check_create_complete') diff --git a/heat/tests/test_neutron_autoscaling.py b/heat/tests/test_neutron_autoscaling.py index 86bc7e9ef..0ee388e5d 100644 --- a/heat/tests/test_neutron_autoscaling.py +++ b/heat/tests/test_neutron_autoscaling.py @@ -20,7 +20,6 @@ from oslo.config import cfg from heat.common import template_format from heat.db import api as db_api -from heat.engine.clients.os import glance from heat.engine import environment from heat.engine import parser from heat.engine.resources import instance @@ -129,7 +128,6 @@ class AutoScalingTest(HeatTestCase): self.m.StubOutWithMock(instance.Instance, 'handle_create') self.m.StubOutWithMock(instance.Instance, 'check_create_complete') - self.m.StubOutWithMock(glance.ImageConstraint, "validate") def test_lb(self): @@ -278,8 +276,7 @@ class AutoScalingTest(HeatTestCase): instance.Instance.check_create_complete(mox.IgnoreArg())\ .AndReturn(True) - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() nova_utils.server_to_ipaddress( mox.IgnoreArg(), diff --git a/heat/tests/test_server.py b/heat/tests/test_server.py index c3d70b267..4780be1c7 100644 --- a/heat/tests/test_server.py +++ b/heat/tests/test_server.py @@ -826,14 +826,11 @@ class ServersTest(HeatTestCase): server = servers.Server('server_validate_test', resource_defns['WebServer'], stack) - self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') - self.m.StubOutWithMock(glance.ImageConstraint, "validate") - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) - self.m.ReplayAll() + self.stub_ImageConstraint_validate() self.m.ReplayAll() self.assertIsNone(server.validate()) + self.m.VerifyAll() def test_server_validate_with_invalid_ssh_key(self): @@ -1233,9 +1230,7 @@ class ServersTest(HeatTestCase): image_id = self.getUniqueString() self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') nova.NovaClientPlugin._create().AndReturn(self.fc) - self.m.StubOutWithMock(glance.ImageConstraint, "validate") - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() self.m.ReplayAll() update_template = copy.deepcopy(server.t) @@ -1243,6 +1238,8 @@ class ServersTest(HeatTestCase): updater = scheduler.TaskRunner(server.update, update_template) self.assertRaises(resource.UpdateReplace, updater) + self.m.VerifyAll() + def _test_server_update_image_rebuild(self, status, policy='REBUILD'): # Server.handle_update supports changing the image, and makes # the change making a rebuild API call against Nova. @@ -1343,9 +1340,7 @@ class ServersTest(HeatTestCase): server = self._create_test_server(return_server, 'update_prop') - self.m.StubOutWithMock(glance.ImageConstraint, "validate") - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() self.m.ReplayAll() update_template = copy.deepcopy(server.t) @@ -1353,6 +1348,8 @@ class ServersTest(HeatTestCase): updater = scheduler.TaskRunner(server.update, update_template) self.assertRaises(resource.UpdateReplace, updater) + self.m.VerifyAll() + def test_server_status_build(self): return_server = self.fc.servers.list()[0] server = self._setup_test_server(return_server, diff --git a/heat/tests/test_volume.py b/heat/tests/test_volume.py index 639e55ff7..8aaac99cd 100644 --- a/heat/tests/test_volume.py +++ b/heat/tests/test_volume.py @@ -223,13 +223,12 @@ class VolumeTest(HeatTestCase): self.m.StubOutWithMock(instance.Instance, 'check_create_complete') self.m.StubOutWithMock(vol.VolumeAttachment, 'handle_create') self.m.StubOutWithMock(vol.VolumeAttachment, 'check_create_complete') - self.m.StubOutWithMock(glance.ImageConstraint, "validate") + instance.Instance.handle_create().AndReturn(None) instance.Instance.check_create_complete(None).AndReturn(True) cinder.CinderClientPlugin._create().AndReturn( self.cinder_fc) - glance.ImageConstraint.validate( - mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndReturn(True) + self.stub_ImageConstraint_validate() vol_name = utils.PhysName(stack_name, 'DataVolume') self.cinder_fc.volumes.create( size=1, availability_zone=None,