From f62513ad0693187e26ec66e605fa4136a683622e Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 22 Sep 2017 10:59:56 +0000 Subject: [PATCH] Expose {disk,container}_format options The disk_format option was hardcoded and the container_format option was unset. This change exposes both to the user allowing the admin to restrict what formats are uploaded. Closes-Bug# 1570875 Change-Id: I19fdc75b30863e997affb2dc90b0dd3bd19c9d27 --- config.yaml | 10 ++++++++ hooks/glance_contexts.py | 11 ++++++++ hooks/glance_utils.py | 1 + templates/juno/glance-api.conf | 2 +- templates/kilo/glance-api.conf | 5 +++- templates/mitaka/glance-api.conf | 5 +++- tests/basic_deployment.py | 41 ++++++++++++++++++++++++++++++ unit_tests/test_glance_contexts.py | 16 ++++++++++++ 8 files changed, 88 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index 2243daf0..445b21d3 100644 --- a/config.yaml +++ b/config.yaml @@ -158,6 +158,16 @@ options: type: string default: openstack description: RabbitMQ virtual host to request access on rabbitmq-server. + container-formats: + type: string + default: + description: | + Comma separated list of container formats that Glance will support. + disk-formats: + type: string + default: ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar + description: | + Comma separated list of disk formats that Glance will support. # HA configuration settings dns-ha: type: boolean diff --git a/hooks/glance_contexts.py b/hooks/glance_contexts.py index 757d40a1..be51fe12 100644 --- a/hooks/glance_contexts.py +++ b/hooks/glance_contexts.py @@ -38,6 +38,17 @@ from charmhelpers.contrib.openstack.utils import ( ) +class GlanceContext(OSContextGenerator): + + def __call__(self): + ctxt = { + 'disk_formats': config('disk-formats') + } + if config('container-formats'): + ctxt['container_formats'] = config('container-formats') + return ctxt + + class CephGlanceContext(OSContextGenerator): interfaces = ['ceph-glance'] diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index c2757b2d..66b78b76 100644 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -188,6 +188,7 @@ CONFIG_FILES = OrderedDict([ context.IdentityServiceContext( service='glance', service_user='glance'), + glance_contexts.GlanceContext(), glance_contexts.CephGlanceContext(), glance_contexts.ObjectStoreContext(), glance_contexts.CinderStoreContext(), diff --git a/templates/juno/glance-api.conf b/templates/juno/glance-api.conf index 49643437..56195e33 100644 --- a/templates/juno/glance-api.conf +++ b/templates/juno/glance-api.conf @@ -4,7 +4,7 @@ use_syslog = {{ use_syslog }} debug = {{ debug }} workers = {{ workers }} -disk_formats=ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar +disk_formats = {{ disk_formats }} known_stores = {{ known_stores }} {% if rbd_pool -%} diff --git a/templates/kilo/glance-api.conf b/templates/kilo/glance-api.conf index 2bd56bee..9b592f45 100644 --- a/templates/kilo/glance-api.conf +++ b/templates/kilo/glance-api.conf @@ -76,7 +76,10 @@ rbd_store_chunk_size = 8 {% endif -%} [image_format] -disk_formats=ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar +disk_formats = {{ disk_formats }} +{% if container_formats -%} +container_formats = {{ container_formats }} +{% endif -%} {% include "section-keystone-authtoken" %} diff --git a/templates/mitaka/glance-api.conf b/templates/mitaka/glance-api.conf index f31eb20e..9bee3908 100644 --- a/templates/mitaka/glance-api.conf +++ b/templates/mitaka/glance-api.conf @@ -74,7 +74,10 @@ rbd_store_chunk_size = 8 {% endif -%} [image_format] -disk_formats=ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar +disk_formats = {{ disk_formats }} +{% if container_formats -%} +container_formats = {{ container_formats }} +{% endif -%} {% include "section-keystone-authtoken-mitaka" %} diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index 81a4c637..58936e58 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -20,6 +20,7 @@ Basic glance amulet functional tests. import amulet import os +import time import yaml from charmhelpers.contrib.openstack.amulet.deployment import ( @@ -566,6 +567,46 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): img_id = img_new.id u.delete_resource(self.glance.images, img_id, msg="glance image") + def test_411_set_disk_format(self): + sleep_time = 30 + if self._get_openstack_release() >= self.trusty_kilo: + section = 'image_format' + elif self._get_openstack_release() > self.trusty_icehouse: + section = 'DEFAULT' + else: + u.log.debug('Test not supported before juno') + return + sentry = self.glance_sentry + juju_service = 'glance' + + # Expected default and alternate values + set_default = { + 'disk-formats': 'ami,ari,aki,vhd,vmdk,raw,qcow2,vdi,iso,root-tar'} + set_alternate = {'disk-formats': 'qcow2'} + + # Config file affected by juju set config change + conf_file = '/etc/glance/glance-api.conf' + + # Make config change, check for service restarts + u.log.debug('Setting disk format {}...'.format(juju_service)) + self.d.configure(juju_service, set_alternate) + + u.log.debug('Sleeping to let hooks fire') + time.sleep(sleep_time) + u.log.debug("Checking disk format option has updated") + ret = u.validate_config_data( + sentry, + conf_file, + section, + {'disk_formats': 'qcow2'}) + if ret: + msg = "disk_formats was not updated in section {} in {}".format( + section, + conf_file) + amulet.raise_status(amulet.FAIL, msg=msg) + + self.d.configure(juju_service, set_default) + def test_900_glance_restart_on_config_change(self): """Verify that the specified services are restarted when the config is changed.""" diff --git a/unit_tests/test_glance_contexts.py b/unit_tests/test_glance_contexts.py index 34efe70d..c09b6ff4 100644 --- a/unit_tests/test_glance_contexts.py +++ b/unit_tests/test_glance_contexts.py @@ -38,6 +38,22 @@ class TestGlanceContexts(CharmTestCase): self.cache = cache cache.clear() + def test_glance_context(self): + config = { + 'disk-formats': 'dfmt1', + 'container-formats': ''} + self.config.side_effect = lambda x: config[x] + self.assertEqual(contexts.GlanceContext()(), {'disk_formats': 'dfmt1'}) + + def test_glance_context_container_fmt(self): + config = { + 'disk-formats': 'dfmt1', + 'container-formats': 'cmft1'} + self.config.side_effect = lambda x: config[x] + self.assertEqual(contexts.GlanceContext()(), + {'disk_formats': 'dfmt1', + 'container_formats': 'cmft1'}) + def test_swift_not_related(self): self.relation_ids.return_value = [] self.assertEqual(contexts.ObjectStoreContext()(), {})