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
=== modified file 'bin/called-by-tarmac.py'
--- bin/called-by-tarmac.py 2014-11-21 13:42:55 +0000
+++ bin/called-by-tarmac.py 2015-01-14 10:17:09 +0000
@@ -16,6 +16,14 @@
16sys.path.insert(0, os.path.join(HERE, '..'))16sys.path.insert(0, os.path.join(HERE, '..'))
17from testing import venv17from testing import venv
1818
19# List of systems that should be deployed before running all tests.
20# It assumes the systems can co-exist under the same tenant, i.e.
21# common services will be shared (e.g. rabbit).
22testing_systems = (
23 'ci-airline',
24 'ci-ubuntucore',
25)
26
1927
20def check_lxc_mounted():28def check_lxc_mounted():
21 out = subprocess.check_output(['mount'])29 out = subprocess.check_output(['mount'])
@@ -61,6 +69,24 @@
61 return True69 return True
6270
6371
72def deploy_testing_systems():
73 """Deploy 'testing_systems'.
74
75 Stops if `deploy.main()` failed for any specified system and returns
76 its 'return_code', otherwise returns ZERO.
77 """
78 # deploy.py isn't in our pythonpath when run as a script
79 sys.path.append(os.path.abspath('juju-deployer'))
80 import deploy
81
82 rc = 0
83 for name in testing_systems:
84 rc = deploy.main(['--name', name])
85 if rc != 0:
86 break
87 return rc
88
89
64def destroy_environment():90def destroy_environment():
65 '''Destroy the local environment. Return True if successful, False91 '''Destroy the local environment. Return True if successful, False
66 otherwise.'''92 otherwise.'''
@@ -200,9 +226,6 @@
200 raise226 raise
201227
202 from testing import run_tests228 from testing import run_tests
203 # deploy.py isn't in our pythonpath when run as a script
204 sys.path.append(os.path.abspath('juju-deployer'))
205 import deploy
206229
207 try:230 try:
208 with open('/dev/null', 'w') as null:231 with open('/dev/null', 'w') as null:
@@ -221,7 +244,7 @@
221 logging.info('Deploying.')244 logging.info('Deploying.')
222 t = time.time()245 t = time.time()
223 # Bootstrap, then deploy.246 # Bootstrap, then deploy.
224 if not bootstrap() or deploy.main() != 0:247 if not bootstrap() or deploy_testing_systems() != 0:
225 metrics.timing('counters.failures.deploy')248 metrics.timing('counters.failures.deploy')
226 return 1249 return 1
227 metrics.timing('deploy')250 metrics.timing('deploy')
228251
=== modified file 'juju-deployer/deploy.py'
--- juju-deployer/deploy.py 2015-01-06 18:41:34 +0000
+++ juju-deployer/deploy.py 2015-01-14 10:17:09 +0000
@@ -933,7 +933,7 @@
933 help='Build the deployment for --working-dir.')933 help='Build the deployment for --working-dir.')
934 parser.add_argument('--name', default='ci-airline',934 parser.add_argument('--name', default='ci-airline',
935 choices=('ci-airline', 'ci-airline-experimental',935 choices=('ci-airline', 'ci-airline-experimental',
936 'ci-airline-for-britney'),936 'ci-airline-for-britney', 'ci-ubuntucore'),
937 help='''The name of the juju-deployer "stack".937 help='''The name of the juju-deployer "stack".
938 Default=%(default)s''')938 Default=%(default)s''')
939 parser.add_argument(939 parser.add_argument(
@@ -987,8 +987,8 @@
987 bootstrap()987 bootstrap()
988988
989989
990def main():990def main(args=None):
991 args = _get_args()991 args = _get_args(args)
992992
993 # You can configure the system to use private PPAs only or by providing993 # You can configure the system to use private PPAs only or by providing
994 # the option --private-ppas-only or by setting the environment variable994 # the option --private-ppas-only or by setting the environment variable
995995
=== modified file 'juju-deployer/relations.yaml'
--- juju-deployer/relations.yaml 2014-11-26 23:37:34 +0000
+++ juju-deployer/relations.yaml 2015-01-14 10:17:09 +0000
@@ -118,3 +118,6 @@
118 - ["ci-airline-nfss-restish:pgsql", "ci-airline-nfss-postgres:db"]118 - ["ci-airline-nfss-restish:pgsql", "ci-airline-nfss-postgres:db"]
119 - ["ci-airline-nfss-apache:reverseproxy", "ci-airline-nfss-restish:website"]119 - ["ci-airline-nfss-apache:reverseproxy", "ci-airline-nfss-restish:website"]
120 - ["ci-airline-nfss-apache", "ci-airline-nfss-content-fetcher"]120 - ["ci-airline-nfss-apache", "ci-airline-nfss-content-fetcher"]
121
122ci-ubuntucore:
123 inherits: common
121124
=== modified file 'juju-deployer/services.yaml.tmpl'
--- juju-deployer/services.yaml.tmpl 2015-01-06 18:41:34 +0000
+++ juju-deployer/services.yaml.tmpl 2015-01-14 10:17:09 +0000
@@ -417,3 +417,16 @@
417 ci-airline-nfss-postgres:417 ci-airline-nfss-postgres:
418 branch: lp:charms/trusty/postgresql@95418 branch: lp:charms/trusty/postgresql@95
419 charm: postgresql419 charm: postgresql
420
421ci-ubuntucore:
422 series: precise
423 inherits: common
424 services:
425 ci-ubuntucore-webui-apache:
426 charm: apache2
427 constraints: "mem=1024M"
428 branch: lp:charms/precise/apache2@54
429 options:
430 enable_modules: "rewrite proxy proxy_http ssl"
431 servername: ci_ubuntu_core_webui_apache
432 expose: true
420433
=== modified file 'tests/deployers.py'
--- tests/deployers.py 2014-11-06 13:40:54 +0000
+++ tests/deployers.py 2015-01-14 10:17:09 +0000
@@ -97,6 +97,24 @@
97class DeployerTest(testing.TestCaseWithGnupg):97class DeployerTest(testing.TestCaseWithGnupg):
98 '''Base class for building juju deployer based tests.'''98 '''Base class for building juju deployer based tests.'''
9999
100 required_service = None
101
102 def setUp(self):
103 """Check for 'required_service' availability."""
104 super(DeployerTest, self).setUp()
105 self.assertIsNotNone(
106 self.required_service,
107 "The test class should provide a 'self.required_service' to be "
108 "verified before running the tests.")
109 status = deploy.juju_status()
110 try:
111 units = status['services'][self.required_service]['units']
112 units['{}/0'.format(self.required_service)]
113 except KeyError:
114 self.skipTest(
115 'Required service {} not available'.format(
116 self.required_service))
117
100 def get_ip_and_port(self, service, unit=0):118 def get_ip_and_port(self, service, unit=0):
101 return juju_get_ip_and_port(service, unit)119 return juju_get_ip_and_port(service, unit)
102120
103121
=== modified file 'tests/test_britney.py'
--- tests/test_britney.py 2015-01-08 10:42:09 +0000
+++ tests/test_britney.py 2015-01-14 10:17:09 +0000
@@ -43,14 +43,6 @@
43)43)
4444
4545
46def requires_britney_deployment(test, status):
47 try:
48 br = status['services']['ci-airline-for-britney-requests']['units']
49 br['ci-airline-for-britney-requests/0']
50 except KeyError:
51 test.skipTest('Not a ci-airline-for-britney deployment')
52
53
54def get_rabbit_ip(status):46def get_rabbit_ip(status):
55 units = status['services']['ci-airline-rabbit']['units']47 units = status['services']['ci-airline-rabbit']['units']
56 rabbit_ip = units['ci-airline-rabbit/0']['public-address']48 rabbit_ip = units['ci-airline-rabbit/0']['public-address']
@@ -59,6 +51,8 @@
5951
60class TestProcessRequests(deployers.DeployerTest):52class TestProcessRequests(deployers.DeployerTest):
6153
54 required_service = 'ci-airline-for-britney-requests'
55
62 scenarios = scenarii.multiply_scenarios(56 scenarios = scenarii.multiply_scenarios(
63 # series57 # series
64 ([('trusty', dict(series='trusty', result='PASSED')),58 ([('trusty', dict(series='trusty', result='PASSED')),
@@ -69,7 +63,6 @@
69 def setUp(self):63 def setUp(self):
70 super(TestProcessRequests, self).setUp()64 super(TestProcessRequests, self).setUp()
71 status = deploy.juju_status()65 status = deploy.juju_status()
72 requires_britney_deployment(self, status)
73 deployers.expose_rabbit(self, get_rabbit_ip(status),66 deployers.expose_rabbit(self, get_rabbit_ip(status),
74 'tester', 's3cr3t')67 'tester', 's3cr3t')
7568
@@ -175,10 +168,11 @@
175168
176class TestPost(deployers.DeployerTest):169class TestPost(deployers.DeployerTest):
177170
171 required_service = 'ci-airline-for-britney-requests'
172
178 def setUp(self):173 def setUp(self):
179 super(TestPost, self).setUp()174 super(TestPost, self).setUp()
180 status = deploy.juju_status()175 status = deploy.juju_status()
181 requires_britney_deployment(self, status)
182 fixtures.set_uniq_cwd(self)176 fixtures.set_uniq_cwd(self)
183 fixtures.isolate_from_env(self, dict(HOME=self.uniq_dir))177 fixtures.isolate_from_env(self, dict(HOME=self.uniq_dir))
184 units = status['services']['ci-airline-rabbit']['units']178 units = status['services']['ci-airline-rabbit']['units']
185179
=== modified file 'tests/test_bsbuilder.py'
--- tests/test_bsbuilder.py 2014-06-23 19:41:51 +0000
+++ tests/test_bsbuilder.py 2015-01-14 10:17:09 +0000
@@ -22,6 +22,8 @@
22class TestBsBuilder(deployers.DeployerTest):22class TestBsBuilder(deployers.DeployerTest):
23 """Integration tests for bsbuilder service run on a juju deployment"""23 """Integration tests for bsbuilder service run on a juju deployment"""
2424
25 required_service = 'ci-airline-bsb-worker'
26
25 def test_worker_running(self):27 def test_worker_running(self):
26 '''ensure the rabbit worker is deployed and running'''28 '''ensure the rabbit worker is deployed and running'''
27 self.assert_job_running('ci-airline-bsb-worker')29 self.assert_job_running('ci-airline-bsb-worker')
2830
=== modified file 'tests/test_image_builder.py'
--- tests/test_image_builder.py 2014-10-07 10:04:01 +0000
+++ tests/test_image_builder.py 2015-01-14 10:17:09 +0000
@@ -22,6 +22,8 @@
22class TestImageBuilder(deployers.DeployerTest):22class TestImageBuilder(deployers.DeployerTest):
23 """Integration tests for image builder service run on a juju deployment"""23 """Integration tests for image builder service run on a juju deployment"""
2424
25 required_service = 'ci-airline-imagebuild-worker'
26
25 def test_worker_running(self):27 def test_worker_running(self):
26 '''ensure the rabbit worker is deployed and running'''28 '''ensure the rabbit worker is deployed and running'''
27 self.assert_job_running('ci-airline-imagebuild-worker')29 self.assert_job_running('ci-airline-imagebuild-worker')
2830
=== modified file 'tests/test_ppacreator.py'
--- tests/test_ppacreator.py 2014-10-30 20:46:10 +0000
+++ tests/test_ppacreator.py 2015-01-14 10:17:09 +0000
@@ -27,6 +27,8 @@
27class TestPPACreator(deployers.DeployerTest):27class TestPPACreator(deployers.DeployerTest):
28 """Integration tests for ppacreator service run on a juju deployment"""28 """Integration tests for ppacreator service run on a juju deployment"""
2929
30 required_service = 'ci-airline-ppa-creator-worker'
31
30 def setUp(self):32 def setUp(self):
31 super(TestPPACreator, self).setUp()33 super(TestPPACreator, self).setUp()
32 status = deploy.juju_status()34 status = deploy.juju_status()
3335
=== modified file 'tests/test_publisher.py'
--- tests/test_publisher.py 2014-10-07 10:04:01 +0000
+++ tests/test_publisher.py 2015-01-14 10:17:09 +0000
@@ -24,6 +24,8 @@
24class TestPublisher(deployers.DeployerTest):24class TestPublisher(deployers.DeployerTest):
25 """Integration tests for publisher service run on a juju deployment"""25 """Integration tests for publisher service run on a juju deployment"""
2626
27 required_service = 'ci-airline-publisher-worker'
28
27 def test_worker_running(self):29 def test_worker_running(self):
28 """Ensure the publisher worker is deployed and running."""30 """Ensure the publisher worker is deployed and running."""
29 self.assert_job_running('ci-airline-publisher-worker')31 self.assert_job_running('ci-airline-publisher-worker')
3032
=== modified file 'tests/test_rabbit.py'
--- tests/test_rabbit.py 2014-10-23 14:07:48 +0000
+++ tests/test_rabbit.py 2015-01-14 10:17:09 +0000
@@ -29,6 +29,8 @@
29@features.requires(features.bootstrapped_juju)29@features.requires(features.bootstrapped_juju)
30class TestRabbit(deployers.DeployerTest):30class TestRabbit(deployers.DeployerTest):
3131
32 required_service = RABBIT_SERVICE
33
32 def setUp(self):34 def setUp(self):
33 super(TestRabbit, self).setUp()35 super(TestRabbit, self).setUp()
34 self.create_user('tester', 's3cr3t')36 self.create_user('tester', 's3cr3t')
3537
=== modified file 'tests/test_test_runner.py'
--- tests/test_test_runner.py 2015-01-09 11:24:30 +0000
+++ tests/test_test_runner.py 2015-01-14 10:17:09 +0000
@@ -33,6 +33,8 @@
33class SmokeTestTestRunner(deployers.DeployerTest):33class SmokeTestTestRunner(deployers.DeployerTest):
34 """Integration tests for test runner service run on a juju deployment"""34 """Integration tests for test runner service run on a juju deployment"""
3535
36 required_service = 'ci-airline-tr-rabbit-worker'
37
36 def test_worker_running(self):38 def test_worker_running(self):
37 '''Ensure the rabbit worker is deployed and running.'''39 '''Ensure the rabbit worker is deployed and running.'''
38 # TODO ev 2014-06-16 We should really write status APIs that40 # TODO ev 2014-06-16 We should really write status APIs that
@@ -42,6 +44,8 @@
4244
43class TestTestRunner(deployers.DeployerTest):45class TestTestRunner(deployers.DeployerTest):
4446
47 required_service = 'ci-airline-tr-rabbit-worker'
48
45 def setUp(self):49 def setUp(self):
46 super(TestTestRunner, self).setUp()50 super(TestTestRunner, self).setUp()
47 status = deploy.juju_status()51 status = deploy.juju_status()
4852
=== modified file 'tests/test_ticket_system.py'
--- tests/test_ticket_system.py 2014-11-25 01:21:41 +0000
+++ tests/test_ticket_system.py 2015-01-14 10:17:09 +0000
@@ -24,12 +24,7 @@
24class TicketSystemTest(deployers.DeployerTest):24class TicketSystemTest(deployers.DeployerTest):
25 """Integration tests for ticket-system service run on a juju deployment"""25 """Integration tests for ticket-system service run on a juju deployment"""
2626
27 def setUp(self):27 required_service = 'ci-airline-webui-apache'
28 super(TicketSystemTest, self).setUp()
29 # Adding get_ip_and_port('ts-django') in order to allow the deployment
30 # further time to settle before running the tests.
31 # http://pad.lv/1319077
32 self.get_ip_and_port('ci-airline-ts-django')
3328
34 def get_server_status_and_content(self, url):29 def get_server_status_and_content(self, url):
35 """Issue an WebUI GET and return response and page content."""30 """Issue an WebUI GET and return response and page content."""
3631
=== modified file 'tests/test_validator.py'
--- tests/test_validator.py 2014-08-14 17:21:56 +0000
+++ tests/test_validator.py 2015-01-14 10:17:09 +0000
@@ -21,6 +21,8 @@
21class TestValidator(deployers.DeployerTest):21class TestValidator(deployers.DeployerTest):
22 """Integration tests for validator service."""22 """Integration tests for validator service."""
2323
24 required_service = 'ci-airline-validator-worker'
25
24 def test_worker_running(self):26 def test_worker_running(self):
25 """Ensure the validator worker is deployed and running."""27 """Ensure the validator worker is deployed and running."""
26 self.assert_job_running('ci-airline-validator-worker')28 self.assert_job_running('ci-airline-validator-worker')
2729
=== modified file 'tests/test_webui.py'
--- tests/test_webui.py 2015-01-09 13:27:24 +0000
+++ tests/test_webui.py 2015-01-14 10:17:09 +0000
@@ -50,8 +50,11 @@
50 def setUp(self):50 def setUp(self):
51 """Sets browser base_url based on the available deployment."""51 """Sets browser base_url based on the available deployment."""
52 super(WebUITest, self).setUp()52 super(WebUITest, self).setUp()
53 set_base_url('http://{}/'.format(53 try:
54 deployers.juju_get_ip_and_port('ci-airline-webui-apache')[0]))54 set_base_url('http://{}/'.format(
55 deployers.juju_get_ip_and_port('ci-airline-webui-apache')[0]))
56 except KeyError:
57 self.skipTest('WebUI not available')
55 set_window_size(1280, 1024)58 set_window_size(1280, 1024)
5659
57 def test_home(self):60 def test_home(self):
@@ -535,5 +538,26 @@
535 self.assertEqual('Engine health', active_link.text)538 self.assertEqual('Engine health', active_link.text)
536539
537540
541class UbuntuCoreWebUITest(cases.SSTTestCase):
542
543 browser_factory = browsers.PhantomJSFactory()
544
545 def setUp(self):
546 """Sets browser base_url based on the available deployment."""
547 super(UbuntuCoreWebUITest, self).setUp()
548 try:
549 set_base_url('http://{}/'.format(
550 deployers.juju_get_ip_and_port(
551 'ci-ubuntucore-webui-apache')[0]))
552 except KeyError:
553 self.skipTest('UbuntuCore WebUI not available')
554 set_window_size(1280, 1024)
555
556 def test_home(self):
557 # Placeholder test, since UbuntuCore apache is still unconfigured.
558 go_to('/')
559 assert_title('403 Forbidden')
560
561
538if __name__ == "__main__":562if __name__ == "__main__":
539 unittest.main()563 unittest.main()

Subscribers

People subscribed via source and target branches