Merge lp:~aisrael/juju-deployer/workaround-lp-1421315 into lp:juju-deployer

Proposed by Adam Israel
Status: Merged
Merged at revision: 146
Proposed branch: lp:~aisrael/juju-deployer/workaround-lp-1421315
Merge into: lp:juju-deployer
Diff against target: 63 lines (+25/-6)
1 file modified
deployer/action/importer.py (+25/-6)
To merge this branch: bzr merge lp:~aisrael/juju-deployer/workaround-lp-1421315
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Review via email: mp+254328@code.launchpad.net

Description of the change

I recently ran into a bug lp:1421315 while reviewing a merge request (lp:238283)

juju-deployer would throw an exception due to the service not being available in the watch status output. This fix expands on the original workaround, to wait 5.1 seconds for status (which is supposed to be available in 5 seconds) to be available. In this merge, the check is wrapped in a while block that will attempt to read the status for the specific unit, for up to 60 seconds, before failing.

I have tested this against the above merge request, and it eliminated all related testing errors.

To post a comment you must log in.
Revision history for this message
Adam Israel (aisrael) wrote :
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deployer/action/importer.py'
2--- deployer/action/importer.py 2015-03-24 17:38:56 +0000
3+++ deployer/action/importer.py 2015-03-27 00:25:46 +0000
4@@ -23,8 +23,22 @@
5 env_status = self.env.status()
6 reloaded = False
7
8+ # Workaround an issue where watch output doesn't include subordinate
9+ # services right away, and add_unit would fail while attempting to add
10+ # units to a non-existant service. See lp:1421315 for details.
11+ cur_units = 0
12 for svc in self.deployment.get_services():
13- cur_units = len(env_status['services'][svc.name].get('units', ()))
14+ delay = time.time() + 60
15+ while delay > time.time():
16+ if svc.name in env_status['services']:
17+ cur_units = len(
18+ env_status['services'][svc.name].get('units', ())
19+ )
20+ if cur_units > 0:
21+ break
22+ time.sleep(5)
23+ env_status = self.env.status()
24+
25 delta = (svc.num_units - cur_units)
26
27 if delta <= 0:
28@@ -45,9 +59,14 @@
29 if svc.unit_placement:
30 # Reload status once after non placed services units are done.
31 if reloaded is False:
32- # Crappy workaround juju-core api inconsistency
33- time.sleep(5.1)
34- env_status = self.env.status()
35+ # Improved crappy workaround juju-core api inconsistency
36+ delay = time.time() + 60
37+ while delay > time.time():
38+ time.sleep(5.1)
39+ env_status = self.env.status()
40+ if svc.name in env_status['services']:
41+ break
42+
43 reloaded = True
44
45 placement = self.deployment.get_unit_placement(svc, env_status)
46@@ -70,7 +89,7 @@
47 foo: bar
48 1:
49 constraints: "mem=4G"
50-
51+
52 This method first attempts to create any machines in the 'machines'
53 section of the bundle specification with the given constraints and
54 annotations. Then, if there are any machines requested for containers
55@@ -81,7 +100,7 @@
56 self.log.info("Creating machines...")
57 for machine_name, spec in machines.items():
58 self.machines[machine_name] = self.env.add_machine(
59- series=spec.get('series',
60+ series=spec.get('series',
61 self.deployment.data['series']),
62 constraints=spec.get('constraints'))
63 annotations = spec.get('annotations')

Subscribers

People subscribed via source and target branches