コード例 #1
0
    def test_023_groups(self):
        """test nodeset with groups"""
        # Special tests that require a default group source set
        f = make_temp_file("""
[Main]
default: test

[test]
map: echo example[1-100]
all: echo @foo,@bar,@moo
list: echo foo bar moo
        """)
        ClusterShell.NodeSet.RESOLVER_STD_GROUP = GroupResolverConfig(f.name)
        try:
            self._nodeset_t(["--split=2","-r", "unknown2", "unknown3"], None, \
                            "unknown2\nunknown3\n")
            self._nodeset_t(["-f", "-a"], None, "example[1-100]\n")
            self._nodeset_t(["-f", "@moo"], None, "example[1-100]\n")
            self._nodeset_t(["-f", "@moo", "@bar"], None, "example[1-100]\n")
            self._nodeset_t(["-e", "-a"], None,
                            ' '.join(["example%d" % i
                                      for i in range(1, 101)]) + '\n')
            self._nodeset_t(["-c", "-a"], None, "100\n")
            self._nodeset_t(["-r", "-a"], None, "@bar\n")
            self._nodeset_t(["-s", "test", "-r", "-a"], None, "@test:bar\n")
            self._nodeset_t(["-s", "test", "-G", "-r", "-a"], None, "@bar\n")
            self._nodeset_t(["-f", "-a", "-"], "example101\n",
                            "example[1-101]\n")
            self._nodeset_t(["-f", "-a", "-"], "example102 example101\n",
                            "example[1-102]\n")
        finally:
            ClusterShell.NodeSet.RESOLVER_STD_GROUP = DEF_RESOLVER_STD_GROUP
コード例 #2
0
ファイル: CLIDisplayTest.py プロジェクト: ypsah/clustershell
    def testDisplayRegroup(self):
        """test CLI.Display (regroup)"""
        f = makeTestFile("""
# A comment

[Main]
default: local

[local]
map: echo hostfoo
#all:
list: echo all
#reverse:
        """)
        res = GroupResolverConfig(f.name)
        set_std_group_resolver(res)
        try:
            parser = OptionParser("dummy")
            parser.install_display_options(verbose_options=True)
            options, _ = parser.parse_args(["-r"])

            disp = Display(options, color=False)
            self.assertEqual(disp.regroup, True)
            disp.out = StringIO()
            disp.err = StringIO()
            self.assertEqual(disp.line_mode, False)

            ns = NodeSet("hostfoo")

            # nodeset.regroup() is performed by print_gather()
            disp.print_gather(ns, "message0\nmessage1\n")
            self.assertEqual(disp.out.getvalue(),
                "---------------\n@all\n---------------\nmessage0\nmessage1\n\n")
        finally:
            set_std_group_resolver(None)
コード例 #3
0
    def testDisplayRegroup(self):
        """test CLI.Display (regroup)"""
        parser = OptionParser("dummy")
        parser.install_display_options(verbose_options=True)
        options, _ = parser.parse_args(["-r"])

        mtree = MsgTree()
        mtree.add("localhost", "message0")
        mtree.add("localhost", "message1")

        disp = Display(options)
        self.assertEqual(disp.regroup, True)
        disp.out = open("/dev/null", "w")
        disp.err = open("/dev/null", "w")
        self.assert_(disp != None)
        self.assertEqual(disp.line_mode, False)

        f = makeTestFile("""
# A comment

[Main]
default: local

[local]
map: echo localhost
#all:
list: echo all
#reverse:
        """)
        res = GroupResolverConfig(f.name)
        ns = NodeSet("localhost", resolver=res)

        # nodeset.regroup() is performed by print_gather()
        disp.print_gather(ns, list(mtree.walk())[0][0])
コード例 #4
0
    def setUp(self):
        # Special tests that require a default group source set
        f = make_temp_file("""
[Main]
default: local

[local]
map: echo example[1-100]
all: echo example[1-1000]
list: echo foo bar moo
        """)
        set_std_group_resolver(GroupResolverConfig(f.name))
コード例 #5
0
    def test_022_list(self):
        """test nodeset --list"""

        f = make_temp_file("""
[Main]
default: local

[local]
map: echo example[1-100]
all: echo example[1-1000]
list: echo foo bar moo
        """)
        ClusterShell.NodeSet.RESOLVER_STD_GROUP = GroupResolverConfig(f.name)
        try:
            self._nodeset_t(["--list"], None, "@foo\n@bar\n@moo\n")
            self._nodeset_t(
                ["-ll"], None,
                "@foo example[1-100]\n@bar example[1-100]\n@moo example[1-100]\n"
            )
            self._nodeset_t(
                ["-lll"], None,
                "@foo example[1-100] 100\n@bar example[1-100] 100\n@moo example[1-100] 100\n"
            )
            self._nodeset_t(["-l", "example[4,95]", "example5"], None,
                            "@moo\n@bar\n@foo\n")
            self._nodeset_t(
                ["-ll", "example[4,95]", "example5"], None,
                "@moo example[4-5,95]\n@bar example[4-5,95]\n@foo example[4-5,95]\n"
            )
            self._nodeset_t(
                ["-lll", "example[4,95]", "example5"], None,
                "@moo example[4-5,95] 3/100\n@bar example[4-5,95] 3/100\n@foo example[4-5,95] 3/100\n"
            )
            # test empty result
            self._nodeset_t(["-l", "foo[3-70]", "bar6"], None, "")
            # more arg-mixed tests
            self._nodeset_t(["-a", "-l"], None, "@moo\n@bar\n@foo\n")
            self._nodeset_t(["-a", "-l", "-x example[1-100]"], None, "")
            self._nodeset_t(["-a", "-l", "-x example[1-40]"], None,
                            "@moo\n@bar\n@foo\n")
            self._nodeset_t(["-l", "-x example3"], None,
                            "")  # no -a, remove from nothing
            self._nodeset_t(["-l", "-i example3"], None,
                            "")  # no -a, intersect from nothing
            self._nodeset_t(["-l", "-X example3"], None,
                            "@moo\n@bar\n@foo\n")  # no -a, xor from nothing
            self._nodeset_t(["-l", "-", "-i example3"], "example[3,500]\n",
                            "@moo\n@bar\n@foo\n")
        finally:
            ClusterShell.NodeSet.RESOLVER_STD_GROUP = DEF_RESOLVER_STD_GROUP
コード例 #6
0
    def setUp(self):
        # Special tests that require a default group source set
        f = make_temp_file("""
[Main]
default: test

[test]
map: echo example[1-100]
all: echo @foo,@bar,@moo
list: echo foo bar moo

[other]
map: echo nova[030-489]
all: echo @baz,@qux,@norf
list: echo baz qux norf
        """)
        set_std_group_resolver(GroupResolverConfig(f.name))