Merge lp:~gmb/charms/oneiric/buildbot-master/tests-fixes into lp:~yellow/charms/oneiric/buildbot-master/trunk

Proposed by Graham Binns
Status: Merged
Approved by: Brad Crittenden
Approved revision: 17
Merged at revision: 16
Proposed branch: lp:~gmb/charms/oneiric/buildbot-master/tests-fixes
Merge into: lp:~yellow/charms/oneiric/buildbot-master/trunk
Diff against target: 47 lines (+20/-3)
1 file modified
hooks/helpers.py (+20/-3)
To merge this branch: bzr merge lp:~gmb/charms/oneiric/buildbot-master/tests-fixes
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+92091@code.launchpad.net

Description of the change

Changes from gmb and frankban 2012-02-08:
=========================================

 - Added some tweaks to helpers.py to make testing a bit easier.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Francesco and Graham,

These changes look good.

I think if you use base64.b64encode() you don't get the extra '\n' and may not need to strip it.

s/proably/probably

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/helpers.py'
2--- hooks/helpers.py 2012-02-07 14:37:13 +0000
3+++ hooks/helpers.py 2012-02-08 17:46:18 +0000
4@@ -19,9 +19,11 @@
5 'unit_info',
6 ]
7
8+import base64
9 import json
10 import os
11 import re
12+import StringIO
13 import subprocess
14 import sys
15 from textwrap import dedent
16@@ -90,13 +92,28 @@
17
18 def unit_info(service_name, item_name, data=None):
19 if data is None:
20- data = yaml.safe_load(run('juju', 'status'))
21- services = data['services'][service_name]
22- units = services['units']
23+ output = subprocess.check_output(['juju', 'status'], shell=False)
24+ data = yaml.safe_load(output)
25+ service = data['services'].get(service_name)
26+ if service is None:
27+ # XXX 2012-02-08 gmb:
28+ # This allows us to cope with the race condition that we
29+ # have between deploying a service and having it come up in
30+ # `juju status`. We could proably do with cleaning it up so
31+ # that it fails a bit more noisily after a while.
32+ return ''
33+ units = service['units']
34 item = units.items()[0][1][item_name]
35 return item
36
37
38+def encode_file(filename):
39+ """base64 encode the contents of a file and return it."""
40+ with open(filename) as f:
41+ contents = f.read()
42+ return base64.encodestring(contents).strip()
43+
44+
45 def grep(content, filename):
46 with open(filename) as f:
47 for line in f:

Subscribers

People subscribed via source and target branches

to all changes: