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

Proposed by Francesco Banconi
Status: Merged
Approved by: Graham Binns
Approved revision: 11
Merged at revision: 10
Proposed branch: lp:~frankban/charms/oneiric/buildbot-slave/tests_again
Merge into: lp:~yellow/charms/oneiric/buildbot-slave/trunk
Diff against target: 185 lines (+56/-63)
2 files modified
hooks/install (+2/-2)
tests/buildbot-slave.test (+54/-61)
To merge this branch: bzr merge lp:~frankban/charms/oneiric/buildbot-slave/tests_again
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+92256@code.launchpad.net

Description of the change

- buildslave charm tests refactoring
- using run function to chmod the script in install hook
- changed symlinks (helpers.py, tests.cfg)

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

82 + wait_for_unit(service_name, timeout=600)

We should probably add an XXX here to remind ourselves to try and either bring this down or do something smarter with it depending on the state of the Juju environment.

review: Approve (code)
12. By Francesco Banconi

Added timeout XXX.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/install'
--- hooks/install 2012-02-09 10:05:06 +0000
+++ hooks/install 2012-02-09 12:09:17 +0000
@@ -10,6 +10,7 @@
10 log,10 log,
11 log_entry,11 log_entry,
12 log_exit,12 log_exit,
13 run,
13 )14 )
14import os15import os
15import shlex16import shlex
@@ -70,8 +71,7 @@
70 log('Retrieving script: {}.'.format(url))71 log('Retrieving script: {}.'.format(url))
71 script = retrieve(url, path)72 script = retrieve(url, path)
72 log('Changing script mode.')73 log('Changing script mode.')
73 chmod = command('chmod')74 run('chmod', '+x', script)
74 chmod('+x', script)
75 log('Executing script: {}.'.format(script))75 log('Executing script: {}.'.format(script))
76 return subprocess.call([script] + shlex.split(str(args)))76 return subprocess.call([script] + shlex.split(str(args)))
7777
7878
=== modified file 'tests/buildbot-slave.test'
--- tests/buildbot-slave.test 2012-02-08 18:00:09 +0000
+++ tests/buildbot-slave.test 2012-02-09 12:09:17 +0000
@@ -12,6 +12,8 @@
12 command,12 command,
13 encode_file,13 encode_file,
14 unit_info,14 unit_info,
15 wait_for_unit,
16 wait_for_relation,
15 )17 )
16from openport import (18from openport import (
17 PORT,19 PORT,
@@ -19,12 +21,6 @@
19 )21 )
2022
2123
22# To run tests, having juju bootstrapped:
23# JUJU_REPOSITORY=. oneiric/buildbot-slave/tests/buildbot-slave.test
24# XXX 2012-02-08 gmb:
25# This needs reducing; it's set high for debugging purposes only.
26MAX_ATTEMPTS = 600
27
28juju = command('juju')24juju = command('juju')
2925
3026
@@ -35,10 +31,15 @@
35 self.repository = os.getenv('JUJU_REPOSITORY')31 self.repository = os.getenv('JUJU_REPOSITORY')
36 self.environment = os.getenv('JUJU_ENVIRONMENT')32 self.environment = os.getenv('JUJU_ENVIRONMENT')
37 self.tests_dir = os.path.dirname(os.path.abspath(__file__))33 self.tests_dir = os.path.dirname(os.path.abspath(__file__))
3834 self.started_services = set()
39 def deploy(self, config=None, sleep_time=0.1, charm_name=None):35
40 deploy_name = charm_name = charm_name or self.charm_name36 def tearDown(self):
37 for service_name in self.started_services:
38 juju('destroy-service', service_name)
39
40 def deploy(self, service_name, config=None):
41 args = ['deploy']41 args = ['deploy']
42 deploy_name = service_name
42 if self.repository is not None:43 if self.repository is not None:
43 args.append('--repository=' + self.repository)44 args.append('--repository=' + self.repository)
44 deploy_name = 'local:' + deploy_name45 deploy_name = 'local:' + deploy_name
@@ -48,24 +49,29 @@
48 args.append('--config=' + config)49 args.append('--config=' + config)
49 args.append(deploy_name)50 args.append(deploy_name)
50 juju(*args)51 juju(*args)
51 status_attempts = 052 self.started_services.add(service_name)
52 while status_attempts < MAX_ATTEMPTS:53 # XXX 2012-02-09 frankban
53 status = unit_info(charm_name, 'state')54 # We use a timeout of 600 seconds to avoid runtime errors
54 if 'error' in status:55 # occurring if the instance is not created
55 return False56 # (e.g. just after `juju bootstrap`).
56 if status == 'started':57 # We should try to wait for unit in a smarter way
57 return True58 # (maybe checking for "pending"?).
58 time.sleep(sleep_time)59 wait_for_unit(service_name, timeout=600)
59 status_attempts += 160
60 raise Exception("Charm took too long to deploy.")61 def add_relation(self, relation, service1, service2):
62 juju('add-relation',
63 '{}:{}'.format(service1, relation),
64 '{}:{}'.format(service2, relation))
65 wait_for_relation(service1, relation)
66
67 def get_url(self, service_name, port, path=''):
68 address = unit_info(service_name, 'public-address')
69 return 'http://{}:{}{}'.format(address, port, path)
6170
62 def test_deploy(self):71 def test_deploy(self):
63 # Ensure the charm starts correctly when deployed.72 # Ensure the charm starts correctly when deployed.
64 try:73 self.deploy(self.charm_name)
65 started = self.deploy()74 self.assertEqual('started', unit_info(self.charm_name, 'state'))
66 self.assertTrue(started)
67 finally:
68 juju('destroy-service', self.charm_name)
6975
70 def do_not_test_script(self):76 def do_not_test_script(self):
71 # DISABLED BECAUSE IT FAILS ALL THE TIME.77 # DISABLED BECAUSE IT FAILS ALL THE TIME.
@@ -87,44 +93,31 @@
8793
88 def test_master_slave_relationship(self):94 def test_master_slave_relationship(self):
89 master_charm_name = 'buildbot-master'95 master_charm_name = 'buildbot-master'
96 self.deploy(master_charm_name)
97 self.deploy(self.charm_name)
98 juju('set', master_charm_name, 'extra-packages=git')
99 config_path = os.path.join(os.path.dirname(__file__), 'test.cfg')
100 config = encode_file(config_path)
101 juju('set', 'buildbot-master', 'config-file='+config)
102 juju('expose', master_charm_name)
103 juju('set', self.charm_name, 'builders=runtests')
104 # XXX 2012-02-08 gmb
105 # This avoids us trying to check whether the slave
106 # is connected until the relation is initialized,
107 # but... (see next XXX)
108 self.add_relation('buildbot', self.charm_name, master_charm_name)
109 # XXX 2012-02-08 gmb:
110 # This still sometimes gets called _before_ the
111 # buildslave connects to the buildbot master. Hence
112 # this rather ugly sleep here.
113 time.sleep(5)
114 url = self.get_url(master_charm_name, 8010, '/buildslaves')
90 try:115 try:
91 self.deploy(charm_name=master_charm_name)116 stream = urllib2.urlopen(url)
92 self.deploy()117 except urllib2.HTTPError:
93 juju('set', master_charm_name, 'extra-packages=git')118 self.fail('Unable to connect to {}.'.format(url))
94 encoded_config = encode_file(119 self.assertIn('Idle', stream.read())
95 os.path.join(self.tests_dir, '..', 'examples', 'master.cfg'))120
96 juju(
97 'set', master_charm_name,
98 'config-file={}'.format(encoded_config))
99 juju('expose', master_charm_name)
100 juju('set', self.charm_name, 'builders=runtests')
101 juju('add-relation', self.charm_name, master_charm_name)
102 address = unit_info(master_charm_name, 'public-address')
103 url = 'http://{}:{}/buildslaves'.format(address, 8010)
104 # Wait for buildbot to restart, since there's a
105 # potential race condition with an asynchronous service.
106 while True:
107 # XXX 2012-02-08 gmb
108 # This avoids us trying to check whether the slave
109 # is connected until the relation is initialized,
110 # but... (see next XXX)
111 relation_info = unit_info(self.charm_name, 'relations')
112 if relation_info['buildbot']['state'] == 'up':
113 break
114 time.sleep(0.1)
115 try:
116 # XXX 2012-02-08 gmb:
117 # This still sometimes gets called _before_ the
118 # buildslave connects to the buildbot master. Hence
119 # this rather ugly sleep here.
120 time.sleep(5)
121 stream = urllib2.urlopen(url)
122 except urllib2.HTTPError:
123 self.fail('Unable to connect to {}.'.format(url))
124 self.assertIn('Idle', stream.read())
125 finally:
126 juju('destroy-service', self.charm_name)
127 juju('destroy-service', master_charm_name)
128121
129if __name__ == '__main__':122if __name__ == '__main__':
130 unittest.main()123 unittest.main()
131124
=== modified symlink 'tests/helpers.py'
=== target changed u'../../buildbot-master/hooks/helpers.py' => u'../hooks/helpers.py'
=== added symlink 'tests/test.cfg'
=== target is u'../../buildbot-master/tests/test.cfg'

Subscribers

People subscribed via source and target branches