Merge lp:~frankban/charms/oneiric/buildbot-slave/02-09 into lp:~yellow/charms/oneiric/buildbot-slave/trunk

Proposed by Francesco Banconi
Status: Merged
Approved by: Brad Crittenden
Approved revision: 18
Merged at revision: 12
Proposed branch: lp:~frankban/charms/oneiric/buildbot-slave/02-09
Merge into: lp:~yellow/charms/oneiric/buildbot-slave/trunk
Diff against target: 231 lines (+95/-58)
6 files modified
HACKING.txt (+27/-0)
juju_wrapper (+22/-0)
tests/buildbot-slave.test (+23/-17)
tests/config.test.yaml (+2/-3)
tests/create_file.py (+21/-0)
tests/openport.py (+0/-38)
To merge this branch: bzr merge lp:~frankban/charms/oneiric/buildbot-slave/02-09
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+92340@code.launchpad.net

Description of the change

Changes from frankban and gmb (2012-02-09)
==========================================

- added hacking info
- charms repository for tests is now handled by juju_wrapper
- implemented the script test (ensure that a script is correctly downloaded and executed when `juju deploy` is called using a config file).

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

Hi this branch looks good.

I was a bit confused by the trailing '--' in the ssh command set up. It appears to be undocumented and unnecessary. Unless you have a reason that it must be there, please delete or comment its use.

The duplication of the juju_wrapper is also thorny. I checked around jelmer's work on bzr nested trees is not yet ready. I'm at a loss for a workable solution to these shared files. Very annoying.

Since this branch is self-contained and no one depends on it I am not going to merge it today (as I did for branches yesterday).

review: Approve (code)
Revision history for this message
Brad Crittenden (bac) wrote :

Benji and I talked about the '--' trailing option on ssh and he convinced me it may be useful in some circumstances I hadn't considered. Please keep it but add a comment.

19. By Francesco Banconi

Comment for double dash.

Revision history for this message
Francesco Banconi (frankban) wrote :

Thank you Brad. Added a comment for "--", merging.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'HACKING.txt'
2--- HACKING.txt 1970-01-01 00:00:00 +0000
3+++ HACKING.txt 2012-02-10 09:42:18 +0000
4@@ -0,0 +1,27 @@
5+Running the charm tests
6+=======================
7+
8+1) Establish a charm repository if you do not already have one. A charm
9+ repository is a directory with subdirectories for each Ubuntu version being
10+ used. Inside those per-Ubuntu-version directories are the charm
11+ directories. For example, to make a charm repository for this charm under
12+ Oneiric follow these steps:
13+
14+ a) mkdir -p ~/juju-charms/oneiric
15+ b) ln -s `pwd` ~/juju-charms/oneiric/buildbot-slave
16+
17+2) Copy the juju_wrapper file into some place earlier in your PATH than the
18+ real juju executable, naming it "juju". Edit the CHARM_TEST_REPO variable
19+ therein to reflect the location of the charm repo from step 1.
20+
21+3) Bootstrap the juju environment if not already done:
22+
23+ juju bootstrap
24+
25+4) Run the tests: RESOLVE_TEST_CHARMS=1 tests/buildbot-slave.test
26+
27+
28+Running the charm helper tests
29+==============================
30+
31+Just run "python hooks/tests.py".
32
33=== added file 'juju_wrapper'
34--- juju_wrapper 1970-01-01 00:00:00 +0000
35+++ juju_wrapper 2012-02-10 09:42:18 +0000
36@@ -0,0 +1,22 @@
37+#!/bin/sh
38+
39+# Copyright 2012 Canonical Ltd. This software is licensed under the
40+# GNU Affero General Public License version 3 (see the file LICENSE).
41+
42+[ -n "$RESOLVE_TEST_CHARMS" ] || exec /usr/bin/juju $@
43+#set -x
44+
45+CHARM_TEST_REPO=~/juju-charms # <---- Change this.
46+
47+cmd=$1
48+case $cmd in
49+deploy)
50+ shift
51+ charm=$1
52+ shift
53+ exec /usr/bin/juju deploy --repository $CHARM_TEST_REPO local:$charm $@
54+ ;;
55+*)
56+ exec /usr/bin/juju $@
57+ ;;
58+esac
59
60=== modified file 'tests/buildbot-slave.test'
61--- tests/buildbot-slave.test 2012-02-09 15:49:50 +0000
62+++ tests/buildbot-slave.test 2012-02-10 09:42:18 +0000
63@@ -4,7 +4,6 @@
64 # GNU Affero General Public License version 3 (see the file LICENSE).
65
66 import os
67-import time
68 import unittest
69
70 from helpers import (
71@@ -15,9 +14,9 @@
72 wait_for_relation,
73 wait_for_unit,
74 )
75-from openport import (
76- PORT,
77- TEXT,
78+from create_file import (
79+ CONTENT,
80+ PATH,
81 )
82
83
84@@ -28,7 +27,6 @@
85
86 def setUp(self):
87 self.charm_name = 'buildbot-slave'
88- self.repository = os.getenv('JUJU_REPOSITORY')
89 self.environment = os.getenv('JUJU_ENVIRONMENT')
90 self.tests_dir = os.path.dirname(os.path.abspath(__file__))
91 self.started_services = set()
92@@ -38,24 +36,13 @@
93 juju('destroy-service', service_name)
94
95 def deploy(self, service_name, config=None):
96- args = ['deploy']
97- deploy_name = service_name
98- if self.repository is not None:
99- args.append('--repository=' + self.repository)
100- deploy_name = 'local:' + deploy_name
101+ args = ['deploy', service_name]
102 if self.environment is not None:
103 args.append('--environment=' + self.environment)
104 if config:
105 args.append('--config=' + config)
106- args.append(deploy_name)
107 juju(*args)
108 self.started_services.add(service_name)
109- # XXX 2012-02-09 frankban
110- # We use a timeout of 600 seconds to avoid runtime errors
111- # occurring if the instance is not created
112- # (e.g. just after `juju bootstrap`).
113- # We should try to wait for unit in a smarter way
114- # (maybe checking for "pending"?).
115
116 def add_relation(self, relation, service1, service2):
117 juju('add-relation',
118@@ -74,6 +61,7 @@
119 self.assertEqual('started', unit_info(self.charm_name, 'state'))
120
121 def test_master_slave_relationship(self):
122+ # Ensure the master-slave relationship is correctly established.
123 master_charm_name = 'buildbot-master'
124 # We deploy both and then wait because it's quite a bit faster.
125 self.deploy(master_charm_name)
126@@ -91,6 +79,24 @@
127 wait_for_page_contents(url, 'buildbot-slave/')
128 wait_for_page_contents(url, 'Idle')
129
130+ def test_script(self):
131+ # Ensure the script is run when the charm is deployed.
132+ config = os.path.join(self.tests_dir, 'config.test.yaml')
133+ self.deploy(self.charm_name, config=config)
134+ wait_for_unit(self.charm_name)
135+ address = unit_info(self.charm_name, 'public-address')
136+ ssh = command(
137+ 'ssh',
138+ '-o', 'StrictHostKeyChecking=no',
139+ '-o', 'UserKnownHostsFile=/dev/null',
140+ 'ubuntu@' + address,
141+ # Double dash here tells ssh not to try to parse what comes
142+ # after it as command line options.
143+ '--',
144+ )
145+ self.assertEqual(CONTENT, ssh('cat {}'.format(PATH)))
146+ ssh('rm {}'.format(PATH))
147+
148
149 if __name__ == '__main__':
150 unittest.main()
151
152=== modified file 'tests/config.test.yaml'
153--- tests/config.test.yaml 2012-02-08 14:38:12 +0000
154+++ tests/config.test.yaml 2012-02-10 09:42:18 +0000
155@@ -1,5 +1,4 @@
156 buildbot-slave:
157 script-retrieval-method: bzr_cat
158- script-url: "http://bazaar.launchpad.net/~yellow/charms/oneiric/buildbot-slave/charm-tests/tests/openport.py"
159- script-path: openport.py
160- script-args: -d
161+ script-url: "http://bazaar.launchpad.net/~yellow/charms/oneiric/buildbot-slave/charm-tests/tests/create_file.py"
162+ script-path: create_file.py
163
164=== added file 'tests/create_file.py'
165--- tests/create_file.py 1970-01-01 00:00:00 +0000
166+++ tests/create_file.py 2012-02-10 09:42:18 +0000
167@@ -0,0 +1,21 @@
168+#!/usr/bin/env python
169+
170+# Copyright 2012 Canonical Ltd. This software is licensed under the
171+# GNU Affero General Public License version 3 (see the file LICENSE).
172+
173+# A little python script to create a file on the buildslave so that we can
174+# test that it's actually deployed successfully.
175+
176+import pwd
177+import os
178+
179+CONTENT = 'IT WORKS!'
180+PATH = '/tmp/buildslave_test'
181+
182+
183+if __name__ == "__main__":
184+ with open(PATH, 'w') as f:
185+ f.write(CONTENT)
186+ os.chmod(PATH, 0777)
187+ userdata = pwd.getpwnam('ubuntu')
188+ os.chown(PATH, userdata.pw_uid, userdata.pw_gid)
189
190=== removed file 'tests/openport.py'
191--- tests/openport.py 2012-02-08 14:45:58 +0000
192+++ tests/openport.py 1970-01-01 00:00:00 +0000
193@@ -1,38 +0,0 @@
194-#!/usr/bin/env python
195-
196-# Copyright 2012 Canonical Ltd. This software is licensed under the
197-# GNU Affero General Public License version 3 (see the file LICENSE).
198-
199-# A little python script to open a port on the buildslave so that we can
200-# test that it's actually deployed successfully.
201-
202-import os
203-import sys
204-import subprocess
205-from BaseHTTPServer import (
206- BaseHTTPRequestHandler,
207- HTTPServer,
208- )
209-
210-
211-PORT = 9000
212-TEXT = 'The slave is UP!'
213-
214-
215-class Handler(BaseHTTPRequestHandler):
216- def do_GET(self):
217- self.send_response(200, 'OK')
218- self.send_header('Content-type', 'text/palin')
219- self.end_headers()
220- self.wfile.write(TEXT)
221-
222-
223-if __name__ == "__main__":
224- ## HACKETTY HACK.
225- options = sys.argv[1:]
226- if options and options[0] == '-d':
227- # OH MY GOD.
228- os.system('{} &'.format(sys.argv[0]))
229- sys.exit(0)
230- subprocess.call(['open-port', '{}/TCP'.format(PORT)])
231- HTTPServer(('', PORT), Handler).serve_forever()

Subscribers

People subscribed via source and target branches