本文整理汇总了Python中ClusterShell.NodeSet类的典型用法代码示例。如果您正苦于以下问题:Python NodeSet类的具体用法?Python NodeSet怎么用?Python NodeSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testConfigGroupsDirExistsNoOther
def testConfigGroupsDirExistsNoOther(self):
"""test groups with groupsdir defined (real, no other)"""
dname1 = make_temp_dir()
dname2 = make_temp_dir()
f = make_temp_file("""
[Main]
default: new_local
groupsdir: %s %s
""" % (dname1, dname2))
f2 = make_temp_file("""
[new_local]
map: echo example[1-100]
#all:
list: echo bar
#reverse:
""", suffix=".conf", dir=dname2)
try:
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@bar")
self.assertEqual(str(NodeSet("@bar", resolver=res)), "example[1-100]")
finally:
f2.close()
f.close()
shutil.rmtree(dname1, ignore_errors=True)
shutil.rmtree(dname2, ignore_errors=True)
示例2: test_fromall_grouplist
def test_fromall_grouplist(self):
"""test NodeSet.fromall() without all upcall"""
# Group Source that has no all upcall and that can handle special char
test_groups2 = makeTestG2()
source = UpcallGroupSource("simple",
"sed -n 's/^$GROUP:\(.*\)/\\1/p' %s" % test_groups2.name,
None,
"sed -n 's/^\([0-9A-Za-z_-\%%]*\):.*/\\1/p' %s"
% test_groups2.name,
None)
res = GroupResolver(source)
# fromall will trigger ParserEngine.grouplist() that we want to test here
nsall = NodeSet.fromall(resolver=res)
# if working, group resolution worked with % char
self.assertEqual(str(NodeSet.fromall(resolver=res)), "montana[32-55,87-90]")
self.assertEqual(len(nsall), 28)
# btw explicitly check escaped char
nsesc = NodeSet('@escape%test', resolver=res)
self.assertEqual(str(nsesc), 'montana[87-90]')
self.assertEqual(len(nsesc), 4)
nsesc2 = NodeSet('@esc%test2', resolver=res)
self.assertEqual(nsesc, nsesc2)
ns = NodeSet('montana[87-90]', resolver=res)
# could also result in escape%test?
self.assertEqual(ns.regroup(), '@esc%test2')
示例3: testConfigBasicNoMain
def testConfigBasicNoMain(self):
"""test groups with a local config without main section"""
f = make_temp_file("""
# A comment
[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
示例4: testGroupListDefault
def testGroupListDefault(self):
"""test NodeSet group listing GroupResolver.grouplist()"""
groups = ClusterShell.NodeSet.RESOLVER_STD_GROUP.grouplist()
self.assertEqual(len(groups), 20)
helper_groups = grouplist()
self.assertEqual(len(helper_groups), 20)
total = 0
nodes = NodeSet()
for group in groups:
ns = NodeSet("@%s" % group)
total += len(ns)
nodes.update(ns)
self.assertEqual(total, 310)
all_nodes = NodeSet.fromall()
self.assertEqual(len(all_nodes), len(nodes))
self.assertEqual(all_nodes, nodes)
示例5: testConfigNoListButReverseQuery
def testConfigNoListButReverseQuery(self):
"""test groups with no list but reverse upcall"""
f = make_temp_file("""
# A comment
[Main]
default: local
[local]
map: echo example[1-100]
#all:
#list: echo foo
reverse: echo foo
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
示例6: testConfigWithEmptyList
def testConfigWithEmptyList(self):
"""test groups with list upcall returning nothing"""
f = make_temp_file("""
# A comment
[Main]
default: local
[local]
map: echo example[1-100]
#all:
list: :
reverse: echo foo
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
示例7: testConfigBasicLocalAlternative
def testConfigBasicLocalAlternative(self):
"""test groups with a basic local config file (= alternative)"""
f = make_temp_file("""
# A comment
[Main]
default=local
[local]
map=echo example[1-100]
#all=
list=echo foo
#reverse=
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
示例8: testConfigNoListNoReverse
def testConfigNoListNoReverse(self):
"""test groups with no list and not reverse upcall"""
f = make_temp_file("""
# A comment
[Main]
default: local
[local]
map: echo example[1-100]
#all:
#list:
#reverse:
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
# not able to regroup, should still return valid nodeset
self.assertEqual(nodeset.regroup(), "example[1-100]")
示例9: testConfigCFGDIR
def testConfigCFGDIR(self):
"""test groups with $CFGDIR use in upcalls"""
f = make_temp_file("""
[Main]
default: local
[local]
map: echo example[1-100]
list: basename $CFGDIR
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
# just a trick to check $CFGDIR resolution...
tmpgroup = os.path.basename(os.path.dirname(f.name))
self.assertEqual(nodeset.groups().keys(), ['@%s' % tmpgroup])
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@%s" % tmpgroup)
self.assertEqual(str(NodeSet("@%s" % tmpgroup, resolver=res)),
"example[1-100]")
示例10: testConfigBasicEmptyDefault
def testConfigBasicEmptyDefault(self):
"""test groups with a empty default namespace"""
f = make_temp_file("""
# A comment
[Main]
default:
[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
示例11: testConfigGroupsDirDummy
def testConfigGroupsDirDummy(self):
"""test groups with groupsdir defined (dummy)"""
f = make_temp_file("""
[Main]
default: local
groupsdir: /path/to/nowhere
[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
示例12: testConfigBasicLocalVerbose
def testConfigBasicLocalVerbose(self):
"""test groups with a basic local config file (verbose)"""
f = make_temp_file("""
# A comment
[Main]
default: local
[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
""")
res = GroupResolverConfig(f.name)
res.set_verbosity(1)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
示例13: testGroupGroups
def testGroupGroups(self):
"""test NodeSet.groups()"""
nodeset = NodeSet("montana[32-37,42-55]")
self.assertEqual(sorted(nodeset.groups().keys()), ['@all', '@chassis1', '@chassis10', '@chassis11', '@chassis12', '@chassis2', '@chassis3', '@chassis6', '@chassis7', '@chassis8', '@chassis9', '@compute'])
testns = NodeSet()
for gnodes, inodes in nodeset.groups().itervalues():
testns.update(inodes)
self.assertEqual(testns, nodeset)
示例14: testConfigBasicLocal
def testConfigBasicLocal(self):
"""test groups with a basic local config file"""
f = make_temp_file("""
# A comment
[Main]
default: local
[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
""")
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(nodeset.groups().keys(), ["@foo"])
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")
# No 'all' defined: all_nodes() should raise an error
self.assertRaises(GroupSourceNoUpcall, res.all_nodes)
# No 'reverse' defined: node_groups() should raise an error
self.assertRaises(GroupSourceNoUpcall, res.node_groups, "example1")
# regroup with rest
nodeset = NodeSet("example[1-101]", resolver=res)
self.assertEqual(nodeset.regroup(), "@foo,example101")
# regroup incomplete
nodeset = NodeSet("example[50-200]", resolver=res)
self.assertEqual(nodeset.regroup(), "example[50-200]")
# regroup no matching
nodeset = NodeSet("example[102-200]", resolver=res)
self.assertEqual(nodeset.regroup(), "example[102-200]")
示例15: testConfigGroupsMultipleDirs
def testConfigGroupsMultipleDirs(self):
"""test groups with multiple confdir defined"""
dname1 = make_temp_dir()
dname2 = make_temp_dir()
# Notes:
# - use dname1 two times to check dup checking code
# - use quotes on one of the directory path
f = make_temp_file("""
[Main]
default: local2
confdir: "%s" %s %s
[local]
map: echo example[1-100]
list: echo foo
""" % (dname1, dname2, dname1))
fs1 = make_temp_file("""
[local1]
map: echo loc1node[1-100]
list: echo bar
""", suffix=".conf", dir=dname1)
fs2 = make_temp_file("""
[local2]
map: echo loc2node[02-50]
list: echo toto
""", suffix=".conf", dir=dname2)
try:
res = GroupResolverConfig(f.name)
nodeset = NodeSet("example[1-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
# local
self.assertEqual(nodeset.regroup("local"), "@local:foo")
self.assertEqual(str(NodeSet("@local:foo", resolver=res)), "example[1-100]")
# local1
nodeset = NodeSet("loc1node[1-100]", resolver=res)
self.assertEqual(nodeset.regroup("local1"), "@local1:bar")
self.assertEqual(str(NodeSet("@local1:bar", resolver=res)), "loc1node[1-100]")
# local2
nodeset = NodeSet("loc2node[02-50]", resolver=res)
self.assertEqual(nodeset.regroup(), "@toto") # default group source
self.assertEqual(str(NodeSet("@toto", resolver=res)), "loc2node[02-50]")
finally:
fs2.close()
fs1.close()
f.close()
shutil.rmtree(dname2, ignore_errors=True)
shutil.rmtree(dname1, ignore_errors=True)