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 690d1d190c)
(cherry picked from commit 6691684d89b1353f8815be40a7d7dc659a6d7336)
This commit is contained in:
Marcin Wilk 2022-02-07 11:12:07 +00:00 committed by Erlon R. Cruz
parent b7e3c30388
commit b137e2bbfc
4 changed files with 35 additions and 0 deletions

View File

@ -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.

View File

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

View File

@ -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 }}

View File

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