def test_restart_map(self):
     ex_map = OrderedDict([
         ('/etc/openstack-dashboard/local_settings.py',
          ['apache2', 'memcached']),
         ('/etc/apache2/conf.d/openstack-dashboard.conf',
          ['apache2', 'memcached']),
         ('/etc/apache2/conf-available/openstack-dashboard.conf',
          ['apache2', 'memcached']),
         ('/etc/apache2/sites-available/default-ssl',
          ['apache2', 'memcached']),
         ('/etc/apache2/sites-available/default-ssl.conf',
          ['apache2', 'memcached']),
         ('/etc/apache2/sites-available/default', ['apache2', 'memcached']),
         ('/etc/apache2/sites-available/000-default.conf',
          ['apache2', 'memcached']),
         ('/etc/apache2/ports.conf', ['apache2', 'memcached']),
         ('/etc/haproxy/haproxy.cfg', ['haproxy']),
         ('/usr/share/openstack-dashboard/openstack_dashboard/enabled/'
          '_40_router.py', ['apache2', 'memcached']),
         ('/usr/share/openstack-dashboard/openstack_dashboard/conf/'
          'keystonev3_policy.json', ['apache2', 'memcached']),
         ('/usr/share/openstack-dashboard/openstack_dashboard/conf/'
          'cinder_policy.d/consistencygroup.yaml', ['apache2',
                                                    'memcached']),
     ])
     self.assertEqual(horizon_utils.restart_map(), ex_map)
# python-apt is not installed as part of test-requirements but is imported by
# some charmhelpers modules so create a fake import.
sys.modules['apt'] = MagicMock()

import hooks.horizon_utils as utils
_register_configs = utils.register_configs
utils.register_configs = MagicMock()

with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
    mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f: lambda *args,
                            **kwargs: f(*args, **kwargs))

    import hooks.horizon_hooks as hooks

RESTART_MAP = utils.restart_map()
utils.register_configs = _register_configs

TO_PATCH = [
    'config',
    'relation_set',
    'relation_get',
    'configure_installation_source',
    'apt_update',
    'apt_install',
    'filter_installed_packages',
    'open_port',
    'CONFIGS',
    'relation_ids',
    'enable_ssl',
    'openstack_upgrade_available',
# python-apt is not installed as part of test-requirements but is imported by
# some charmhelpers modules so create a fake import.
sys.modules['apt'] = MagicMock()

import hooks.horizon_utils as utils
_register_configs = utils.register_configs
utils.register_configs = MagicMock()

with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
    mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:
                            lambda *args, **kwargs: f(*args, **kwargs))

    import hooks.horizon_hooks as hooks

RESTART_MAP = utils.restart_map()
utils.register_configs = _register_configs

TO_PATCH = [
    'config',
    'relation_set',
    'relation_get',
    'configure_installation_source',
    'apt_update',
    'apt_install',
    'filter_installed_packages',
    'open_port',
    'CONFIGS',
    'relation_ids',
    'enable_ssl',
    'openstack_upgrade_available',
Esempio n. 4
0
    apt_update(fatal=True)
    packages = determine_packages()
    _os_release = os_release('openstack-dashboard')
    if CompareOpenStackReleases(_os_release) < 'icehouse':
        packages += ['nodejs', 'node-less']
    if lsb_release()['DISTRIB_CODENAME'] == 'precise':
        # Explicitly upgrade python-six Bug#1420708
        apt_install('python-six', fatal=True)
    packages = filter_installed_packages(packages)
    if packages:
        status_set('maintenance', 'Installing packages')
        apt_install(packages, fatal=True)


@hooks.hook('upgrade-charm')
@restart_on_change(restart_map(), stopstart=True, sleep=3)
@harden()
def upgrade_charm():
    execd_preinstall()
    apt_install(filter_installed_packages(determine_packages()), fatal=True)
    packages_removed = remove_old_packages()
    update_nrpe_config()
    CONFIGS.write_all()
    if packages_removed:
        log("Package purge detected, restarting services", "INFO")
        for s in services():
            service_restart(s)
    check_custom_theme()


@hooks.hook('config-changed')
    apt_update(fatal=True)
    packages = determine_packages()
    _os_release = os_release('openstack-dashboard')
    if CompareOpenStackReleases(_os_release) < 'icehouse':
        packages += ['nodejs', 'node-less']
    if lsb_release()['DISTRIB_CODENAME'] == 'precise':
        # Explicitly upgrade python-six Bug#1420708
        apt_install('python-six', fatal=True)
    packages = filter_installed_packages(packages)
    if packages:
        status_set('maintenance', 'Installing packages')
        apt_install(packages, fatal=True)


@hooks.hook('upgrade-charm')
@restart_on_change(restart_map(), stopstart=True, sleep=3)
@harden()
def upgrade_charm():
    execd_preinstall()
    apt_install(filter_installed_packages(determine_packages()), fatal=True)
    packages_removed = remove_old_packages()
    update_nrpe_config()
    CONFIGS.write_all()
    if packages_removed:
        log("Package purge detected, restarting services", "INFO")
        for s in services():
            service_restart(s)
    check_custom_theme()


@hooks.hook('config-changed')