def test_assess_status(self):
     with patch.object(utils, 'assess_status_func') as asf:
         callee = MagicMock()
         asf.return_value = callee
         utils.assess_status('test-config')
         asf.assert_called_once_with('test-config')
         callee.assert_called_once_with()
Example #2
0
 def test_assess_status(self):
     with patch.object(utils, 'assess_status_func') as asf:
         callee = MagicMock()
         asf.return_value = callee
         utils.assess_status('test-config')
         asf.assert_called_once_with('test-config')
         callee.assert_called_once_with()
         self.os_application_version_set.assert_called_with(
             utils.VERSION_PACKAGE)
 def test_assess_status(self):
     with patch.object(utils, 'assess_status_func') as asf:
         callee = MagicMock()
         asf.return_value = callee
         utils.assess_status('test-config')
         asf.assert_called_once_with('test-config')
         callee.assert_called_once_with()
         self.os_application_version_set.assert_called_with(
             utils.VERSION_PACKAGE
         )
Example #4
0
def resume(args):
    """Resume the Ceilometer services.

    @raises Exception should the service fail to start."""
    services = CEILOMETER_BASE_SERVICES + ceilometer_release_services()
    for service in services:
        if not service_resume(service):
            raise Exception("Failed to resume %s." % service)

    db = kv()
    db.set('unit-paused', False)
    db.flush()

    assess_status(CONFIGS)
Example #5
0
def ceilometer_upgrade(args):
    """Run ceilometer-upgrade

    @raises Exception if the ceilometer-upgrade fails.
    """
    try:
        ceilometer_upgrade_helper(register_configs())
        action_set({'outcome': 'success, ceilometer-upgrade completed.'})
    except FailedAction as e:
        if e.outcome:
            action_set({'outcome': e.outcome})
        if e.trace:
            action_set({'traceback': e.trace})
        raise Exception(str(e))
    assess_status(register_configs())

@hooks.hook('post-series-upgrade')
def post_series_upgrade():
    log("Running complete series upgrade hook", "INFO")
    series_upgrade_complete(resume_unit_helper, CONFIGS)


@hooks.hook('certificates-relation-joined')
def certs_joined(relation_id=None):
    relation_set(relation_id=relation_id,
                 relation_settings=cert_utils.get_certificate_request())


@hooks.hook('certificates-relation-changed')
def certs_changed(relation_id=None, unit=None):
    @restart_on_change(restart_map())
    def _certs_changed():
        cert_utils.process_certificates('ceilometer-api', relation_id, unit)
        configure_https()

    _certs_changed()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    assess_status(CONFIGS)
    context = get_ceilometer_context()
    # This value gets tranformed to a path by the context we need to
    # pass the data to agents.
    if 'rabbit_ssl_ca' in context:
        with open(context['rabbit_ssl_ca']) as fh:
            context['rabbit_ssl_ca'] = base64.b64encode(fh.read())
    for relid in relation_ids('ceilometer-service'):
        relation_set(relid, context)


@hooks.hook('nrpe-external-master-relation-joined',
            'nrpe-external-master-relation-changed')
def update_nrpe_config():
    # python-dbus is used by check_upstart_job
    apt_install('python-dbus')
    hostname = nrpe.get_nagios_hostname()
    current_unit = nrpe.get_nagios_unit_name()
    nrpe_setup = nrpe.NRPE(hostname=hostname)
    nrpe.copy_nrpe_checks()
    nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
    nrpe.add_haproxy_checks(nrpe_setup, current_unit)
    nrpe_setup.write()


if __name__ == '__main__':
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log('Unknown hook {} - skipping.'.format(e))
    assess_status(CONFIGS)