98
100
self.relation = self.mysql_states["relation"]
101
def add_another_blog(self, service_name):
102
blog_ep = RelationEndpoint(
103
service_name, "client-server", "database", "client")
104
mysql_ep = RelationEndpoint(
105
"mysql", "client-server", "db", "server")
106
yield self.add_relation_service_unit_from_endpoints(
103
def add_another_blog(self, blog_name):
104
blog_ep = RelationEndpoint(blog_name, "client-server", "app", "client")
105
# Fully construct states for the relation connecting to this additional blog
106
other_mysql_states = yield self.add_relation_service_unit_to_another_endpoint(
107
self.mysql_states, blog_ep)
108
# Then complete in the opposite direction
109
blog_states = yield self.add_opposite_service_unit(other_mysql_states)
110
yield blog_states['service_relations'][-1].add_unit_state(
111
self.mysql_states['unit'])
112
returnValue(blog_states)
110
115
def add_db_admin_tool(self, admin_name):
111
116
"""Add another relation, using a different relation name"""
112
117
admin_ep = RelationEndpoint(
113
118
admin_name, "client-server", "admin-app", "client")
114
mysql_ep = RelationEndpoint(
119
mysql_admin_ep = RelationEndpoint(
115
120
"mysql", "client-server", "db-admin", "server")
116
yield self.add_relation_service_unit_from_endpoints(
121
mysql_admin_states = yield self.reuse_service_unit_in_new_relation(
122
self.mysql_states, mysql_admin_ep, admin_ep)
123
admin_states = yield self.add_opposite_service_unit(mysql_admin_states)
124
returnValue(admin_states)
127
def reuse_service_unit_in_new_relation(self, reused_states, *endpoints):
128
"""Reuse an existing service unit as part of a new relation"""
129
service_state = reused_states["service"]
130
unit_state = reused_states["unit"]
132
# 1. Setup all service states
133
service_states = [service_state]
134
for endpoint in endpoints[1:]:
135
service_state = yield self.add_service(endpoint.service_name)
136
service_states.append(service_state)
138
# 2. And join together in a relation
139
relation_state, service_relation_states = \
140
yield self.relation_manager.add_relation_state(
142
# 3. Add a service unit to only the first endpoint - we need
143
# to test what happens when service units are added to the
144
# other service state (if any), so do so separately
145
relation_unit_state = yield service_relation_states[0].add_unit_state(
149
"endpoints": list(endpoints),
150
"service": service_states[0],
151
"services": service_states,
153
"relation": relation_state,
154
"service_relation": service_relation_states[0],
155
"unit_relation": relation_unit_state,
156
"service_relations": service_relation_states})
120
160
class HookContextTest(HookContextTestBase, CommonHookContextTestsMixin):
162
202
set((yield new_context.get_relation_idents(None))),
163
203
set(["db:0", "db:1", "db:2", "db-admin:3"]))
206
def test_get_relation_idents_partial_updates_to_zk(self):
207
"""Verify relation idents do not reflect partial updates to ZK."""
208
log = self.capture_logging(level=logging.DEBUG)
210
# 1. Partial update - no corresponding service relation unit
211
yield self.add_relation_service_unit_to_another_endpoint(
214
"wordpress2", "client-server", "app", "client"))
216
# 2. Do a complete update of adding another relation and
217
# corresponding units
218
yield self.add_another_blog("wordpress3")
219
context = self.get_context("mysql/0")
221
# 3. Observe only the relation ids for wordpress, wordpress3
223
set((yield context.get_relation_idents("db"))),
224
set(["db:0", "db:2"]))
225
self.assertIn("Ignoring partially constructed relation: db:1",
228
# 4. Finally, relation ids for a nonexistent relation are
229
# still not seen, or cause an error.
231
set((yield context.get_relation_idents("not-a-relation"))),
166
235
class RelationHookContextTest(HookContextTestBase,
167
236
CommonHookContextTestsMixin):