本文整理汇总了Python中ClusterShell.NodeSet.regroup方法的典型用法代码示例。如果您正苦于以下问题:Python NodeSet.regroup方法的具体用法?Python NodeSet.regroup怎么用?Python NodeSet.regroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClusterShell.NodeSet
的用法示例。
在下文中一共展示了NodeSet.regroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_yaml_basic
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
def test_yaml_basic(self):
"""test groups with a basic YAML config file"""
dname = make_temp_dir()
f = make_temp_file("""
# A comment
[Main]
default: yaml
autodir: %s
""" % dname)
yamlfile = make_temp_file("""
yaml:
foo: example[1-4,91-100],example90
bar: example[5-89]
""", suffix=".yaml", dir=dname)
res = GroupResolverConfig(f.name)
# Group resolution
nodeset = NodeSet("@foo", resolver=res)
self.assertEqual(str(nodeset), "example[1-4,90-100]")
nodeset = NodeSet("@bar", resolver=res)
self.assertEqual(str(nodeset), "example[5-89]")
nodeset = NodeSet("@foo,@bar", resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
nodeset = NodeSet("@unknown", resolver=res)
self.assertEqual(len(nodeset), 0)
# Regroup
nodeset = NodeSet("example[1-4,90-100]", resolver=res)
self.assertEqual(str(nodeset), "example[1-4,90-100]")
self.assertEqual(nodeset.regroup(), "@foo")
self.assertEqual(nodeset.groups().keys(), ["@foo"])
self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-4,90-100]")
# No 'all' defined: all_nodes() should raise an error
self.assertRaises(GroupSourceError, res.all_nodes)
# but then NodeSet falls back to the union of all groups
nodeset = NodeSet.fromall(resolver=res)
self.assertEqual(str(nodeset), "example[1-100]")
# regroup doesn't use @all in that case
self.assertEqual(nodeset.regroup(), "@bar,@foo")
# No 'reverse' defined: node_groups() should raise an error
self.assertRaises(GroupSourceError, res.node_groups, "example1")
# regroup with rest
nodeset = NodeSet("example[1-101]", resolver=res)
self.assertEqual(nodeset.regroup(), "@bar,@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]")
示例2: testConfigGroupsMultipleDirs
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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)
示例3: testConfigGroupsDirExistsNoOther
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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)
示例4: test_fromall_grouplist
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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')
示例5: testConfigBasicLocal
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例6: testConfigBasicNoMain
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例7: testConfigWithEmptyList
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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")
示例8: testConfigNoListButReverseQuery
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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")
示例9: testConfigGroupsDirDummy
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例10: testConfigBasicEmptyDefault
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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: testConfigBasicLocalAlternative
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例12: testConfigNoListNoReverse
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例13: testConfigCFGDIR
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例14: testConfigBasicLocalVerbose
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
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]")
示例15: testGroupResolverReverse
# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import regroup [as 别名]
def testGroupResolverReverse(self):
"""test NodeSet GroupResolver with reverse upcall"""
test_groups3 = makeTestG3()
test_reverse3 = makeTestR3()
source = GroupSource("test",
"sed -n 's/^$GROUP:\(.*\)/\\1/p' %s" % test_groups3.name,
"sed -n 's/^all:\(.*\)/\\1/p' %s" % test_groups3.name,
"sed -n 's/^\([0-9A-Za-z_-]*\):.*/\\1/p' %s" % test_groups3.name,
"awk -F: '/^$NODE:/ { gsub(\",\",\"\\n\",$2); print $2 }' %s" % test_reverse3.name)
# create custom resolver with default source
res = GroupResolver(source)
nodeset = NodeSet("@all", resolver=res)
self.assertEqual(nodeset, NodeSet("montana[32-55]"))
self.assertEqual(str(nodeset), "montana[32-55]")
self.assertEqual(nodeset.regroup(), "@all")
self.assertEqual(nodeset.regroup(), "@all")
nodeset = NodeSet("@overclock", resolver=res)
self.assertEqual(nodeset, NodeSet("montana[41-42]"))
self.assertEqual(str(nodeset), "montana[41-42]")
self.assertEqual(nodeset.regroup(), "@overclock")
self.assertEqual(nodeset.regroup(), "@overclock")
nodeset = NodeSet("@gpu,@overclock", resolver=res)
self.assertEqual(nodeset, NodeSet("montana[38-42]"))
self.assertEqual(str(nodeset), "montana[38-42]")
# un-overlap :)
self.assertEqual(nodeset.regroup(), "@gpu,montana42")
self.assertEqual(nodeset.regroup(), "@gpu,montana42")
self.assertEqual(nodeset.regroup(overlap=True), "@gpu,@overclock")
nodeset = NodeSet("montana41", resolver=res)
self.assertEqual(nodeset.regroup(), "montana41")
self.assertEqual(nodeset.regroup(), "montana41")
# test regroup code when using unindexed node
nodeset = NodeSet("idaho", resolver=res)
self.assertEqual(nodeset.regroup(), "@single")
self.assertEqual(nodeset.regroup(), "@single")
nodeset = NodeSet("@single", resolver=res)
self.assertEqual(str(nodeset), "idaho")
# unresolved unindexed:
nodeset = NodeSet("utah", resolver=res)
self.assertEqual(nodeset.regroup(), "utah")
self.assertEqual(nodeset.regroup(), "utah")
nodeset = NodeSet("@all!montana38", resolver=res)
self.assertEqual(nodeset, NodeSet("montana[32-37,39-55]"))
self.assertEqual(str(nodeset), "montana[32-37,39-55]")
self.assertEqual(nodeset.regroup(), "@para,montana[39-41]")
self.assertEqual(nodeset.regroup(), "@para,montana[39-41]")
self.assertEqual(nodeset.regroup(overlap=True),
"@chassis[1-3],@login,@overclock,@para,montana[39-40]")
self.assertEqual(nodeset.regroup(overlap=True),
"@chassis[1-3],@login,@overclock,@para,montana[39-40]")
nodeset = NodeSet("montana[32-37]", resolver=res)
self.assertEqual(nodeset.regroup(), "@chassis[1-3]")
self.assertEqual(nodeset.regroup(), "@chassis[1-3]")