本文整理汇总了Python中heat.engine.resource.Metadata.__set__方法的典型用法代码示例。如果您正苦于以下问题:Python Metadata.__set__方法的具体用法?Python Metadata.__set__怎么用?Python Metadata.__set__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类heat.engine.resource.Metadata
的用法示例。
在下文中一共展示了Metadata.__set__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_stubs
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __set__ [as 别名]
def _create_stubs(self, key_name='test', stub_meta=True):
self.m.StubOutWithMock(user.User, 'keystone')
user.User.keystone().AndReturn(self.fkc)
self.m.StubOutWithMock(user.AccessKey, 'keystone')
user.AccessKey.keystone().AndReturn(self.fkc)
self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fkc)
server_name = utils.PhysName(utils.PhysName('test_stack',
'LoadBalancer'),
'LB_instance')
clients.OpenStackClients.nova(
"compute").MultipleTimes().AndReturn(self.fc)
self.fc.servers.create(
flavor=2, image=745, key_name=key_name,
meta=None, nics=None, name=server_name,
scheduler_hints=None, userdata=mox.IgnoreArg(),
security_groups=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
if stub_meta:
Metadata.__set__(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])
示例2: _stub_meta_expected
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __set__ [as 别名]
def _stub_meta_expected(self, now, data, nmeta=1):
# Stop time at now
self.m.StubOutWithMock(timeutils, 'utcnow')
timeutils.utcnow().MultipleTimes().AndReturn(now)
# Then set a stub to ensure the metadata update is as
# expected based on the timestamp and data
self.m.StubOutWithMock(Metadata, '__set__')
expected = {timeutils.strtime(now): data}
# Note for ScalingPolicy, we expect to get a metadata
# update for the policy and autoscaling group, so pass nmeta=2
for x in range(nmeta):
Metadata.__set__(mox.IgnoreArg(), expected).AndReturn(None)
示例3: test_loadbalancer
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __set__ [as 别名]
def test_loadbalancer(self):
self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep')
scheduler.TaskRunner._sleep(mox.IsA(int)).MultipleTimes()
self.m.StubOutWithMock(user.User, 'keystone')
user.User.keystone().AndReturn(self.fkc)
self.m.StubOutWithMock(user.AccessKey, 'keystone')
user.AccessKey.keystone().AndReturn(self.fkc)
self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fkc)
clients.OpenStackClients.nova(
"compute").MultipleTimes().AndReturn(self.fc)
self.fc.servers.create(
flavor=2, image=745, key_name='test',
meta=None, nics=None, name=u'test_stack.LoadBalancer.LB_instance',
scheduler_hints=None, userdata=mox.IgnoreArg(),
security_groups=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
Metadata.__set__(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])
self.m.ReplayAll()
t = template_format.parse(lb_template)
s = parse_stack(t)
s.store()
rsrc = self.create_loadbalancer(t, s, 'LoadBalancer')
hc = {
'Target': 'HTTP:80/',
'HealthyThreshold': '3',
'UnhealthyThreshold': '5',
'Interval': '30',
'Timeout': '5'}
rsrc.t['Properties']['HealthCheck'] = hc
self.assertEqual(None, rsrc.validate())
hc['Timeout'] = 35
self.assertEqual(
{'Error': 'Interval must be larger than Timeout'},
rsrc.validate())
hc['Timeout'] = 5
self.assertEqual('LoadBalancer', rsrc.FnGetRefId())
templ = template_format.parse(lb.lb_template)
ha_cfg = rsrc._haproxy_config(templ, rsrc.properties['Instances'])
self.assertRegexpMatches(ha_cfg, 'bind \*:80')
self.assertRegexpMatches(ha_cfg, 'server server1 1\.2\.3\.4:80 '
'check inter 30s fall 5 rise 3')
self.assertRegexpMatches(ha_cfg, 'timeout check 5s')
id_list = []
for inst_name in ['WikiServerOne1', 'WikiServerOne2']:
inst = instance.Instance(inst_name,
s.t['Resources']['WikiServerOne'],
s)
id_list.append(inst.FnGetRefId())
rsrc.reload(id_list)
self.assertEqual('4.5.6.7', rsrc.FnGetAtt('DNSName'))
self.assertEqual('', rsrc.FnGetAtt('SourceSecurityGroupName'))
try:
rsrc.FnGetAtt('Foo')
raise Exception('Expected InvalidTemplateAttribute')
except exception.InvalidTemplateAttribute:
pass
self.assertRaises(resource.UpdateReplace,
rsrc.handle_update, {}, {}, {})
self.m.VerifyAll()
示例4: test_loadbalancer
# 需要导入模块: from heat.engine.resource import Metadata [as 别名]
# 或者: from heat.engine.resource.Metadata import __set__ [as 别名]
def test_loadbalancer(self):
self.m.StubOutWithMock(user.User, 'keystone')
user.User.keystone().MultipleTimes().AndReturn(self.fkc)
self.m.StubOutWithMock(user.AccessKey, 'keystone')
user.AccessKey.keystone().MultipleTimes().AndReturn(self.fkc)
lb.LoadBalancer.nova().AndReturn(self.fc)
instance.Instance.nova().MultipleTimes().AndReturn(self.fc)
self.fc.servers.create(
flavor=2, image=745, key_name='test',
meta=None, nics=None, name=u'test_stack.LoadBalancer.LB_instance',
scheduler_hints=None, userdata=mox.IgnoreArg(),
security_groups=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
#stack.Stack.create_with_template(mox.IgnoreArg()).AndReturn(None)
Metadata.__set__(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
lb.LoadBalancer.nova().MultipleTimes().AndReturn(self.fc)
self.m.ReplayAll()
t = self.load_template()
s = self.parse_stack(t)
resource = self.create_loadbalancer(t, s, 'LoadBalancer')
hc = {
'Target': 'HTTP:80/',
'HealthyThreshold': '3',
'UnhealthyThreshold': '5',
'Interval': '30',
'Timeout': '5'}
resource.t['Properties']['HealthCheck'] = hc
self.assertEqual(None, resource.validate())
hc['Timeout'] = 35
self.assertEqual(
{'Error': 'Interval must be larger than Timeout'},
resource.validate())
hc['Timeout'] = 5
self.assertEqual('LoadBalancer', resource.FnGetRefId())
templ = template_format.parse(lb.lb_template)
ha_cfg = resource._haproxy_config(templ,
resource.properties['Instances'])
self.assertRegexpMatches(ha_cfg, 'bind \*:80')
self.assertRegexpMatches(ha_cfg, 'server server1 1\.2\.3\.4:80 '
'check inter 30s fall 5 rise 3')
self.assertRegexpMatches(ha_cfg, 'timeout check 5s')
id_list = []
for inst_name in ['WikiServerOne1', 'WikiServerOne2']:
inst = instance.Instance(inst_name,
s.t['Resources']['WikiServerOne'],
s)
id_list.append(inst.FnGetRefId())
resource.nested().create()
resource.reload(id_list)
self.assertEqual('4.5.6.7', resource.FnGetAtt('DNSName'))
self.assertEqual('', resource.FnGetAtt('SourceSecurityGroupName'))
try:
resource.FnGetAtt('Foo')
raise Exception('Expected InvalidTemplateAttribute')
except exception.InvalidTemplateAttribute:
pass
self.assertEqual(lb.LoadBalancer.UPDATE_REPLACE,
resource.handle_update({}))
self.m.VerifyAll()