Example #1
0
 def test_is_relation_running(self):
     """The unit relation's workflow state can be categorized as a
     boolean.
     """
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, False)
     self.assertIdentical(state, None)
     yield self.workflow.fire_transition("start")
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, True)
     self.assertEqual(state, "up")
     yield self.workflow.fire_transition("stop")
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, False)
     self.assertEqual(state, "down")
Example #2
0
 def test_is_relation_running(self):
     """The unit relation's workflow state can be categorized as a
     boolean.
     """
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, False)
     self.assertIdentical(state, None)
     yield self.workflow.fire_transition("start")
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, True)
     self.assertEqual(state, "up")
     yield self.workflow.fire_transition("stop")
     running, state = yield is_relation_running(
         self.client, self.states["unit_relation"])
     self.assertIdentical(running, False)
     self.assertEqual(state, "down")
Example #3
0
    def test_is_relation_running(self):
        """The unit relation's workflow state can be categorized as a
        boolean.
        """
        with (yield self.workflow.lock()):
            running, state = yield is_relation_running(
                self.client, self.states["unit_relation"])
            self.assertIdentical(running, False)
            self.assertIdentical(state, None)
            relation_state = self.workflow.get_relation_info()
            self.assertEquals(relation_state,
                              {"relation-0000000000":
                               {"relation_name": "mysql/0",
                                "relation_scope": "global"}})

            yield self.workflow.fire_transition("start")
            running, state = yield is_relation_running(
                self.client, self.states["unit_relation"])
            self.assertIdentical(running, True)
            self.assertEqual(state, "up")

            relation_state = self.workflow.get_relation_info()
            self.assertEquals(relation_state,
                              {"relation-0000000000":
                               {"relation_name": "mysql/0",
                                "relation_scope": "global"}})

            yield self.workflow.fire_transition("stop")
            running, state = yield is_relation_running(
                self.client, self.states["unit_relation"])
            self.assertIdentical(running, False)
            self.assertEqual(state, "down")
            relation_state = self.workflow.get_relation_info()
            self.assertEquals(relation_state,
                              {"relation-0000000000":
                               {"relation_name": "mysql/0",
                                "relation_scope": "global"}})
Example #4
0
def resolved(config, environment, verbose, log, unit_name, relation_name,
             retry):
    """Mark an error as resolved in a unit or unit relation.

    If one of a unit's charm non-relation hooks returns a non-zero exit
    status, the entire unit can be considered to be in a non-running state.

    As a resolution, the the unit can be manually returned a running state
    via the juju resolved command. Optionally this command can also
    rerun the failed hook.

    This resolution also applies separately to each of the unit's relations.
    If one of the relation-hooks failed. In that case there is no
    notion of retrying (the change is gone), but resolving will allow
    additional relation hooks for that relation to proceed.
    """
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    service_manager = ServiceStateManager(client)
    relation_manager = RelationStateManager(client)

    unit_state = yield service_manager.get_unit_state(unit_name)
    service_state = yield service_manager.get_service_state(
        unit_name.split("/")[0])

    retry = retry and RETRY_HOOKS or NO_HOOKS

    if not relation_name:
        running, workflow_state = yield is_unit_running(client, unit_state)
        if running:
            log.info("Unit %r already running: %s", unit_name, workflow_state)
            client.close()
            returnValue(False)

        yield unit_state.set_resolved(retry)
        log.info("Marked unit %r as resolved", unit_name)
        returnValue(True)

    # Check for the matching relations
    service_relations = yield relation_manager.get_relations_for_service(
        service_state)
    service_relations = [
        sr for sr in service_relations if sr.relation_name == relation_name
    ]
    if not service_relations:
        raise RelationStateNotFound()

    # Verify the relations are in need of resolution.
    resolved_relations = {}
    for service_relation in service_relations:
        unit_relation = yield service_relation.get_unit_state(unit_state)
        running, state = yield is_relation_running(client, unit_relation)
        if not running:
            resolved_relations[unit_relation.internal_relation_id] = retry

    if not resolved_relations:
        log.warning("Matched relations are all running")
        client.close()
        returnValue(False)

    # Mark the relations as resolved.
    yield unit_state.set_relation_resolved(resolved_relations)
    log.info("Marked unit %r relation %r as resolved", unit_name,
             relation_name)
    client.close()
Example #5
0
def resolved(
    config, environment, verbose, log, unit_name, relation_name, retry):
    """Mark an error as resolved in a unit or unit relation.

    If one of a unit's charm non-relation hooks returns a non-zero exit
    status, the entire unit can be considered to be in a non-running state.

    As a resolution, the the unit can be manually returned a running state
    via the juju resolved command. Optionally this command can also
    rerun the failed hook.

    This resolution also applies separately to each of the unit's relations.
    If one of the relation-hooks failed. In that case there is no
    notion of retrying (the change is gone), but resolving will allow
    additional relation hooks for that relation to proceed.
    """
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    service_manager = ServiceStateManager(client)
    relation_manager = RelationStateManager(client)

    unit_state = yield service_manager.get_unit_state(unit_name)
    service_state = yield service_manager.get_service_state(
        unit_name.split("/")[0])

    retry = retry and RETRY_HOOKS or NO_HOOKS

    if not relation_name:
        running, workflow_state = yield is_unit_running(client, unit_state)
        if running:
            log.info("Unit %r already running: %s", unit_name, workflow_state)
            client.close()
            returnValue(False)

        yield unit_state.set_resolved(retry)
        log.info("Marked unit %r as resolved", unit_name)
        returnValue(True)

    # Check for the matching relations
    service_relations = yield relation_manager.get_relations_for_service(
        service_state)
    service_relations = [
        sr for sr in service_relations if sr.relation_name == relation_name]
    if not service_relations:
        raise RelationStateNotFound()

    # Verify the relations are in need of resolution.
    resolved_relations = {}
    for service_relation in service_relations:
        unit_relation = yield service_relation.get_unit_state(unit_state)
        running, state = yield is_relation_running(client, unit_relation)
        if not running:
            resolved_relations[unit_relation.internal_relation_id] = retry

    if not resolved_relations:
        log.warning("Matched relations are all running")
        client.close()
        returnValue(False)

    # Mark the relations as resolved.
    yield unit_state.set_relation_resolved(resolved_relations)
    log.info(
        "Marked unit %r relation %r as resolved", unit_name, relation_name)
    client.close()