Exemple #1
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])
    def testDisplay(self):
        """test CLI.Display"""
        parser = OptionParser("dummy")
        parser.install_display_options(verbose_options=True)
        options, _ = parser.parse_args([])

        ns = NodeSet("hostfoo")
        mtree = MsgTree()
        mtree.add("hostfoo", "message0")
        mtree.add("hostfoo", "message1")

        for whencolor in WHENCOLOR_CHOICES:  # test whencolor switch
            for label in [True, False]:  # test no-label switch
                options.label = label
                options.whencolor = whencolor
                disp = Display(options)
                # inhibit output
                disp.out = StringIO()
                disp.err = StringIO()
                # test print_* methods...
                disp.print_line(ns, "foo bar")
                disp.print_line_error(ns, "foo bar")
                disp.print_gather(ns, list(mtree.walk())[0][0])
                # test also string nodeset as parameter
                disp.print_gather("hostfoo", list(mtree.walk())[0][0])
                # test line_mode property
                self.assertEqual(disp.line_mode, False)
                disp.line_mode = True
                self.assertEqual(disp.line_mode, True)
                disp.print_gather("hostfoo", list(mtree.walk())[0][0])
                disp.line_mode = False
                self.assertEqual(disp.line_mode, False)
Exemple #3
0
 def __init__(self, cmd, result_iter, rng, pretty_str, canceller=None):
     self._result_iter = result_iter
     self._rng = rng
     self._pretty_str = pretty_str
     self._errors = {}
     self._res_tree = MsgTree()
     self._canceller = canceller
     self._cmd = cmd
Exemple #4
0
 def ev_read(self, worker):
     # Read new line from node
     node = worker.current_node
     self._nodecnt[node] += 1
     cnt = self._nodecnt[node]
     if len(self._mtreeq) < cnt:
         self._mtreeq.append(MsgTree())
     self._mtreeq[cnt - self._offload - 1].add(node, worker.current_msg)
     self._live_line(worker)
Exemple #5
0
def clubak():
    """script subroutine"""

    # Argument management
    parser = OptionParser("%prog [options]")
    parser.install_display_options(verbose_options=True,
                                   separator_option=True,
                                   dshbak_compat=True,
                                   msgtree_mode=True)
    options = parser.parse_args()[0]

    if options.interpret_keys == THREE_CHOICES[-1]:  # auto?
        enable_nodeset_key = None  # AUTO
    else:
        enable_nodeset_key = (options.interpret_keys == THREE_CHOICES[1])

    # Create new message tree
    if options.trace_mode:
        tree_mode = MODE_TRACE
    else:
        tree_mode = MODE_DEFER
    tree = MsgTree(mode=tree_mode)
    fast_mode = options.fast_mode
    if fast_mode:
        if tree_mode != MODE_DEFER or options.line_mode:
            parser.error("incompatible tree options")
        preload_msgs = {}

    # Feed the tree from standard input lines
    for line in sys.stdin:
        try:
            linestripped = line.rstrip('\r\n')
            if options.verbose or options.debug:
                print "INPUT %s" % linestripped
            key, content = linestripped.split(options.separator, 1)
            key = key.strip()
            if not key:
                raise ValueError("no node found")
            if enable_nodeset_key is False:  # interpret-keys=never?
                keyset = [key]
            else:
                try:
                    keyset = NodeSet(key)
                except NodeSetParseError:
                    if enable_nodeset_key:  # interpret-keys=always?
                        raise
                    enable_nodeset_key = False  # auto => switch off
                    keyset = [key]
            if fast_mode:
                for node in keyset:
                    preload_msgs.setdefault(node, []).append(content)
            else:
                for node in keyset:
                    tree.add(node, content)
        except ValueError, ex:
            raise ValueError("%s (\"%s\")" % (ex, linestripped))
Exemple #6
0
 def ev_read(self, worker, node, sname, msg):
     if sname != worker.SNAME_STDOUT:
         GatherOutputHandler.ev_read(self, worker, node, sname, msg)
         return
     # Read new line from node
     self._nodecnt[node] += 1
     cnt = self._nodecnt[node]
     if len(self._mtreeq) < cnt:
         self._mtreeq.append(MsgTree())
     self._mtreeq[cnt - self._offload - 1].add(node, msg)
     self._live_line(worker)
Exemple #7
0
    def _run_actions(self):
        """
        Start actions run-loop.

        It clears all previous proxy errors and starts task run-loop. This
        launches all FSProxyAction prepared before by example.
        """
        self.proxy_errors = MsgTree()
        task_self().set_default("stderr_msgtree", False)
        task_self().set_info('connect_timeout',
                             Globals().get_ssh_connect_timeout())
        task_self().resume()
Exemple #8
0
    def testDisplay(self):
        """test CLI.Display"""
        parser = OptionParser("dummy")
        parser.install_display_options(verbose_options=True)
        options, _ = parser.parse_args([])

        ns = NodeSet("hostfoo")
        mtree = MsgTree()
        mtree.add("hostfoo", b"message0")
        mtree.add("hostfoo", b"message1")

        list_env_vars = []
        list_env_vars.append(dict())
        list_env_vars.append(dict(NO_COLOR='0'))
        list_env_vars.append(dict(CLICOLOR='0'))
        list_env_vars.append(dict(CLICOLOR='1'))
        list_env_vars.append(dict(CLICOLOR='0', CLICOLOR_FORCE='0'))
        list_env_vars.append(dict(CLICOLOR_FORCE='1'))

        for env_vars in list_env_vars:
            for var_name in env_vars:
                var_value = env_vars[var_name]
                os.environ[var_name] = var_value

            for whencolor in THREE_CHOICES:  # test whencolor switch
                if whencolor == "":
                    options.whencolor = None
                else:
                    options.whencolor = whencolor
                for label in [True, False]:  # test no-label switch
                    options.label = label
                    disp = Display(options)
                    # inhibit output
                    disp.out = BytesIO()
                    disp.err = BytesIO()
                    # test print_* methods...
                    disp.print_line(ns, b"foo bar")
                    disp.print_line_error(ns, b"foo bar")
                    disp.print_gather(ns, list(mtree.walk())[0][0])
                    # test also string nodeset as parameter
                    disp.print_gather("hostfoo", list(mtree.walk())[0][0])
                    # test line_mode property
                    self.assertEqual(disp.line_mode, False)
                    disp.line_mode = True
                    self.assertEqual(disp.line_mode, True)
                    disp.print_gather("hostfoo", list(mtree.walk())[0][0])
                    disp.line_mode = False
                    self.assertEqual(disp.line_mode, False)

            for var_name in env_vars:
                os.environ.pop(var_name)
Exemple #9
0
    def __init__(self, fs, action, nodes, debug, comps=None, **kwargs):

        CommonAction.__init__(self)

        self.progpath = os.path.abspath(sys.argv[0])
        self.fs = fs
        self.action = action
        self.nodes = nodes
        self.debug = debug

        self._comps = comps

        self.options = {}
        for optname in ('addopts', 'failover', 'mountdata', 'fanout',
                        'dryrun'):
            self.options[optname] = kwargs.get(optname)

        self._outputs = MsgTree()
        self._errpickle = MsgTree()
        self._silentnodes = NodeSet()  # Error nodes without output

        if self.fs.debug:
            print "FSProxyAction %s on %s" % (action, nodes)
Exemple #10
0
    def __init__(self, fs_name, event_handler=None):
        self.fs_name = fs_name
        self.hdlr = event_handler or EventHandler()
        self.proxy_errors = MsgTree()

        # All FS components (MGT, MDT, OST, Clients, ...)
        self.components = ComponentGroup()

        # file system MGT
        self.mgt = None

        # Local server reference
        self.local_server = None

        self.debug = False
        self.logger = self._setup_logging()
Exemple #11
0
def clubak():
    """script subroutine"""

    # Argument management
    parser = OptionParser("%prog [options]")
    parser.install_groupsconf_option()
    parser.install_display_options(verbose_options=True,
                                   separator_option=True,
                                   dshbak_compat=True,
                                   msgtree_mode=True)
    options = parser.parse_args()[0]

    set_std_group_resolver_config(options.groupsconf)

    if options.interpret_keys == THREE_CHOICES[-1]:  # auto?
        enable_nodeset_key = None  # AUTO
    else:
        enable_nodeset_key = (options.interpret_keys == THREE_CHOICES[1])

    # Create new message tree
    if options.trace_mode:
        tree_mode = MODE_TRACE
    else:
        tree_mode = MODE_DEFER
    tree = MsgTree(mode=tree_mode)
    fast_mode = options.fast_mode
    if fast_mode:
        if tree_mode != MODE_DEFER or options.line_mode:
            parser.error("incompatible tree options")
        preload_msgs = {}

    separator = options.separator.encode()

    # Feed the tree from standard input lines
    for line in sys_stdin():
        try:
            linestripped = line.rstrip(b'\r\n')
            if options.verbose or options.debug:
                sys_stdout().write(b'INPUT ' + linestripped + b'\n')
            key, content = linestripped.split(separator, 1)
            key = key.strip().decode()  # NodeSet requires encoded string
            if not key:
                raise ValueError("no node found")
            if enable_nodeset_key is False:  # interpret-keys=never?
                keyset = [key]
            else:
                try:
                    keyset = NodeSet(key)
                except NodeSetParseError:
                    if enable_nodeset_key:  # interpret-keys=always?
                        raise
                    enable_nodeset_key = False  # auto => switch off
                    keyset = [key]
            if fast_mode:
                for node in keyset:
                    preload_msgs.setdefault(node, []).append(content)
            else:
                for node in keyset:
                    tree.add(node, content)
        except ValueError as ex:
            raise ValueError('%s: "%s"' % (ex, linestripped.decode()))

    if fast_mode:
        # Messages per node have been aggregated, now add to tree one
        # full msg per node
        for key, wholemsg in preload_msgs.items():
            tree.add(key, b'\n'.join(wholemsg))

    # Display results
    try:
        disp = Display(options)
    except ValueError as exc:
        parser.error("option mismatch (%s)" % exc)
        return

    if options.debug:
        std_group_resolver().set_verbosity(1)
        print("clubak: line_mode=%s gather=%s tree_depth=%d" %
              (bool(options.line_mode), bool(disp.gather), tree._depth()),
              file=sys.stderr)
    display(tree, disp, disp.gather or disp.regroup, \
            options.trace_mode, enable_nodeset_key is not False)