Merge "Move suspend/resume autoscaling tests to functional"

This commit is contained in:
Jenkins 2015-02-05 10:23:38 +00:00 committed by Gerrit Code Review
commit 3b395b0847
2 changed files with 29 additions and 218 deletions

View File

@ -118,38 +118,6 @@ class AutoScalingTest(common.HeatTestCase):
instance.Instance.check_delete_complete(
task).MultipleTimes().AndReturn(True)
def _stub_suspend(self, cookies=None, with_error=None):
cookies = cookies or []
self.m.StubOutWithMock(instance.Instance, 'handle_suspend')
self.m.StubOutWithMock(instance.Instance, 'check_suspend_complete')
if with_error:
instance.Instance.handle_suspend().AndRaise(
exception.Error(with_error))
return
inst_cookies = cookies or [(object(), object(), object())]
for cookie in inst_cookies:
instance.Instance.handle_suspend().InAnyOrder().AndReturn(cookie)
instance.Instance.check_suspend_complete(
cookie).InAnyOrder().AndReturn(False)
instance.Instance.check_suspend_complete(
cookie).InAnyOrder().AndReturn(True)
def _stub_resume(self, cookies=None, with_error=None):
cookies = cookies or []
self.m.StubOutWithMock(instance.Instance, 'handle_resume')
self.m.StubOutWithMock(instance.Instance, 'check_resume_complete')
if with_error:
instance.Instance.handle_resume().AndRaise(
exception.Error(with_error))
return
inst_cookies = cookies or [(object(), object(), object())]
for cookie in inst_cookies:
instance.Instance.handle_resume().InAnyOrder().AndReturn(cookie)
instance.Instance.check_resume_complete(
cookie).InAnyOrder().AndReturn(False)
instance.Instance.check_resume_complete(
cookie).InAnyOrder().AndReturn(True)
def _stub_lb_reload(self, num, unset=True, nochange=False):
expected_list = [self.dummy_instance_id] * num
if unset:
@ -219,192 +187,6 @@ class AutoScalingTest(common.HeatTestCase):
for x in range(nmeta):
resource.Resource.metadata_set(expected).AndReturn(None)
def test_scaling_group_suspend(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(1)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_suspend()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.suspend)()
self.assertEqual((rsrc.SUSPEND, rsrc.COMPLETE), rsrc.state)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_resume(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(1)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_resume()
self.m.ReplayAll()
rsrc.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
for i in rsrc.nested().values():
i.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
scheduler.TaskRunner(rsrc.resume)()
self.assertEqual((rsrc.RESUME, rsrc.COMPLETE), rsrc.state)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_suspend_multiple(self):
t = template_format.parse(as_template)
properties = t['Resources']['WebServerGroup']['Properties']
properties['DesiredCapacity'] = '2'
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 2')
self._stub_create(2)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(2, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_suspend(cookies=[('foo1', 'foo2', 'foo3'),
('bar1', 'bar2', 'bar3')])
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.suspend)()
self.assertEqual((rsrc.SUSPEND, rsrc.COMPLETE), rsrc.state)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_resume_multiple(self):
t = template_format.parse(as_template)
properties = t['Resources']['WebServerGroup']['Properties']
properties['DesiredCapacity'] = '2'
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 2')
self._stub_create(2)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(2, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_resume(cookies=[('foo1', 'foo2', 'foo3'),
('bar1', 'bar2', 'bar3')])
self.m.ReplayAll()
rsrc.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
for i in rsrc.nested().values():
i.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
scheduler.TaskRunner(rsrc.resume)()
self.assertEqual((rsrc.RESUME, rsrc.COMPLETE), rsrc.state)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_suspend_fail(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(1)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_suspend(with_error='oops')
self.m.ReplayAll()
sus_task = scheduler.TaskRunner(rsrc.suspend)
self.assertRaises(exception.ResourceFailure, sus_task, ())
self.assertEqual((rsrc.SUSPEND, rsrc.FAILED), rsrc.state)
self.assertEqual('Error: Resource SUSPEND failed: Error: oops',
rsrc.status_reason)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_resume_fail(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
self._stub_lb_reload(1)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
rsrc = self.create_scaling_group(t, stack, 'WebServerGroup')
self.assertEqual(utils.PhysName(stack.name, rsrc.name),
rsrc.FnGetRefId())
self.assertEqual(1, len(grouputils.get_member_names(rsrc)))
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
self.m.VerifyAll()
self.m.UnsetStubs()
self._stub_resume(with_error='oops')
self.m.ReplayAll()
rsrc.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
for i in rsrc.nested().values():
i.state_set(rsrc.SUSPEND, rsrc.COMPLETE)
sus_task = scheduler.TaskRunner(rsrc.resume)
self.assertRaises(exception.ResourceFailure, sus_task, ())
self.assertEqual((rsrc.RESUME, rsrc.FAILED), rsrc.state)
self.assertEqual('Error: Resource RESUME failed: Error: oops',
rsrc.status_reason)
rsrc.delete()
self.m.VerifyAll()
def test_scaling_group_create_error(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)

View File

@ -302,6 +302,35 @@ class AutoscalingGroupBasicTest(AutoscalingGroupTest):
res.resource_name,
'CREATE_FAILED')
def test_group_suspend_resume(self):
files = {'provider.yaml': self.instance_template}
env = {'resource_registry': {'AWS::EC2::Instance': 'provider.yaml'},
'parameters': {'size': 4,
'image': self.conf.image_ref,
'flavor': self.conf.instance_type}}
stack_identifier = self.stack_create(template=self.template,
files=files, environment=env)
nested_ident = self.assert_resource_is_a_stack(stack_identifier,
'JobServerGroup')
self.client.actions.suspend(stack_id=stack_identifier)
self._wait_for_resource_status(
stack_identifier, 'JobServerGroup', 'SUSPEND_COMPLETE')
for res in self.client.resources.list(nested_ident):
self._wait_for_resource_status(nested_ident,
res.resource_name,
'SUSPEND_COMPLETE')
self.client.actions.resume(stack_id=stack_identifier)
self._wait_for_resource_status(
stack_identifier, 'JobServerGroup', 'RESUME_COMPLETE')
for res in self.client.resources.list(nested_ident):
self._wait_for_resource_status(nested_ident,
res.resource_name,
'RESUME_COMPLETE')
class AutoscalingGroupUpdatePolicyTest(AutoscalingGroupTest):