本文整理汇总了Python中heat.engine.resource.Metadata.__get__方法的典型用法代码示例。如果您正苦于以下问题:Python Metadata.__get__方法的具体用法?Python Metadata.__get__怎么用?Python Metadata.__get__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类heat.engine.resource.Metadata
的用法示例。
在下文中一共展示了Metadata.__get__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scaling_policy_cooldown_none
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_none(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
# Create initial group
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')
stack.resources['WebServerGroup'] = rsrc
self.assertEqual(['WebServerGroup-0'], rsrc.get_instance_names())
# Create the scaling policy no Cooldown property, should behave the
# same as when Cooldown==0
properties = t['Resources']['WebServerScaleUpPolicy']['Properties']
del(properties['Cooldown'])
self._stub_lb_reload(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.StubOutWithMock(asc.ScalingPolicy, 'keystone')
asc.ScalingPolicy.keystone().MultipleTimes().AndReturn(
self.fc)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.signal()
self.assertEqual(['WebServerGroup-0', 'WebServerGroup-1'],
rsrc.get_instance_names())
# Now trigger another scale-up without changing time, should work
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()
).AndReturn(previous_meta)
self._stub_lb_reload(3, unset=False)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.signal()
self.assertEqual(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'],
rsrc.get_instance_names())
rsrc.delete()
self.m.VerifyAll()
示例2: test_scaling_policy_cooldown_toosoon
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_toosoon(self):
t = template_format.parse(as_template)
stack = parse_stack(t, params=self.params)
# Create initial group
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')
stack.resources['WebServerGroup'] = rsrc
self.assertEqual('WebServerGroup-0', rsrc.resource_id)
# Scale up one
self._stub_lb_reload(2)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.StubOutWithMock(asc.ScalingPolicy, 'keystone')
asc.ScalingPolicy.keystone().MultipleTimes().AndReturn(
self.fc)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
# Now move time on 10 seconds - Cooldown in template is 60
# so this should not update the policy metadata, and the
# scaling group instances should be unchanged
# Note we have to stub Metadata.__get__ since up_policy isn't
# stored in the DB (because the stack hasn't really been created)
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=10)
self.m.StubOutWithMock(timeutils, 'utcnow')
timeutils.utcnow().MultipleTimes().AndReturn(now)
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
self.m.ReplayAll()
up_policy.signal()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
rsrc.delete()
self.m.VerifyAll()
示例3: test_scaling_policy_cooldown_ok
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_ok(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
# Create initial group
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')
stack.resources['WebServerGroup'] = rsrc
self.assertEqual(['WebServerGroup-0'], rsrc.get_instance_names())
# Scale up one
self._stub_lb_reload(2)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.StubOutWithMock(asc.ScalingPolicy, 'keystone')
asc.ScalingPolicy.keystone().MultipleTimes().AndReturn(
self.fc)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.signal()
self.assertEqual(['WebServerGroup-0', 'WebServerGroup-1'],
rsrc.get_instance_names())
# Now move time on 61 seconds - Cooldown in template is 60
# so this should trigger a scale-up
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()
).AndReturn(previous_meta)
now = now + datetime.timedelta(seconds=61)
self._stub_lb_reload(3, unset=False)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.signal()
self.assertEqual(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'],
rsrc.get_instance_names())
rsrc.delete()
self.m.VerifyAll()
示例4: test_scaling_policy_cooldown_none
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_none(self):
t = self.load_template()
stack = self.parse_stack(t)
# Create initial group
self._stub_lb_reload(['WebServerGroup-0'])
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, 'WebServerGroup')
stack.resources['WebServerGroup'] = resource
self.assertEqual('WebServerGroup-0', resource.resource_id)
# Create the scaling policy no Cooldown property, should behave the
# same as when Cooldown==0
properties = t['Resources']['WebServerScaleUpPolicy']['Properties']
del(properties['Cooldown'])
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1'])
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
resource.resource_id)
# Now trigger another scale-up without changing time, should work
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()
).AndReturn(previous_meta)
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'], unset=False)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
resource.resource_id)
resource.delete()
self.m.VerifyAll()
示例5: test_scaling_group_cooldown_toosoon
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_toosoon(self):
t = self.load_template()
stack = self.parse_stack(t)
# Create initial group, 2 instances, Cooldown 60s
properties = t['Resources']['WebServerGroup']['Properties']
properties['DesiredCapacity'] = '2'
properties['Cooldown'] = '60'
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1'])
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 2')
self._stub_create(2)
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, 'WebServerGroup')
stack.resources['WebServerGroup'] = resource
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
resource.resource_id)
# reduce by 50%
self._stub_lb_reload(['WebServerGroup-0'])
self._stub_meta_expected(now, 'PercentChangeInCapacity : -50')
self.m.ReplayAll()
resource.adjust(-50, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0',
resource.resource_id)
# Now move time on 10 seconds - Cooldown in template is 60
# so this should not update the policy metadata, and the
# scaling group instances should be unchanged
# Note we have to stub Metadata.__get__ since up_policy isn't
# stored in the DB (because the stack hasn't really been created)
previous_meta = {timeutils.strtime(now):
'PercentChangeInCapacity : -50'}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=10)
self.m.StubOutWithMock(timeutils, 'utcnow')
timeutils.utcnow().AndReturn(now)
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()
).AndReturn(previous_meta)
self.m.ReplayAll()
# raise by 200%, too soon for Cooldown so there should be no change
resource.adjust(200, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0', resource.resource_id)
resource.delete()
示例6: test_scaling_group_cooldown_ok
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_ok(self):
t = self.load_template()
stack = self.parse_stack(t)
# Create initial group, 2 instances, Cooldown 60s
properties = t['Resources']['WebServerGroup']['Properties']
properties['DesiredCapacity'] = '2'
properties['Cooldown'] = '60'
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1'])
self._stub_create(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 2')
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, 'WebServerGroup')
stack.resources['WebServerGroup'] = resource
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
resource.resource_id)
# reduce by 50%
self._stub_lb_reload(['WebServerGroup-0'])
self._stub_meta_expected(now, 'PercentChangeInCapacity : -50')
self.m.ReplayAll()
resource.adjust(-50, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0',
resource.resource_id)
# Now move time on 61 seconds - Cooldown in template is 60
# so this should update the policy metadata, and the
# scaling group instances updated
previous_meta = {timeutils.strtime(now):
'PercentChangeInCapacity : -50'}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=61)
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()
).AndReturn(previous_meta)
# raise by 200%, should work
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'], unset=False)
self._stub_create(2)
self._stub_meta_expected(now, 'PercentChangeInCapacity : 200')
self.m.ReplayAll()
resource.adjust(200, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
resource.resource_id)
resource.delete()
示例7: test_scaling_policy_cooldown_ok
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_ok(self):
t = self.load_template()
stack = self.parse_stack(t)
# Create initial group
self._stub_lb_reload(['WebServerGroup-0'])
now = timeutils.utcnow()
self._stub_meta_expected(now, 'ExactCapacity : 1')
self._stub_create(1)
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, 'WebServerGroup')
stack.resources['WebServerGroup'] = resource
self.assertEqual('WebServerGroup-0', resource.resource_id)
# Scale up one
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1'])
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
resource.resource_id)
# Now move time on 61 seconds - Cooldown in template is 60
# so this should trigger a scale-up
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()
).AndReturn(previous_meta)
now = now + datetime.timedelta(seconds=61)
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'], unset=False)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
resource.resource_id)
resource.delete()
self.m.VerifyAll()
示例8: test_scaling_policy_cooldown_zero
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_zero(self):
t = template_format.parse(as_template)
stack = parse_stack(t)
# Create initial group
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')
stack.resources['WebServerGroup'] = rsrc
self.assertEqual('WebServerGroup-0', rsrc.resource_id)
# Create the scaling policy (with Cooldown=0) and scale up one
properties = t['Resources']['WebServerScaleUpPolicy']['Properties']
properties['Cooldown'] = '0'
self._stub_lb_reload(2)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack,
'WebServerScaleUpPolicy')
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
# Now trigger another scale-up without changing time, should work
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()
).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()
).AndReturn(previous_meta)
self._stub_lb_reload(3, unset=False)
self._stub_meta_expected(now, 'ChangeInCapacity : 1', 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
rsrc.resource_id)
rsrc.delete()
self.m.VerifyAll()
示例9: test_scaling_group_cooldown_zero
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_zero(self):
t = template_format.parse(as_template)
stack = parse_stack(t)
# Create initial group, 2 instances, Cooldown 0
properties = t['Resources']['WebServerGroup']['Properties']
properties['DesiredCapacity'] = '2'
properties['Cooldown'] = '0'
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1'])
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')
stack.resources['WebServerGroup'] = rsrc
self.assertEqual('WebServerGroup-0,WebServerGroup-1',
rsrc.resource_id)
# reduce by 50%
self._stub_lb_reload(['WebServerGroup-0'])
self._stub_meta_expected(now, 'PercentChangeInCapacity : -50')
self.m.ReplayAll()
rsrc.adjust(-50, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0',
rsrc.resource_id)
# Don't move time, since cooldown is zero, it should work
previous_meta = {timeutils.strtime(now):
'PercentChangeInCapacity : -50'}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, '__get__')
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()
).AndReturn(previous_meta)
# raise by 200%, should work
self._stub_lb_reload(['WebServerGroup-0', 'WebServerGroup-1',
'WebServerGroup-2'], unset=False)
self._stub_meta_expected(now, 'PercentChangeInCapacity : 200')
self._stub_create(2)
self.m.ReplayAll()
rsrc.adjust(200, 'PercentChangeInCapacity')
self.assertEqual('WebServerGroup-0,WebServerGroup-1,WebServerGroup-2',
rsrc.resource_id)
rsrc.delete()
self.m.VerifyAll()
示例10: test_scaling_group_cooldown_toosoon
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_toosoon(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
# Create initial group, 2 instances, Cooldown 60s
properties = t["Resources"]["WebServerGroup"]["Properties"]
properties["DesiredCapacity"] = "2"
properties["Cooldown"] = "60"
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")
stack.resources["WebServerGroup"] = rsrc
self.assertEqual(["WebServerGroup-0", "WebServerGroup-1"], rsrc.get_instance_names())
# reduce by 50%
self._stub_lb_reload(1)
self._stub_validate()
self._stub_meta_expected(now, "PercentChangeInCapacity : -50")
self.m.ReplayAll()
rsrc.adjust(-50, "PercentChangeInCapacity")
self.assertEqual(["WebServerGroup-0"], rsrc.get_instance_names())
# Now move time on 10 seconds - Cooldown in template is 60
# so this should not update the policy metadata, and the
# scaling group instances should be unchanged
# Note we have to stub Metadata.__get__ since up_policy isn't
# stored in the DB (because the stack hasn't really been created)
previous_meta = {timeutils.strtime(now): "PercentChangeInCapacity : -50"}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=10)
self.m.StubOutWithMock(timeutils, "utcnow")
timeutils.utcnow().MultipleTimes().AndReturn(now)
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()).AndReturn(previous_meta)
self.m.ReplayAll()
# raise by 200%, too soon for Cooldown so there should be no change
rsrc.adjust(200, "PercentChangeInCapacity")
self.assertEqual(["WebServerGroup-0"], rsrc.get_instance_names())
rsrc.delete()
示例11: test_scaling_policy_cooldown_none
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_none(self):
t = template_format.parse(as_template)
stack = parse_stack(t)
# Create initial group
self._stub_lb_reload(["WebServerGroup-0"])
now = timeutils.utcnow()
self._stub_meta_expected(now, "ExactCapacity : 1")
self._stub_create(1)
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, "WebServerGroup")
stack.resources["WebServerGroup"] = resource
self.assertEqual("WebServerGroup-0", resource.resource_id)
# Create the scaling policy no Cooldown property, should behave the
# same as when Cooldown==0
properties = t["Resources"]["WebServerScaleUpPolicy"]["Properties"]
del (properties["Cooldown"])
self._stub_lb_reload(["WebServerGroup-0", "WebServerGroup-1"])
now = timeutils.utcnow()
self._stub_meta_expected(now, "ChangeInCapacity : 1", 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack, "WebServerScaleUpPolicy")
up_policy.alarm()
self.assertEqual("WebServerGroup-0,WebServerGroup-1", resource.resource_id)
# Now trigger another scale-up without changing time, should work
previous_meta = {timeutils.strtime(now): "ChangeInCapacity : 1"}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()).AndReturn(previous_meta)
self._stub_lb_reload(["WebServerGroup-0", "WebServerGroup-1", "WebServerGroup-2"], unset=False)
self._stub_meta_expected(now, "ChangeInCapacity : 1", 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.alarm()
self.assertEqual("WebServerGroup-0,WebServerGroup-1,WebServerGroup-2", resource.resource_id)
resource.delete()
self.m.VerifyAll()
示例12: test_scaling_policy_cooldown_toosoon
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_toosoon(self):
t = template_format.parse(as_template)
stack = parse_stack(t)
# Create initial group
self._stub_lb_reload(["WebServerGroup-0"])
now = timeutils.utcnow()
self._stub_meta_expected(now, "ExactCapacity : 1")
self._stub_create(1)
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, "WebServerGroup")
stack.resources["WebServerGroup"] = resource
self.assertEqual("WebServerGroup-0", resource.resource_id)
# Scale up one
self._stub_lb_reload(["WebServerGroup-0", "WebServerGroup-1"])
self._stub_meta_expected(now, "ChangeInCapacity : 1", 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack, "WebServerScaleUpPolicy")
up_policy.alarm()
self.assertEqual("WebServerGroup-0,WebServerGroup-1", resource.resource_id)
# Now move time on 10 seconds - Cooldown in template is 60
# so this should not update the policy metadata, and the
# scaling group instances should be unchanged
# Note we have to stub Metadata.__get__ since up_policy isn't
# stored in the DB (because the stack hasn't really been created)
previous_meta = {timeutils.strtime(now): "ChangeInCapacity : 1"}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=10)
self.m.StubOutWithMock(timeutils, "utcnow")
timeutils.utcnow().AndReturn(now)
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()).AndReturn(previous_meta)
self.m.ReplayAll()
up_policy.alarm()
self.assertEqual("WebServerGroup-0,WebServerGroup-1", resource.resource_id)
resource.delete()
self.m.VerifyAll()
示例13: test_scaling_group_cooldown_ok
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_ok(self):
t = template_format.parse(as_template)
stack = parse_stack(t)
# Create initial group, 2 instances, Cooldown 60s
properties = t["Resources"]["WebServerGroup"]["Properties"]
properties["DesiredCapacity"] = "2"
properties["Cooldown"] = "60"
self._stub_lb_reload(["WebServerGroup-0", "WebServerGroup-1"])
self._stub_create(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, "ExactCapacity : 2")
self.m.ReplayAll()
resource = self.create_scaling_group(t, stack, "WebServerGroup")
stack.resources["WebServerGroup"] = resource
self.assertEqual("WebServerGroup-0,WebServerGroup-1", resource.resource_id)
# reduce by 50%
self._stub_lb_reload(["WebServerGroup-0"])
self._stub_meta_expected(now, "PercentChangeInCapacity : -50")
self.m.ReplayAll()
resource.adjust(-50, "PercentChangeInCapacity")
self.assertEqual("WebServerGroup-0", resource.resource_id)
# Now move time on 61 seconds - Cooldown in template is 60
# so this should update the policy metadata, and the
# scaling group instances updated
previous_meta = {timeutils.strtime(now): "PercentChangeInCapacity : -50"}
self.m.VerifyAll()
self.m.UnsetStubs()
now = now + datetime.timedelta(seconds=61)
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), resource, mox.IgnoreArg()).AndReturn(previous_meta)
# raise by 200%, should work
self._stub_lb_reload(["WebServerGroup-0", "WebServerGroup-1", "WebServerGroup-2"], unset=False)
self._stub_create(2)
self._stub_meta_expected(now, "PercentChangeInCapacity : 200")
self.m.ReplayAll()
resource.adjust(200, "PercentChangeInCapacity")
self.assertEqual("WebServerGroup-0,WebServerGroup-1,WebServerGroup-2", resource.resource_id)
resource.delete()
示例14: test_scaling_policy_cooldown_none
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_policy_cooldown_none(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
# Create initial group
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")
stack.resources["WebServerGroup"] = rsrc
self.assertEqual(["WebServerGroup-0"], rsrc.get_instance_names())
# Create the scaling policy no Cooldown property, should behave the
# same as when Cooldown==0
properties = t["Resources"]["WebServerScaleUpPolicy"]["Properties"]
del (properties["Cooldown"])
self._stub_lb_reload(2)
now = timeutils.utcnow()
self._stub_meta_expected(now, "ChangeInCapacity : 1", 2)
self._stub_create(1)
self.m.StubOutWithMock(asc.ScalingPolicy, "keystone")
asc.ScalingPolicy.keystone().MultipleTimes().AndReturn(self.fc)
self.m.ReplayAll()
up_policy = self.create_scaling_policy(t, stack, "WebServerScaleUpPolicy")
up_policy.signal()
self.assertEqual(["WebServerGroup-0", "WebServerGroup-1"], rsrc.get_instance_names())
# Now trigger another scale-up without changing time, should work
previous_meta = {timeutils.strtime(now): "ChangeInCapacity : 1"}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), up_policy, mox.IgnoreArg()).AndReturn(previous_meta)
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()).AndReturn(previous_meta)
# stub for the metadata accesses while creating the addtional instance
Metadata.__get__(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self._stub_lb_reload(3, unset=False)
self._stub_meta_expected(now, "ChangeInCapacity : 1", 2)
self._stub_create(1)
self.m.ReplayAll()
up_policy.signal()
self.assertEqual(["WebServerGroup-0", "WebServerGroup-1", "WebServerGroup-2"], rsrc.get_instance_names())
rsrc.delete()
self.m.VerifyAll()
示例15: test_scaling_group_cooldown_zero
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __get__ [as 别名]
def test_scaling_group_cooldown_zero(self):
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=self.params)
# Create initial group, 2 instances, Cooldown 0
properties = t["Resources"]["WebServerGroup"]["Properties"]
properties["DesiredCapacity"] = "2"
properties["Cooldown"] = "0"
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")
stack.resources["WebServerGroup"] = rsrc
self.assertEqual(["WebServerGroup-0", "WebServerGroup-1"], rsrc.get_instance_names())
# reduce by 50%
self._stub_lb_reload(1)
self._stub_meta_expected(now, "PercentChangeInCapacity : -50")
self._stub_validate()
self.m.ReplayAll()
rsrc.adjust(-50, "PercentChangeInCapacity")
self.assertEqual(["WebServerGroup-0"], rsrc.get_instance_names())
# Don't move time, since cooldown is zero, it should work
previous_meta = {timeutils.strtime(now): "PercentChangeInCapacity : -50"}
self.m.VerifyAll()
self.m.UnsetStubs()
self.m.StubOutWithMock(Metadata, "__get__")
Metadata.__get__(mox.IgnoreArg(), rsrc, mox.IgnoreArg()).AndReturn(previous_meta)
# stub for the metadata accesses while creating the two instances
Metadata.__get__(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
Metadata.__get__(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
# raise by 200%, should work
self._stub_lb_reload(3, unset=False)
self._stub_meta_expected(now, "PercentChangeInCapacity : 200")
self._stub_create(2)
self.m.ReplayAll()
rsrc.adjust(200, "PercentChangeInCapacity")
self.assertEqual(["WebServerGroup-0", "WebServerGroup-1", "WebServerGroup-2"], rsrc.get_instance_names())
rsrc.delete()
self.m.VerifyAll()