Merge lp:~cprov/uci-engine/tarmac-multienv into lp:uci-engine

Proposed by Celso Providelo
Status: Merged
Approved by: Celso Providelo
Approved revision: 927
Merged at revision: 921
Proposed branch: lp:~cprov/uci-engine/tarmac-multienv
Merge into: lp:uci-engine
Diff against target: 359 lines (+111/-25)
15 files modified
bin/called-by-tarmac.py (+27/-4)
juju-deployer/deploy.py (+3/-3)
juju-deployer/relations.yaml (+3/-0)
juju-deployer/services.yaml.tmpl (+13/-0)
tests/deployers.py (+18/-0)
tests/test_britney.py (+4/-10)
tests/test_bsbuilder.py (+2/-0)
tests/test_image_builder.py (+2/-0)
tests/test_ppacreator.py (+2/-0)
tests/test_publisher.py (+2/-0)
tests/test_rabbit.py (+2/-0)
tests/test_test_runner.py (+4/-0)
tests/test_ticket_system.py (+1/-6)
tests/test_validator.py (+2/-0)
tests/test_webui.py (+26/-2)
To merge this branch: bzr merge lp:~cprov/uci-engine/tarmac-multienv
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
Francis Ginther Needs Information
Review via email: mp+246333@code.launchpad.net

Commit message

Supporting multi-system deployment for tests.

Description of the change

Supporting multi-system deployment for tests.

`called-by-tarmac`.py was modified to deploy one or more systems before running the tests, it was done under the premise that system *can* co-exist on the same tenant, i.e common services will be shared (e.g. rabbit).

`DeployerTest` was extended to require an specific service, if not available the test is skipped. Existing integration tests were adjusted.

In order to test the feature a minimal 'ci-ubuntucore' configuration was created for deploying rabbit, TR and Apache. There is also an integration test checking that the apache is alive but not configured (:-/).

To post a comment you must log in.
lp:~cprov/uci-engine/tarmac-multienv updated
926. By Celso Providelo

typo

Revision history for this message
Francis Ginther (fginther) wrote :

A novel way to solve the problem. Just have a question inline.

review: Needs Information
Revision history for this message
Vincent Ladeuil (vila) wrote :

Excellent !

I like the way this makes the test dependency purely declarative.

Only one minor nit inline otherwise, good to land.

review: Needs Fixing
Revision history for this message
Celso Providelo (cprov) wrote :

Thanks Francis and Vincent,

I've extended the base test class to fail if 'required_service' is not provided by client implementations, it will force us to write clearer tests.

Let's see if tarmac likes it too.

lp:~cprov/uci-engine/tarmac-multienv updated
927. By Celso Providelo

Addressing review comments, 'required_service' becomes mandatory for test implementations.

Revision history for this message
Vincent Ladeuil (vila) wrote :

\o/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/called-by-tarmac.py'
2--- bin/called-by-tarmac.py 2014-11-21 13:42:55 +0000
3+++ bin/called-by-tarmac.py 2015-01-14 10:17:09 +0000
4@@ -16,6 +16,14 @@
5 sys.path.insert(0, os.path.join(HERE, '..'))
6 from testing import venv
7
8+# List of systems that should be deployed before running all tests.
9+# It assumes the systems can co-exist under the same tenant, i.e.
10+# common services will be shared (e.g. rabbit).
11+testing_systems = (
12+ 'ci-airline',
13+ 'ci-ubuntucore',
14+)
15+
16
17 def check_lxc_mounted():
18 out = subprocess.check_output(['mount'])
19@@ -61,6 +69,24 @@
20 return True
21
22
23+def deploy_testing_systems():
24+ """Deploy 'testing_systems'.
25+
26+ Stops if `deploy.main()` failed for any specified system and returns
27+ its 'return_code', otherwise returns ZERO.
28+ """
29+ # deploy.py isn't in our pythonpath when run as a script
30+ sys.path.append(os.path.abspath('juju-deployer'))
31+ import deploy
32+
33+ rc = 0
34+ for name in testing_systems:
35+ rc = deploy.main(['--name', name])
36+ if rc != 0:
37+ break
38+ return rc
39+
40+
41 def destroy_environment():
42 '''Destroy the local environment. Return True if successful, False
43 otherwise.'''
44@@ -200,9 +226,6 @@
45 raise
46
47 from testing import run_tests
48- # deploy.py isn't in our pythonpath when run as a script
49- sys.path.append(os.path.abspath('juju-deployer'))
50- import deploy
51
52 try:
53 with open('/dev/null', 'w') as null:
54@@ -221,7 +244,7 @@
55 logging.info('Deploying.')
56 t = time.time()
57 # Bootstrap, then deploy.
58- if not bootstrap() or deploy.main() != 0:
59+ if not bootstrap() or deploy_testing_systems() != 0:
60 metrics.timing('counters.failures.deploy')
61 return 1
62 metrics.timing('deploy')
63
64=== modified file 'juju-deployer/deploy.py'
65--- juju-deployer/deploy.py 2015-01-06 18:41:34 +0000
66+++ juju-deployer/deploy.py 2015-01-14 10:17:09 +0000
67@@ -933,7 +933,7 @@
68 help='Build the deployment for --working-dir.')
69 parser.add_argument('--name', default='ci-airline',
70 choices=('ci-airline', 'ci-airline-experimental',
71- 'ci-airline-for-britney'),
72+ 'ci-airline-for-britney', 'ci-ubuntucore'),
73 help='''The name of the juju-deployer "stack".
74 Default=%(default)s''')
75 parser.add_argument(
76@@ -987,8 +987,8 @@
77 bootstrap()
78
79
80-def main():
81- args = _get_args()
82+def main(args=None):
83+ args = _get_args(args)
84
85 # You can configure the system to use private PPAs only or by providing
86 # the option --private-ppas-only or by setting the environment variable
87
88=== modified file 'juju-deployer/relations.yaml'
89--- juju-deployer/relations.yaml 2014-11-26 23:37:34 +0000
90+++ juju-deployer/relations.yaml 2015-01-14 10:17:09 +0000
91@@ -118,3 +118,6 @@
92 - ["ci-airline-nfss-restish:pgsql", "ci-airline-nfss-postgres:db"]
93 - ["ci-airline-nfss-apache:reverseproxy", "ci-airline-nfss-restish:website"]
94 - ["ci-airline-nfss-apache", "ci-airline-nfss-content-fetcher"]
95+
96+ci-ubuntucore:
97+ inherits: common
98
99=== modified file 'juju-deployer/services.yaml.tmpl'
100--- juju-deployer/services.yaml.tmpl 2015-01-06 18:41:34 +0000
101+++ juju-deployer/services.yaml.tmpl 2015-01-14 10:17:09 +0000
102@@ -417,3 +417,16 @@
103 ci-airline-nfss-postgres:
104 branch: lp:charms/trusty/postgresql@95
105 charm: postgresql
106+
107+ci-ubuntucore:
108+ series: precise
109+ inherits: common
110+ services:
111+ ci-ubuntucore-webui-apache:
112+ charm: apache2
113+ constraints: "mem=1024M"
114+ branch: lp:charms/precise/apache2@54
115+ options:
116+ enable_modules: "rewrite proxy proxy_http ssl"
117+ servername: ci_ubuntu_core_webui_apache
118+ expose: true
119
120=== modified file 'tests/deployers.py'
121--- tests/deployers.py 2014-11-06 13:40:54 +0000
122+++ tests/deployers.py 2015-01-14 10:17:09 +0000
123@@ -97,6 +97,24 @@
124 class DeployerTest(testing.TestCaseWithGnupg):
125 '''Base class for building juju deployer based tests.'''
126
127+ required_service = None
128+
129+ def setUp(self):
130+ """Check for 'required_service' availability."""
131+ super(DeployerTest, self).setUp()
132+ self.assertIsNotNone(
133+ self.required_service,
134+ "The test class should provide a 'self.required_service' to be "
135+ "verified before running the tests.")
136+ status = deploy.juju_status()
137+ try:
138+ units = status['services'][self.required_service]['units']
139+ units['{}/0'.format(self.required_service)]
140+ except KeyError:
141+ self.skipTest(
142+ 'Required service {} not available'.format(
143+ self.required_service))
144+
145 def get_ip_and_port(self, service, unit=0):
146 return juju_get_ip_and_port(service, unit)
147
148
149=== modified file 'tests/test_britney.py'
150--- tests/test_britney.py 2015-01-08 10:42:09 +0000
151+++ tests/test_britney.py 2015-01-14 10:17:09 +0000
152@@ -43,14 +43,6 @@
153 )
154
155
156-def requires_britney_deployment(test, status):
157- try:
158- br = status['services']['ci-airline-for-britney-requests']['units']
159- br['ci-airline-for-britney-requests/0']
160- except KeyError:
161- test.skipTest('Not a ci-airline-for-britney deployment')
162-
163-
164 def get_rabbit_ip(status):
165 units = status['services']['ci-airline-rabbit']['units']
166 rabbit_ip = units['ci-airline-rabbit/0']['public-address']
167@@ -59,6 +51,8 @@
168
169 class TestProcessRequests(deployers.DeployerTest):
170
171+ required_service = 'ci-airline-for-britney-requests'
172+
173 scenarios = scenarii.multiply_scenarios(
174 # series
175 ([('trusty', dict(series='trusty', result='PASSED')),
176@@ -69,7 +63,6 @@
177 def setUp(self):
178 super(TestProcessRequests, self).setUp()
179 status = deploy.juju_status()
180- requires_britney_deployment(self, status)
181 deployers.expose_rabbit(self, get_rabbit_ip(status),
182 'tester', 's3cr3t')
183
184@@ -175,10 +168,11 @@
185
186 class TestPost(deployers.DeployerTest):
187
188+ required_service = 'ci-airline-for-britney-requests'
189+
190 def setUp(self):
191 super(TestPost, self).setUp()
192 status = deploy.juju_status()
193- requires_britney_deployment(self, status)
194 fixtures.set_uniq_cwd(self)
195 fixtures.isolate_from_env(self, dict(HOME=self.uniq_dir))
196 units = status['services']['ci-airline-rabbit']['units']
197
198=== modified file 'tests/test_bsbuilder.py'
199--- tests/test_bsbuilder.py 2014-06-23 19:41:51 +0000
200+++ tests/test_bsbuilder.py 2015-01-14 10:17:09 +0000
201@@ -22,6 +22,8 @@
202 class TestBsBuilder(deployers.DeployerTest):
203 """Integration tests for bsbuilder service run on a juju deployment"""
204
205+ required_service = 'ci-airline-bsb-worker'
206+
207 def test_worker_running(self):
208 '''ensure the rabbit worker is deployed and running'''
209 self.assert_job_running('ci-airline-bsb-worker')
210
211=== modified file 'tests/test_image_builder.py'
212--- tests/test_image_builder.py 2014-10-07 10:04:01 +0000
213+++ tests/test_image_builder.py 2015-01-14 10:17:09 +0000
214@@ -22,6 +22,8 @@
215 class TestImageBuilder(deployers.DeployerTest):
216 """Integration tests for image builder service run on a juju deployment"""
217
218+ required_service = 'ci-airline-imagebuild-worker'
219+
220 def test_worker_running(self):
221 '''ensure the rabbit worker is deployed and running'''
222 self.assert_job_running('ci-airline-imagebuild-worker')
223
224=== modified file 'tests/test_ppacreator.py'
225--- tests/test_ppacreator.py 2014-10-30 20:46:10 +0000
226+++ tests/test_ppacreator.py 2015-01-14 10:17:09 +0000
227@@ -27,6 +27,8 @@
228 class TestPPACreator(deployers.DeployerTest):
229 """Integration tests for ppacreator service run on a juju deployment"""
230
231+ required_service = 'ci-airline-ppa-creator-worker'
232+
233 def setUp(self):
234 super(TestPPACreator, self).setUp()
235 status = deploy.juju_status()
236
237=== modified file 'tests/test_publisher.py'
238--- tests/test_publisher.py 2014-10-07 10:04:01 +0000
239+++ tests/test_publisher.py 2015-01-14 10:17:09 +0000
240@@ -24,6 +24,8 @@
241 class TestPublisher(deployers.DeployerTest):
242 """Integration tests for publisher service run on a juju deployment"""
243
244+ required_service = 'ci-airline-publisher-worker'
245+
246 def test_worker_running(self):
247 """Ensure the publisher worker is deployed and running."""
248 self.assert_job_running('ci-airline-publisher-worker')
249
250=== modified file 'tests/test_rabbit.py'
251--- tests/test_rabbit.py 2014-10-23 14:07:48 +0000
252+++ tests/test_rabbit.py 2015-01-14 10:17:09 +0000
253@@ -29,6 +29,8 @@
254 @features.requires(features.bootstrapped_juju)
255 class TestRabbit(deployers.DeployerTest):
256
257+ required_service = RABBIT_SERVICE
258+
259 def setUp(self):
260 super(TestRabbit, self).setUp()
261 self.create_user('tester', 's3cr3t')
262
263=== modified file 'tests/test_test_runner.py'
264--- tests/test_test_runner.py 2015-01-09 11:24:30 +0000
265+++ tests/test_test_runner.py 2015-01-14 10:17:09 +0000
266@@ -33,6 +33,8 @@
267 class SmokeTestTestRunner(deployers.DeployerTest):
268 """Integration tests for test runner service run on a juju deployment"""
269
270+ required_service = 'ci-airline-tr-rabbit-worker'
271+
272 def test_worker_running(self):
273 '''Ensure the rabbit worker is deployed and running.'''
274 # TODO ev 2014-06-16 We should really write status APIs that
275@@ -42,6 +44,8 @@
276
277 class TestTestRunner(deployers.DeployerTest):
278
279+ required_service = 'ci-airline-tr-rabbit-worker'
280+
281 def setUp(self):
282 super(TestTestRunner, self).setUp()
283 status = deploy.juju_status()
284
285=== modified file 'tests/test_ticket_system.py'
286--- tests/test_ticket_system.py 2014-11-25 01:21:41 +0000
287+++ tests/test_ticket_system.py 2015-01-14 10:17:09 +0000
288@@ -24,12 +24,7 @@
289 class TicketSystemTest(deployers.DeployerTest):
290 """Integration tests for ticket-system service run on a juju deployment"""
291
292- def setUp(self):
293- super(TicketSystemTest, self).setUp()
294- # Adding get_ip_and_port('ts-django') in order to allow the deployment
295- # further time to settle before running the tests.
296- # http://pad.lv/1319077
297- self.get_ip_and_port('ci-airline-ts-django')
298+ required_service = 'ci-airline-webui-apache'
299
300 def get_server_status_and_content(self, url):
301 """Issue an WebUI GET and return response and page content."""
302
303=== modified file 'tests/test_validator.py'
304--- tests/test_validator.py 2014-08-14 17:21:56 +0000
305+++ tests/test_validator.py 2015-01-14 10:17:09 +0000
306@@ -21,6 +21,8 @@
307 class TestValidator(deployers.DeployerTest):
308 """Integration tests for validator service."""
309
310+ required_service = 'ci-airline-validator-worker'
311+
312 def test_worker_running(self):
313 """Ensure the validator worker is deployed and running."""
314 self.assert_job_running('ci-airline-validator-worker')
315
316=== modified file 'tests/test_webui.py'
317--- tests/test_webui.py 2015-01-09 13:27:24 +0000
318+++ tests/test_webui.py 2015-01-14 10:17:09 +0000
319@@ -50,8 +50,11 @@
320 def setUp(self):
321 """Sets browser base_url based on the available deployment."""
322 super(WebUITest, self).setUp()
323- set_base_url('http://{}/'.format(
324- deployers.juju_get_ip_and_port('ci-airline-webui-apache')[0]))
325+ try:
326+ set_base_url('http://{}/'.format(
327+ deployers.juju_get_ip_and_port('ci-airline-webui-apache')[0]))
328+ except KeyError:
329+ self.skipTest('WebUI not available')
330 set_window_size(1280, 1024)
331
332 def test_home(self):
333@@ -535,5 +538,26 @@
334 self.assertEqual('Engine health', active_link.text)
335
336
337+class UbuntuCoreWebUITest(cases.SSTTestCase):
338+
339+ browser_factory = browsers.PhantomJSFactory()
340+
341+ def setUp(self):
342+ """Sets browser base_url based on the available deployment."""
343+ super(UbuntuCoreWebUITest, self).setUp()
344+ try:
345+ set_base_url('http://{}/'.format(
346+ deployers.juju_get_ip_and_port(
347+ 'ci-ubuntucore-webui-apache')[0]))
348+ except KeyError:
349+ self.skipTest('UbuntuCore WebUI not available')
350+ set_window_size(1280, 1024)
351+
352+ def test_home(self):
353+ # Placeholder test, since UbuntuCore apache is still unconfigured.
354+ go_to('/')
355+ assert_title('403 Forbidden')
356+
357+
358 if __name__ == "__main__":
359 unittest.main()

Subscribers

People subscribed via source and target branches