Esempio n. 1
0
    def test_install_dryrun(self):
        """Install a file in dry-run mode"""
        tmp = Utils.makeTempFile("")
        act = Install(self.localname, self.fs, tmp.name, dryrun=True)
        self.mock_copy(act)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.localname)
        self.assertEqual(self.eh.msglist[0], text)
        self.assertEqual(len(self.eh.msglist), 1)

        # Status checks
        self.assertEqual(act.status(), ACT_OK)
Esempio n. 2
0
    def test_install_dryrun(self):
        """Install a file in dry-run mode"""
        tmp = Utils.makeTempFile("")
        act = Install(self.localname, self.fs, tmp.name, dryrun=True)
        self.mock_copy(act)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.localname)
        self.assertEqual(self.eh.msglist[0], text)
        self.assertEqual(len(self.eh.msglist), 1)

        # Status checks
        self.assertEqual(act.status(), ACT_OK)
Esempio n. 3
0
    def test_install_bad_file(self):
        """Install a non-existent file is corrected reported"""
        act = Install(self.localname, self.fs, '/bad/file')
        act.launch()
        self.fs._run_actions()

        text = '[COPY] /bad/file on %s' % self.localname
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `file' on %s" % self.localname
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 4
0
    def test_install_bad_file(self):
        """Install a non-existent file is corrected reported"""
        act = Install(self.localname, self.fs, '/bad/file')
        act.launch()
        self.fs._run_actions()

        text = '[COPY] /bad/file on %s' % self.localname
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `file' on %s" % self.localname
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 5
0
    def test_install_ok(self):
        """Install a simple file"""
        tmp = Utils.makeTempFile('')
        act = Install(self.localname, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        msgs = ['[COPY] %s on %s' % (tmp.name, self.localname),
                "Updating configuration file `%s' on %s" % \
                 (os.path.basename(tmp.name), self.localname)]
        self.assertEqual(self.eh.msglist, msgs)

        # Status checks
        self.assertEqual(act.status(), ACT_OK)
Esempio n. 6
0
    def test_install_ok(self):
        """Install a simple file"""
        tmp = Utils.makeTempFile('')
        act = Install(self.localname, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        msgs = ['[COPY] %s on %s' % (tmp.name, self.localname),
                "Updating configuration file `%s' on %s" % \
                 (os.path.basename(tmp.name), self.localname)]
        self.assertEqual(self.eh.msglist, msgs)

        # Status checks
        self.assertEqual(act.status(), ACT_OK)
Esempio n. 7
0
    def test_install_bad_nodes(self):
        """Install to a bad node is corrected reported"""
        tmp = Utils.makeTempFile("")
        act = Install(self.badnames, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.badnames)
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `%s' on %d servers" % \
            (os.path.basename(tmp.name), len(self.badnames))
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 8
0
    def test_install_bad_nodes(self):
        """Install to a bad node is corrected reported"""
        tmp = Utils.makeTempFile("")
        act = Install(self.badnames, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.badnames)
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `%s' on %d servers" % \
            (os.path.basename(tmp.name), len(self.badnames))
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 9
0
    def tune(self, tuning_model, comps=None, **kwargs):
        """Tune server."""
        comps = (comps or self.components).managed()

        actions = ActionGroup()
        for server, srvcomps in comps.groupbyserver():
            if server.is_local():
                actions.add(
                    server.tune(tuning_model, srvcomps, self.fs_name,
                                **kwargs))
            else:
                act = self._proxy_action('tune', server.hostname, srvcomps,
                                         **kwargs)
                if tuning_model.filename:
                    copy = Install(server.hostname,
                                   self,
                                   tuning_model.filename,
                                   comps=srvcomps,
                                   **kwargs)
                    act.depends_on(copy)
                    actions.add(copy)

                actions.add(act)

        # Run local actions and FSProxyAction
        actions.launch()
        self._run_actions()

        # Check actions status and return MOUNTED if no error
        return self._check_errors([MOUNTED], None, actions)
Esempio n. 10
0
    def test_install_mix_nodes(self):
        """Install to a mix of bad and good nodes is correctly reported"""
        tmp = Utils.makeTempFile("")
        act = Install(self.badnames | self.localname, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.badnames | self.localname)
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `%s' on %d servers" % \
            (os.path.basename(tmp.name), len(self.badnames | self.localname))
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        self.assertEqual(len(self.fs.proxy_errors), 15)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 11
0
    def test_install_mix_nodes(self):
        """Install to a mix of bad and good nodes is correctly reported"""
        tmp = Utils.makeTempFile("")
        act = Install(self.badnames | self.localname, self.fs, tmp.name)
        act.launch()
        self.fs._run_actions()

        text = '[COPY] %s on %s' % (tmp.name, self.badnames | self.localname)
        self.assertEqual(self.eh.msglist[0], text)
        text = "Updating configuration file `%s' on %d servers" % \
            (os.path.basename(tmp.name), len(self.badnames | self.localname))
        self.assertEqual(self.eh.msglist[1], text)
        self.assertEqual(len(self.eh.msglist), 2)

        self.assertEqual(len(self.fs.proxy_errors), 15)

        # Status checks
        self.assertEqual(act.status(), ACT_ERROR)
Esempio n. 12
0
    def _prepare(self,
                 action,
                 comps=None,
                 groupby=None,
                 reverse=False,
                 need_unload=False,
                 tunings=None,
                 allservers=False,
                 **kwargs):
        """
        Instanciate all actions for the component list and but them in a graph
        of ActionGroup().

        Action could be local or proxy actions.
        Components list is filtered, based on action name.
        """

        graph = ActionGroup()

        comps = comps or self.components

        first_comps = None
        last_comps = None
        localsrv = None
        modules = set()
        localcomps = None

        if groupby:
            iterable = comps.groupby(attr=groupby, reverse=reverse)
        else:
            iterable = [(None, comps)]

        # Iterate over targets, grouping them by start order and server.
        for _order, comps in iterable:

            graph.add(ActionGroup())
            compgrp = ActionGroup()
            proxygrp = ActionGroup()

            for srv, comps in comps.groupbyserver(allservers=allservers):
                if srv.action_enabled is True:
                    if srv.is_local():
                        localsrv = srv
                        localcomps = comps
                        for comp in comps:
                            compgrp.add(getattr(comp, action)(**kwargs))
                    else:
                        act = self._proxy_action(action, srv.hostname, comps,
                                                 **kwargs)
                        if tunings and tunings.filename:
                            copy = Install(srv.hostname,
                                           self,
                                           tunings.filename,
                                           comps=comps,
                                           **kwargs)
                            act.depends_on(copy)
                            proxygrp.add(copy)
                        proxygrp.add(act)

            if len(compgrp) > 0:
                graph[-1].add(compgrp)
                # Keep track of first comp group
                if first_comps is None:
                    first_comps = compgrp
                    first_comps.parent = graph[-1]
                # Keep track of last comp group
                last_comps = compgrp
                last_comps.parent = graph[-1]

                # Build module loading list, if needed
                for comp_action in compgrp:
                    modules.update(comp_action.needed_modules())

            if len(proxygrp) > 0:
                graph[-1].add(proxygrp)

        # Add module loading, if needed.
        if first_comps is not None and len(modules) > 0:
            modgrp = ActionGroup()
            for module in modules:
                modgrp.add(localsrv.load_modules(modname=module, **kwargs))

            # Serialize modules loading actions
            modgrp.sequential()

            first_comps.parent.add(modgrp)
            first_comps.depends_on(modgrp)

        # Apply tuning to last component group, if needed
        if tunings is not None and last_comps is not None:
            tune = localsrv.tune(tunings, localcomps, self.fs_name, **kwargs)
            last_comps.parent.add(tune)
            tune.depends_on(last_comps)

        # Add module unloading to last component group, if needed.
        if need_unload and last_comps is not None:
            unload = localsrv.unload_modules(**kwargs)
            last_comps.parent.add(unload)
            unload.depends_on(last_comps)

        # Join the different part together
        graph.sequential()

        return graph