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')