From 47757ada085b7f4d1569d15af6f0eb64597ea60d Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Tue, 3 Sep 2013 11:54:58 -0700 Subject: [PATCH] Make Image Service image formats configurable Allow configuration of the available image formats for image creation (corresponds to a feature added Glance). Incidentally fixes a test issue where the domain_get call wasn't being properly stubbed out. Fixes bug 1216157 Change-Id: Ifc72915d34767ce83f9d85b92ddeae0c2c00b8c6 --- .../dashboards/admin/projects/tests.py | 6 +++-- .../images_and_snapshots/images/forms.py | 24 +++++-------------- .../local/local_settings.py.example | 18 ++++++++++++++ openstack_dashboard/test/settings.py | 15 ++++++++++++ run_tests.sh | 2 +- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/projects/tests.py b/openstack_dashboard/dashboards/admin/projects/tests.py index 49e883d7c9..60f6b0d718 100644 --- a/openstack_dashboard/dashboards/admin/projects/tests.py +++ b/openstack_dashboard/dashboards/admin/projects/tests.py @@ -189,7 +189,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests): @test.create_stubs({api.keystone: ('get_default_role', 'user_list', 'group_list', - 'role_list'), + 'role_list', + 'domain_get'), api.neutron: ('is_extension_supported', 'tenant_quota_get'), quotas: ('get_default_quota_data',)}) @@ -237,7 +238,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests): 'tenant_create', 'user_list', 'group_list', - 'role_list'), + 'role_list', + 'domain_get'), quotas: ('get_default_quota_data',), api.cinder: ('tenant_quota_update',), api.nova: ('tenant_quota_update',)}) diff --git a/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py b/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py index d4ecf761b9..74c11e5035 100644 --- a/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py +++ b/openstack_dashboard/dashboards/project/images_and_snapshots/images/forms.py @@ -36,6 +36,10 @@ from horizon import messages from openstack_dashboard import api +IMAGE_BACKEND_SETTINGS = getattr(settings, 'OPENSTACK_IMAGE_BACKEND', {}) +IMAGE_FORMAT_CHOICES = IMAGE_BACKEND_SETTINGS.get('image_formats', []) + + LOG = logging.getLogger(__name__) @@ -71,24 +75,7 @@ class CreateImageForm(forms.SelfHandlingForm): required=False) disk_format = forms.ChoiceField(label=_('Format'), required=True, - choices=[('', ''), - ('aki', - _('AKI - Amazon Kernel ' - 'Image')), - ('ami', - _('AMI - Amazon Machine ' - 'Image')), - ('ari', - _('ARI - Amazon Ramdisk ' - 'Image')), - ('iso', - _('ISO - Optical Disk Image')), - ('qcow2', - _('QCOW2 - QEMU Emulator')), - ('raw', 'Raw'), - ('vdi', 'VDI'), - ('vhd', 'VHD'), - ('vmdk', 'VMDK')], + choices=[], widget=forms.Select(attrs={'class': 'switchable'})) minimum_disk = forms.IntegerField(label=_("Minimum Disk (GB)"), @@ -112,6 +99,7 @@ class CreateImageForm(forms.SelfHandlingForm): super(CreateImageForm, self).__init__(*args, **kwargs) if not settings.HORIZON_IMAGES_ALLOW_UPLOAD: self.fields['image_file'].widget = HiddenInput() + self.fields['disk_format'].choices = IMAGE_FORMAT_CHOICES def clean(self): data = super(CreateImageForm, self).clean() diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index 96325fee0b..4457f28d32 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -159,6 +159,24 @@ OPENSTACK_NEUTRON_NETWORK = { 'enable_security_group': True, } +# 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': [ + ('', ''), + ('aki', _('AKI - Amazon Kernel Image')), + ('ami', _('AMI - Amazon Machine Image')), + ('ari', _('ARI - Amazon Ramdisk Image')), + ('iso', _('ISO - Optical Disk Image')), + ('qcow2', _('QCOW2 - QEMU Emulator')), + ('raw', _('Raw')), + ('vdi', _('VDI')), + ('vhd', _('VHD')), + ('vmdk', _('VMDK')) + ] +} + # OPENSTACK_ENDPOINT_TYPE specifies the endpoint type to use for the endpoints # in the Keystone service catalog. Use this setting when Horizon is running # external to the OpenStack environment. The default is 'publicURL'. diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py index efef386644..7edfe7e356 100644 --- a/openstack_dashboard/test/settings.py +++ b/openstack_dashboard/test/settings.py @@ -91,6 +91,21 @@ OPENSTACK_HYPERVISOR_FEATURES = { 'can_set_mount_point': True, } +OPENSTACK_IMAGE_BACKEND = { + 'image_formats': [ + ('', ''), + ('aki', _('AKI - Amazon Kernel Image')), + ('ami', _('AMI - Amazon Machine Image')), + ('ari', _('ARI - Amazon Ramdisk Image')), + ('iso', _('ISO - Optical Disk Image')), + ('qcow2', _('QCOW2 - QEMU Emulator')), + ('raw', _('Raw')), + ('vdi', _('VDI')), + ('vhd', _('VHD')), + ('vmdk', _('VMDK')) + ] +} + LOGGING['loggers']['openstack_dashboard'] = { 'handlers': ['test'], 'propagate': False, diff --git a/run_tests.sh b/run_tests.sh index 682465ab2c..1a8f68ca62 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -6,7 +6,7 @@ set -o errexit # Increment me any time the environment should be rebuilt. # This includes dependncy changes, directory renames, etc. # Simple integer secuence: 1, 2, 3... -environment_version=39 +environment_version=40 #--------------------------------------------------------# function usage {