systemd detection result caching nit fixes
Change-Id: If54dd5c33a2e6535cc2ae9cf96179a202f6ed1a3 Related-bug: #1756823
This commit is contained in:
parent
357da989c1
commit
48f1826711
|
@ -33,8 +33,7 @@ from nova.virt.libvirt.volume import quobyte
|
|||
|
||||
|
||||
@ddt.ddt
|
||||
@mock.patch.object(quobyte, 'found_sysd', False)
|
||||
@mock.patch.object(quobyte, 'sysd_checked', False)
|
||||
@mock.patch.object(quobyte, '_is_systemd', None)
|
||||
class QuobyteTestCase(test.NoDBTestCase):
|
||||
"""Tests the nova.virt.libvirt.volume.quobyte module utilities."""
|
||||
|
||||
|
@ -74,8 +73,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
"is-system-running",
|
||||
check_exit_code=[0, 1])
|
||||
mock_proc.assert_called_once()
|
||||
self.assertTrue(quobyte.sysd_checked)
|
||||
self.assertTrue(quobyte.found_sysd)
|
||||
self.assertTrue(quobyte.is_systemd())
|
||||
|
||||
@mock.patch.object(psutil.Process, "name", return_value="NOT_systemd")
|
||||
@mock.patch.object(os.path, "exists", return_value=False)
|
||||
|
@ -83,8 +81,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
self.assertFalse(quobyte.is_systemd())
|
||||
mock_exists.assert_called_once_with(quobyte.SYSTEMCTL_CHECK_PATH)
|
||||
mock_proc.assert_called_once_with()
|
||||
self.assertTrue(quobyte.sysd_checked)
|
||||
self.assertFalse(quobyte.found_sysd)
|
||||
self.assertFalse(quobyte.is_systemd())
|
||||
|
||||
@mock.patch.object(psutil.Process, "name", return_value="NOT_systemd")
|
||||
@mock.patch.object(processutils, "execute")
|
||||
|
@ -100,8 +97,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
"is-system-running",
|
||||
check_exit_code=[0, 1])
|
||||
mock_proc.assert_called_once_with()
|
||||
self.assertTrue(quobyte.sysd_checked)
|
||||
self.assertFalse(quobyte.found_sysd)
|
||||
self.assertFalse(quobyte.is_systemd())
|
||||
|
||||
@ddt.data(None, '/some/arbitrary/path')
|
||||
@mock.patch.object(fileutils, "ensure_tree")
|
||||
|
@ -113,6 +109,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
|
||||
quobyte._is_systemd = False
|
||||
quobyte.mount_volume(quobyte_volume, export_mnt_base, cfg_file)
|
||||
|
||||
mock_ensure_tree.assert_called_once_with(export_mnt_base)
|
||||
|
@ -129,7 +126,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
quobyte_volume = '192.168.1.1/volume-00001'
|
||||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
quobyte.found_sysd = True
|
||||
quobyte._is_systemd = True
|
||||
|
||||
quobyte.mount_volume(quobyte_volume, export_mnt_base, cfg_file)
|
||||
|
||||
|
@ -146,7 +143,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
quobyte_volume = '192.168.1.1/volume-00001'
|
||||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
|
||||
quobyte._is_systemd = False
|
||||
self.assertRaises(processutils.ProcessExecutionError,
|
||||
quobyte.mount_volume,
|
||||
quobyte_volume,
|
||||
|
@ -160,6 +157,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
|
||||
quobyte._is_systemd = False
|
||||
quobyte.umount_volume(export_mnt_base)
|
||||
|
||||
mock_lv_umount.assert_called_once_with(export_mnt_base)
|
||||
|
@ -170,7 +168,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
quobyte_volume = '192.168.1.1/volume-00001'
|
||||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
quobyte.found_sysd = True
|
||||
quobyte._is_systemd = True
|
||||
|
||||
quobyte.umount_volume(export_mnt_base)
|
||||
|
||||
|
@ -183,7 +181,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
quobyte_volume = '192.168.1.1/volume-00001'
|
||||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
quobyte.found_sysd = True
|
||||
quobyte._is_systemd = True
|
||||
|
||||
def exec_side_effect(*cmd, **kwargs):
|
||||
exerror = processutils.ProcessExecutionError(
|
||||
|
@ -205,7 +203,7 @@ class QuobyteTestCase(test.NoDBTestCase):
|
|||
quobyte_volume = '192.168.1.1/volume-00001'
|
||||
export_mnt_base = os.path.join(mnt_base,
|
||||
utils.get_hash_str(quobyte_volume))
|
||||
quobyte.found_sysd = True
|
||||
quobyte._is_systemd = True
|
||||
|
||||
quobyte.umount_volume(export_mnt_base)
|
||||
|
||||
|
|
|
@ -41,30 +41,34 @@ DRIVER_IO = 'native'
|
|||
VALID_SYSD_STATES = ["starting", "running", "degraded"]
|
||||
SYSTEMCTL_CHECK_PATH = "/run/systemd/system"
|
||||
|
||||
sysd_checked = False
|
||||
found_sysd = False
|
||||
|
||||
_is_systemd = None
|
||||
|
||||
|
||||
def is_systemd():
|
||||
"""Checks if the host is running systemd"""
|
||||
global sysd_checked
|
||||
global found_sysd
|
||||
global _is_systemd
|
||||
|
||||
if _is_systemd is not None:
|
||||
return _is_systemd
|
||||
|
||||
tmp_is_systemd = False
|
||||
|
||||
if psutil.Process(1).name() == "systemd" or os.path.exists(
|
||||
SYSTEMCTL_CHECK_PATH):
|
||||
# NOTE(kaisers): exit code might be >1 in theory but in practice this
|
||||
# is hard coded to 1. Due to backwards compatibility and systemd
|
||||
# CODING_STYLE this is unlikely to change.
|
||||
sysdout, sysderr = processutils.execute("systemctl",
|
||||
"is-system-running",
|
||||
check_exit_code=[0, 1])
|
||||
"is-system-running",
|
||||
check_exit_code=[0, 1])
|
||||
for state in VALID_SYSD_STATES:
|
||||
if state == sysdout.strip():
|
||||
found_sysd = True
|
||||
sysd_checked = True
|
||||
return found_sysd
|
||||
tmp_is_systemd = True
|
||||
break
|
||||
|
||||
sysd_checked = True
|
||||
return False
|
||||
_is_systemd = tmp_is_systemd
|
||||
return _is_systemd
|
||||
|
||||
|
||||
def mount_volume(volume, mnt_base, configfile=None):
|
||||
|
@ -73,7 +77,7 @@ def mount_volume(volume, mnt_base, configfile=None):
|
|||
|
||||
# Note(kaisers): with systemd this requires a separate CGROUP to
|
||||
# prevent Nova service stop/restarts from killing the mount.
|
||||
if found_sysd:
|
||||
if is_systemd():
|
||||
LOG.debug('Mounting volume %s at mount point %s via systemd-run',
|
||||
volume, mnt_base)
|
||||
nova.privsep.libvirt.systemd_run_qb_mount(volume, mnt_base,
|
||||
|
@ -90,7 +94,7 @@ def mount_volume(volume, mnt_base, configfile=None):
|
|||
def umount_volume(mnt_base):
|
||||
"""Wraps execute calls for unmouting a Quobyte volume"""
|
||||
try:
|
||||
if found_sysd:
|
||||
if is_systemd():
|
||||
nova.privsep.libvirt.umount(mnt_base)
|
||||
else:
|
||||
nova.privsep.libvirt.unprivileged_umount(mnt_base)
|
||||
|
@ -133,9 +137,6 @@ def validate_volume(mount_path):
|
|||
class LibvirtQuobyteVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
||||
"""Class implements libvirt part of volume driver for Quobyte."""
|
||||
|
||||
def __init__(self, host):
|
||||
super(LibvirtQuobyteVolumeDriver, self).__init__(host)
|
||||
|
||||
def _get_mount_point_base(self):
|
||||
return CONF.libvirt.quobyte_mount_point_base
|
||||
|
||||
|
|
Loading…
Reference in New Issue