Beispiel #1
0
 def add_relation_unit_states(self, relation_state, unit_states, states):
     for unit_state, state in zip(unit_states, states):
         relation_unit_state = yield relation_state.add_unit_state(
             unit_state)
         workflow_client = ZookeeperWorkflowState(
             self.client, relation_unit_state)
         yield workflow_client.set_state(state)
Beispiel #2
0
 def set_unit_state(self, unit_state, state, port_protos=()):
     unit_state.set_public_address(
         "%s.example.com" % unit_state.unit_name.replace("/", "-"))
     workflow_client = ZookeeperWorkflowState(self.client, unit_state)
     yield workflow_client.set_state(state)
     for port_proto in port_protos:
         yield unit_state.open_port(*port_proto)
Beispiel #3
0
    def test_peer_relation(self):
        """Verify status works with peer relations.
        """
        m1 = yield self.add_provider_machine()
        m2 = yield self.add_provider_machine()

        riak = yield self.add_service_from_charm("riak")
        riak_u1 = yield self.add_unit(riak, m1)
        riak_u2 = yield self.add_unit(riak, m2, with_agent=lambda _: False)
        yield self.set_unit_state(riak_u1, "started")
        yield self.set_unit_state(riak_u2, "started")

        _, (peer_rel,) = yield self.relation_state_manager.add_relation_state(
            RelationEndpoint("riak", "peer", "ring", "peer"))

        riak_u1_relation = yield peer_rel.add_unit_state(riak_u1)
        riak_u1_workflow = ZookeeperWorkflowState(
            self.client, riak_u1_relation)
        with (yield riak_u1_workflow.lock()):
            yield riak_u1_workflow.set_state("up")
        yield peer_rel.add_unit_state(riak_u2)

        state = yield collect(
            ["riak"], self.provider, self.client, None)
        self.assertEqual(
            state["services"]["riak"],
            {"charm": "local:series/riak-7",
             "relations": {"ring": ["riak"]},
             "units": {"riak/0": {"machine": 0,
                                  "public-address": "riak-0.example.com",
                                  "agent-state": "started"},
                       "riak/1": {"machine": 1,
                                  "public-address": "riak-1.example.com",
                                  "agent-state": "down"}}})
Beispiel #4
0
 def add_relation_unit_states(self, relation_state, unit_states, states):
     for unit_state, state in zip(unit_states, states):
         relation_unit_state = yield relation_state.add_unit_state(
             unit_state)
         workflow_client = ZookeeperWorkflowState(self.client,
                                                  relation_unit_state)
         yield workflow_client.set_state(state)
Beispiel #5
0
 def set_unit_state(self, unit_state, state, port_protos=()):
     unit_state.set_public_address("%s.example.com" %
                                   unit_state.unit_name.replace("/", "-"))
     workflow_client = ZookeeperWorkflowState(self.client, unit_state)
     yield workflow_client.set_state(state)
     for port_proto in port_protos:
         yield unit_state.open_port(*port_proto)
Beispiel #6
0
    def test_peer_relation(self):
        """Verify status works with peer relations.
        """
        m1 = yield self.machine_state_manager.add_machine_state()
        m2 = yield self.machine_state_manager.add_machine_state()
        yield self.provider.start_machine({
            "machine-id": 0,
            "dns-name": "steamcloud-1.com"
        })
        yield self.provider.start_machine({
            "machine-id": 1,
            "dns-name": "steamcloud-2.com"
        })
        yield m1.set_instance_id(0)
        yield m2.set_instance_id(1)

        riak = yield self.add_service_from_charm("riak")
        riak_u1 = yield self.add_unit(riak, m1)
        riak_u2 = yield self.add_unit(riak, m2, with_agent=lambda _: False)
        yield self.set_unit_state(riak_u1, "started")
        yield self.set_unit_state(riak_u2, "started")

        _, (peer_rel, ) = yield self.relation_state_manager.add_relation_state(
            RelationEndpoint("riak", "peer", "ring", "peer"))

        yield ZookeeperWorkflowState(
            self.client,
            (yield peer_rel.add_unit_state(riak_u1))).set_state("up")
        yield peer_rel.add_unit_state(riak_u2)

        state = yield status.collect(["riak"], self.provider, self.client,
                                     None)
        self.assertEqual(
            state["services"]["riak"], {
                "charm": "local:series/riak-7",
                "relations": {
                    "ring": "riak"
                },
                "units": {
                    "riak/0": {
                        "machine": 0,
                        "public-address": "riak-0.example.com",
                        "relations": {
                            "ring": {
                                "state": "up"
                            }
                        },
                        "state": "started"
                    },
                    "riak/1": {
                        "machine": 1,
                        "public-address": "riak-1.example.com",
                        "relations": {
                            "ring": {
                                "state": None
                            }
                        },
                        "state": "down"
                    }
                }
            })