~dpb/pyjuju/dont-proxy-https

« back to all changes in this revision

Viewing changes to juju/unit/tests/test_lifecycle.py

merge unit-rel-lifecycle-start-invoker [r=hazmat][f=992329]

Ensure Invoker.start is called from UnitRelationLifecycle usage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from juju.unit.tests.test_charm import CharmPublisherTestBase
35
35
 
36
36
from juju.lib.testing import TestCase
37
 
from juju.lib.mocker import (ANY, MATCH, Mocker)
 
37
from juju.lib.mocker import MATCH
38
38
 
39
39
 
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})
360
360
 
361
 
 
362
361
        # Wait for the relation to come back up
363
362
        value = yield self.states["unit"].get_relation_resolved()
364
363
 
889
888
        self.assertEqual("up", (yield staying_workflow.get_state()))
890
889
        yield new_lifecycle.stop()
891
890
 
 
891
    @inlineCallbacks
 
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
 
897
        self.write_hook(
 
898
            "start",
 
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(
 
904
                        self.states,
 
905
                        RelationEndpoint(
 
906
                            "wordpress-%d" % i,
 
907
                            "client-server", "db", "client"))))
 
908
 
 
909
        finished = self.wait_on_hook("app-relation-changed", 3)
 
910
        yield self.lifecycle.start()
 
911
        yield finished
 
912
 
 
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
 
918
        # covered here.
 
919
        self.assertLogLines(
 
920
            self.hook_log.getvalue(),
 
921
            ["Cached relation hook contexts: ['app:0', 'app:1', 'app:2']"] * 2)
 
922
 
892
923
 
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
1292
1323
 
 
1324
    @inlineCallbacks
 
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(
 
1334
                        self.states,
 
1335
                        RelationEndpoint(
 
1336
                            "wordpress-%d" % i,
 
1337
                            "client-server", "db", "client"))))
 
1338
        yield self.lifecycle.start()
 
1339
        yield self.wait_on_hook(
 
1340
            sequence=["app-relation-joined", "app-relation-changed"])
 
1341
 
 
1342
        # Currently the only action taken by the invoker.start is to
 
1343
        # cache the relation hook context; app:0 is excluded because
 
1344
        # it is the parent
 
1345
        self.assertIn(
 
1346
            ("Cached relation hook contexts on 'app:0': "
 
1347
             "['app:1', 'app:2', 'app:3', 'app:4']"),
 
1348
            self.hook_log.getvalue())
 
1349
 
1293
1350
 
1294
1351
class SubordinateUnitLifecycleTest(LifecycleTestBase, CharmPublisherTestBase):
1295
1352