Example #1
0
def test_actor_phases_detect_cycles():
    # Expected a cycle to be detected
    with pytest.raises(CyclingDependenciesError):
        PhaseActors(CycleTag1.actors, 'Test')

    # This should not cause a cycle to be present
    PhaseActors(PhaseActorsModelsTag1.actors, 'Test')
Example #2
0
def test_actor_phases_order():
    initial_actors = (CycleActor3, CycleActor2)
    phase_actors = PhaseActors(initial_actors, 'Test')

    assert len(phase_actors.actors) == 2
    assert phase_actors.actors[0] is CycleActor2
    assert phase_actors.actors[1] is CycleActor3
Example #3
0
    def __init__(self, logger=None, auto_reboot=False):
        """
        :param logger: Optional logger to be used instead of leapp.workflow
        :type logger: Instance of :py:class:`logging.Logger`
        """
        self.log = (logger or logging.getLogger('leapp')).getChild('workflow')
        self._errors = []
        self._all_consumed = set()
        self._all_produced = set()
        self._initial = set()
        self._phase_actors = []
        self._experimental_whitelist = set()
        self._auto_reboot = auto_reboot
        self._unhandled_exception = False
        self._answer_store = AnswerStore()
        self._dialogs = []
        self._stop_after_phase_requested = False

        if self.configuration:
            config_actors = [
                actor for actor in self.tag.actors
                if self.configuration in actor.produces
            ]
            if config_actors:
                if len(config_actors) == 1:
                    self._phase_actors.append(
                        (_ConfigPhase, PhaseActors((), 'Before'),
                         PhaseActors(tuple(config_actors),
                                     'Main'), PhaseActors((), 'After')))
                else:
                    config_actor_names = [a.name for a in config_actors]
                    raise MultipleConfigActorsError(config_actor_names)
        self.description = self.description or type(self).__doc__

        for phase in self.phases:
            phase.filter.tags += (self.tag, )
            self._phase_actors.append((
                phase,
                # filters all actors with the give tags
                # phasetag .Before
                self._apply_phase(phase.filter.get_before(), 'Before'),
                # phasetag
                self._apply_phase(phase.filter.get(), 'Main'),
                # phasetag .After
                self._apply_phase(phase.filter.get_after(), 'After')))
Example #4
0
def test_actor_phases_check_models():
    phase_actors = PhaseActors(PhaseActorsModelsTag1.actors, 'Test')
    assert len(
        phase_actors.initial) == 1 and phase_actors.initial[0] is CycleModel2

    assert len(phase_actors.consumes) == 2
    assert CycleModel1 in phase_actors.consumes
    assert CycleModel2 in phase_actors.consumes

    assert len(phase_actors.produces) == 1
    assert CycleModel1 in phase_actors.produces
Example #5
0
 def _apply_phase(self, actors, stage):
     phase_actors = PhaseActors(actors, stage)
     self._initial.update(set(phase_actors.initial) - self._all_produced)
     self._all_consumed.update(phase_actors.consumes)
     self._all_produced.update(phase_actors.produces)
     return phase_actors