Skip to content

Commit da47bf6

Browse files
committed
lib/host: improve logging info
Signed-off-by: Olivier Hoareau <olivier.hoareau@vates.tech>
1 parent 79731cc commit da47bf6

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

lib/host.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def xo_server_connected(self) -> bool:
360360

361361
def xo_server_reconnect(self) -> None:
362362
assert self.xo_srv_id is not None
363-
logging.info("Reconnect XO to host %s" % self)
363+
logging.info(f"[{self}] Reconnect XO to host")
364364
xo_cli('server.disable', {'id': self.xo_srv_id})
365365
xo_cli('server.enable', {'id': self.xo_srv_id})
366366
wait_for(self.xo_server_connected, timeout_secs=10)
@@ -384,9 +384,9 @@ def cached_vm(self, uri: str, sr_uuid: str) -> VM | None:
384384
# Assumption: if the first disk is on the SR, the VM is.
385385
# If there's no VDI at all, then it is virtually on any SR.
386386
if not vm.vdi_uuids() or vm.get_sr().uuid == sr_uuid:
387-
logging.info(f"Reusing cached VM {vm.uuid} for {uri}")
387+
logging.info(f"[{self}] Reusing cached VM {vm.uuid} for {uri}")
388388
return vm
389-
logging.info("Could not find a VM in cache for %r", uri)
389+
logging.info(f"[{self}] Could not find a VM in cache for {uri!r}")
390390
return None
391391

392392
def import_vm(self, uri: str, sr_uuid: str | None = None, use_cache: bool = False) -> VM:
@@ -412,7 +412,7 @@ def import_vm(self, uri: str, sr_uuid: str | None = None, use_cache: bool = Fals
412412
assert not ('://' in uri and uri.startswith("clone")), "clone URIs require cache enabled"
413413

414414
params: dict[str, str | bool | dict[str, str]] = {}
415-
msg = "Import VM %s" % uri
415+
msg = f"[{self}] Import VM {uri}"
416416
if '://' in uri:
417417
params['url'] = uri
418418
else:
@@ -430,7 +430,7 @@ def import_vm(self, uri: str, sr_uuid: str | None = None, use_cache: bool = Fals
430430
vif.move(self.management_network())
431431
if use_cache:
432432
cache_key = self.vm_cache_key(uri)
433-
logging.info(f"Marking VM {vm.uuid} as cached")
433+
logging.info(f"[{self}] Marking VM {vm.uuid} as cached")
434434
vm.param_set('name-description', cache_key)
435435
return vm
436436

@@ -450,13 +450,13 @@ def import_iso(self, uri: str, sr: SR) -> VDI:
450450
try:
451451
params: dict[str, str | bool | dict[str, str]] = {'uuid': vdi_uuid}
452452
if '://' in uri:
453-
logging.info(f"Download ISO {uri}")
453+
logging.info(f"[{self}] Download ISO {uri}")
454454
download_path = f'/tmp/{vdi_uuid}'
455455
self.ssh(f"curl -o '{download_path}' '{uri}'")
456456
params['filename'] = download_path
457457
else:
458458
params['filename'] = uri
459-
logging.info(f"Import ISO {uri}: name {random_name}, uuid {vdi_uuid}")
459+
logging.info(f"[{self}] Import ISO {uri}: name {random_name}, uuid {vdi_uuid}")
460460

461461
self.xe('vdi-import', params)
462462
finally:
@@ -552,7 +552,7 @@ def update(self, enablerepos: list[str] = [], reboot: bool = True) -> None:
552552
logging.info(f"[{self}] Updated successfully!")
553553

554554
def restart_toolstack(self, verify: bool = False) -> None:
555-
logging.info("Restart toolstack on host %s" % self)
555+
logging.info(f"[{self}] Restart toolstack on host")
556556
self.ssh('xe-toolstack-restart')
557557
if verify:
558558
self.wait_for_xapi_enabled()
@@ -625,7 +625,7 @@ def get_last_yum_history_tid(self) -> int:
625625
# yum history list fails if the list is empty, and it's also not possible to rollback
626626
# to before the first transaction, so "0" would not be appropriate as last transaction.
627627
# To workaround this, create transactions: install and remove a small package.
628-
logging.info('Install and remove a small package to workaround empty yum history.')
628+
logging.info(f"[{self}] Install and remove a small package to workaround empty yum history.")
629629
self.yum_install(['gpm-libs'])
630630
self.yum_remove(['gpm-libs'])
631631
history_str = self.ssh('yum history list --noplugins')
@@ -646,14 +646,14 @@ def get_last_yum_history_tid(self) -> int:
646646
raise Exception('Unable to parse correctly last yum history tid. Output:\n' + history_str)
647647

648648
def yum_install(self, packages: list[str], enablerepo: str | None = None) -> str:
649-
logging.info('Install packages: %s on host %s' % (' '.join(packages), self))
649+
logging.info(f"[{self}] Install packages: {' '.join(packages)} on host")
650650
cmd = 'yum install --setopt=skip_missing_names_on_install=False -y'
651651
if enablerepo is not None:
652652
cmd = f'{cmd} --enablerepo={enablerepo}'
653653
return self.ssh(f'{cmd} {" ".join(packages)}')
654654

655655
def yum_remove(self, packages: list[str]) -> str:
656-
logging.info('Remove packages: %s from host %s' % (' '.join(packages), self))
656+
logging.info(f"[{self}] Remove packages: {' '.join(packages)} from host")
657657
return self.ssh(f'yum remove -y {" ".join(packages)}')
658658

659659
def packages(self) -> list[str]:
@@ -671,14 +671,14 @@ def is_package_installed(self, package: str) -> bool:
671671
return self.ssh_with_result(f'rpm -q {package}').returncode == 0
672672

673673
def yum_save_state(self) -> None:
674-
logging.info(f"Save yum state for host {self}")
674+
logging.info(f"[{self}] Save yum state for host")
675675
# For now, that saved state feature does not support several saved states
676676
assert self.saved_packages_list is None, "There is already a saved package list set"
677677
self.saved_packages_list = self.packages()
678678
self.saved_rollback_id = self.get_last_yum_history_tid()
679679

680680
def yum_restore_saved_state(self) -> None:
681-
logging.info(f"Restore yum state for host {self}")
681+
logging.info(f"[{self}] Restore yum state for host")
682682
""" Restore yum state to saved state. """
683683
assert self.saved_packages_list is not None, \
684684
"Can't restore previous state without a package list: no saved packages list"
@@ -703,7 +703,7 @@ def yum_restore_saved_state(self) -> None:
703703
self.saved_rollback_id = None
704704

705705
def reboot(self, verify: bool = False) -> None:
706-
logging.info("Reboot host %s" % self)
706+
logging.info(f"[{self}] Reboot host")
707707
# Running `reboot` directly immediately disconnects the ssh session and makes the ssh client return with an
708708
# error code. Instead, we schedule the reboot a few seconds later to let the ssh command return properly.
709709
self.ssh('systemd-run --on-active=2s reboot')
@@ -889,7 +889,7 @@ def sr_create(self, sr_type: str, label: str, device_config: dict[str, str], sha
889889
params['device-config:{}'.format(key)] = value
890890

891891
logging.info(
892-
f"Create {sr_type} SR on host {self} with label '{label}' and device-config: {str(device_config)}"
892+
f"[{self}] Create {sr_type} SR on host with label '{label}' and device-config: {str(device_config)}"
893893
)
894894
sr_uuid = self.xe('sr-create', params)
895895
sr = SR(sr_uuid, self.pool)
@@ -1047,7 +1047,7 @@ def create_bond(self, network: Network, pifs: list[PIF], mode: str | None = None
10471047
args['mode'] = mode
10481048

10491049
uuid = self.xe("bond-create", args, minimal=True)
1050-
logging.info(f"New Bond: {uuid}")
1050+
logging.info(f"[{self}] New Bond: {uuid}")
10511051

10521052
return Bond(self, uuid)
10531053

@@ -1059,8 +1059,8 @@ def create_network(self, label: str, description: str | None = None) -> Network:
10591059
if description is not None:
10601060
args['name-description'] = description
10611061

1062-
logging.info(f"Creating network '{label}'")
1062+
logging.info(f"[{self}] Creating network '{label}'")
10631063
uuid = self.xe("network-create", args, minimal=True)
1064-
logging.info(f"New Network: {uuid}")
1064+
logging.info(f"[{self}] New Network: {uuid}")
10651065

10661066
return Network(self, uuid)

0 commit comments

Comments
 (0)