Merge lp:~gz/ubuntu-ci-services-itself/intergration_test_fancy into lp:ubuntu-ci-services-itself

Proposed by Martin Packman
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 52
Merged at revision: 52
Proposed branch: lp:~gz/ubuntu-ci-services-itself/intergration_test_fancy
Merge into: lp:ubuntu-ci-services-itself
Prerequisite: lp:~vila/ubuntu-ci-services-itself/ppa-assigner-integration-test
Diff against target: 107 lines (+55/-35)
1 file modified
tests/ppa_assigner/test.py (+55/-35)
To merge this branch: bzr merge lp:~gz/ubuntu-ci-services-itself/intergration_test_fancy
Reviewer Review Type Date Requested Status
Evan (community) Approve
Review via email: mp+199637@code.launchpad.net

Commit message

Use python fixtures to isolate the deployer part into its own fixture.

Description of the change

Refactoring of new integration tests to use some testing niceties, which should make reuse of the concepts easier.

Implements the setup of a juju deployment in terms of a lp:python-fixtures Fixture, this means tests can be explicit about reusing the same environment, and has room for adding cleanUp() and reset() methods.

The test assertions are now bundled in a unittest testcase as previously planned.

To post a comment you must log in.
Revision history for this message
Evan (ev) wrote :

The import sys is no longer needed, otherwise +1.

review: Approve
Revision history for this message
Chris Johnston (cjohnston) wrote :
Revision history for this message
Chris Johnston (cjohnston) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/ppa_assigner/test.py'
--- tests/ppa_assigner/test.py 2013-12-19 11:24:51 +0000
+++ tests/ppa_assigner/test.py 2013-12-19 11:24:51 +0000
@@ -1,48 +1,68 @@
1#!/usr/bin/env python1#!/usr/bin/env python
22
3import json3import json
4import os
5import sys
6import unittest
7
4import httplib28import httplib2
9import fixtures
5import yaml10import yaml
6import os11
7import sys12import amulet
813
9opd = os.path.dirname14opd = os.path.dirname
1015
11root_dir = opd(opd(opd((os.path.abspath(__file__)))))16root_dir = opd(opd(opd((os.path.abspath(__file__)))))
1217
13import amulet18
1419class AmuletDeployment(fixtures.Fixture):
15def main():20 """Fixture for a deployed set of juju services from a deployer config"""
16 # FIXME: Running amulet with sentries is vurrently bogus in multiple ways21
17 # and we can get juju status ourselves -- vila 2013-12-1822 def __init__(self, deployer_cfg, juju_env=None, sentries=False):
18 depl = amulet.Deployment(sentries=False)23 self.deployment = amulet.Deployment(juju_env, sentries=sentries)
19 jd_path = os.path.join(root_dir, 'juju-deployer', 'ppa-assigner.yaml')24 with open(deployer_cfg) as f:
20 with open(jd_path) as f:25 jd_script = yaml.safe_load(f.read())
21 jd_script = yaml.safe_load(f.read())26 # Use juju_env given or defaulted above rather than taking the name
22 # Override the juju env provided by ppa-assigner or amulet gets confused27 # from the deployer config and assuming an env of that name exists
23 script = {depl.juju_env: jd_script.values()[0]}28 script = {self.deployment.juju_env: jd_script.values()[0]}
24 depl.load(script)29 self.deployment.load(script)
25 # This is a no-op if (as expected) the ppa-assigner has already been30
26 # deployed, but it *will* be deployed if needed anyway.31 def setUp(self):
27 depl.setup()32 super(AmuletDeployment, self).setUp()
2833 self.deployment.setup()
29 status = amulet.waiter.status(depl.juju_env)34
30 units = status['services']['django']['units']35
31 ip = units['django/0']['public-address']36class PPAAssignerTest(fixtures.TestWithFixtures):
32 port, _ = units['django/0']['open-ports'][0].split('/')37 """Integration tests for ppa-assigner service run on a juju deployment"""
33 # Issue a simple command against the ppa assigner API38
34 url = 'http://{}:{}/api/v1/ppa'.format(ip, port)39 @staticmethod
35 client = httplib2.Http()40 def _get_deployer_cfg():
36 resp, content = client.request(url, 'GET')41 return os.path.join(root_dir, 'juju-deployer', 'ppa-assigner.yaml')
37 jcontent = json.loads(content)42
38 # Target43 def setUp(self):
39 # self.assertEqual('200', resp['status'])44 super(PPAAssignerTest, self).setUp()
40 # self.assertNotEqual([], jcontent['objects'])45 self.deployer_fixture = AmuletDeployment(self._get_deployer_cfg())
41 if '200' != resp['status']:46
42 sys.exit(1)47 def get_ip_and_port(self):
43 if [] == jcontent['objects']:48 status = amulet.waiter.status(self.deployer_fixture.deployment.juju_env)
44 sys.exit(2)49 units = status['services']['django']['units']
50 ip = units['django/0']['public-address']
51 port, _ = units['django/0']['open-ports'][0].split('/')
52 return ip, port
53
54 def test_ppa_api(self):
55 self.useFixture(self.deployer_fixture)
56
57 url = 'http://{}:{}/api/v1/ppa'.format(*self.get_ip_and_port())
58
59 # Issue a simple command against the ppa assigner API
60 client = httplib2.Http()
61 resp, content = client.request(url, 'GET')
62 jcontent = json.loads(content)
63 self.assertEqual('200', resp['status'])
64 self.assertNotEqual([], jcontent['objects'])
4565
4666
47if __name__ == "__main__":67if __name__ == "__main__":
48 main()68 unittest.main()

Subscribers

People subscribed via source and target branches