Exemplo n.º 1
0
    def test_P_A_Deps_A_KO(self):
        """
        A parallel with two actions. The first one has an explicit
        dependency on the last one. The last one will fail.

        This is not supported: any id referenced in a deps should be
        defined first in the document.

        """
        doc = ISE(PAR(ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A1.STD", "A1.ERR"),
                             id="1", deps="2"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_KO,
                                                    "A2.STD", "A2.ERR"),
                             id="2"),
                      desc="P_A_Deps_A_KO")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(ACTION_RC_KO, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(1, len(actionsMap))
            self.assertEquals(1, len(execution.error_actions))
            a1 = actionsMap["2"]
            self.assertEquals(a1.rc, ACTION_RC_KO)
            self.assertEquals(a1.stdout, "A2.STD")
            self.assertEquals(a1.stderr, "A2.ERR")
Exemplo n.º 2
0
    def test_P_ASA_OK(self):
        """
        A parallel composed of an action, a sequence (with 2
        actions) and an action
        """

        doc = ISE(PAR(ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A1.STD", "A1.ERR"),
                             id="1"),
                      SEQ(ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                        "A2.STD", "A2.ERR"),
                                 id="2"),
                          ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                        "A3.STD", "A3.ERR"),
                                 id="3")),
                      ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                        "A4.STD", "A4.ERR"),
                                 id="4"),
                      desc="P_ASA_OK")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(ACTION_RC_OK, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(4, len(actionsMap))
            self.assertEquals(0, len(execution.error_actions))
            for i in range(1, 5):
                self.assertActionAttributes(actionsMap, str(i))

            self._checkPASAOrder(actionsMap)
Exemplo n.º 3
0
    def test_PAA_KO(self):
        """
        A parallel, where second action returns KO -> first action
        should have been executed
        """

        doc = ISE(PAR(ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A1.STD", "A1.ERR"),
                             id="1"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_KO,
                                                    "A2.STD", "A2.ERR"),
                             id="2"),
                      desc="PAA_KO")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            actionsMap = execution.executed_actions
            self.assertEquals(2, len(actionsMap))
            self.assertEquals(1, len(execution.error_actions))
            self.assertTrue("1" in actionsMap)
            self.assertTrue("2" in actionsMap)
            self.assertTrue("2" in execution.error_actions)
            action = actionsMap["1"]
            self.assertEquals(action.rc, ACTION_RC_OK)
            self.assertEquals(action.stdout, "A1.STD")
            self.assertEquals(action.stderr, "A1.ERR")
            action = actionsMap["2"]
            self.assertEquals(action.rc, ACTION_RC_KO)
            self.assertEquals(action.stdout, "A2.STD")
            self.assertEquals(action.stderr, "A2.ERR")
Exemplo n.º 4
0
    def test_P_A_KO_A_Deps(self):
        """
        A parallel with two actions. The second action has an explicit
        dependency on the first one. The first one will fail.
        """

        doc = ISE(PAR(ACTION(tools.getMockActionCmd(ACTION_RC_KO,
                                                    "A1.STD", "A1.ERR"),
                             id="1"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A2.STD", "A2.ERR"),
                             id="2", deps="1"),
                      desc="P_A_KO_A_Deps")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(ACTION_RC_KO, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(1, len(actionsMap))
            self.assertEquals(1, len(execution.error_actions))
            self.assertTrue("1" in actionsMap)
            self.assertTrue("1" in execution.error_actions)
            a1 = actionsMap["1"]
            self.assertEquals(a1.rc, ACTION_RC_KO)
            self.assertEquals(a1.stdout, "A1.STD")
            self.assertEquals(a1.stderr, "A1.ERR")
Exemplo n.º 5
0
    def _test_SA_rc_A(self, rc):
        """ A sequence, where first action returns given rc -> next action
        should not be executed

        rc should be either WARNING or KO
        """

        doc = ISE(SEQ(ACTION(tools.getMockActionCmd(rc,
                                                    "A1.STD", "A1.ERR"),
                             id="1"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A2.STD", "A2.ERR"),
                             id="2"),
                      desc="SA_" + str(rc) + "_A")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            actionsMap = execution.executed_actions
            self.assertEquals(1, len(actionsMap))
            self.assertEquals(1, len(execution.error_actions))
            self.assertTrue("1" in actionsMap)
            self.assertTrue("1" in execution.error_actions)
            action = actionsMap["1"]
            self.assertEquals(action.rc, rc)
            self.assertEquals(action.stdout, "A1.STD")
            self.assertEquals(action.stderr, "A1.ERR")
Exemplo n.º 6
0
    def test_P_AA(self):

        doc = ISE(
            PAR(ACTION(
                tools.getMockActionCmd(ACTION_RC_OK, "A1.STD", "A1.ERR"),
                id="1"),
                ACTION(
                    tools.getMockActionCmd(ACTION_RC_OK, "A2.STD", "A2.ERR"),
                    id="2",
                    deps="1"),
                desc="P_AA"))

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(ACTION_RC_OK, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(2, len(actionsMap))
            for i in range(1, 2):
                self.assertActionAttributes(actionsMap, str(i))

            a1 = actionsMap["1"]
            a2 = actionsMap["2"]
            self.assertTrue(a2.started_time > a1.ended_time)
Exemplo n.º 7
0
 def test_EmptyAction(self):
     doc = ISE(SEQ(ACTION("", id="EmptyAction")))
     xml = lxml.etree.tostring(doc, pretty_print=True)
     print(xml)
     with io.StringIO(unicode(xml)) as reader:
         execution = api.execute(reader)
         self.assertEquals(ACTION_RC_OK, execution.rc)
         actionsMap = execution.executed_actions
         self.assertEquals(0, len(actionsMap))
         errorActionsMap = execution.error_actions
         self.assertEquals(1, len(errorActionsMap))
         self.assertTrue("EmptyAction" in errorActionsMap)
         action = errorActionsMap["EmptyAction"]
         self.assertEquals("EmptyAction", action.id)
         self.assertEquals(ACTION_RC_UNEXECUTED, action.rc)
Exemplo n.º 8
0
    def _checkSimpleAction(self, doc, action_id, expected_rc, expected_std,
                           expected_err):

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(expected_rc, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(1, len(actionsMap))
            self.assertTrue(action_id in actionsMap)
            action = actionsMap[action_id]
            self.assertEquals(action_id, action.id)
            self.assertEquals(expected_rc, action.rc)
            self.assertEquals(expected_std, action.stdout)
            self.assertEquals(expected_err, action.stderr)
Exemplo n.º 9
0
    def test_P_A_W_AA_Deps_Force(self):
        """
        A parallel with three actions. The last one has an explicit
        dependency on first ones. The first one will fail with a
        WARNING but with force mode. Therefore, the second one should
        get executed, *and* also the third one.
        """
        doc = ISE(
            PAR(ACTION(
                tools.getMockActionCmd(ACTION_RC_WARNING, "A1.STD", "A1.ERR"),
                id="1"),
                ACTION(
                    tools.getMockActionCmd(ACTION_RC_OK, "A2.STD", "A2.ERR"),
                    id="2"),
                ACTION(
                    tools.getMockActionCmd(ACTION_RC_OK, "A3.STD", "A3.ERR"),
                    id="3",
                    deps="1,2"),
                desc="P_A_W_AA_Deps_Force"))

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader, force=True)
            self.assertEquals(ACTION_RC_WARNING, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(3, len(actionsMap),
                              "actionsMap: %s" % actionsMap)
            self.assertEquals(0, len(execution.error_actions))
            self.assertTrue("1" in actionsMap)
            self.assertTrue("2" in actionsMap)
            self.assertTrue("3" in actionsMap)
            a1 = actionsMap["1"]
            self.assertEquals(a1.rc, ACTION_RC_WARNING)
            self.assertEquals(a1.stdout, "A1.STD")
            self.assertEquals(a1.stderr, "A1.ERR")
            a2 = actionsMap["2"]
            self.assertEquals(a2.rc, ACTION_RC_OK)
            self.assertEquals(a2.stdout, "A2.STD")
            self.assertEquals(a2.stderr, "A2.ERR")
            a3 = actionsMap["3"]
            self.assertEquals(a3.rc, ACTION_RC_OK)
            self.assertEquals(a3.stdout, "A3.STD")
            self.assertEquals(a3.stderr, "A3.ERR")
Exemplo n.º 10
0
 def _assert_SA_W_A_Force(self, doc, force_option, assert_dep_executed):
     xml = lxml.etree.tostring(doc, pretty_print=True)
     print(xml)
     with io.StringIO(unicode(xml)) as reader:
         execution = api.execute(reader, force=force_option)
         actionsMap = execution.executed_actions
         self.assertTrue("1" in actionsMap)
         action = actionsMap["1"]
         self.assertEquals(action.rc, ACTION_RC_WARNING)
         self.assertEquals(action.stdout, "A1.STD")
         self.assertEquals(action.stderr, "A1.ERR")
         if assert_dep_executed:
             self.assertEquals(0, len(execution.error_actions))
             action = actionsMap["2"]
             self.assertEquals(action.rc, ACTION_RC_OK)
             self.assertEquals(action.stdout, "A2.STD")
             self.assertEquals(action.stderr, "A2.ERR")
         else:
             self.assertEquals(1, len(execution.error_actions))
Exemplo n.º 11
0
    def _test_P_A_rc_AA_Deps(self, rc):
        """
        A parallel with three actions. The last one has an explicit
        dependency on first ones. The first one will fail with rc
        (either WARNING or KO). Therefore, the second one should get
        executed, but not the third one.
        """
        doc = ISE(PAR(ACTION(tools.getMockActionCmd(rc,
                                                    "A1.STD", "A1.ERR"),
                             id="1"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A2.STD", "A2.ERR"),
                             id="2"),
                      ACTION(tools.getMockActionCmd(ACTION_RC_OK,
                                                    "A3.STD", "A3.ERR"),
                             id="3", deps="1,2"),
                      desc="P_A_" + str(rc) + "_AA_Deps")
                  )

        xml = lxml.etree.tostring(doc, pretty_print=True)
        print(xml)
        with io.StringIO(unicode(xml)) as reader:
            execution = api.execute(reader)
            self.assertEquals(rc, execution.rc)
            actionsMap = execution.executed_actions
            self.assertEquals(2, len(actionsMap), "actionsMap: %s" % actionsMap)
            self.assertEquals(1, len(execution.error_actions))
            self.assertTrue("1" in actionsMap)
            self.assertTrue("2" in actionsMap)
            self.assertTrue("1" in execution.error_actions)
            a1 = actionsMap["1"]
            self.assertEquals(a1.rc, rc)
            self.assertEquals(a1.stdout, "A1.STD")
            self.assertEquals(a1.stderr, "A1.ERR")
            a2 = actionsMap["2"]
            self.assertEquals(a2.rc, ACTION_RC_OK)
            self.assertEquals(a2.stdout, "A2.STD")
            self.assertEquals(a2.stderr, "A2.ERR")