def test_restart_map_newton(self):
     self.enable_memcache.return_value = True
     restart_map = utils.restart_map()
     expect = {
         '/etc/ceilometer/ceilometer.conf': ['ceilometer-agent-compute'],
         '/etc/memcached.conf': ['memcached']}
     self.assertEqual(restart_map, expect)
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()
 def test_restart_map_mitaka(self):
     """Ensure that alarming services are missing for OpenStack Mitaka"""
     self.get_os_codename_install_source.return_value = 'mitaka'
     self.os_release.return_value = 'mitaka'
     self.maxDiff = None
     restart_map = utils.restart_map()
     self.assertEqual(
         restart_map,
         {'/etc/ceilometer/ceilometer.conf': [
             'ceilometer-agent-central',
             'ceilometer-collector',
             'ceilometer-api',
             'ceilometer-agent-notification'],
          '/etc/ceilometer/pipeline.yaml': [
              'ceilometer-collector'],
          '/etc/systemd/system/ceilometer-api.service.d/override.conf': [
             'ceilometer-api'],
          '/etc/haproxy/haproxy.cfg': ['haproxy'],
          '/etc/memcached.conf': ['memcached'],
          "/etc/apache2/sites-available/openstack_https_frontend": [
              'ceilometer-api', 'apache2'],
          "/etc/apache2/sites-available/openstack_https_frontend.conf": [
              'ceilometer-api', 'apache2']
          }
     )
 def test_restart_map_queens(self):
     """Ensure that alarming services are missing for OpenStack Queens"""
     self.get_os_codename_install_source.return_value = 'queens'
     self.os_release.return_value = 'queens'
     self.maxDiff = None
     restart_map = utils.restart_map()
     self.assertEqual(
         restart_map, {
             '/etc/ceilometer/ceilometer.conf':
             ['ceilometer-agent-central', 'ceilometer-agent-notification'],
         })
 def test_restart_map_queens(self):
     """Ensure that alarming services are missing for OpenStack Queens"""
     self.get_os_codename_install_source.return_value = 'queens'
     self.os_release.return_value = 'queens'
     self.maxDiff = None
     restart_map = utils.restart_map()
     self.assertEqual(
         restart_map,
         {'/etc/ceilometer/ceilometer.conf': [
             'ceilometer-agent-central',
             'ceilometer-agent-notification'],
          '/etc/ceilometer/polling.yaml': [
             'ceilometer-agent-central',
             'ceilometer-agent-notification'],
          }
     )
 def test_restart_map(self):
     restart_map = utils.restart_map()
     self.assertEquals(
         restart_map,
         {'/etc/ceilometer/ceilometer.conf': [
             'ceilometer-agent-central',
             'ceilometer-collector',
             'ceilometer-api',
             'ceilometer-agent-notification'],
          '/etc/haproxy/haproxy.cfg': ['haproxy'],
          "/etc/apache2/sites-available/openstack_https_frontend": [
              'apache2'],
          "/etc/apache2/sites-available/openstack_https_frontend.conf": [
              'apache2']
          }
     )
 def test_restart_map_mitaka(self):
     """Ensure that alarming services are missing for OpenStack Mitaka"""
     self.get_os_codename_install_source.return_value = 'mitaka'
     restart_map = utils.restart_map()
     self.assertEquals(
         restart_map,
         {'/etc/ceilometer/ceilometer.conf': [
             'ceilometer-agent-central',
             'ceilometer-collector',
             'ceilometer-api',
             'ceilometer-agent-notification'],
          '/etc/haproxy/haproxy.cfg': ['haproxy'],
          "/etc/apache2/sites-available/openstack_https_frontend": [
              'apache2'],
          "/etc/apache2/sites-available/openstack_https_frontend.conf": [
              'apache2']
          }
     )
 def test_restart_map_mitaka(self):
     """Ensure that alarming services are missing for OpenStack Mitaka"""
     self.get_os_codename_install_source.return_value = 'mitaka'
     self.os_release.return_value = 'mitaka'
     self.maxDiff = None
     restart_map = utils.restart_map()
     self.assertEqual(
         restart_map, {
             '/etc/ceilometer/ceilometer.conf': [
                 'ceilometer-agent-central', 'ceilometer-collector',
                 'ceilometer-api', 'ceilometer-agent-notification'
             ],
             '/etc/systemd/system/ceilometer-api.service.d/override.conf':
             ['ceilometer-api'],
             '/etc/haproxy/haproxy.cfg': ['haproxy'],
             '/etc/memcached.conf': ['memcached'],
             "/etc/apache2/sites-available/openstack_https_frontend":
             ['ceilometer-api', 'apache2'],
             "/etc/apache2/sites-available/openstack_https_frontend.conf":
             ['ceilometer-api', 'apache2']
         })
    "amqp-relation-changed",
    "amqp-relation-departed",
    "amqp-listener-relation-changed",
    "amqp-listener-relation-departed",
    "shared-db-relation-changed",
    "shared-db-relation-departed",
    "identity-service-relation-changed",
    "identity-service-relation-departed",
    "identity-credentials-relation-changed",
    "identity-credentials-relation-departed",
    "metric-service-relation-changed",
    "metric-service-relation-departed",
    "event-service-relation-changed",
    "event-service-relation-departed",
)
@restart_on_change(restart_map())
def any_changed():
    CONFIGS.write_all()
    for r_id in relation_ids('certificates'):
        for unit in related_units(r_id):
            certs_changed(r_id, unit)
    configure_https()
    for rid in relation_ids('identity-service'):
        keystone_joined(relid=rid)
    ceilometer_joined()


def configure_https():
    """Enables SSL API Apache config if appropriate."""
    # need to write all to ensure changes to the entire request pipeline
    # propagate (c-api, haprxy, apache)
@hooks.hook("amqp-relation-joined")
def amqp_joined():
    relation_set(username=config('rabbit-user'),
                 vhost=config('rabbit-vhost'))


@hooks.hook("shared-db-relation-joined")
def db_joined():
    relation_set(ceilometer_database=CEILOMETER_DB)


@hooks.hook("amqp-relation-changed",
            "shared-db-relation-changed",
            "shared-db-relation-departed")
@restart_on_change(restart_map())
def any_changed():
    CONFIGS.write_all()
    configure_https()
    ceilometer_joined()


@hooks.hook("identity-service-relation-changed")
@restart_on_change(restart_map())
def identity_service_relation_changed():
    CONFIGS.write_all()
    configure_https()
    keystone_joined()
    ceilometer_joined()

 def test_restart_map(self):
     self.enable_memcache.return_value = False
     restart_map = utils.restart_map()
     self.assertEqual(restart_map,
                      {'/etc/ceilometer/ceilometer.conf': [
                          'ceilometer-agent-compute']})