Merge lp:~james-page/charms/precise/glance/unit-test-part2 into lp:~charmers/charms/precise/glance/trunk

Proposed by James Page
Status: Merged
Merged at revision: 40
Proposed branch: lp:~james-page/charms/precise/glance/unit-test-part2
Merge into: lp:~charmers/charms/precise/glance/trunk
Diff against target: 245 lines (+226/-0)
4 files modified
.project (+17/-0)
.pydevproject (+9/-0)
unit_tests/test_glance_contexts.py (+55/-0)
unit_tests/test_glance_utils.py (+145/-0)
To merge this branch: bzr merge lp:~james-page/charms/precise/glance/unit-test-part2
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+192267@code.launchpad.net

Description of the change

Add missing unit tests from previous unit tests merge.

Improves coverage alot

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Hi James! Thanks for these updates, as always they are much appreciated. With this, it appears coverage is up to 98%! Most excellent. LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.project'
2--- .project 1970-01-01 00:00:00 +0000
3+++ .project 2013-10-22 23:17:00 +0000
4@@ -0,0 +1,17 @@
5+<?xml version="1.0" encoding="UTF-8"?>
6+<projectDescription>
7+ <name>glance</name>
8+ <comment></comment>
9+ <projects>
10+ </projects>
11+ <buildSpec>
12+ <buildCommand>
13+ <name>org.python.pydev.PyDevBuilder</name>
14+ <arguments>
15+ </arguments>
16+ </buildCommand>
17+ </buildSpec>
18+ <natures>
19+ <nature>org.python.pydev.pythonNature</nature>
20+ </natures>
21+</projectDescription>
22
23=== added file '.pydevproject'
24--- .pydevproject 1970-01-01 00:00:00 +0000
25+++ .pydevproject 2013-10-22 23:17:00 +0000
26@@ -0,0 +1,9 @@
27+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
28+<?eclipse-pydev version="1.0"?><pydev_project>
29+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
30+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
31+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
32+<path>/glance/hooks</path>
33+<path>/glance/unit_tests</path>
34+</pydev_pathproperty>
35+</pydev_project>
36
37=== added file 'unit_tests/test_glance_contexts.py'
38--- unit_tests/test_glance_contexts.py 1970-01-01 00:00:00 +0000
39+++ unit_tests/test_glance_contexts.py 2013-10-22 23:17:00 +0000
40@@ -0,0 +1,55 @@
41+from mock import patch
42+import glance_contexts as contexts
43+
44+from test_utils import (
45+ CharmTestCase
46+)
47+
48+TO_PATCH = [
49+ 'relation_ids',
50+ 'is_relation_made',
51+ 'service_name',
52+ 'determine_haproxy_port',
53+ 'determine_api_port',
54+]
55+
56+
57+class TestGlanceContexts(CharmTestCase):
58+ def setUp(self):
59+ super(TestGlanceContexts, self).setUp(contexts, TO_PATCH)
60+
61+ def test_swift_not_related(self):
62+ self.relation_ids.return_value = []
63+ self.assertEquals(contexts.ObjectStoreContext()(), {})
64+
65+ def test_swift_related(self):
66+ self.relation_ids.return_value = ['object-store:0']
67+ self.assertEquals(contexts.ObjectStoreContext()(),
68+ {'swift_store': True})
69+
70+ def test_ceph_not_related(self):
71+ self.is_relation_made.return_value = False
72+ self.assertEquals(contexts.CephGlanceContext()(), {})
73+
74+ def test_ceph_related(self):
75+ self.is_relation_made.return_value = True
76+ service = 'glance'
77+ self.service_name.return_value = service
78+ self.assertEquals(
79+ contexts.CephGlanceContext()(),
80+ {'rbd_pool': service,
81+ 'rbd_user': service})
82+
83+ def test_haproxy_configuration(self):
84+ self.determine_haproxy_port.return_value = 9292
85+ self.determine_api_port.return_value = 9282
86+ self.assertEquals(
87+ contexts.HAProxyContext()(),
88+ {'service_ports': {'glance_api': [9292, 9282]},
89+ 'bind_port': 9282})
90+
91+ @patch('charmhelpers.contrib.openstack.context.https')
92+ def test_apache_ssl_context_service_enabled(self,
93+ https):
94+ https.return_value = False
95+ self.assertEquals(contexts.ApacheSSLContext()(), {})
96
97=== added file 'unit_tests/test_glance_utils.py'
98--- unit_tests/test_glance_utils.py 1970-01-01 00:00:00 +0000
99+++ unit_tests/test_glance_utils.py 2013-10-22 23:17:00 +0000
100@@ -0,0 +1,145 @@
101+from mock import patch, call, MagicMock
102+
103+from collections import OrderedDict
104+
105+import glance_utils as utils
106+
107+from test_utils import (
108+ CharmTestCase,
109+)
110+
111+TO_PATCH = [
112+ 'config',
113+ 'log',
114+ 'ceph_create_pool',
115+ 'ceph_pool_exists',
116+ 'relation_ids',
117+ 'get_os_codename_package',
118+ 'get_os_codename_install_source',
119+ 'configure_installation_source',
120+ 'eligible_leader',
121+ 'templating',
122+ 'apt_update',
123+ 'apt_install',
124+ 'mkdir'
125+]
126+
127+
128+class TestGlanceUtils(CharmTestCase):
129+ def setUp(self):
130+ super(TestGlanceUtils, self).setUp(utils, TO_PATCH)
131+ self.config.side_effect = self.test_config.get_all
132+
133+ @patch('subprocess.check_call')
134+ def test_migrate_database(self, check_call):
135+ '''It migrates database with cinder-manage'''
136+ utils.migrate_database()
137+ check_call.assert_called_with(['glance-manage', 'db_sync'])
138+
139+ def test_ensure_ceph_pool(self):
140+ self.ceph_pool_exists.return_value = False
141+ utils.ensure_ceph_pool(service='glance', replicas=3)
142+ self.ceph_create_pool.assert_called_with(service='glance',
143+ name='glance',
144+ replicas=3)
145+
146+ def test_ensure_ceph_pool_already_exists(self):
147+ self.ceph_pool_exists.return_value = True
148+ utils.ensure_ceph_pool(service='glance', replicas=3)
149+ self.assertFalse(self.ceph_create_pool.called)
150+
151+ @patch('os.path.exists')
152+ def test_register_configs_apache(self, exists):
153+ exists.return_value = False
154+ self.get_os_codename_package.return_value = 'grizzly'
155+ self.relation_ids.return_value = False
156+ configs = utils.register_configs()
157+ calls = []
158+ for conf in [utils.GLANCE_REGISTRY_CONF,
159+ utils.GLANCE_API_CONF,
160+ utils.GLANCE_API_PASTE_INI,
161+ utils.GLANCE_REGISTRY_PASTE_INI,
162+ utils.HAPROXY_CONF,
163+ utils.HTTPS_APACHE_CONF]:
164+ calls.append(
165+ call(conf,
166+ utils.CONFIG_FILES[conf]['hook_contexts'])
167+ )
168+ configs.register.assert_has_calls(calls, any_order=True)
169+
170+ @patch('os.path.exists')
171+ def test_register_configs_apache24(self, exists):
172+ exists.return_value = True
173+ self.get_os_codename_package.return_value = 'grizzly'
174+ self.relation_ids.return_value = False
175+ configs = utils.register_configs()
176+ calls = []
177+ for conf in [utils.GLANCE_REGISTRY_CONF,
178+ utils.GLANCE_API_CONF,
179+ utils.GLANCE_API_PASTE_INI,
180+ utils.GLANCE_REGISTRY_PASTE_INI,
181+ utils.HAPROXY_CONF,
182+ utils.HTTPS_APACHE_24_CONF]:
183+ calls.append(
184+ call(conf,
185+ utils.CONFIG_FILES[conf]['hook_contexts'])
186+ )
187+ configs.register.assert_has_calls(calls, any_order=True)
188+
189+ @patch('os.path.exists')
190+ def test_register_configs_ceph(self, exists):
191+ exists.return_value = False
192+ self.get_os_codename_package.return_value = 'grizzly'
193+ self.relation_ids.return_value = ['ceph:0']
194+ configs = utils.register_configs()
195+ calls = []
196+ for conf in [utils.GLANCE_REGISTRY_CONF,
197+ utils.GLANCE_API_CONF,
198+ utils.GLANCE_API_PASTE_INI,
199+ utils.GLANCE_REGISTRY_PASTE_INI,
200+ utils.HAPROXY_CONF,
201+ utils.HTTPS_APACHE_CONF,
202+ utils.CEPH_CONF]:
203+ calls.append(
204+ call(conf,
205+ utils.CONFIG_FILES[conf]['hook_contexts'])
206+ )
207+ configs.register.assert_has_calls(calls, any_order=True)
208+ self.mkdir.assert_called_with('/etc/ceph')
209+
210+ def test_restart_map(self):
211+ ex_map = OrderedDict([
212+ (utils.GLANCE_REGISTRY_CONF, ['glance-registry']),
213+ (utils.GLANCE_API_CONF, ['glance-api']),
214+ (utils.GLANCE_API_PASTE_INI, ['glance-api']),
215+ (utils.GLANCE_REGISTRY_PASTE_INI, ['glance-registry']),
216+ (utils.CEPH_CONF, ['glance-api', 'glance-registry']),
217+ (utils.HAPROXY_CONF, ['haproxy']),
218+ (utils.HTTPS_APACHE_CONF, ['apache2']),
219+ (utils.HTTPS_APACHE_24_CONF, ['apache2'])
220+ ])
221+ self.assertEquals(ex_map, utils.restart_map())
222+
223+ @patch.object(utils, 'migrate_database')
224+ def test_openstack_upgrade_leader(self, migrate):
225+ self.config.side_effect = None
226+ self.config.return_value = 'cloud:precise-havana'
227+ self.eligible_leader.return_value = True
228+ self.get_os_codename_install_source.return_value = 'havana'
229+ configs = MagicMock()
230+ utils.do_openstack_upgrade(configs)
231+ self.assertTrue(configs.write_all.called)
232+ configs.set_release.assert_called_with(openstack_release='havana')
233+ self.assertTrue(migrate.called)
234+
235+ @patch.object(utils, 'migrate_database')
236+ def test_openstack_upgrade_not_leader(self, migrate):
237+ self.config.side_effect = None
238+ self.config.return_value = 'cloud:precise-havana'
239+ self.eligible_leader.return_value = False
240+ self.get_os_codename_install_source.return_value = 'havana'
241+ configs = MagicMock()
242+ utils.do_openstack_upgrade(configs)
243+ self.assertTrue(configs.write_all.called)
244+ configs.set_release.assert_called_with(openstack_release='havana')
245+ self.assertFalse(migrate.called)

Subscribers

People subscribed via source and target branches

to all changes: