Exemplo n.º 1
0
def restart(protocol=None, uris=None, parallel=None, **kwargs):
    logger.debug("uris: %s" % uris)
    logger.debug("parallel: %s" % parallel)
    logger.debug("kwargs: %s" % kwargs)

    components = restore_current_state()
    service_uris = expand_hosts(uris)
    service_uris = glob_hosts(components, service_uris)

    logging.debug("service uris: %s" % service_uris)

    stop_plan = metalogic(STOP, uris, plan_post_handler=identity)

    service_states = {}
    for action in stop_plan.actions:
        service_states[action.uri] = components[action.uri].state
    logging.debug("current states: %s" % service_states)

    start_uris = [uri for uri, state in service_states.iteritems()
                  if state == UP] + uris
    start_uris = set(start_uris)
    logging.info("restarting %s" % ", ".join(start_uris))
    start_plan = metalogic(START, start_uris, plan_post_handler=identity)

    plan = ActionPlan('restart', [stop_plan, start_plan], nr_workers=1)

    for line in plan.dump(include_preconditions=True).splitlines():
        logging.info(line)

    plan = apply_instructions(plan, parallel)
    dump_action_plan('restart', plan)
    return 'restart'
Exemplo n.º 2
0
def reboot(protocol=None, uris=None, parallel=None, **kwargs):
    for uri in uris:
        if not uri.startswith("host://"):
            message = "Cannot reboot %s" % uri
            logger.error(message)
            raise ValueError(message)

    components = restore_current_state()
    host_uris = expand_hosts(uris)
    host_uris = glob_hosts(components, host_uris)

    hosts_to_reboot = uris
    stop_plan = create_plan_to_stop_all_services_on(hosts_to_reboot)

    all_stopped_services = set()
    for action in stop_plan.actions:
        all_stopped_services.add(action.uri)

    start_plan = create_plan_to_start_services_after_rebooting(all_stopped_services,
                                                               hosts_to_reboot,
                                                               components)

    reboot_actions = set([create_reboot_action_for(components[host_uri]) for host_uri in hosts_to_reboot])

    all_actions = set(start_plan.actions) | set(
        stop_plan.actions) | reboot_actions
    all_plan = ActionPlan('all', all_actions)
    all_plan = chop_minimal_related_chunks(all_plan)

    reboot_chunks = set()
    for chunk in all_plan.actions:
        all_chunk_cmds = set(a.cmd for a in chunk.actions)
        if yadtshell.settings.UPDATE in all_chunk_cmds:
            reboot_chunks.add(chunk)
            continue

    prestart_chunks = set()
    for possible_prestart_chunk in all_plan.actions:
        if possible_prestart_chunk in reboot_chunks:
            continue
        if possible_prestart_chunk.is_not_empty:
            prestart_chunks.add(possible_prestart_chunk)

    plan = ActionPlan(
        'update', [ActionPlan('prestart', prestart_chunks),
                   ActionPlan('stoprebootstart', reboot_chunks)
                   ], nr_workers=1)
    plan = apply_instructions(plan, parallel)
    dump_action_plan('reboot', plan)

    return 'reboot'
Exemplo n.º 3
0
def restart(protocol=None, uris=None, parallel=None, **kwargs):
    logger.debug("uris: %s" % uris)
    logger.debug("parallel: %s" % parallel)
    logger.debug("kwargs: %s" % kwargs)

    components = restore_current_state()
    service_uris = expand_hosts(uris)
    service_uris = glob_hosts(components, service_uris)

    logging.debug("service uris: %s" % service_uris)

    plan_all = []
    stop_plan = metalogic(STOP, uris, plan_post_handler=identity)
    stop_plan = chop_minimal_related_chunks(stop_plan)
    for chunk in stop_plan.actions:
        stops = ActionPlan("stop", chunk.actions)

        service_states = {}
        for action in chunk.actions:
            service_states[action.uri] = components[action.uri].state
        logging.debug("current states: %s" % service_states)

        start_uris = [uri for uri, state in service_states.iteritems()
                      if state == UP]
        start_uris = set(start_uris)
        logging.info("restarting %s" % ", ".join(start_uris))
        starts = metalogic(START, start_uris, plan_post_handler=identity)

        plan_all.append(ActionPlan("chunk", [stops, starts], nr_workers=1))

    plan = ActionPlan('restart', plan_all)

    for line in plan.dump(include_preconditions=True).splitlines():
        logging.info(line)

    plan = apply_instructions(plan, parallel)
    dump_action_plan('restart', plan)
    return 'restart'
Exemplo n.º 4
0
    def test_should_not_raise_when_restored_state_is_too_old_and_must_not_be_fresh(self, _, age_of_state):
        age_of_state.return_value = 1337  # the limit is 600 for 10 minutes

        restore_current_state(must_be_fresh=False)  # this should not raise
Exemplo n.º 5
0
    def test_should_restore_current_state(self, restore_function, age_of_state):
        age_of_state.return_value = 0

        restore_current_state()

        restore_function.assert_called_with('/out/dir/current_state.components')