Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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)