From b137e2bbfc3b4020bf5d068bcea043617daf1d2e Mon Sep 17 00:00:00 2001 From: Marcin Wilk Date: Mon, 7 Feb 2022 11:12:07 +0000 Subject: [PATCH] Allow resizing to the same host By default resizing an instance to the same host as the source is not enabled. This change adds new charm config option that maps directly to the nova.conf setting which effectively gives a user possibility to enable/disable this functionality. Closes-Bug: #1946620 Change-Id: I13d0c332cd0b110344b7a1645e3e4fd250fce33a (cherry picked from commit 690d1d190ca35958abd8d2c280a954e884e2c2f2) (cherry picked from commit 6691684d89b1353f8815be40a7d7dc659a6d7336) --- config.yaml | 7 +++++++ hooks/nova_cc_context.py | 4 ++++ templates/train/nova.conf | 4 ++++ unit_tests/test_nova_cc_contexts.py | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/config.yaml b/config.yaml index bbef82d5..bcc6f0b2 100644 --- a/config.yaml +++ b/config.yaml @@ -684,3 +684,10 @@ options: cloud utilization. . Note: only effective from Pike onward + allow-resize-to-same-host: + type: boolean + default: False + description: | + Allow resizing to the same host. Setting this option to True will add the + source host to the destination options for consideration by the + scheduler when resizing an instance. diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index 83731346..e68983af 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -405,11 +405,15 @@ class NovaConfigContext(ch_context.WorkerConfigContext): ctxt['cpu_allocation_ratio'] = hookenv.config('cpu-allocation-ratio') ctxt['ram_allocation_ratio'] = hookenv.config('ram-allocation-ratio') + ctxt['allow_resize_to_same_host'] = hookenv.config( + 'allow-resize-to-same-host') + for rid in hookenv.relation_ids('cloud-compute'): rdata = { 'disk_allocation_ratio': ctxt['disk_allocation_ratio'], 'cpu_allocation_ratio': ctxt['cpu_allocation_ratio'], 'ram_allocation_ratio': ctxt['ram_allocation_ratio'], + 'allow_resize_to_same_host': ctxt['allow_resize_to_same_host'], } hookenv.relation_set(relation_settings=rdata, relation_id=rid) diff --git a/templates/train/nova.conf b/templates/train/nova.conf index 95131a46..7e9a9205 100644 --- a/templates/train/nova.conf +++ b/templates/train/nova.conf @@ -112,6 +112,10 @@ default_floating_pool = {{ default_floating_pool }} volume_api_class=nova.volume.cinder.API {% endif -%} +{% if allow_resize_to_same_host -%} +allow_resize_to_same_host = True +{% endif -%} + {% if user_config_flags -%} {% for key, value in user_config_flags.items() -%} {{ key }} = {{ value }} diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index a5724671..d6d3abd4 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -410,6 +410,26 @@ class NovaComputeContextTests(CharmTestCase): _pci_alias_list = [_pci_alias1, _pci_alias2] + @mock.patch('charmhelpers.contrib.openstack.ip.config') + @mock.patch('charmhelpers.core.hookenv.local_unit') + @mock.patch('charmhelpers.contrib.openstack.context.config') + def test_allow_resize_to_same_host(self, mock_config, + local_unit, mock_config_ip): + _rel_data = {'disk_allocation_ratio': + self.config('disk-allocation-ratio'), + 'cpu_allocation_ratio': + self.config('cpu-allocation-ratio'), + 'ram_allocation_ratio': + self.config('ram-allocation-ratio'), + 'allow_resize_to_same_host': True} + self.test_config.set('allow-resize-to-same-host', True) + self.relation_ids.return_value = ['nova-compute:0'] + ctxt = context.NovaConfigContext()() + self.assertEqual(ctxt['allow_resize_to_same_host'], + self.config('allow-resize-to-same-host')) + self.relation_set.assert_called_with(relation_id=mock.ANY, + relation_settings=_rel_data) + @mock.patch('charmhelpers.contrib.openstack.ip.resolve_address') @mock.patch('charmhelpers.contrib.openstack.ip.unit_get') @mock.patch('charmhelpers.contrib.hahelpers.cluster.relation_ids')