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
This commit is contained in:
Liam Young 2017-09-22 10:59:56 +00:00
parent 603c5d7c2b
commit f62513ad06
8 changed files with 88 additions and 3 deletions

View File

@ -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

View File

@ -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']

View File

@ -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(),

View File

@ -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 -%}

View File

@ -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" %}

View File

@ -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" %}

View File

@ -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."""

View File

@ -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()(), {})