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
Depends-On: I13d0c332cd0b110344b7a1645e3e4fd250fce33a
Change-Id: I2f2e9e44f6bba48e15621a216539089c7e3abc1d
(cherry picked from commit c3bd6788a7)
(cherry picked from commit 649c9a7737)
(cherry picked from commit d16dadfab9)
This commit is contained in:
Marcin Wilk 2022-02-07 10:07:53 +00:00 committed by Erlon R. Cruz
parent c1f90b13a9
commit 777d3dea84
3 changed files with 61 additions and 3 deletions

View File

@ -336,7 +336,19 @@ class NovaComputeLibvirtOverrideContext(context.OSContextGenerator):
class NovaComputeVirtContext(context.OSContextGenerator):
interfaces = []
interfaces = ['cloud-compute']
@property
def allow_resize_to_same_host(self):
for rid in relation_ids('cloud-compute'):
for unit in related_units(rid):
_allow_resize_same_host =\
relation_get('allow_resize_to_same_host',
rid=rid,
unit=unit)
if _allow_resize_same_host:
return bool_from_string(_allow_resize_same_host)
return False
def __call__(self):
ctxt = {}
@ -346,6 +358,7 @@ class NovaComputeVirtContext(context.OSContextGenerator):
ctxt['enable_live_migration'] = config('enable-live-migration')
ctxt['resume_guests_state_on_host_boot'] =\
config('resume-guests-state-on-host-boot')
ctxt['allow_resize_to_same_host'] = self.allow_resize_to_same_host
return ctxt

View File

@ -177,6 +177,10 @@ disk_allocation_ratio = {{ disk_allocation_ratio }}
default_ephemeral_format = {{ default_ephemeral_format }}
{% endif %}
{% if allow_resize_to_same_host -%}
allow_resize_to_same_host = {{ allow_resize_to_same_host }}
{% endif -%}
[pci]
{% if pci_passthrough_whitelist -%}
passthrough_whitelist = {{ pci_passthrough_whitelist }}

View File

@ -655,7 +655,9 @@ class NovaComputeContextTests(CharmTestCase):
self.test_config.set('virt-type', 'lxd')
lxd = context.NovaComputeVirtContext()
self.assertEqual({'resume_guests_state_on_host_boot': False}, lxd())
self.assertEqual(
{'resume_guests_state_on_host_boot': False,
'allow_resize_to_same_host': False}, lxd())
def test_lxd_live_migration_opts_yakkety(self):
self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid})
@ -667,6 +669,7 @@ class NovaComputeContextTests(CharmTestCase):
self.assertEqual(
{'enable_live_migration': True,
'resume_guests_state_on_host_boot': False,
'allow_resize_to_same_host': False,
'virt_type': 'lxd'}, lxd())
def test_resume_guests_state_on_host_boot(self):
@ -675,7 +678,45 @@ class NovaComputeContextTests(CharmTestCase):
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}
self.test_config.set('resume-guests-state-on-host-boot', True)
lxd = context.NovaComputeVirtContext()
self.assertEqual({'resume_guests_state_on_host_boot': True}, lxd())
self.assertEqual(
{'resume_guests_state_on_host_boot': True,
'allow_resize_to_same_host': False}, lxd())
def test_allow_resize_to_same_host_empty(self):
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}
self.relation_ids.return_value = ['cloud-compute:0']
self.related_units.return_value = 'nova-cloud-controller/0'
self.test_relation.set({
'allow_resize_to_same_host': None,
})
self.assertEqual(
{'resume_guests_state_on_host_boot': False,
'allow_resize_to_same_host': False},
context.NovaComputeVirtContext()())
def test_allow_resize_to_same_host_enabled(self):
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}
self.relation_ids.return_value = ['cloud-compute:0']
self.related_units.return_value = 'nova-cloud-controller/0'
self.test_relation.set({
'allow_resize_to_same_host': 'true',
})
self.assertEqual(
{'resume_guests_state_on_host_boot': False,
'allow_resize_to_same_host': True},
context.NovaComputeVirtContext()())
def test_allow_resize_to_same_host_disabled(self):
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}
self.relation_ids.return_value = ['cloud-compute:0']
self.related_units.return_value = 'nova-cloud-controller/0'
self.test_relation.set({
'allow_resize_to_same_host': 'false',
})
self.assertEqual(
{'resume_guests_state_on_host_boot': False,
'allow_resize_to_same_host': False},
context.NovaComputeVirtContext()())
@patch.object(context.uuid, 'uuid4')
def test_libvirt_new_uuid(self, mock_uuid):