From fe8ba96582c2f1e971d05eb69c8b77bdcc450543 Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Tue, 5 Sep 2023 21:27:49 +0300 Subject: [PATCH 1/2] Fix hanging SSH command on Ubuntu worker When executing `sudo /sbin/xxxx` on a Ubuntu worker machine, sudo will always ask for a password, even though the user is set as passwordless, and even if the binary does not exist. This patch removes any trace of `/sbin/xxxx` sudo commands. --- coriolis/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coriolis/utils.py b/coriolis/utils.py index 09ff85b5c..a55191865 100644 --- a/coriolis/utils.py +++ b/coriolis/utils.py @@ -710,7 +710,7 @@ def _reload_and_start(start=True): get_pty=True) def _correct_selinux_label(): - cmd = "sudo /sbin/restorecon -v %s" % serviceFilePath + cmd = "sudo restorecon -v %s" % serviceFilePath try: exec_ssh_cmd(ssh, cmd, get_pty=True) except exception.CoriolisException: From 252466490cc67499b0a5372ec127fa676bb09377 Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Tue, 5 Sep 2023 21:31:05 +0300 Subject: [PATCH 2/2] Rename duplicate VG names Duplicate VG names interfere with the OSMorphing process. This patch makes sure there are no duplicate volume group names before activating them. --- coriolis/osmorphing/osmount/base.py | 52 +++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/coriolis/osmorphing/osmount/base.py b/coriolis/osmorphing/osmount/base.py index 1eb805717..fbf393a30 100644 --- a/coriolis/osmorphing/osmount/base.py +++ b/coriolis/osmorphing/osmount/base.py @@ -8,6 +8,7 @@ import itertools import os import re +import uuid from oslo_log import log as logging import paramiko @@ -16,6 +17,7 @@ from coriolis import exception from coriolis import utils + LOG = logging.getLogger(__name__) MAJOR_COLUMN_INDEX = 4 @@ -130,6 +132,34 @@ def _get_pvs(self): LOG.debug("Physical Volume attributes: %s", pvs) return pvs + def _get_vgs(self): + vgs_cmd = ( + "sudo vgs -o vg_name,pv_name,vg_uuid, --noheadings --separator :") + out = self._exec_cmd(vgs_cmd).decode().splitlines() + LOG.debug("Output of %s command: %s", vgs_cmd, out) + vgs = {} + for line in out: + if line == "": + continue + line = line.strip().split(":") + if len(line) >= 3: + vg_name, pv_name, vg_uuid = line[0], line[1], line[2] + if vgs.get(vg_name) is None: + vgs[vg_name] = pv_name + else: + new_name = str(uuid.uuid4()) + LOG.debug( + "VG with name '%s' already detected. Renaming VG with " + "UUID '%s' to '%s' to avoid conflicts", + vg_name, vg_uuid, new_name) + self._exec_cmd("sudo vgrename %s %s" % (vg_uuid, new_name)) + vgs[new_name] = pv_name + else: + LOG.warning("Ignoring improper `vgs` output entry: %s", line) + LOG.debug("Volume groups: %s", vgs) + + return vgs + def _check_vgs(self): try: self._exec_cmd("sudo vgck") @@ -500,20 +530,14 @@ def mount_os(self): lvm_dev_paths = [] self._check_vgs() - pvs = self._get_pvs() - for vg_name in self._get_vgnames(): - found = False - for pv in pvs[vg_name]: - if pv in dev_paths: - found = True - break - if not found: - continue - self._exec_cmd("sudo vgchange -ay %s" % vg_name) - self._exec_cmd("sudo vgchange --refresh") - dev_paths_for_group = self._exec_cmd( - "sudo ls -1 /dev/%s/*" % vg_name).decode().splitlines() - lvm_dev_paths.extend(dev_paths_for_group) + vgs = self._get_vgs() + for vg_name, pv_name in vgs.items(): + if pv_name in dev_paths: + self._exec_cmd("sudo vgchange -ay %s" % vg_name) + self._exec_cmd("sudo vgchange --refresh") + dev_paths_for_group = self._exec_cmd( + "sudo ls -1 /dev/%s/*" % vg_name).decode().splitlines() + lvm_dev_paths.extend(dev_paths_for_group) LOG.debug("All LVM vols to scan: %s", lvm_dev_paths) valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs']