From 4aaa2ce5a34679a753e261f90f16c7e5bc0c05f9 Mon Sep 17 00:00:00 2001 From: Hernan Garcia Date: Tue, 18 May 2021 06:26:27 -0500 Subject: [PATCH] add config to enable convertion to raw format image-convertion config enables image convertion to raw format this optimizes back-end capabilities while not putting the burden of converting images to their end users func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/582 Closes-Bug: 1899767 Change-Id: Id3791721f9e38899c87b88591cdc42e46ffea5c1 --- config.yaml | 6 ++++++ hooks/glance_contexts.py | 9 +++++++++ hooks/glance_utils.py | 6 +++++- templates/parts/section-image-import | 7 +++++++ templates/stein/glance-api.conf | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 templates/parts/section-image-import diff --git a/config.yaml b/config.yaml index 6e049e84..08201f0c 100644 --- a/config.yaml +++ b/config.yaml @@ -525,3 +525,9 @@ options: description: | Value of bluestore compression max blob size for solid state media on pools requested by this charm. + image-conversion: + type: boolean + default: False + description: | + Enable conversion of all images to raw format during image upload, + only supported on stein or newer. diff --git a/hooks/glance_contexts.py b/hooks/glance_contexts.py index 3f71f842..6e8e1bad 100644 --- a/hooks/glance_contexts.py +++ b/hooks/glance_contexts.py @@ -100,6 +100,15 @@ class GlancePolicyContext(OSContextGenerator): return ctxt +class GlanceImageImportContext(OSContextGenerator): + + def __call__(self): + ctxt = {} + if config('image-conversion'): + ctxt['image_conversion'] = config('image-conversion') + return ctxt + + class CephGlanceContext(OSContextGenerator): interfaces = ['ceph-glance'] diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 1ab1b03b..ced29026 100644 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -200,7 +200,8 @@ CONFIG_FILES = OrderedDict([ interface=['storage-backend'], service=['glance-api'], config_file=GLANCE_API_CONF), - context.MemcacheContext()], + context.MemcacheContext(), + glance_contexts.GlanceImageImportContext()], 'services': ['glance-api'] }), (GLANCE_SWIFT_CONF, { @@ -301,6 +302,9 @@ def determine_packages(): if CompareOpenStackReleases(os_release(VERSION_PACKAGE)) >= 'rocky': packages = [p for p in packages if not p.startswith('python-')] packages.extend(PY3_PACKAGES) + if CompareOpenStackReleases(os_release(VERSION_PACKAGE)) >= 'stein': + # required for image-conversion + packages.extend(['qemu-utils']) return sorted(packages) diff --git a/templates/parts/section-image-import b/templates/parts/section-image-import new file mode 100644 index 00000000..afd1cbd4 --- /dev/null +++ b/templates/parts/section-image-import @@ -0,0 +1,7 @@ +{% if image_conversion -%} +[image_import_opts] +image_import_plugins = ['image_conversion'] + +[image_conversion] +output_format = raw +{% endif -%} diff --git a/templates/stein/glance-api.conf b/templates/stein/glance-api.conf index 32757fb0..2a0eb151 100644 --- a/templates/stein/glance-api.conf +++ b/templates/stein/glance-api.conf @@ -111,3 +111,5 @@ auth_endpoint = {{ service_protocol }}://{{ service_host }}:{{ service_port }}/v {{ key }} = {{ val }} {% endfor -%} {% endfor%} + +{% include "parts/section-image-import" %}