From 55b9667193cd610e504d399a3f51dc1bdd8bc969 Mon Sep 17 00:00:00 2001 From: Nobuto Murata Date: Mon, 13 Nov 2017 16:18:35 +0900 Subject: [PATCH] Allow to override the default volume creation behavior Now that Horizon upstream added the ability to configure the default "create volume" value when launching an instance (See. LP: #1678109), expose it as a new charm config. Change-Id: I68a6f199a72c11ad4eff2b587cb4279c91da52ae Closes-Bug: #1711342 --- config.yaml | 8 +++++++ hooks/horizon_contexts.py | 3 ++- templates/ocata/local_settings.py | 6 ++++- unit_tests/test_horizon_contexts.py | 37 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/config.yaml b/config.yaml index f81cd4a4..055facb0 100644 --- a/config.yaml +++ b/config.yaml @@ -342,3 +342,11 @@ options: default: False description: | Setting this to True will allow password form autocompletion by browser. + default-create-volume: + type: boolean + default: True + description: | + The default value for the option of creating a new volume in the + workflow for image and instance snapshot sources when launching an + instance. This option has an effect only to Ocata or newer + releases. diff --git a/hooks/horizon_contexts.py b/hooks/horizon_contexts.py index 30fe6b0a..cafbb9e4 100644 --- a/hooks/horizon_contexts.py +++ b/hooks/horizon_contexts.py @@ -202,7 +202,8 @@ class HorizonContext(OSContextGenerator): 'virtualenv': git_pip_venv_dir(projects_yaml) if config('openstack-origin-git') else None, 'default_domain': config('default-domain'), - 'multi_domain': False if config('default-domain') else True + 'multi_domain': False if config('default-domain') else True, + "default_create_volume": config("default-create-volume"), } return ctxt diff --git a/templates/ocata/local_settings.py b/templates/ocata/local_settings.py index eaa6b33e..cd0c4bfd 100644 --- a/templates/ocata/local_settings.py +++ b/templates/ocata/local_settings.py @@ -288,12 +288,16 @@ OPENSTACK_ENABLE_PASSWORD_RETRIEVE = True # properties found in the Launch Instance modal. #LAUNCH_INSTANCE_DEFAULTS = { # 'config_drive': False, -# 'enable_scheduler_hints': True +# 'enable_scheduler_hints': True, # 'disable_image': False, # 'disable_instance_snapshot': False, # 'disable_volume': False, # 'disable_volume_snapshot': False, +# 'create_volume': True, #} +LAUNCH_INSTANCE_DEFAULTS = { + 'create_volume': {{ default_create_volume }} +} # The Xen Hypervisor has the ability to set the mount point for volumes # attached to instances (other Hypervisors currently do not). Setting diff --git a/unit_tests/test_horizon_contexts.py b/unit_tests/test_horizon_contexts.py index 0bddf6c2..de6173fe 100644 --- a/unit_tests/test_horizon_contexts.py +++ b/unit_tests/test_horizon_contexts.py @@ -138,6 +138,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -162,6 +163,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": "example_domain", "multi_domain": False, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -186,6 +188,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -210,6 +213,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -235,6 +239,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -263,6 +268,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -287,6 +293,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -311,6 +318,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -340,6 +348,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -364,6 +373,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -388,6 +398,7 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": False, + "default_create_volume": True, } ) @@ -412,6 +423,32 @@ class TestHorizonContexts(CharmTestCase): "default_domain": None, "multi_domain": True, "allow_password_autocompletion": True, + "default_create_volume": True, + } + ) + + def test_HorizonContext_default_create_volume(self): + self.test_config.set('default-create-volume', False) + 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": False, } )