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
This commit is contained in:
Marcin Wilk
2022-02-07 11:12:07 +00:00
parent 4f1665cbfa
commit 690d1d190c
4 changed files with 35 additions and 0 deletions

View File

@@ -763,3 +763,10 @@ options:
placement-aggregate-required-for-tenants options.
.
This is only supported on OpenStack Train or later releases.
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

@@ -418,6 +418,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')