Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(197)

Delta Between Two Patch Sets: juju/state/tests/test_initialize.py

Issue 5845061: juju/control should be aware of subordinates
Left Patch Set: Created 13 years ago
Right Patch Set: juju/control should be aware of subordinates Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « juju/state/tests/test_hook.py ('k') | juju/state/tests/test_machine.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import zookeeper 1 import zookeeper
2 2
3 from twisted.internet.defer import inlineCallbacks 3 from twisted.internet.defer import inlineCallbacks
4
5 from txzookeeper import ZookeeperClient 4 from txzookeeper import ZookeeperClient
6 from txzookeeper.tests.utils import deleteTree 5 from txzookeeper.tests.utils import deleteTree
7 6
7 from juju.environment.tests.test_config import EnvironmentsConfigTestBase
8 from juju.state.auth import make_identity 8 from juju.state.auth import make_identity
9 from juju.state.environment import GlobalSettingsStateManager 9 from juju.state.environment import (
10 GlobalSettingsStateManager, EnvironmentStateManager)
10 from juju.state.initialize import StateHierarchy 11 from juju.state.initialize import StateHierarchy
11 from juju.state.machine import MachineStateManager 12 from juju.state.machine import MachineStateManager
12
13 from juju.lib.testing import TestCase
14 from juju.tests.common import get_test_zookeeper_address 13 from juju.tests.common import get_test_zookeeper_address
15 14
16 15
17 class LayoutTest(TestCase): 16 class LayoutTest(EnvironmentsConfigTestBase):
18 17
18 @inlineCallbacks
19 def setUp(self): 19 def setUp(self):
20 yield super(LayoutTest, self).setUp()
20 self.log = self.capture_logging("juju.state.init") 21 self.log = self.capture_logging("juju.state.init")
21 zookeeper.set_debug_level(0) 22 zookeeper.set_debug_level(0)
22 self.client = ZookeeperClient(get_test_zookeeper_address()) 23 self.client = ZookeeperClient(get_test_zookeeper_address())
23 self.identity = make_identity("admin:genie") 24 self.identity = make_identity("admin:genie")
25 constraints_data = {
26 "arch": "arm",
27 "cpu": None,
28 "ubuntu-series": "cranky",
29 "provider-type": "dummy"}
24 self.layout = StateHierarchy( 30 self.layout = StateHierarchy(
25 self.client, self.identity, "i-abcdef", "dummy") 31 self.client, self.identity, "i-abcdef", constraints_data, "dummy")
26 return self.client.connect() 32 yield self.client.connect()
27 33
28 def tearDown(self): 34 def tearDown(self):
29 deleteTree(handle=self.client.handle) 35 deleteTree(handle=self.client.handle)
30 self.client.close() 36 self.client.close()
31 37
32 @inlineCallbacks 38 @inlineCallbacks
33 def assert_existence_and_acl(self, path): 39 def assert_existence_and_acl(self, path):
34 exists = yield self.client.exists(path) 40 exists = yield self.client.exists(path)
35 self.assertTrue(exists) 41 self.assertTrue(exists)
36 acls, stat = yield self.client.get_acl(path) 42 acls, stat = yield self.client.get_acl(path)
37 43
38 found_admin_acl = False 44 found_admin_acl = False
39 for acl in acls: 45 for acl in acls:
40 if acl["id"] == self.identity \ 46 if acl["id"] == self.identity \
41 and acl["perms"] == zookeeper.PERM_ALL: 47 and acl["perms"] == zookeeper.PERM_ALL:
42 found_admin_acl = True 48 found_admin_acl = True
43 break 49 break
44 self.assertTrue(found_admin_acl) 50 self.assertTrue(found_admin_acl)
45 51
46 @inlineCallbacks 52 @inlineCallbacks
47 def test_initialize(self): 53 def test_initialize(self):
48 lsb_release = self.makeFile(
49 "BLAH=blah\nDISTRIB_CODENAME=cantankerous\nBLAH=blah\n")
50 from juju.state import initialize
51 self.patch(initialize, "LSB_RELEASE_PATH", lsb_release)
52
53 yield self.layout.initialize() 54 yield self.layout.initialize()
54 55
55 yield self.assert_existence_and_acl("/charms") 56 yield self.assert_existence_and_acl("/charms")
56 yield self.assert_existence_and_acl("/services") 57 yield self.assert_existence_and_acl("/services")
57 yield self.assert_existence_and_acl("/units") 58 yield self.assert_existence_and_acl("/units")
58 yield self.assert_existence_and_acl("/machines") 59 yield self.assert_existence_and_acl("/machines")
59 yield self.assert_existence_and_acl("/relations") 60 yield self.assert_existence_and_acl("/relations")
60 yield self.assert_existence_and_acl("/initialized") 61 yield self.assert_existence_and_acl("/initialized")
61 62
63 # To check that the constraints landed correctly, we need the
64 # environment config to have been sent, or we won't be able to
65 # get a provider to help us construct the appropriate objects.
66 yield self.push_default_config(with_constraints=False)
67
68 esm = EnvironmentStateManager(self.client)
69 env_constraints = yield esm.get_constraints()
70 self.assertEquals(env_constraints, {
71 "provider-type": "dummy",
72 "ubuntu-series": None,
73 "arch": "arm",
74 "cpu": None,
75 "mem": 512})
76
62 machine_state_manager = MachineStateManager(self.client) 77 machine_state_manager = MachineStateManager(self.client)
63 machine_state = yield machine_state_manager.get_machine_state(0) 78 machine_state = yield machine_state_manager.get_machine_state(0)
64 constraints = yield machine_state.get_constraints() 79 machine_constraints = yield machine_state.get_constraints()
65 self.assertTrue(constraints.complete) 80 self.assertTrue(machine_constraints.complete)
66 self.assertEquals(constraints["provider-type"], "dummy") 81 self.assertEquals(machine_constraints, {
67 self.assertEquals(constraints["ubuntu-series"], "cantankerous") 82 "provider-type": "dummy",
83 "ubuntu-series": "cranky",
84 "arch": "arm",
85 "cpu": None,
86 "mem": 512})
68 instance_id = yield machine_state.get_instance_id() 87 instance_id = yield machine_state.get_instance_id()
69 self.assertEqual(instance_id, "i-abcdef") 88 self.assertEqual(instance_id, "i-abcdef")
70 89
71 settings_manager = GlobalSettingsStateManager(self.client) 90 settings_manager = GlobalSettingsStateManager(self.client)
72 self.assertEqual((yield settings_manager.get_provider_type()), "dummy") 91 self.assertEqual((yield settings_manager.get_provider_type()), "dummy")
73 self.assertEqual( 92 self.assertEqual(
74 self.log.getvalue().strip(), 93 self.log.getvalue().strip(),
75 "Initializing zookeeper hierarchy") 94 "Initializing zookeeper hierarchy")
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b