Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def __init__(self, srv, tuning_conf, comps, fsname):
     ActionGroup.__init__(self)
     self._server = srv
     self._comps = comps
     self._conf = tuning_conf
     self._fsname = fsname
     self._init = False
Ejemplo n.º 3
0
 def __init__(self, srv, tuning_conf, comps, fsname, **kwargs):
     ActionGroup.__init__(self)
     self._server = srv
     self._comps = comps
     self._conf = tuning_conf
     self._fsname = fsname
     self._init = False
     self.dryrun = kwargs.get('dryrun', False)
Ejemplo n.º 4
0
 def __init__(self, srv, tuning_conf, comps, fsname, **kwargs):
     ActionGroup.__init__(self)
     self._server = srv
     self._comps = comps
     self._conf = tuning_conf
     self._fsname = fsname
     self._init = False
     self.dryrun = kwargs.get('dryrun', False)
Ejemplo n.º 5
0
 def launch(self):
     # First time launch is called, we need to create all the sub actions.
     # As the graph is calling launch a couple of times, we need to do this
     # only once.
     if not self._init:
         self._add_actions()
     # Then call the real launch().
     ActionGroup.launch(self)
Ejemplo n.º 6
0
 def _launch(self):
     # First time launch is called, we need to create all the sub actions.
     # As the graph is calling launch a couple of times, we need to do this
     # only once.
     if not self._init:
         self._server.action_event(self, 'start')
         self._add_actions()
         self._init = True
     # Then call the real _launch()
     ActionGroup._launch(self)
Ejemplo n.º 7
0
 def _launch(self):
     # First time launch is called, we need to create all the sub actions.
     # As the graph is calling launch a couple of times, we need to do this
     # only once.
     if not self._init:
         self._server.action_event(self, 'start')
         self._add_actions()
         self._init = True
     # Then call the real _launch()
     ActionGroup._launch(self)
Ejemplo n.º 8
0
    def test_one_dep_after_error(self):
        """An action with an error group dependency is on error"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(act.status(), ACT_ERROR)
Ejemplo n.º 9
0
    def test_two_deps_after_error(self):
        """2 ok actions with an error group dependency are on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)
Ejemplo n.º 10
0
    def set_status(self, status):
        """
        Update action status.

        If this is a final state, raise corresponding events.
        """
        # Do not raise events if start event was not raised.
        # Start event is raised when init is set.
        if self._init:
            if status == ACT_OK:
                self._server.action_event(self, 'done')
            elif status == ACT_ERROR:
                # Build an error string
                errors = []
                for act in self:
                    if act.status() == ACT_ERROR:
                        errors.append("'%s' failed" % act._command)
                result = ErrorResult("\n".join(errors))
                self._server.action_event(self, 'failed', result)

        ActionGroup.set_status(self, status)
Ejemplo n.º 11
0
    def set_status(self, status):
        """
        Update action status.

        If this is a final state, raise corresponding events.
        """
        # Do not raise events if start event was not raised.
        # Start event is raised when init is set.
        if self._init:
            if status == ACT_OK:
                self._server.action_event(self, 'done')
            elif status == ACT_ERROR:
                # Build an error string
                errors = []
                for act in self:
                    if act.status() == ACT_ERROR:
                        errors.append("'%s' failed" % act._command)
                result = ErrorResult("\n".join(errors))
                self._server.action_event(self, 'failed', result)

        ActionGroup.set_status(self, status)
Ejemplo n.º 12
0
    def test_one_dep_after_error(self):
        """An action with an error group dependency is on error"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(act.status(), ACT_ERROR)
Ejemplo n.º 13
0
    def test_two_deps_after_error(self):
        """2 ok actions with an error group dependency are on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)
Ejemplo n.º 14
0
    def test_group_dep_ok(self):
        """A ok group which depends on an ok group is ok"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/true')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp1.depends_on(grp2)

        grp1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(grp1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(grp2.status(), ACT_OK)
Ejemplo n.º 15
0
class ActionGroupTests(unittest.TestCase):
    def setUp(self):
        self.grp = ActionGroup()

    def test_group_len_and_iter(self):
        """Action group length and __iter__ are correct"""
        self.assertEqual(len(self.grp), 0)
        act1 = TestAction('/bin/foo')
        self.grp.add(act1)
        self.assertEqual(len(self.grp), 1)
        self.assertEqual(self.grp[0], act1)
        self.assertEqual(self.grp[-1], act1)
        act2 = TestAction('/bin/bar')
        self.grp.add(act2)
        # Add it twice does not raise an error
        self.grp.add(act2)
        self.assertEqual(len(self.grp), 2)
        self.assertEqual(self.grp[0], act1)
        self.assertEqual(self.grp[1], act2)
        self.assertEqual(self.grp[-1], act2)
        self.assertEqual(list(iter(self.grp)), [act1, act2])

    def test_sequential(self):
        """A group could be easily sequentialized"""
        act1 = TestAction('/bin/foo')
        self.grp.add(act1)
        act2 = TestAction('/bin/foo')
        self.grp.add(act2)
        self.grp.sequential()
        self.assertEqual(act1.deps, set([]))
        self.assertEqual(act2.deps, set([act1]))
        self.assertEqual(act1.followers, set([self.grp, act2]))
        self.assertEqual(act2.followers, set([self.grp]))

    def test_empty(self):
        """Launching an empty group is ok"""
        self.grp.launch()
        task_self().run()
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_action(self):
        """A group with its only action both run ok"""
        act = TestAction('/bin/true')
        self.grp.add(act)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_two_actions_ok_and_ok(self):
        """A group with 2 actions all run fine"""
        act1 = TestAction('/bin/true')
        act2 = TestAction('/bin/true')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_action_error(self):
        """A group with only an error action is on error"""
        act = TestAction('/bin/false')
        self.grp.add(act)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_actions_ok_and_error(self):
        """A group with a ok action and an error action is on error"""
        act1 = TestAction('/bin/true')
        act2 = TestAction('/bin/false')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_actions_2_errors(self):
        """A group with 2 error actions is on error"""
        act1 = TestAction('/bin/false')
        act2 = TestAction('/bin/false')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_one_dep_ok(self):
        """A group with one ok dependency is ok"""
        act = TestAction('/bin/true')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(act)

        self.grp.launch()
        task_self().run()

        self.assertEqual(act.status(), ACT_OK)
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_dep_error(self):
        """A group with an error dependency is on error, content is not run"""
        act = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(act)

        self.grp.launch()
        task_self().run()

        self.assertEqual(act.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_deps_ok_and_ok(self):
        """A group with two ok dependencies is ok"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_OK)
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_two_deps_ok_and_error(self):
        """A group with one error dep and one ok dep is on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_deps_error_and_error(self):
        """A group with 2 error dependencies is on error"""
        dep1 = TestAction('/bin/false')
        dep2 = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_one_dep_after_ok(self):
        """An action with an ok group dependency is ok"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)
        self.assertEqual(act.status(), ACT_OK)

    def test_one_dep_after_error(self):
        """An action with an error group dependency is on error"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(act.status(), ACT_ERROR)

    def test_two_deps_after_ok(self):
        """2 ok actions with an ok group dependency are ok"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)
        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_OK)

    def test_two_deps_after_error(self):
        """2 ok actions with an error group dependency are on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)

    def test_group_dep_ok(self):
        """A ok group which depends on an ok group is ok"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/true')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp1.depends_on(grp2)

        grp1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(grp1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(grp2.status(), ACT_OK)

    def test_group_dep_error(self):
        """A ok group which depends on an error group is on error"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/false')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp2.depends_on(grp1)

        grp2.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(grp1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_WAITING)
        self.assertEqual(grp2.status(), ACT_ERROR)
Ejemplo n.º 16
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
Ejemplo n.º 17
0
    def test_group_dep_error(self):
        """A ok group which depends on an error group is on error"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/false')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp2.depends_on(grp1)

        grp2.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(grp1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_WAITING)
        self.assertEqual(grp2.status(), ACT_ERROR)
Ejemplo n.º 18
0
class ActionGroupTests(unittest.TestCase):

    def setUp(self):
        self.grp = ActionGroup()

    def test_group_len_and_iter(self):
        """Action group length and __iter__ are correct"""
        self.assertEqual(len(self.grp), 0)
        act1 = TestAction('/bin/foo')
        self.grp.add(act1)
        self.assertEqual(len(self.grp), 1)
        self.assertEqual(self.grp[0], act1)
        self.assertEqual(self.grp[-1], act1)
        act2 = TestAction('/bin/bar')
        self.grp.add(act2)
        # Add it twice does not raise an error
        self.grp.add(act2)
        self.assertEqual(len(self.grp), 2)
        self.assertEqual(self.grp[0], act1)
        self.assertEqual(self.grp[1], act2)
        self.assertEqual(self.grp[-1], act2)
        self.assertEqual(list(iter(self.grp)), [act1, act2])

    def test_sequential(self):
        """A group could be easily sequentialized"""
        act1 = TestAction('/bin/foo')
        self.grp.add(act1)
        act2 = TestAction('/bin/foo')
        self.grp.add(act2)
        self.grp.sequential()
        self.assertEqual(act1.deps, set([]))
        self.assertEqual(act2.deps, set([act1]))
        self.assertEqual(act1.followers, set([self.grp, act2]))
        self.assertEqual(act2.followers, set([self.grp]))

    def test_empty(self):
        """Launching an empty group is ok"""
        self.grp.launch()
        task_self().run()
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_action(self):
        """A group with its only action both run ok"""
        act = TestAction('/bin/true')
        self.grp.add(act)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_two_actions_ok_and_ok(self):
        """A group with 2 actions all run fine"""
        act1 = TestAction('/bin/true')
        act2 = TestAction('/bin/true')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_action_error(self):
        """A group with only an error action is on error"""
        act = TestAction('/bin/false')
        self.grp.add(act)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_actions_ok_and_error(self):
        """A group with a ok action and an error action is on error"""
        act1 = TestAction('/bin/true')
        act2 = TestAction('/bin/false')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_actions_2_errors(self):
        """A group with 2 error actions is on error"""
        act1 = TestAction('/bin/false')
        act2 = TestAction('/bin/false')
        self.grp.add(act1)
        self.grp.add(act2)
        self.grp.launch()
        task_self().run()
        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_one_dep_ok(self):
        """A group with one ok dependency is ok"""
        act = TestAction('/bin/true')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(act)

        self.grp.launch()
        task_self().run()

        self.assertEqual(act.status(), ACT_OK)
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_one_dep_error(self):
        """A group with an error dependency is on error, content is not run"""
        act = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(act)

        self.grp.launch()
        task_self().run()

        self.assertEqual(act.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_deps_ok_and_ok(self):
        """A group with two ok dependencies is ok"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_OK)
        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)

    def test_two_deps_ok_and_error(self):
        """A group with one error dep and one ok dep is on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_two_deps_error_and_error(self):
        """A group with 2 error dependencies is on error"""
        dep1 = TestAction('/bin/false')
        dep2 = TestAction('/bin/false')
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        self.grp.depends_on(dep1)
        self.grp.depends_on(dep2)

        self.grp.launch()
        task_self().run()

        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)
        self.assertEqual(act1.status(), ACT_WAITING)
        self.assertEqual(self.grp.status(), ACT_ERROR)

    def test_one_dep_after_ok(self):
        """An action with an ok group dependency is ok"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)
        self.assertEqual(act.status(), ACT_OK)

    def test_one_dep_after_error(self):
        """An action with an error group dependency is on error"""
        act = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        act.depends_on(self.grp)

        act.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(act.status(), ACT_ERROR)

    def test_two_deps_after_ok(self):
        """2 ok actions with an ok group dependency are ok"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/true')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(self.grp.status(), ACT_OK)
        self.assertEqual(dep1.status(), ACT_OK)
        self.assertEqual(dep2.status(), ACT_OK)

    def test_two_deps_after_error(self):
        """2 ok actions with an error group dependency are on error"""
        dep1 = TestAction('/bin/true')
        dep2 = TestAction('/bin/true')
        self.grp = ActionGroup()
        act1 = TestAction('/bin/false')
        self.grp.add(act1)

        dep1.depends_on(self.grp)
        dep2.depends_on(self.grp)

        dep1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(self.grp.status(), ACT_ERROR)
        self.assertEqual(dep1.status(), ACT_ERROR)
        self.assertEqual(dep2.status(), ACT_ERROR)

    def test_group_dep_ok(self):
        """A ok group which depends on an ok group is ok"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/true')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp1.depends_on(grp2)

        grp1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(grp1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(grp2.status(), ACT_OK)

    def test_group_dep_error(self):
        """A ok group which depends on an error group is on error"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/false')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp2.depends_on(grp1)

        grp2.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(grp1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_WAITING)
        self.assertEqual(grp2.status(), ACT_ERROR)
Ejemplo n.º 19
0
 def setUp(self):
     self.grp = ActionGroup()
Ejemplo n.º 20
0
 def setUp(self):
     self.grp = ActionGroup()
Ejemplo n.º 21
0
    def test_group_dep_ok(self):
        """A ok group which depends on an ok group is ok"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/true')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp1.depends_on(grp2)

        grp1.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_OK)
        self.assertEqual(grp1.status(), ACT_OK)
        self.assertEqual(act2.status(), ACT_OK)
        self.assertEqual(grp2.status(), ACT_OK)
Ejemplo n.º 22
0
    def test_group_dep_error(self):
        """A ok group which depends on an error group is on error"""
        grp1 = ActionGroup()
        act1 = TestAction('/bin/false')
        grp1.add(act1)
        grp2 = ActionGroup()
        act2 = TestAction('/bin/true')
        grp2.add(act2)

        grp2.depends_on(grp1)

        grp2.launch()
        task_self().run()

        self.assertEqual(act1.status(), ACT_ERROR)
        self.assertEqual(grp1.status(), ACT_ERROR)
        self.assertEqual(act2.status(), ACT_WAITING)
        self.assertEqual(grp2.status(), ACT_ERROR)