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
=== added file '.project'
--- .project 1970-01-01 00:00:00 +0000
+++ .project 2013-10-22 23:17:00 +0000
@@ -0,0 +1,17 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<projectDescription>
3 <name>glance</name>
4 <comment></comment>
5 <projects>
6 </projects>
7 <buildSpec>
8 <buildCommand>
9 <name>org.python.pydev.PyDevBuilder</name>
10 <arguments>
11 </arguments>
12 </buildCommand>
13 </buildSpec>
14 <natures>
15 <nature>org.python.pydev.pythonNature</nature>
16 </natures>
17</projectDescription>
018
=== added file '.pydevproject'
--- .pydevproject 1970-01-01 00:00:00 +0000
+++ .pydevproject 2013-10-22 23:17:00 +0000
@@ -0,0 +1,9 @@
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<?eclipse-pydev version="1.0"?><pydev_project>
3<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
4<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
5<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
6<path>/glance/hooks</path>
7<path>/glance/unit_tests</path>
8</pydev_pathproperty>
9</pydev_project>
010
=== added file 'unit_tests/test_glance_contexts.py'
--- unit_tests/test_glance_contexts.py 1970-01-01 00:00:00 +0000
+++ unit_tests/test_glance_contexts.py 2013-10-22 23:17:00 +0000
@@ -0,0 +1,55 @@
1from mock import patch
2import glance_contexts as contexts
3
4from test_utils import (
5 CharmTestCase
6)
7
8TO_PATCH = [
9 'relation_ids',
10 'is_relation_made',
11 'service_name',
12 'determine_haproxy_port',
13 'determine_api_port',
14]
15
16
17class TestGlanceContexts(CharmTestCase):
18 def setUp(self):
19 super(TestGlanceContexts, self).setUp(contexts, TO_PATCH)
20
21 def test_swift_not_related(self):
22 self.relation_ids.return_value = []
23 self.assertEquals(contexts.ObjectStoreContext()(), {})
24
25 def test_swift_related(self):
26 self.relation_ids.return_value = ['object-store:0']
27 self.assertEquals(contexts.ObjectStoreContext()(),
28 {'swift_store': True})
29
30 def test_ceph_not_related(self):
31 self.is_relation_made.return_value = False
32 self.assertEquals(contexts.CephGlanceContext()(), {})
33
34 def test_ceph_related(self):
35 self.is_relation_made.return_value = True
36 service = 'glance'
37 self.service_name.return_value = service
38 self.assertEquals(
39 contexts.CephGlanceContext()(),
40 {'rbd_pool': service,
41 'rbd_user': service})
42
43 def test_haproxy_configuration(self):
44 self.determine_haproxy_port.return_value = 9292
45 self.determine_api_port.return_value = 9282
46 self.assertEquals(
47 contexts.HAProxyContext()(),
48 {'service_ports': {'glance_api': [9292, 9282]},
49 'bind_port': 9282})
50
51 @patch('charmhelpers.contrib.openstack.context.https')
52 def test_apache_ssl_context_service_enabled(self,
53 https):
54 https.return_value = False
55 self.assertEquals(contexts.ApacheSSLContext()(), {})
056
=== added file 'unit_tests/test_glance_utils.py'
--- unit_tests/test_glance_utils.py 1970-01-01 00:00:00 +0000
+++ unit_tests/test_glance_utils.py 2013-10-22 23:17:00 +0000
@@ -0,0 +1,145 @@
1from mock import patch, call, MagicMock
2
3from collections import OrderedDict
4
5import glance_utils as utils
6
7from test_utils import (
8 CharmTestCase,
9)
10
11TO_PATCH = [
12 'config',
13 'log',
14 'ceph_create_pool',
15 'ceph_pool_exists',
16 'relation_ids',
17 'get_os_codename_package',
18 'get_os_codename_install_source',
19 'configure_installation_source',
20 'eligible_leader',
21 'templating',
22 'apt_update',
23 'apt_install',
24 'mkdir'
25]
26
27
28class TestGlanceUtils(CharmTestCase):
29 def setUp(self):
30 super(TestGlanceUtils, self).setUp(utils, TO_PATCH)
31 self.config.side_effect = self.test_config.get_all
32
33 @patch('subprocess.check_call')
34 def test_migrate_database(self, check_call):
35 '''It migrates database with cinder-manage'''
36 utils.migrate_database()
37 check_call.assert_called_with(['glance-manage', 'db_sync'])
38
39 def test_ensure_ceph_pool(self):
40 self.ceph_pool_exists.return_value = False
41 utils.ensure_ceph_pool(service='glance', replicas=3)
42 self.ceph_create_pool.assert_called_with(service='glance',
43 name='glance',
44 replicas=3)
45
46 def test_ensure_ceph_pool_already_exists(self):
47 self.ceph_pool_exists.return_value = True
48 utils.ensure_ceph_pool(service='glance', replicas=3)
49 self.assertFalse(self.ceph_create_pool.called)
50
51 @patch('os.path.exists')
52 def test_register_configs_apache(self, exists):
53 exists.return_value = False
54 self.get_os_codename_package.return_value = 'grizzly'
55 self.relation_ids.return_value = False
56 configs = utils.register_configs()
57 calls = []
58 for conf in [utils.GLANCE_REGISTRY_CONF,
59 utils.GLANCE_API_CONF,
60 utils.GLANCE_API_PASTE_INI,
61 utils.GLANCE_REGISTRY_PASTE_INI,
62 utils.HAPROXY_CONF,
63 utils.HTTPS_APACHE_CONF]:
64 calls.append(
65 call(conf,
66 utils.CONFIG_FILES[conf]['hook_contexts'])
67 )
68 configs.register.assert_has_calls(calls, any_order=True)
69
70 @patch('os.path.exists')
71 def test_register_configs_apache24(self, exists):
72 exists.return_value = True
73 self.get_os_codename_package.return_value = 'grizzly'
74 self.relation_ids.return_value = False
75 configs = utils.register_configs()
76 calls = []
77 for conf in [utils.GLANCE_REGISTRY_CONF,
78 utils.GLANCE_API_CONF,
79 utils.GLANCE_API_PASTE_INI,
80 utils.GLANCE_REGISTRY_PASTE_INI,
81 utils.HAPROXY_CONF,
82 utils.HTTPS_APACHE_24_CONF]:
83 calls.append(
84 call(conf,
85 utils.CONFIG_FILES[conf]['hook_contexts'])
86 )
87 configs.register.assert_has_calls(calls, any_order=True)
88
89 @patch('os.path.exists')
90 def test_register_configs_ceph(self, exists):
91 exists.return_value = False
92 self.get_os_codename_package.return_value = 'grizzly'
93 self.relation_ids.return_value = ['ceph:0']
94 configs = utils.register_configs()
95 calls = []
96 for conf in [utils.GLANCE_REGISTRY_CONF,
97 utils.GLANCE_API_CONF,
98 utils.GLANCE_API_PASTE_INI,
99 utils.GLANCE_REGISTRY_PASTE_INI,
100 utils.HAPROXY_CONF,
101 utils.HTTPS_APACHE_CONF,
102 utils.CEPH_CONF]:
103 calls.append(
104 call(conf,
105 utils.CONFIG_FILES[conf]['hook_contexts'])
106 )
107 configs.register.assert_has_calls(calls, any_order=True)
108 self.mkdir.assert_called_with('/etc/ceph')
109
110 def test_restart_map(self):
111 ex_map = OrderedDict([
112 (utils.GLANCE_REGISTRY_CONF, ['glance-registry']),
113 (utils.GLANCE_API_CONF, ['glance-api']),
114 (utils.GLANCE_API_PASTE_INI, ['glance-api']),
115 (utils.GLANCE_REGISTRY_PASTE_INI, ['glance-registry']),
116 (utils.CEPH_CONF, ['glance-api', 'glance-registry']),
117 (utils.HAPROXY_CONF, ['haproxy']),
118 (utils.HTTPS_APACHE_CONF, ['apache2']),
119 (utils.HTTPS_APACHE_24_CONF, ['apache2'])
120 ])
121 self.assertEquals(ex_map, utils.restart_map())
122
123 @patch.object(utils, 'migrate_database')
124 def test_openstack_upgrade_leader(self, migrate):
125 self.config.side_effect = None
126 self.config.return_value = 'cloud:precise-havana'
127 self.eligible_leader.return_value = True
128 self.get_os_codename_install_source.return_value = 'havana'
129 configs = MagicMock()
130 utils.do_openstack_upgrade(configs)
131 self.assertTrue(configs.write_all.called)
132 configs.set_release.assert_called_with(openstack_release='havana')
133 self.assertTrue(migrate.called)
134
135 @patch.object(utils, 'migrate_database')
136 def test_openstack_upgrade_not_leader(self, migrate):
137 self.config.side_effect = None
138 self.config.return_value = 'cloud:precise-havana'
139 self.eligible_leader.return_value = False
140 self.get_os_codename_install_source.return_value = 'havana'
141 configs = MagicMock()
142 utils.do_openstack_upgrade(configs)
143 self.assertTrue(configs.write_all.called)
144 configs.set_release.assert_called_with(openstack_release='havana')
145 self.assertFalse(migrate.called)

Subscribers

People subscribed via source and target branches

to all changes: