Introduce libvirt (un)mask)_command config option

On Ubunu Focal, libvirtd can be activated by other systemd units. To
avoid this unwanted activation, and only have libvirtd start when we
tell it to start, we need to mask it. This patch introduced the config
options to mask and unmask the libvirtd service. They will be used in
a susequent patch that starts using the Focal image to unskip some
tests.

Change-Id: Ib28811fd4f155cbc02f10b43d470f4cef142513b
This commit is contained in:
Artom Lifshitz 2020-09-04 14:11:04 -04:00
parent 1de36b3268
commit 072b2c71ec
4 changed files with 26 additions and 3 deletions

View File

@ -20,6 +20,8 @@ function configure {
iniset $TEMPEST_CONFIG whitebox-libvirt start_command "$WHITEBOX_LIBVIRT_START_COMMAND"
iniset $TEMPEST_CONFIG whitebox-libvirt stop_command "$WHITEBOX_LIBVIRT_STOP_COMMAND"
iniset $TEMPEST_CONFIG whitebox-libvirt mask_command "$WHITEBOX_LIBVIRT_MASK_COMMAND"
iniset $TEMPEST_CONFIG whitebox-libvirt unmask_command "$WHITEBOX_LIBVIRT_UNMASK_COMMAND"
iniset $TEMPEST_CONFIG whitebox-database user $DATABASE_USER
iniset $TEMPEST_CONFIG whitebox-database password $DATABASE_PASSWORD

View File

@ -10,5 +10,7 @@ WHITEBOX_NOVA_COMPUTE_START_COMMAND=${WHITEBOX_NOVA_COMPUTE_START_COMMAND:-'syst
WHITEBOX_LIBVIRT_START_COMMAND=${WHITEBOX_LIBVIRT_START_COMMAND:-'systemctl start libvirtd'}
WHITEBOX_LIBVIRT_STOP_COMMAND=${WHITEBOX_LIBVIRT_STOP_COMMAND:-'systemctl stop libvirtd'}
WHITEBOX_LIBVIRT_MASK_COMMAND=${WHITEBOX_LIBVIRT_MASK_COMMAND:-'systemctl mask libvirtd'}
WHITEBOX_LIBVIRT_UNMASK_COMMAND=${WHITEBOX_LIBVIRT_UNMASK_COMMAND:-'systemctl unmask libvirtd'}
WHITEBOX_CPU_TOPOLOGY=${WHITEBOX_CPU_TOPOLOGY:-''}

View File

@ -109,7 +109,20 @@ libvirt_opts = [
help='Command to stop the libvirt service, without any '
'privilege management (ie, no sudo).',
deprecated_opts=[cfg.DeprecatedOpt('stop_command',
group='whitebox-nova-libvirt')])
group='whitebox-nova-libvirt')]),
cfg.StrOpt(
'mask_command',
help='In some situations (Ubuntu Focal, for example), libvirtd can '
'be activated by other systemd units even if it is stopped. '
'In such cases, it can be useful to mask a service (ie, disable '
'it completely) to prevent it from being started outside of our '
'control. This config options sets the command to mask libvirt. '
'If set, it will be executed after every stop command.'),
cfg.StrOpt(
'unmask_command',
help='Similar to the mask_command option, this config options sets '
'the command to unmask libvirt. If set, it will be run before '
'every start command.'),
]
database_group = cfg.OptGroup(

View File

@ -86,9 +86,11 @@ class ServiceManager(SSHClient):
raise exceptions.MissingServiceSectionException(service=service)
self.service = service
self.config_path = getattr(conf, 'config_path', None)
self.restart_command = getattr(conf, 'restart_command', None)
self.stop_command = getattr(conf, 'stop_command', None)
self.start_command = getattr(conf, 'start_command', None)
self.stop_command = getattr(conf, 'stop_command', None)
self.restart_command = getattr(conf, 'restart_command', None)
self.mask_command = getattr(conf, 'mask_command', None)
self.unmask_command = getattr(conf, 'unmask_command', None)
@contextlib.contextmanager
def config_options(self, *opts):
@ -162,10 +164,14 @@ class ServiceManager(SSHClient):
return self.execute(command, container_name=None, sudo=True)
def start(self):
if self.unmask_command:
self.execute(self.unmask_command, sudo=True)
self.execute(self.start_command, sudo=True)
def stop(self):
self.execute(self.stop_command, sudo=True)
if self.unmask_command:
self.execute(self.mask_command, sudo=True)
def restart(self):
self.execute(self.restart_command, sudo=True)