1717# flake8: noqa: E402
1818sys .path .append (f"{ os .path .abspath (os .path .dirname (__file__ ))} /.." )
1919from lib import pxe
20- from lib .commands import SSHCommandFailed , scp , ssh
20+ from lib .commands import SSHCommandFailed , ssh
2121from lib .common import is_uuid , wait_for
2222from lib .host import host_data
2323from lib .pool import Pool
@@ -62,7 +62,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
6262</installation>
6363 """ )
6464 elif action == 'restore' :
65- answerfile .write (f """<?xml version="1.0"?>
65+ answerfile .write ("""<?xml version="1.0"?>
6666<restore>
6767</restore>
6868 """ )
@@ -160,7 +160,7 @@ def main():
160160 try :
161161 pool = Pool (args .host ) # will fail if host is not XCP-ng or XAPI doesn't respond yet
162162 except Exception as e :
163- raise Exception (f"Host `{ args .host } ` isn't ready or isn't an XCP-ng host" )
163+ raise Exception (f"Host `{ args .host } ` isn't ready or isn't an XCP-ng host" ) from e
164164
165165 host = pool .master
166166 assert host .is_enabled ()
@@ -178,6 +178,7 @@ def main():
178178 vm = VM (args .vm_uuid , host )
179179 vif = vm .vifs ()[0 ]
180180 mac_address = vif .param_get ('MAC' )
181+ assert mac_address is not None
181182 with tempfile .TemporaryDirectory (suffix = mac_address ) as tmp_local_path :
182183 logging .info ('Generate files: answerfile.xml and boot.conf' )
183184 hdd = 'nvme0n1' if vm .is_uefi else 'sda'
@@ -201,11 +202,12 @@ def main():
201202 "Waiting for the installation process to complete and the VM to reboot and be up" , 3600 , 10
202203 )
203204 vm_ip_address = get_new_host_ip (mac_address )
205+ assert vm_ip_address is not None
204206 logging .info ('The IP address of the installed XCP-ng is: ' + vm_ip_address )
205207 wait_for (lambda : is_new_host_ready (vm_ip_address ), "Waiting for XAPI to be ready" , 600 , 10 )
206208 pool2 = Pool (vm_ip_address )
207209 host2 = pool2 .master
208- host2 .inventory = host2 ._get_xensource_inventory ()
210+ host2 .inventory = host2 ._get_xensource_inventory () # noqa: SLF001
209211 check_mac_address (host2 , mac_address )
210212 logging .info (f'Target host is started and enabled in version: { host2 .xcp_version } ' )
211213 if args .action == 'restore' and host2 .xcp_version >= version .parse (xcp_version ):
0 commit comments