Skip to content

Commit 539fabb

Browse files
fabi200123Dany9966
authored andcommitted
Fix issue with files containing non-utf8 characters
1 parent f276288 commit 539fabb

14 files changed

Lines changed: 144 additions & 138 deletions

File tree

coriolis/osmorphing/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _read_config_file_sudo(self, chroot_path, check_exists=False):
335335
if check_exists:
336336
raise IOError("could not find %s" % chroot_path)
337337
return {}
338-
content = self._read_file_sudo(chroot_path).decode()
338+
content = self._read_file_sudo(chroot_path)
339339
config = utils.parse_ini_config(content)
340340
return config
341341

@@ -484,7 +484,7 @@ def _test_path_chroot(self, path):
484484
if path.startswith('/') is False:
485485
path = "/%s" % path
486486
exists = self._exec_cmd_chroot(
487-
'[ -f "%s" ] && echo 1 || echo 0' % path).decode().rstrip('\n')
487+
'[ -f "%s" ] && echo 1 || echo 0' % path).rstrip('\n')
488488
return exists == "1"
489489

490490
def _read_file_sudo(self, chroot_path):
@@ -497,7 +497,7 @@ def _read_file_sudo(self, chroot_path):
497497
def _read_grub_config(self, config):
498498
if self._test_path_chroot(config) is False:
499499
raise IOError("could not find %s" % config)
500-
contents = self._read_file_sudo(config).decode()
500+
contents = self._read_file_sudo(config)
501501
ret = {}
502502
for line in contents.split('\n'):
503503
if line.startswith("#"):
@@ -512,7 +512,7 @@ def _get_grub_config_obj(self, grub_conf=None):
512512
grub_conf = grub_conf or "/etc/default/grub"
513513
if self._test_path_chroot(grub_conf) is False:
514514
raise IOError("could not find %s" % grub_conf)
515-
tmp_file = self._exec_cmd_chroot("mktemp").decode().rstrip('\n')
515+
tmp_file = self._exec_cmd_chroot("mktemp").rstrip('\n')
516516
self._exec_cmd_chroot(
517517
"/bin/cp -fp %s %s" % (grub_conf, tmp_file))
518518
config_file = self._read_grub_config(tmp_file)
@@ -561,7 +561,7 @@ def replace_in_cfg(opt, val):
561561
replace_in_cfg(option, value)
562562
else:
563563
append_to_cfg(option, value)
564-
cfg = self._read_file_sudo(config_obj["location"]).decode()
564+
cfg = self._read_file_sudo(config_obj["location"])
565565
LOG.warning("TEMP CONFIG IS: %r" % cfg)
566566

567567
def _set_grub2_cmdline(self, config_obj, options, clobber=False):

coriolis/osmorphing/debian.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def disable_predictable_nic_names(self):
4242
grub_cfg = "etc/default/grub"
4343
if self._test_path_chroot(grub_cfg) is False:
4444
return
45-
contents = self._read_file_sudo(grub_cfg).decode()
45+
contents = self._read_file_sudo(grub_cfg)
4646
cfg = utils.Grub2ConfigEditor(contents)
4747
cfg.append_to_option(
4848
"GRUB_CMDLINE_LINUX_DEFAULT",
@@ -127,8 +127,7 @@ def set_net_config(self, nics_info, dhcp):
127127
def get_installed_packages(self):
128128
cmd = "dpkg-query -f '${binary:Package}\\n' -W"
129129
try:
130-
self.installed_packages = self._exec_cmd_chroot(
131-
cmd).decode('utf-8').splitlines()
130+
self.installed_packages = self._exec_cmd_chroot(cmd).splitlines()
132131
except exception.CoriolisException:
133132
self.installed_packages = []
134133

coriolis/osmorphing/osmount/base.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_connection(self):
122122

123123
class BaseLinuxOSMountTools(BaseSSHOSMountTools):
124124
def _get_pvs(self):
125-
out = self._exec_cmd("sudo pvdisplay -c").decode().splitlines()
125+
out = self._exec_cmd("sudo pvdisplay -c").splitlines()
126126
LOG.debug("Output of 'pvdisplay -c' command: %s", out)
127127
pvs = {}
128128
for line in out:
@@ -150,7 +150,7 @@ def _get_vgs(self):
150150
"""
151151
vgs_cmd = (
152152
"sudo vgs -o vg_name,pv_name,vg_uuid, --noheadings --separator :")
153-
out = self._exec_cmd(vgs_cmd).decode().splitlines()
153+
out = self._exec_cmd(vgs_cmd).splitlines()
154154
LOG.debug("Output of %s command: %s", vgs_cmd, out)
155155
vgs_uuid_map = {}
156156
for line in out:
@@ -197,8 +197,7 @@ def _check_vgs(self):
197197

198198
def _get_vgnames(self):
199199
vg_names = []
200-
vgscan_out_lines = self._exec_cmd(
201-
"sudo vgscan").decode().splitlines()
200+
vgscan_out_lines = self._exec_cmd("sudo vgscan").splitlines()
202201
LOG.debug("Output of vgscan commnad: %s", vgscan_out_lines)
203202
for vgscan_out_line in vgscan_out_lines:
204203
m = re.match(
@@ -212,7 +211,7 @@ def _get_vgnames(self):
212211
def _get_lv_paths(self):
213212
""" Returns list with paths of available LVM volumes. """
214213
lvm_paths = []
215-
out = self._exec_cmd("sudo lvdisplay -c").decode().strip()
214+
out = self._exec_cmd("sudo lvdisplay -c").strip()
216215
if out:
217216
LOG.debug("Decoded `lvdisplay` output data: %s", out)
218217
out_lines = out.splitlines()
@@ -353,7 +352,7 @@ def _check_mount_fstab_partitions(
353352
def _get_symlink_target(self, symlink):
354353
target = symlink
355354
try:
356-
target = self._exec_cmd('readlink -en %s' % symlink).decode()
355+
target = self._exec_cmd('readlink -en %s' % symlink)
357356
LOG.debug("readlink %s returned: %s" % (symlink, target))
358357
except Exception:
359358
LOG.warn('Target not found for symlink: %s. Original link path '
@@ -375,8 +374,7 @@ def _get_device_file_paths(self, symlink_list):
375374
return dev_file_paths
376375

377376
def _get_mounted_devices(self):
378-
mounts = self._exec_cmd(
379-
"cat /proc/mounts").decode().splitlines()
377+
mounts = self._exec_cmd("cat /proc/mounts").splitlines()
380378
ret = []
381379
mounted_device_numbers = []
382380
dev_nmb_cmd = "mountpoint -x %s"
@@ -390,10 +388,9 @@ def _get_mounted_devices(self):
390388
continue
391389
ret.append(dev_name)
392390
mounted_device_numbers.append(
393-
self._exec_cmd(dev_nmb_cmd % dev_name).decode().rstrip())
391+
self._exec_cmd(dev_nmb_cmd % dev_name).rstrip())
394392

395-
block_devs = self._exec_cmd(
396-
"ls -al /dev | grep ^b").decode().splitlines()
393+
block_devs = self._exec_cmd("ls -al /dev | grep ^b").splitlines()
397394
for dev_line in block_devs:
398395
dev = dev_line.split()
399396
major_minor = "%s:%s" % (
@@ -409,8 +406,7 @@ def _get_mounted_devices(self):
409406
return ret
410407

411408
def _get_mount_destinations(self):
412-
mounts = self._exec_cmd(
413-
"cat /proc/mounts").decode().splitlines()
409+
mounts = self._exec_cmd("cat /proc/mounts").splitlines()
414410
ret = set()
415411
for line in mounts:
416412
colls = line.split()
@@ -424,8 +420,7 @@ def _get_volume_block_devices(self):
424420
# where 'ln -s /dev/dm-N /dev/<VG-name>/<LV-name>'
425421
# Querying for the kernel device name (KNAME) should ensure we get the
426422
# device names we desire both for physical and logical volumes.
427-
volume_devs = self._exec_cmd(
428-
"lsblk -lnao KNAME").decode().splitlines()
423+
volume_devs = self._exec_cmd("lsblk -lnao KNAME").splitlines()
429424
LOG.debug("All block devices: %s", str(volume_devs))
430425

431426
volume_devs = ["/dev/%s" % d for d in volume_devs if
@@ -446,7 +441,7 @@ def _find_dev_with_contents(self, devices, all_files=None,
446441
dev_name = None
447442
for dev_path in devices:
448443
dirs = None
449-
tmp_dir = self._exec_cmd('mktemp -d').decode().splitlines()[0]
444+
tmp_dir = self._exec_cmd('mktemp -d').splitlines()[0]
450445
try:
451446
self._exec_cmd('sudo mount %s %s' % (dev_path, tmp_dir))
452447
# NOTE: it's possible that the device was mounted successfully
@@ -508,7 +503,7 @@ def _find_and_mount_root(self, devices):
508503
"being migrated.")
509504

510505
try:
511-
tmp_dir = self._exec_cmd('mktemp -d').decode().splitlines()[0]
506+
tmp_dir = self._exec_cmd('mktemp -d').splitlines()[0]
512507
self._exec_cmd('sudo mount %s %s' % (os_root_device, tmp_dir))
513508
os_root_dir = tmp_dir
514509
except Exception as ex:
@@ -560,7 +555,7 @@ def mount_os(self):
560555
for volume_dev in volume_devs:
561556
self._exec_cmd("sudo partx -v -a %s || true" % volume_dev)
562557
dev_paths += self._exec_cmd(
563-
"sudo ls -1 %s*" % volume_dev).decode().splitlines()
558+
"sudo ls -1 %s*" % volume_dev).splitlines()
564559
LOG.debug("All simple devices to scan: %s", dev_paths)
565560

566561
lvm_dev_paths = []
@@ -573,7 +568,7 @@ def mount_os(self):
573568
self._exec_cmd("sudo vgchange -ay -S vg_uuid=%s" % vg_uuid)
574569
self._exec_cmd("sudo vgchange --refresh")
575570
dev_paths_for_group = self._exec_cmd(
576-
f"sudo ls -1 /dev/{vg_props['name']}/*").decode().splitlines()
571+
f"sudo ls -1 /dev/{vg_props['name']}/*").splitlines()
577572
lvm_dev_paths.extend(dev_paths_for_group)
578573
LOG.debug("All LVM vols to scan: %s", lvm_dev_paths)
579574

@@ -592,8 +587,8 @@ def mount_os(self):
592587
dev_path, dev_target)
593588
continue
594589
fs_type = self._exec_cmd(
595-
"sudo blkid -o value -s TYPE %s || true" %
596-
dev_path).decode().splitlines()
590+
"sudo blkid -o value -s TYPE %s || true" % dev_path
591+
).splitlines()
597592
LOG.debug('Device %s filesystem types: %s', dev_path, fs_type)
598593
if fs_type and fs_type[0] in valid_filesystems:
599594
if fs_type[0] == "xfs":

coriolis/osmorphing/redhat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def set_net_config(self, nics_info, dhcp):
172172
def get_installed_packages(self):
173173
cmd = 'rpm -qa --qf "%{NAME}\\n"'
174174
try:
175-
self.installed_packages = self._exec_cmd_chroot(
176-
cmd).decode('utf-8').splitlines()
175+
self.installed_packages = self._exec_cmd_chroot(cmd).splitlines()
177176
except exception.CoriolisException:
178177
LOG.warning("Failed to get installed packages")
179178
LOG.trace(utils.get_exception_details())
@@ -231,7 +230,7 @@ def _find_yum_repos(self, repos_to_enable=[]):
231230
for file in repofiles:
232231
path = os.path.join(reposdir_path, file)
233232
try:
234-
content = self._read_file_sudo(path).decode()
233+
content = self._read_file_sudo(path)
235234
except Exception as e:
236235
LOG.warning(
237236
"Could not read yum repository file %s: %s", path, e)

coriolis/osmorphing/suse.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def set_net_config(self, nics_info, dhcp):
6868
def get_installed_packages(self):
6969
cmd = 'rpm -qa --qf "%{NAME}\\n"'
7070
try:
71-
self.installed_packages = self._exec_cmd_chroot(
72-
cmd).decode('utf-8').splitlines()
71+
self.installed_packages = self._exec_cmd_chroot(cmd).splitlines()
7372
except exception.CoriolisException:
7473
LOG.warning("Failed to get installed packages")
7574
LOG.trace(utils.get_exception_details())
@@ -134,7 +133,7 @@ def post_packages_install(self, package_names):
134133

135134
def _enable_sles_module(self, module):
136135
available_modules = self._exec_cmd_chroot(
137-
"SUSEConnect --list-extensions").decode()
136+
"SUSEConnect --list-extensions")
138137
module_match = re.search("%s.*" % module, available_modules)
139138
try:
140139
module_path = module_match.group(0)
@@ -170,8 +169,7 @@ def _add_cloud_tools_repo(self):
170169
def _get_repos(self):
171170
repos = {}
172171
repos_list = self._exec_cmd_chroot(
173-
"zypper repos -u | awk -F '|' '/^\s[0-9]+/ {print $2 $7}'"
174-
).decode()
172+
"zypper repos -u | awk -F '|' '/^\s[0-9]+/ {print $2 $7}'")
175173
for repo in repos_list.splitlines():
176174
alias, uri = repo.strip().split()
177175
repos[alias] = uri

coriolis/providers/backup_writers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def _setup_certificates(self, ssh):
912912
def _read_remote_file_sudo(self, remote_path):
913913
contents = utils.exec_ssh_cmd(
914914
self._ssh, "sudo cat %s" % remote_path, get_pty=True)
915-
return contents.decode()
915+
return contents
916916

917917
def _init_writer(self, ssh, cert_paths):
918918
cmdline = ("%(cmd)s run -ca-cert %(ca_cert)s -key "

0 commit comments

Comments
 (0)