1
from mock import patch, call, MagicMock
3
from collections import OrderedDict
5
import glance_utils as utils
7
from test_utils import (
17
'get_os_codename_package',
18
'get_os_codename_install_source',
19
'configure_installation_source',
28
class TestGlanceUtils(CharmTestCase):
30
super(TestGlanceUtils, self).setUp(utils, TO_PATCH)
31
self.config.side_effect = self.test_config.get_all
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'])
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',
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)
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()
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,
63
utils.HTTPS_APACHE_CONF]:
66
utils.CONFIG_FILES[conf]['hook_contexts'])
68
configs.register.assert_has_calls(calls, any_order=True)
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()
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,
82
utils.HTTPS_APACHE_24_CONF]:
85
utils.CONFIG_FILES[conf]['hook_contexts'])
87
configs.register.assert_has_calls(calls, any_order=True)
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()
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,
101
utils.HTTPS_APACHE_CONF,
105
utils.CONFIG_FILES[conf]['hook_contexts'])
107
configs.register.assert_has_calls(calls, any_order=True)
108
self.mkdir.assert_called_with('/etc/ceph')
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'])
121
self.assertEquals(ex_map, utils.restart_map())
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)
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)