34
34
from juju.unit.tests.test_charm import CharmPublisherTestBase
36
36
from juju.lib.testing import TestCase
37
from juju.lib.mocker import (ANY, MATCH, Mocker)
37
from juju.lib.mocker import MATCH
40
40
class UnwriteablePath(object):
358
358
yield self.states["unit"].set_relation_resolved(
359
359
{self.states["unit_relation"].internal_relation_id: NO_HOOKS})
362
361
# Wait for the relation to come back up
363
362
value = yield self.states["unit"].get_relation_resolved()
889
888
self.assertEqual("up", (yield staying_workflow.get_state()))
890
889
yield new_lifecycle.stop()
892
def test_start_invoker(self):
893
"""Verify the invoker is started by the unit relation lifecycle"""
894
# Setup three different wordpress services, wordpress,
895
# wordpress-1, wordpress-2 with one service unit each. Each of
896
# these will be on the relation with ident app:0, app:1, app:2
899
'#!/bin/sh\n echo "hello world"\n')
900
yield self.add_opposite_service_unit(self.states)
901
for i in range(1, 3):
902
yield self.add_opposite_service_unit(
903
(yield self.add_relation_service_unit_to_another_endpoint(
907
"client-server", "db", "client"))))
909
finished = self.wait_on_hook("app-relation-changed", 3)
910
yield self.lifecycle.start()
913
# This will verify that config-changed and start both are
914
# cached properly. The remaining hook caching will be for the
915
# relation hook contexts, along some permutation based on how
916
# the hooks are actually scheduled. However, this is tested in
917
# UnitRelationLifecycleTest.test_start_invoker so need not be
920
self.hook_log.getvalue(),
921
["Cached relation hook contexts: ['app:0', 'app:1', 'app:2']"] * 2)
893
924
class UnitLifecycleUpgradeTest(
894
925
LifecycleTestBase, CharmPublisherTestBase, CharmUpgradeTestBase):
1290
1321
# The scheduler should run the hooks it queued up earlier
1291
1322
yield hooks_complete
1325
def test_start_invoker(self):
1326
"""Verify the invoker is started by the unit relation lifecycle"""
1327
# Setup 5 different wordpress services, wordpress, wordpress-1
1328
# through wordpress-4 with one service unit each. Each of these
1329
# will be on the relation app:0 ... app:4
1330
yield self.add_opposite_service_unit(self.states)
1331
for i in range(1, 5):
1332
yield self.add_opposite_service_unit(
1333
(yield self.add_relation_service_unit_to_another_endpoint(
1337
"client-server", "db", "client"))))
1338
yield self.lifecycle.start()
1339
yield self.wait_on_hook(
1340
sequence=["app-relation-joined", "app-relation-changed"])
1342
# Currently the only action taken by the invoker.start is to
1343
# cache the relation hook context; app:0 is excluded because
1346
("Cached relation hook contexts on 'app:0': "
1347
"['app:1', 'app:2', 'app:3', 'app:4']"),
1348
self.hook_log.getvalue())
1294
1351
class SubordinateUnitLifecycleTest(LifecycleTestBase, CharmPublisherTestBase):