83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
from collections import OrderedDict
|
|
from mock import patch, MagicMock, call
|
|
from test_utils import CharmTestCase
|
|
|
|
from charmhelpers.core import hookenv
|
|
|
|
_conf = hookenv.config
|
|
hookenv.config = MagicMock()
|
|
|
|
import heat_utils as utils
|
|
|
|
hookenv.config = _conf
|
|
|
|
TO_PATCH = [
|
|
'config',
|
|
'log',
|
|
'os_release',
|
|
'get_os_codename_install_source',
|
|
'configure_installation_source',
|
|
'apt_install',
|
|
'apt_update',
|
|
'apt_upgrade',
|
|
'check_call',
|
|
'service_start',
|
|
'service_stop',
|
|
]
|
|
|
|
|
|
# Restart map should be constructed such that API services restart
|
|
# before frontends (haproxy/apaceh) to avoid port conflicts.
|
|
RESTART_MAP = OrderedDict([
|
|
('/etc/heat/heat.conf', ['heat-api', 'heat-api-cfn', 'heat-engine']),
|
|
('/etc/heat/api-paste.ini', ['heat-api', 'heat-api-cfn']),
|
|
('/etc/haproxy/haproxy.cfg', ['haproxy']),
|
|
('/etc/apache2/sites-available/openstack_https_frontend', ['apache2']),
|
|
('/etc/apache2/sites-available/openstack_https_frontend.conf',
|
|
['apache2']),
|
|
])
|
|
|
|
|
|
class HeatUtilsTests(CharmTestCase):
|
|
|
|
def setUp(self):
|
|
super(HeatUtilsTests, self).setUp(utils, TO_PATCH)
|
|
self.config.side_effect = self.test_config.get
|
|
|
|
@patch('charmhelpers.contrib.openstack.context.SubordinateConfigContext')
|
|
def test_determine_packages(self, subcontext):
|
|
self.os_release.return_value = 'havana'
|
|
pkgs = utils.determine_packages()
|
|
ex = list(set(utils.BASE_PACKAGES + utils.BASE_SERVICES))
|
|
self.assertEquals(ex, pkgs)
|
|
|
|
def test_restart_map(self):
|
|
self.assertEquals(RESTART_MAP, utils.restart_map())
|
|
|
|
def test_openstack_upgrade(self):
|
|
self.config.side_effect = None
|
|
self.config.return_value = 'cloud:precise-havana'
|
|
self.get_os_codename_install_source.return_value = 'havana'
|
|
configs = MagicMock()
|
|
utils.do_openstack_upgrade(configs)
|
|
self.assertTrue(self.apt_update.called)
|
|
self.assertTrue(self.apt_upgrade.called)
|
|
self.assertTrue(self.apt_install.called)
|
|
configs.set_release.assert_called_with(openstack_release='havana')
|
|
self.assertTrue(configs.write_all.called)
|
|
|
|
def test_api_ports(self):
|
|
cfn = utils.api_port('heat-api-cfn')
|
|
self.assertEquals(cfn, 8000)
|
|
cfn = utils.api_port('heat-api')
|
|
self.assertEquals(cfn, 8004)
|
|
|
|
def test_migrate_database(self):
|
|
utils.migrate_database()
|
|
self.assertTrue(self.log.called)
|
|
self.check_call.assert_called_with(['heat-manage', 'db_sync'])
|
|
expected = [call('heat-api'), call('heat-api-cfn'),
|
|
call('heat-engine'), call('apache2')]
|
|
self.service_stop.assert_has_calls(expected, any_order=True)
|
|
self.service_start.assert_has_calls(expected, any_order=True)
|