本文整理汇总了Python中MilkCheck.Engine.ServiceGroup.ServiceGroup.fromdict方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceGroup.fromdict方法的具体用法?Python ServiceGroup.fromdict怎么用?Python ServiceGroup.fromdict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MilkCheck.Engine.ServiceGroup.ServiceGroup
的用法示例。
在下文中一共展示了ServiceGroup.fromdict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_service_imbrications
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_create_service_imbrications(self):
'''Test create service with mutliple level of subservices'''
sergrp = ServiceGroup('groupinit')
sergrp.fromdict(
{'services':
{'svcA':
{'require': ['subgroup'],
'actions':
{'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': 'I am the subservice $NAME'},
'subgroup':
{'services':
{'svcB':
{'require_weak':['svcC'],
'actions':
{'start': {'cmd': '/bin/True'},
' stop': {'cmd': '/bin/False'}},
'desc': 'I am the subservice $NAME'},
'svcC':
{'actions':
{'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': 'I am the subservice $NAME'}},
'target': '127.0.0.1',
'desc': "I'm the service $NAME"}},
'desc': 'I am a group',
'target': 'localhost',
})
for subservice in ('svcA', 'subgroup'):
if isinstance(sergrp._subservices[subservice], ServiceGroup):
for subsubser in ('svcB', 'svcC'):
self.assertTrue(
sergrp._subservices[subservice].has_subservice(subsubser))
self.assertTrue(sergrp.has_subservice(subservice))
示例2: test_non_existing_target
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_non_existing_target(self):
'''Test expected behaviour on an non-existing target'''
sergrp = ServiceGroup('group1')
sergrp.fromdict(
{ 'services':
{ 'svc1': {
'actions': {
'start': {'cmd': '/bin/True'},
},
'target': '@none',
}}})
self.assertEqual(sergrp._subservices['svc1'].target, NodeSet())
示例3: test_resolve_all_with_full_config
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_resolve_all_with_full_config(self):
"""Test instantiation of a service group with variables subservices."""
sergrp = ServiceGroup('S1')
sergrp.add_var('TOUT', 1)
sergrp.add_var('RET', 2)
sergrp.add_var('FAN', 3)
sergrp.add_var('DLY', 4)
sergrp.add_var('ERRS', 0)
sergrp.add_var('WARN', 5)
sergrp.add_var('DSC', 'I am the service')
sergrp.add_var('MD', 'delegate')
sergrp.add_var('REQUIRES', ["dep1", "dep2"])
sergrp.fromdict({
'desc': "Check variables",
'target': "localhost",
'services': {
'dep1':
{'actions': {'start': {'cmd': '/bin/True'}} },
'dep2':
{'actions': {'start': {'cmd': '/bin/True'}} },
'fullvars': {
'target': 'localhost',
'require': "%REQUIRES",
'timeout': "%TOUT",
'retry': "%RET",
'fanout': "%FAN",
'delay': "%DLY",
'errors': "%ERRS",
'warnings': "%WARN",
'mode': "%MD",
'actions': {
'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}
},
'desc': "%DSC"
}
},
})
sergrp.resolve_all()
service = sergrp._subservices['fullvars']
self.assertEqual(service.target, NodeSet('localhost'))
self.assertEqual(service.timeout, 1)
self.assertEqual(service.maxretry, 2)
self.assertEqual(service.fanout, 3)
self.assertEqual(service.delay, 4)
self.assertEqual(service.errors, 0)
self.assertEqual(service.warnings, 5)
self.assertEqual(service.mode, 'delegate')
self.assertEqual(service.desc, "I am the service")
self.assertTrue('dep1' in service.deps())
self.assertTrue('dep2' in service.deps())
示例4: test_graph
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_graph(self):
'''Test DOT graph output'''
manager = ServiceManager()
sergrp = ServiceGroup('S1')
sergrp.fromdict(
{'services':
{'srv1':
{'target': 'localhost',
'actions':
{'start': {'cmd':'/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm the service srv1"
},
'subgroup':
{'services':
{'svcB':
{'require_weak':['svcC'],
'actions':
{'start': {'cmd': '/bin/True'},
' stop': {'cmd': '/bin/False'}},
'desc': 'I am the subservice $NAME'},
'svcC':
{'actions':
{'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': 'I am the subservice $NAME'}},
'target': '127.0.0.1',
'desc': "I'm the service $NAME"}},
})
manager.add_service(sergrp)
self.assertEqual(manager.output_graph(),
"""digraph dependency {
compound=true;
node [style=filled];
subgraph "cluster_S1" {
label="S1";
style=rounded;
node [style=filled];
"S1.__hook" [style=invis];
"S1.srv1";
subgraph "cluster_S1.subgroup" {
label="S1.subgroup";
style=rounded;
node [style=filled];
"S1.subgroup.__hook" [style=invis];
"S1.subgroup.svcB" -> "S1.subgroup.svcC" [style=dashed];
"S1.subgroup.svcC";
}
}
}
""")
示例5: test_require_no_list
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_require_no_list(self):
"""Test parsing require with a simple singleton (no list)"""
grp = ServiceGroup('grp')
grp.fromdict({'services': {
'svc1': {
'actions': {'start': {'cmd': '/bin/true'}}
},
'svc2': {
'require': 'svc1',
'actions': {'start': {'cmd': '/bin/true'}}
}
}})
svc1 = grp._subservices['svc2'].parents['svc1']
self.assertEqual(svc1.dep_type, REQUIRE)
示例6: test_filter
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_filter(self):
"""Test parsing 'filter' dependency type"""
grp = ServiceGroup('grp')
grp.fromdict({
'services': {
'svc1': {
'actions': {'start': {'cmd': '/bin/true'}}
},
'svc2': {
'filter': ['svc1'],
'actions': {'start': {'cmd': '/bin/true'}}
}
}
})
svc1 = grp._subservices['svc2'].parents['svc1']
self.assertEqual(svc1.dep_type, FILTER)
示例7: test_before
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_before(self):
"""Test 'before' as an alias of 'after' (only for v1.0 compat)"""
grp = ServiceGroup('grp')
grp.fromdict({
'services': {
'svc1': {
'actions': {'start': {'cmd': '/bin/true'}}
},
'svc2': {
'before': ['svc1'],
'actions': {'start': {'cmd': '/bin/true'}}
}
}
})
svc1 = grp._subservices['svc2'].parents['svc1']
self.assertEqual(svc1.dep_type, REQUIRE_WEAK)
示例8: test_fromdict_after
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_fromdict_after(self):
"""Test 'after' as an alias of 'require_weak'"""
grp = ServiceGroup('grp')
grp.fromdict({
'services': {
'svc1': {
'actions': { 'start': { 'cmd': '/bin/true' } }
},
'svc2': {
'after': [ 'svc1' ],
'actions': { 'start': { 'cmd': '/bin/true' } }
}
}
})
svc1 = grp._subservices['svc2'].parents['svc1']
self.assertEqual(svc1.dep_type, REQUIRE_WEAK)
示例9: test_servicegroup_with_nodeset_like_actions_with_one_decl
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_servicegroup_with_nodeset_like_actions_with_one_decl(self):
'''Test a service group with several group with nodeset-like names'''
sergrp = ServiceGroup('group1')
sergrp.fromdict({
'services': {
'da[1-3]': {
'actions': {'start': {'cmd': '/bin/True'}}
},
}})
self.assertEqual(len(sergrp._subservices), 3)
self.assertTrue(sergrp.has_subservice('da1'))
self.assertTrue(sergrp.has_subservice('da2'))
self.assertTrue(sergrp.has_subservice('da3'))
self.assertEqual(len(sergrp._subservices['da1']._actions), 1)
self.assertEqual(len(sergrp._subservices['da2']._actions), 1)
self.assertEqual(len(sergrp._subservices['da3']._actions), 1)
示例10: test_variable_with_escaping_pattern
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_variable_with_escaping_pattern(self):
"""fromdict() should not resolve variables"""
grp = ServiceGroup('grp')
grp.fromdict({
'services': {
'svc': {
'variables': {
'foo': 'nice'
},
'actions': {
'start': {'cmd': 'shine config -O %%host %foo'}
}
}
}
})
action = grp._subservices['svc']._actions['start']
self.assertEqual(action.command, 'shine config -O %%host %foo')
示例11: test_fromdict2
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_fromdict2(self):
'''
Test instanciation of a service group with dependencies between
subservices.
'''
sergrp = ServiceGroup('S1')
sergrp.fromdict(
{'services':
{'hpss_nfs':
{'target': 'localhost',
'require': ['lustre', 'test'],
'actions':
{'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm the service hpss_nfs"
},
'lustre':
{'target': 'localhost',
'actions':
{'start': {'cmd':'/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm the service lustre"},
'test':
{'target': 'localhost',
'actions':
{'start': {'cmd':'/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm a test suite"}},
'variables':{'LUSTRE_FS_LIST': 'store0,work0'},
'desc': "I'm the service S1",
'target': 'localhost',
})
self.assertTrue(sergrp.has_subservice('hpss_nfs'))
self.assertTrue(sergrp.has_subservice('lustre'))
self.assertTrue(sergrp.has_subservice('test'))
self.assertFalse(
sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
self.assertTrue(
sergrp._subservices['hpss_nfs'].has_child_dep('source'))
self.assertTrue(
sergrp._subservices['lustre'].has_parent_dep('sink'))
self.assertFalse(
sergrp._subservices['test'].has_child_dep('source'))
self.assertTrue(
sergrp._subservices['test'].has_parent_dep('sink'))
示例12: test_resolve_all_local_variable
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_resolve_all_local_variable(self):
"""Variable resolution in 'require' with a local variable."""
svcgrp = ServiceGroup('group')
svcgrp.fromdict({
'services': {
'dep1': {
'actions': {'start': {'cmd': '/bin/True'}}
},
'dep2': {
'variables': {'foo': ['dep1']},
'require': "%foo",
'actions': {'start': {'cmd': '/bin/True'}}
},
}
})
svcgrp.resolve_all()
service = svcgrp._subservices['dep2']
self.assertTrue('dep1' in service.deps())
示例13: test_group_with_weak_dep_error
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_group_with_weak_dep_error(self):
"""A group with a weak dep error runs fine."""
dep1 = Service('dep1')
dep1.add_action(Action('stop', command='/bin/false'))
grp = ServiceGroup('group')
grp.fromdict({
'services': {
'svc1': {
'actions': {
'stop': { 'cmd': "/bin/true" },
}
}
}
})
grp.add_dep(dep1, sgth=REQUIRE_WEAK)
grp.run('stop')
self.assertEqual(grp.status, DONE)
示例14: test_fromdict1
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_fromdict1(self):
'''Test instanciation of a service group from a dictionnary'''
sergrp = ServiceGroup('S1')
sergrp.fromdict(
{'services':
{'hpss_nfs':
{'target': 'localhost',
'actions':
{'start': {'cmd': '/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm the service hpss_nfs"
},
'lustre':
{'target': 'localhost',
'actions':
{'start': {'cmd':'/bin/True'},
'stop': {'cmd': '/bin/False'}},
'desc': "I'm the service lustre"}},
'desc': "I'm the service S1",
'target': 'localhost',
'variables':{
'var1': 'toto',
'var2': 'titi'
},
})
self.assertEqual(len(sergrp.variables), 2)
self.assertTrue('var1' in sergrp.variables)
self.assertTrue('var2' in sergrp.variables)
self.assertTrue(sergrp.has_subservice('hpss_nfs'))
self.assertTrue(sergrp.has_subservice('lustre'))
self.assertTrue(
sergrp._subservices['hpss_nfs'].has_parent_dep('sink'))
self.assertTrue(
sergrp._subservices['hpss_nfs'].has_child_dep('source'))
self.assertTrue(
sergrp._subservices['lustre'].has_parent_dep('sink'))
self.assertTrue(
sergrp._subservices['lustre'].has_child_dep('source'))
示例15: test_resolve_target_from_parent
# 需要导入模块: from MilkCheck.Engine.ServiceGroup import ServiceGroup [as 别名]
# 或者: from MilkCheck.Engine.ServiceGroup.ServiceGroup import fromdict [as 别名]
def test_resolve_target_from_parent(self):
"""resolve target using a variable declared in parent service group"""
# 'target' property is resolved very early and not in resolve_all()
data = {
'services': {
'mygroup': {
'variables': {
'targets': 'foo',
},
'services': {
'svc': {
'target': '%targets',
'actions': {'start': {'cmd': '/bin/true'}}
}
}
}
}
}
grp = ServiceGroup('grp')
grp.fromdict(data)
svc = grp._subservices['mygroup']._subservices['svc']
self.assertEqual(str(svc.target), 'foo')