示例#1
0
    def test_call_methods(self):
        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Activated")
        sequence = Sequence("test_seq2", required_phase, result_phase, [])

        self.assertEquals(session_dummy.get_phases(), [])
        self.assertEquals(session_dummy.methods, dict()) 

        sequence.method_names = ["build"]
        sequence.call_methods(session_dummy)
        self.assertTrue(session_dummy.get("build"))

        session_dummy = SessionDummy()
        sequence.method_names = ["build", "activate"]
        sequence.call_methods(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("activate"))

        session_dummy = SessionDummy()
        sequence.method_names = ["build", session_dummy.activate]
        sequence.call_methods(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("activate"))

        session_dummy = SessionDummy()
        sequence.method_names = [session_dummy.build, session_dummy.activate]
        sequence.call_methods(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("activate"))
示例#2
0
 def is_activated(self, exact=False):
     db = self.db.session
     if exact:
         query = db.query(RulesPhase).filter(and_(
             RulesPhase.rules == self.rules_name,
             RulesPhase.version == self.rules_dist_version,
             RulesPhase.phase ==
             phases_list.get("Activated")
             ))
     else:
         query = db.query(RulesPhase).filter(and_(
             RulesPhase.rules == self.rules_name,
             RulesPhase.phase ==
             phases_list.get("Activated")
             ))
     return query.count() > 0
示例#3
0
    def test_must_be_called(self):
        session = SessionDummy()
        sequence = Sequence("mysequence", phases_list.get("Built"),
                            phases_list.get("Activated"), ["mymethod"])
        # result phase in session phase => must not
        session.set_test_phases([phases_list.get("Activated")])
        self.assertFalse(sequence.must_be_called(session))

        # result phase in session phase but always => must
        sequence.always = True
        self.assertTrue(sequence.must_be_called(session))

        # not always but result phase not in session phase
        sequence.always = False
        session.set_test_phases([])
        self.assertTrue(sequence.must_be_called(session))

        # result phase in session phases => run
        session = SessionDummy()
        sequence = UnSequence("mysequence", phases_list.get("Built"),
                              phases_list.get("Activated"),
                              phases_list.get("Activated"), ["mydropmethod"])
        session.set_test_phases([phases_list.get("Activated")])

        self.assertTrue(sequence.must_be_called(session))

        # result phase not in session phases => not run
        session.set_test_phases([])
        self.assertFalse(sequence.must_be_called(session))

        # result phase not in session phases but always is set => run
        sequence.always = True
        self.assertTrue(sequence.must_be_called(session))
示例#4
0
    def test_required_phase(self):
        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Activated")
        sequence = Sequence("test_seq2", required_phase, result_phase,
                            ["extract"])
        # Patched == Patched => run
        session_dummy.set_local_current_phase(phases_list.get("Patched"))
        sequence(session_dummy)

        # Activated > Patched => run
        session_dummy.set_local_current_phase(phases_list.get("Activated"))
        sequence(session_dummy)

        # None < Patched => Error
        session_dummy.set_local_current_phase(phases_list.get("None"))
        try:
            sequence(session_dummy)
            self.fail("Current session phase is smaller then requred phase")
        except SequenceError:
            pass

        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Activated")
        sequence = UnSequence("test_unseq2", required_phase, result_phase,
                              result_phase, ["uninstall"])
        # Patched == Patched => run
        session_dummy.set_local_current_phase(phases_list.get("Patched"))
        sequence(session_dummy)

        # Activated > Patched => run
        session_dummy.set_local_current_phase(phases_list.get("Activated"))
        sequence(session_dummy)

        # None < Patched => Error
        session_dummy.set_local_current_phase(phases_list.get("None"))
        try:
            sequence(session_dummy)
            self.fail("Current session phase is smaller then requred phase")
        except SequenceError:
            pass
示例#5
0
 def __init__(self, name, pre_sequence_name, post_sequence_name,
              required_phase_name, set_phase_name, unset_phase_name,
              method_names):
     self.log = kaizen.logging.getLogger(self)
     self.name = name
     self.pre_sequence_name = pre_sequence_name
     self.post_sequence_name = post_sequence_name
     self.required_phase_name = required_phase_name
     if set_phase_name:
         self.set_phase = phases_list.get(set_phase_name)
     else:
         self.set_phase = None
     if unset_phase_name:
         self.unset_phase = phases_list.get(unset_phase_name)
     else:
         self.unset_phase = None
     self.method_names = method_names
     self.is_run = False
     self.pre_sequence = None
     self.post_sequence = None
示例#6
0
 def _install_dependencies(self, depanalyzer):
     dependencies = depanalyzer.analyse()
     missing = depanalyzer.get_missing()
     if missing:
         raise UnresolvedDependencies(self.rules_name, missing)
     for dependency in DependencyEvaluator(dependencies).list():
         if not dependency.get_type() == Dependency.SESSION:
             continue
         if not phases_list.get("Activated") in \
             dependency.rules.get_phases():
             self.install_seq(dependency.rules)
示例#7
0
    def test_parent_sequence(self):
        session_dummy = SessionDummy()
        required_phase = phases_list.get("None")
        result_phase1 = phases_list.get("Built")
        result_phase2 = phases_list.get("Configured")
        sequence1 = Sequence("build", required_phase, result_phase1,
                             ["build"])
        sequence2 = Sequence("configure", required_phase, result_phase2,
                            ["configure"], parent_seq=sequence1)

        session_dummy.set_local_current_phase(phases_list.get("None"))
        sequence2(session_dummy)

        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phases contains built => run only configure 
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Built")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)

        sequence2(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phases contains built and configure => not run
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Built"),
                                       phases_list.get("Configured")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.result_phases), 0)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)

        sequence2(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertFalse(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 0)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_current_phase(),
                          phases_list.get("None"))
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)

        # phases contains built but force is set => run only configure
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Built")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)

        sequence2(session_dummy, True)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phases contains built and configured but force is set
        # => run only configure
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Built"), 
                                       phases_list.get("Configured")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)

        sequence2(session_dummy, True)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phase contains configured but force is set => run both
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Configured")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase2)

        sequence2(session_dummy, True)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase2)
        self.assertEquals(session_dummy.get_phases()[1], result_phase1)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phases contains built and configured but always is set
        # => run only configure
        sequence3 = Sequence("test_par_seq2", required_phase, result_phase2,
                            ["configure"], True, sequence1)
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Built"), 
                                       phases_list.get("Configured")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)

        sequence3(session_dummy, True)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase1)
        self.assertEquals(session_dummy.get_phases()[1], result_phase2)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        # phase contains configured but always is set => run both
        session_dummy = SessionDummy()
        session_dummy.set_test_phases([phases_list.get("Configured")])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase2)

        sequence3(session_dummy, True)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase2)
        self.assertEquals(len(session_dummy.get_phases()), 2)
        self.assertEquals(session_dummy.get_phases()[0], result_phase2)
        self.assertEquals(session_dummy.get_phases()[1], result_phase1)
        self.assertEquals(session_dummy.get_current_phase(), result_phase2)

        result_phase = phases_list.get("Configured")
        unset_phase = phases_list.get("Built")
        unsequence = UnSequence("delete_build", required_phase, result_phase,
                                unset_phase, ["delete_build"], False, sequence2)

        session_dummy = SessionDummy()
        session_dummy.set_local_current_phase(phases_list.get("None"))
        self.assertEquals(len(session_dummy.get_phases()), 0)
        unsequence(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertTrue(session_dummy.get("delete_build"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)

        session_dummy = SessionDummy()
        session_dummy.set_local_current_phase(result_phase)
        session_dummy.set_test_phases([result_phase])

        # configured but build already deleted => not run
        unsequence(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertFalse(session_dummy.get("configure"))
        self.assertFalse(session_dummy.get("delete_build"))
        self.assertEquals(len(session_dummy.result_phases), 0)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)
示例#8
0
    def test__call__(self):
        session_dummy = SessionDummy()
        self.assertEquals(len(session_dummy.result_phases), 0)

        required_phase = phases_list.get("None")
        result_phase = phases_list.get("Configured")
        sequence = Sequence("configure", required_phase, result_phase,
                            ["configure"])
        session_dummy.set_local_current_phase(phases_list.get("None"))
        sequence(session_dummy)

        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)

        # test two methods
        session_dummy = SessionDummy()
        sequence = Sequence("configure", required_phase, result_phase, ["build",
                            "configure"])
        session_dummy.set_local_current_phase(phases_list.get("Configured"))
        sequence(session_dummy)

        self.assertTrue(session_dummy.get("configure"))
        self.assertTrue(session_dummy.get("build"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)

        # test always = True (result_phase is in phases)
        session_dummy = SessionDummy()
        sequence = Sequence("test_seq5", required_phase, result_phase,
                            ["configure"], True)
        session_dummy.set_local_current_phase(phases_list.get("Configured"))
        session_dummy.set_test_phases([phases_list.get("Configured")])
        sequence(session_dummy)

        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)

        # test force (result_phase is in phases but force is set)
        session_dummy = SessionDummy()
        sequence = Sequence("test_seq5", required_phase, result_phase,
                            ["configure"])
        session_dummy.set_local_current_phase(phases_list.get("Configured"))
        session_dummy.set_test_phases([phases_list.get("Configured")])
        sequence(session_dummy, True)

        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.result_phases), 1)
        self.assertEquals(session_dummy.result_phases[0], result_phase)
        self.assertEquals(session_dummy.get_current_phase(), result_phase)
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0], result_phase)
示例#9
0
    def test_call(self):
        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Built")
        sequence = Sequence("test_seq2", required_phase, result_phase,
                            ["build"])

        # current phase < result phase and result phase not in session 
        # phases => run
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_local_current_phase(phases_list.get("Patched"))
        sequence.call(session_dummy)
        self.assertTrue(session_dummy.get("build"))

        # current phase == result phase but result phase not in session
        # phases => run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_local_current_phase(phases_list.get("Built"))
        sequence.call(session_dummy)
        self.assertTrue(session_dummy.get("build"))

        # result phase in session phases => not run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Built")])
        self.assertEquals(len(session_dummy.get_phases()), 1)
        sequence.call(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertEquals(len(session_dummy.get_phases()), 1)

        # result phase in session phases but force is set => run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Built")])
        self.assertEquals(len(session_dummy.get_phases()), 1)
        sequence.call(session_dummy, True)
        self.assertTrue(session_dummy.get("build"))
        self.assertEquals(len(session_dummy.get_phases()), 1)

        # test parent sequence calls
        sequence2 = Sequence("child_seq", required_phase,
                             phases_list.get("Configured"),
                             ["configure"], parent_seq=sequence)

        # Built and Configured not in session phases => run both
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        sequence2.call(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.get_phases()), 2)

        # Configured in session phases => don't run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Configured")])
        self.assertEquals(len(session_dummy.get_phases()), 1)
        sequence2.call(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertFalse(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.get_phases()), 1)

        # Built in session phases => run only configure
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Built")])
        self.assertEquals(len(session_dummy.get_phases()), 1)
        sequence2.call(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.get_phases()), 2)

        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Built")
        unsequence = UnSequence("test_seq2", required_phase, result_phase,
                                result_phase, ["deactivate"])

        # result phase in session phases => run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Built")])
        self.assertEquals(len(session_dummy.get_phases()), 1)
        unsequence.call(session_dummy)
        self.assertTrue(session_dummy.get("deactivate"))
        self.assertEquals(len(session_dummy.get_phases()), 0)

        # result phase not in session phases => not run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        session_dummy.set_test_phases([phases_list.get("Configured")])
        unsequence.call(session_dummy)
        self.assertFalse(session_dummy.get("deactivate"))
        self.assertEquals(len(session_dummy.get_phases()), 1)

        # result phase not in session phases but force is set => run
        session_dummy = SessionDummy()
        self.assertEquals(session_dummy.get_phases(), [])
        unsequence.call(session_dummy, True)
        self.assertTrue(session_dummy.get("deactivate"))
        self.assertEquals(len(session_dummy.get_phases()), 0)

        session_dummy = SessionDummy()
        required_phase = phases_list.get("Patched")
        result_phase = phases_list.get("Built")
        unset_phase = phases_list.get("Built")
        unsequence = UnSequence("test_seq2", required_phase, result_phase,
                              unset_phase, ["delete_build"],
                              parent_seq=sequence)

        self.assertEquals(len(session_dummy.get_phases()), 0)
        unsequence.call(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("delete_build"))
        self.assertEquals(len(session_dummy.get_phases()), 0)

        session_dummy = SessionDummy()
        session_dummy.set_test_phases([result_phase])
        unsequence.call(session_dummy)
        self.assertFalse(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("delete_build"))
        self.assertEquals(len(session_dummy.get_phases()), 0)

        sequence2 = Sequence("child_seq", required_phase,
                             phases_list.get("Configured"),
                             ["configure"], parent_seq=unsequence)

        self.assertEquals(len(session_dummy.get_phases()), 0)
        sequence2.call(session_dummy)
        self.assertTrue(session_dummy.get("build"))
        self.assertTrue(session_dummy.get("delete_build"))
        self.assertTrue(session_dummy.get("configure"))
        self.assertEquals(len(session_dummy.get_phases()), 1)
        self.assertEquals(session_dummy.get_phases()[0],
                          phases_list.get("Configured"))
示例#10
0
 def get_downloaded_rules(self):
     return self.db.session.query(RulesPhase).filter(
                                  RulesPhase.phase ==
                                  phases_list.get("Downloaded")).order_by(
                                          RulesPhase.rules).all()