@@ -360,13 +360,13 @@ 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 )
367367 # wait for XO to know about the host. Apparently a connected server status
368368 # is not enough to guarantee that the host object exists yet.
369- wait_for (lambda : xo_object_exists (self .uuid ), " Wait for XO to know about HOST %s" % self .uuid )
369+ wait_for (lambda : xo_object_exists (self .uuid ), f"[ { self } ] Wait for XO to know about HOST { self .uuid } " )
370370
371371 @staticmethod
372372 def vm_cache_key (uri : str ) -> str :
@@ -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 :
@@ -403,7 +403,7 @@ def import_vm(self, uri: str, sr_uuid: str | None = None, use_cache: bool = Fals
403403 vm .param_clear ('name-description' )
404404 if uri .startswith ("clone+start" ):
405405 vm .start ()
406- wait_for (vm .is_running , " Wait for VM running" )
406+ wait_for (vm .is_running , f"[ { self } ] Wait for VM running ( { vm . uuid } ) " )
407407 else :
408408 vm = self .cached_vm (uri , sr_uuid )
409409 if 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,37 +552,37 @@ 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 ()
559559
560560 def wait_for_host_down (self , timeout_secs : int = 2 * 60 ) -> None :
561561 wait_for_not (
562562 lambda : commands .local_cmd (["ping" , "-c1" , self .hostname_or_ip ], check = False ).returncode == 0 ,
563- " Wait for host down" ,
563+ f"[ { self } ] Wait for host down" ,
564564 timeout_secs = timeout_secs ,
565565 retry_delay_secs = 2 ,
566566 )
567567
568568 def wait_for_host_up (self , timeout_secs : int = 10 * 60 ) -> None :
569569 wait_for (
570570 lambda : commands .local_cmd (["ping" , "-c1" , self .hostname_or_ip ], check = False ).returncode == 0 ,
571- " Wait for host up" ,
571+ f"[ { self } ] Wait for host up" ,
572572 timeout_secs = timeout_secs ,
573573 retry_delay_secs = 10 ,
574574 )
575575
576576 def wait_for_ssh_reachable (self , timeout_secs : int = 10 * 60 ) -> None :
577577 wait_for (
578578 lambda : commands .local_cmd (["nc" , "-zw5" , self .hostname_or_ip , "22" ], check = False ).returncode == 0 ,
579- " Wait for ssh up on host" ,
579+ f"[ { self } ] Wait for ssh up on host" ,
580580 timeout_secs = timeout_secs ,
581581 retry_delay_secs = 5
582582 )
583583
584584 def wait_for_xapi_enabled (self , timeout_secs : int = 30 * 60 ) -> None :
585- logging .info (f"Wait for XAPI to complete initialization on { self . hostname_or_ip } " )
585+ logging .info (f"[ { self } ] Wait for XAPI to complete initialization" )
586586 self .ssh (f"xapi-wait-init-complete { timeout_secs } " )
587587 assert self .is_enabled ()
588588
@@ -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' )
@@ -860,7 +860,7 @@ def _all_available(kname: str) -> bool:
860860 ))
861861
862862 self .block_devices_info = sorted (devices , key = lambda d : d .size , reverse = True )
863- logging .debug (" blockdevs found: %s" , [d .name for d in self .block_devices_info ])
863+ logging .debug (f"[ { self } ] blockdevs found: { [d .name for d in self .block_devices_info ]} " )
864864
865865 def disks (self ) -> list [Host .BlockDeviceInfo ]:
866866 """ List of all block devices (local disks, mdadm arrays, multipath devices). """
@@ -889,12 +889,12 @@ 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 )
896896 if verify :
897- wait_for (sr .exists , " Wait for SR to exist" )
897+ wait_for (sr .exists , f"[ { self } ] Wait for SR { sr_uuid } to exist" )
898898 return sr
899899
900900 def is_master (self ) -> bool :
@@ -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