Merge "Allow resizing to the same host" into stable/ussuri

This commit is contained in:
Zuul
2023-05-26 15:51:14 +00:00
committed by Gerrit Code Review
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')