From 18030fe75b2234133ed65eccfc57ad14d00c6cff Mon Sep 17 00:00:00 2001 From: Xav Paice Date: Thu, 19 Oct 2017 11:52:24 +0100 Subject: [PATCH] Add option for image formats config For Mitaka -> Ocata, add image_formats to local_settings.py. Change-Id: I582e516eb306a52cdee2a0bd4b31046b45af7a51 Closes-bug: 1724271 --- config.yaml | 16 +++++++++++ hooks/horizon_contexts.py | 1 + templates/mitaka/local_settings.py | 35 +++++++++++++----------- templates/newton/local_settings.py | 35 +++++++++++++----------- templates/ocata/local_settings.py | 34 ++++++++++++----------- unit_tests/test_horizon_contexts.py | 42 +++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 48 deletions(-) diff --git a/config.yaml b/config.yaml index 055facb0..f7aabbff 100644 --- a/config.yaml +++ b/config.yaml @@ -350,3 +350,19 @@ options: workflow for image and instance snapshot sources when launching an instance. This option has an effect only to Ocata or newer releases. + image-formats: + type: string + default: "" + description: | + The image-formats setting can be used to alter the default list of + advertised image formats. Many installations cannot use all the formats + that Glance recognizes, restricting the list here prevents unwanted + formats from being listed in Horizon which can lead to confusion. + . + This setting takes a space separated list, for example: iso qcow2 raw + . + Supported formats are: aki, ami, ari, docker, iso, ova, qcow2, raw, vdi, + vhd, vmdk. + . + If not provided, leave the option unconfigured which enables all of the + above. diff --git a/hooks/horizon_contexts.py b/hooks/horizon_contexts.py index cafbb9e4..4ece8ea2 100644 --- a/hooks/horizon_contexts.py +++ b/hooks/horizon_contexts.py @@ -204,6 +204,7 @@ class HorizonContext(OSContextGenerator): 'default_domain': config('default-domain'), 'multi_domain': False if config('default-domain') else True, "default_create_volume": config("default-create-volume"), + 'image_formats': config('image-formats'), } return ctxt diff --git a/templates/mitaka/local_settings.py b/templates/mitaka/local_settings.py index 4c2067c8..85b7124f 100644 --- a/templates/mitaka/local_settings.py +++ b/templates/mitaka/local_settings.py @@ -364,22 +364,25 @@ OPENSTACK_HEAT_STACK = { # The OPENSTACK_IMAGE_BACKEND settings can be used to customize features # in the OpenStack Dashboard related to the Image service, such as the list # of supported image formats. -#OPENSTACK_IMAGE_BACKEND = { -# 'image_formats': [ -# ('', _('Select format')), -# ('aki', _('AKI - Amazon Kernel Image')), -# ('ami', _('AMI - Amazon Machine Image')), -# ('ari', _('ARI - Amazon Ramdisk Image')), -# ('docker', _('Docker')), -# ('iso', _('ISO - Optical Disk Image')), -# ('ova', _('OVA - Open Virtual Appliance')), -# ('qcow2', _('QCOW2 - QEMU Emulator')), -# ('raw', _('Raw')), -# ('vdi', _('VDI - Virtual Disk Image')), -# ('vhd', _('VHD - Virtual Hard Disk')), -# ('vmdk', _('VMDK - Virtual Machine Disk')), -# ], -#} +{% if image_formats -%} +OPENSTACK_IMAGE_BACKEND = { + 'image_formats': [ + ('', _('Select format')), + {% if 'aki' in image_formats -%}('aki', _('AKI - Amazon Kernel Image')),{% endif %} + {% if 'ami' in image_formats -%}('ami', _('AMI - Amazon Machine Image')),{% endif %} + {% if 'ari' in image_formats -%}('ari', _('ARI - Amazon Ramdisk Image')),{% endif %} + {% if 'docker' in image_formats -%}('docker', _('Docker')),{% endif %} + {% if 'iso' in image_formats -%}('iso', _('ISO - Optical Disk Image')),{% endif %} + {% if 'ova' in image_formats -%}('ova', _('OVA - Open Virtual Appliance')),{% endif %} + {% if 'qcow2' in image_formats -%}('qcow2', _('QCOW2 - QEMU Emulator')),{% endif %} + {% if 'raw' in image_formats -%}('raw', _('Raw')),{% endif %} + {% if 'vdi' in image_formats -%}('vdi', _('VDI - Virtual Disk Image')),{% endif %} + {% if 'vhd' in image_formats -%}('vhd', _('VHD - Virtual Hard Disk')),{% endif %} + {% if 'vmdk' in image_formats -%}('vmdk', _('VMDK - Virtual Machine Disk')),{% endif %} + ], +} +{% endif -%} + # The IMAGE_CUSTOM_PROPERTY_TITLES settings is used to customize the titles for # image custom property attributes that appear on image detail pages. diff --git a/templates/newton/local_settings.py b/templates/newton/local_settings.py index 328df9fc..e4281558 100644 --- a/templates/newton/local_settings.py +++ b/templates/newton/local_settings.py @@ -393,22 +393,25 @@ OPENSTACK_HEAT_STACK = { # The OPENSTACK_IMAGE_BACKEND settings can be used to customize features # in the OpenStack Dashboard related to the Image service, such as the list # of supported image formats. -#OPENSTACK_IMAGE_BACKEND = { -# 'image_formats': [ -# ('', _('Select format')), -# ('aki', _('AKI - Amazon Kernel Image')), -# ('ami', _('AMI - Amazon Machine Image')), -# ('ari', _('ARI - Amazon Ramdisk Image')), -# ('docker', _('Docker')), -# ('iso', _('ISO - Optical Disk Image')), -# ('ova', _('OVA - Open Virtual Appliance')), -# ('qcow2', _('QCOW2 - QEMU Emulator')), -# ('raw', _('Raw')), -# ('vdi', _('VDI - Virtual Disk Image')), -# ('vhd', _('VHD - Virtual Hard Disk')), -# ('vmdk', _('VMDK - Virtual Machine Disk')), -# ], -#} +{% if image_formats -%} +OPENSTACK_IMAGE_BACKEND = { + 'image_formats': [ + ('', _('Select format')), + {% if 'aki' in image_formats -%}('aki', _('AKI - Amazon Kernel Image')),{% endif %} + {% if 'ami' in image_formats -%}('ami', _('AMI - Amazon Machine Image')),{% endif %} + {% if 'ari' in image_formats -%}('ari', _('ARI - Amazon Ramdisk Image')),{% endif %} + {% if 'docker' in image_formats -%}('docker', _('Docker')),{% endif %} + {% if 'iso' in image_formats -%}('iso', _('ISO - Optical Disk Image')),{% endif %} + {% if 'ova' in image_formats -%}('ova', _('OVA - Open Virtual Appliance')),{% endif %} + {% if 'qcow2' in image_formats -%}('qcow2', _('QCOW2 - QEMU Emulator')),{% endif %} + {% if 'raw' in image_formats -%}('raw', _('Raw')),{% endif %} + {% if 'vdi' in image_formats -%}('vdi', _('VDI - Virtual Disk Image')),{% endif %} + {% if 'vhd' in image_formats -%}('vhd', _('VHD - Virtual Hard Disk')),{% endif %} + {% if 'vmdk' in image_formats -%}('vmdk', _('VMDK - Virtual Machine Disk')),{% endif %} + ], +} +{% endif -%} + # The IMAGE_CUSTOM_PROPERTY_TITLES settings is used to customize the titles for # image custom property attributes that appear on image detail pages. diff --git a/templates/ocata/local_settings.py b/templates/ocata/local_settings.py index cd0c4bfd..a2167571 100644 --- a/templates/ocata/local_settings.py +++ b/templates/ocata/local_settings.py @@ -397,22 +397,24 @@ OPENSTACK_HEAT_STACK = { # The OPENSTACK_IMAGE_BACKEND settings can be used to customize features # in the OpenStack Dashboard related to the Image service, such as the list # of supported image formats. -#OPENSTACK_IMAGE_BACKEND = { -# 'image_formats': [ -# ('', _('Select format')), -# ('aki', _('AKI - Amazon Kernel Image')), -# ('ami', _('AMI - Amazon Machine Image')), -# ('ari', _('ARI - Amazon Ramdisk Image')), -# ('docker', _('Docker')), -# ('iso', _('ISO - Optical Disk Image')), -# ('ova', _('OVA - Open Virtual Appliance')), -# ('qcow2', _('QCOW2 - QEMU Emulator')), -# ('raw', _('Raw')), -# ('vdi', _('VDI - Virtual Disk Image')), -# ('vhd', _('VHD - Virtual Hard Disk')), -# ('vmdk', _('VMDK - Virtual Machine Disk')), -# ], -#} +{% if image_formats -%} +OPENSTACK_IMAGE_BACKEND = { + 'image_formats': [ + ('', _('Select format')), + {% if 'aki' in image_formats -%}('aki', _('AKI - Amazon Kernel Image')),{% endif %} + {% if 'ami' in image_formats -%}('ami', _('AMI - Amazon Machine Image')),{% endif %} + {% if 'ari' in image_formats -%}('ari', _('ARI - Amazon Ramdisk Image')),{% endif %} + {% if 'docker' in image_formats -%}('docker', _('Docker')),{% endif %} + {% if 'iso' in image_formats -%}('iso', _('ISO - Optical Disk Image')),{% endif %} + {% if 'ova' in image_formats -%}('ova', _('OVA - Open Virtual Appliance')),{% endif %} + {% if 'qcow2' in image_formats -%}('qcow2', _('QCOW2 - QEMU Emulator')),{% endif %} + {% if 'raw' in image_formats -%}('raw', _('Raw')),{% endif %} + {% if 'vdi' in image_formats -%}('vdi', _('VDI - Virtual Disk Image')),{% endif %} + {% if 'vhd' in image_formats -%}('vhd', _('VHD - Virtual Hard Disk')),{% endif %} + {% if 'vmdk' in image_formats -%}('vmdk', _('VMDK - Virtual Machine Disk')),{% endif %} + ], +} +{% endif -%} # The IMAGE_CUSTOM_PROPERTY_TITLES settings is used to customize the titles for # image custom property attributes that appear on image detail pages. diff --git a/unit_tests/test_horizon_contexts.py b/unit_tests/test_horizon_contexts.py index de6173fe..98817e42 100644 --- a/unit_tests/test_horizon_contexts.py +++ b/unit_tests/test_horizon_contexts.py @@ -139,6 +139,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -164,6 +165,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": False, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -189,6 +191,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -214,6 +217,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -240,6 +244,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -269,6 +274,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -294,6 +300,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -319,6 +326,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -349,6 +357,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -374,6 +383,7 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) @@ -399,10 +409,12 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": True, + "image_formats": '', } ) def test_HorizonContext_password_autocompletion(self): + self.maxDiff = 900 self.test_config.set('allow-password-autocompletion', True) self.assertEqual(horizon_contexts.HorizonContext()(), {'compress_offline': True, 'debug': False, @@ -424,10 +436,12 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": True, "default_create_volume": True, + "image_formats": '', } ) def test_HorizonContext_default_create_volume(self): + self.maxDiff = 900 self.test_config.set('default-create-volume', False) self.assertEqual(horizon_contexts.HorizonContext()(), {'compress_offline': True, 'debug': False, @@ -449,6 +463,34 @@ class TestHorizonContexts(CharmTestCase): "multi_domain": True, "allow_password_autocompletion": False, "default_create_volume": False, + "image_formats": '', + } + ) + + def test_HorizonContext_image_formats(self): + self.maxDiff = 900 + self.test_config.set('image-formats', 'iso qcow2 raw') + self.assertEqual(horizon_contexts.HorizonContext()(), + {'compress_offline': True, 'debug': False, + 'customization_module': '', + 'default_role': 'Member', 'webroot': '/horizon', + 'ubuntu_theme': True, + 'default_theme': None, + 'virtualenv': None, + 'secret': 'secret', + 'support_profile': None, + "neutron_network_dvr": False, + "neutron_network_l3ha": False, + "neutron_network_lb": False, + "neutron_network_firewall": False, + "neutron_network_vpn": False, + "cinder_backup": False, + "password_retrieve": False, + "default_domain": None, + "multi_domain": True, + "allow_password_autocompletion": False, + "default_create_volume": True, + "image_formats": 'iso qcow2 raw', } )