Set nova config for rbd instance folder cleanup after evacuations
After evacuations and revert resizes when using rbd storage backend, the instance folder is usually left behind and causes issues when migrating the instance back to the host. With the config option set, the nova-compute service will cleanup those folders as part of the periodic checks that run for instances that have been evacuated/migrated. Closes-bug: #2019141 Change-Id: I846ccb0a95d04139b41fdad6cbf465d303d6cc09 (cherry picked from commite61d89aa47
) (cherry picked from commit003f6b6d70
) (cherry picked from commitcfafa8cf5f
) (cherry picked from commit1ddfe5e6c2
) (cherry picked from commitd3e4cc31c6
) (cherry picked from commitbe845826f9
) (cherry picked from commitf1ff0d55b8
)
This commit is contained in:
parent
1755906cc7
commit
db6fad9810
|
@ -16,6 +16,7 @@ import json
|
|||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import uuid
|
||||
|
||||
from charmhelpers.core.unitdata import kv
|
||||
|
@ -38,6 +39,7 @@ from charmhelpers.core.hookenv import (
|
|||
service_name,
|
||||
ERROR,
|
||||
INFO,
|
||||
DEBUG,
|
||||
)
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
get_os_version_package,
|
||||
|
@ -95,6 +97,16 @@ def _get_availability_zone():
|
|||
return get_az()
|
||||
|
||||
|
||||
def is_local_fs(path):
|
||||
result = False
|
||||
try:
|
||||
subprocess.check_call(["df", "-l", path])
|
||||
result = True
|
||||
except subprocess.CalledProcessError as e:
|
||||
log("Error invoking df -l {}: {}".format(path, e), level=DEBUG)
|
||||
return result
|
||||
|
||||
|
||||
def _neutron_security_groups():
|
||||
'''
|
||||
Inspects current cloud-compute relation and determine if nova-c-c has
|
||||
|
@ -314,6 +326,17 @@ class NovaComputeLibvirtContext(context.OSContextGenerator):
|
|||
|
||||
if config('libvirt-image-backend'):
|
||||
ctxt['libvirt_images_type'] = config('libvirt-image-backend')
|
||||
if config('libvirt-image-backend') == 'rbd':
|
||||
instances_path = config('instances-path')
|
||||
if instances_path in ('', None):
|
||||
instances_path = '/var/lib/nova/instances'
|
||||
if is_local_fs(instances_path):
|
||||
ctxt['ensure_libvirt_rbd_instance_dir_cleanup'] = True
|
||||
else:
|
||||
log("Skipped enabling "
|
||||
"'ensure_libvirt_rbd_instance_dir_cleanup' because"
|
||||
" instances-path is not a local mount.",
|
||||
level=INFO)
|
||||
|
||||
ctxt['force_raw_images'] = config('force-raw-images')
|
||||
ctxt['inject_password'] = config('inject-password')
|
||||
|
|
|
@ -360,6 +360,9 @@ lock_path=/var/lock/nova
|
|||
|
||||
[workarounds]
|
||||
disable_libvirt_livesnapshot = False
|
||||
{% if ensure_libvirt_rbd_instance_dir_cleanup -%}
|
||||
ensure_libvirt_rbd_instance_dir_cleanup = {{ ensure_libvirt_rbd_instance_dir_cleanup }}
|
||||
{% endif -%}
|
||||
|
||||
{% include "parts/section-ephemeral" %}
|
||||
|
||||
|
|
|
@ -384,6 +384,36 @@ class NovaComputeContextTests(CharmTestCase):
|
|||
'default_ephemeral_format': 'ext4',
|
||||
'reserved_host_memory': 512}, libvirt())
|
||||
|
||||
@patch.object(context.subprocess, 'check_call')
|
||||
def test_ensure_rbd_cleanup_rbd(self, call_mock):
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'focal'}
|
||||
self.os_release.return_value = 'ussuri'
|
||||
self.test_config.set('libvirt-image-backend', 'rbd')
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
result = libvirt()
|
||||
self.assertIn('ensure_libvirt_rbd_instance_dir_cleanup', result)
|
||||
self.assertTrue(result['ensure_libvirt_rbd_instance_dir_cleanup'])
|
||||
call_mock.assert_called_once_with(
|
||||
['df', '-l', '/var/lib/nova/instances'])
|
||||
|
||||
@patch.object(context.subprocess, 'check_call')
|
||||
def test_ensure_rbd_cleanup_rbd_non_local_mount(self, call_mock):
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'focal'}
|
||||
self.os_release.return_value = 'ussuri'
|
||||
call_mock.side_effect = [context.subprocess.CalledProcessError(
|
||||
1, 'df -l /var/foo/bar')]
|
||||
self.test_config.set('libvirt-image-backend', 'rbd')
|
||||
self.test_config.set('instances-path', '/var/foo/bar')
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
self.assertNotIn('ensure_libvirt_rbd_instance_dir_cleanup', libvirt())
|
||||
call_mock.assert_called_once_with(['df', '-l', '/var/foo/bar'])
|
||||
|
||||
def test_ensure_rbd_cleanup_non_rbd(self):
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'focal'}
|
||||
self.os_release.return_value = 'ussuri'
|
||||
libvirt = context.NovaComputeLibvirtContext()
|
||||
self.assertNotIn('ensure_libvirt_rbd_instance_dir_cleanup', libvirt())
|
||||
|
||||
def test_libvirt_context_inject_password(self):
|
||||
self.lsb_release.return_value = {'DISTRIB_CODENAME': 'zesty'}
|
||||
self.os_release.return_value = 'ocata'
|
||||
|
|
Loading…
Reference in New Issue