Add locally scoped relation for passing nova configuration

This commit is contained in:
James Page 2013-11-29 15:34:44 +00:00
parent facb11d8d3
commit 4675989c61
5 changed files with 37 additions and 10 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/python
import sys
import json
from charmhelpers.fetch import (
apt_install, filter_installed_packages,
apt_update
@ -8,7 +9,8 @@ from charmhelpers.fetch import (
from charmhelpers.core.hookenv import (
config,
Hooks, UnregisteredHookError,
log
log,
relation_set
)
from charmhelpers.core.host import (
restart_on_change
@ -19,7 +21,8 @@ from charmhelpers.contrib.openstack.utils import (
from ceilometer_utils import (
restart_map,
register_configs,
CEILOMETER_AGENT_PACKAGES
CEILOMETER_AGENT_PACKAGES,
NOVA_SETTINGS
)
hooks = Hooks()
@ -34,9 +37,10 @@ def install():
filter_installed_packages(CEILOMETER_AGENT_PACKAGES),
fatal=True)
# TODO(jamespage): Locally scoped relation for nova and others
#ceilometer_utils.modify_config_file(ceilometer_utils.NOVA_CONF
# ceilometer_utils.NOVA_SETTINGS)
@hooks.hook('nova-ceilometer-relation-joined')
def nova_ceilometer_joined():
relation_set(subordinate_configuration=json.dumps(NOVA_SETTINGS))
@hooks.hook("ceilometer-service-relation-changed",

View File

@ -18,11 +18,20 @@ CEILOMETER_AGENT_PACKAGES = [
]
NOVA_CONF = "/etc/nova/nova.conf"
NOVA_SETTINGS = [
('DEFAULT', 'instance_usage_audit', 'True'),
('DEFAULT', 'instance_usage_audit_period', 'hour'),
('DEFAULT', 'notification_driver', 'ceilometer.compute.nova_notifier')
]
NOVA_SETTINGS = {
"nova": {
"/etc/nova/nova.conf": {
"sections": {
"DEFAULT": [
('instance_usage_audit', 'True'),
('instance_usage_audit_period', 'hour'),
('notification_driver', 'ceilometer.compute.nova_notifier')
]
}
}
}
}
CONFIG_FILES = {
CEILOMETER_CONF: {

View File

@ -14,6 +14,10 @@ description: |
categories:
- miscellaneous
- openstack
provides:
nova-ceilometer:
interface: nova-ceilometer
scope: container
requires:
container:
interface: juju-info

View File

@ -1,3 +1,4 @@
import json
from mock import patch, MagicMock
import ceilometer_utils
@ -19,6 +20,7 @@ TO_PATCH = [
'config',
'filter_installed_packages',
'CONFIGS',
'relation_set',
]
@ -46,3 +48,8 @@ class CeilometerHooksTest(CharmTestCase):
def test_ceilometer_changed(self):
hooks.hooks.execute(['hooks/ceilometer-service-relation-changed'])
self.assertTrue(self.CONFIGS.write_all.called)
def test_nova_ceilometer_joined(self):
hooks.hooks.execute(['hooks/nova-ceilometer-relation-joined'])
self.relation_set.assert_called_with(
subordinate_configuration=json.dumps(ceilometer_utils.NOVA_SETTINGS))

View File

@ -58,6 +58,7 @@ def get_default_config():
class CharmTestCase(unittest.TestCase):
def setUp(self, obj, patches):
super(CharmTestCase, self).setUp()
self.patches = patches
@ -78,6 +79,7 @@ class CharmTestCase(unittest.TestCase):
class TestConfig(object):
def __init__(self):
self.config = get_default_config()
@ -97,6 +99,7 @@ class TestConfig(object):
class TestRelation(object):
def __init__(self, relation_data={}):
self.relation_data = relation_data