Adds volume-usage-audit-period config directive >= kilo.

This change adds the config directive called
volume-usage-audit-period for versions >= kilo.

Also, According to the doc change I90dff1b5c2a7dd2943cfa7ff25bb63c08eb7986d,
messagingv2 should be the default for anything > Icehouse.

So, this change also sets the following configuration section for
versions >= mitaka.

[oslo_messaging_notifications]
driver = messagingv2

This change adds a specific configuration context that installs
a crontab entry for running the cinder-volume-usage-audit recurrently.

Change-Id: I0056edaac55210a1a1f509ec908ae61c0ea887df
Closes-Bug: #1623144
Signed-off-by: Jorge Niedbalski <jorge.niedbalski@canonical.com>
This commit is contained in:
Jorge Niedbalski 2016-09-14 13:25:26 -03:00
parent e3362bcc6c
commit 07ae3acbb4
7 changed files with 48 additions and 3 deletions

View File

@ -6,7 +6,7 @@ options:
verbose:
default: False
type: boolean
description: Enable verbose logging.
description: Enable verbose logging.
use-syslog:
type: boolean
default: False
@ -368,4 +368,9 @@ options:
description: |
Apply system hardening. Supports a space-delimited list of modules
to run. Supported modules currently include os, ssh, apache and mysql.
volume-usage-audit-period:
default: "month"
type: string
description: |
Time period for which to generate volume usages. The options are hour,
day, month, or year.

View File

@ -183,3 +183,22 @@ class RegionContext(OSContextGenerator):
return {'region': region}
else:
return {}
class VolumeUsageAuditContext(OSContextGenerator):
"""This context provides the configuration directive
volume_usage_audit_period and also creates a crontab entry
for running the cinder-volume-usage-audit script recurrently.
"""
DEFAULT_CRONTAB_PATH = '/etc/cron.d/cinder-volume-usage-audit'
def __call__(self):
log("Installing crontab: %s" % self.DEFAULT_CRONTAB_PATH)
with open(self.DEFAULT_CRONTAB_PATH, "w+") as crontab:
# The cinder-volume-usage-audit executable will only gather
# data that fits on the configured volume-usage-audit-period.
crontab.write('0 * * * * root '
'/usr/bin/cinder-volume-usage-audit\n')
return {
'volume_usage_audit_period': config("volume-usage-audit-period")
}

View File

@ -226,7 +226,8 @@ BASE_RESOURCE_MAP = OrderedDict([
context.BindHostContext(),
context.WorkerConfigContext(),
cinder_contexts.RegionContext(),
context.InternalEndpointContext()],
context.InternalEndpointContext(),
cinder_contexts.VolumeUsageAuditContext()],
'services': ['cinder-api', 'cinder-volume', 'cinder-scheduler',
'haproxy']
}),

View File

@ -62,6 +62,8 @@ os_region_name = {{ region }}
{% endfor -%}
{% endif -%}
volume_usage_audit_period = {{ volume_usage_audit_period }}
{% include "parts/backends" %}
{% include "section-keystone-authtoken-legacy" %}

View File

@ -62,6 +62,8 @@ os_region_name = {{ region }}
{% endfor -%}
{% endif -%}
volume_usage_audit_period = {{ volume_usage_audit_period }}
{% include "parts/backends" %}
{% include "section-keystone-authtoken" %}

View File

@ -62,6 +62,8 @@ os_region_name = {{ region }}
{% endfor -%}
{% endif -%}
volume_usage_audit_period = {{ volume_usage_audit_period }}
{% include "parts/backends" %}
{% include "section-keystone-authtoken-mitaka" %}
@ -77,3 +79,8 @@ lock_path = /var/lock/cinder
# XXX: hack to work around http://pad.lv/1516085
# will be superceeded by SRU to cinder package
encryption_auth_url = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v3
[oslo_messaging_notifications]
# .openstack.common.* is pre-icehouse option.
# Check change-id: I90dff1b5c2a7dd2943cfa7ff25bb63c08eb7986d
driver = messagingv2

View File

@ -358,3 +358,12 @@ class TestCinderContext(CharmTestCase):
self.config.return_value = 'two'
ctxt = contexts.RegionContext()()
self.assertEqual('two', ctxt['region'])
@patch('__builtin__.open')
def test_volume_usage_audit_context(self, _open):
self.config.return_value = 'month'
ctxt = contexts.VolumeUsageAuditContext()()
_open.assert_called_with(
contexts.VolumeUsageAuditContext.DEFAULT_CRONTAB_PATH, "w+")
self.assertEqual(self.config.return_value,
ctxt["volume_usage_audit_period"])