@@ -1265,3 +1265,96 @@ def test_install_dism_drivers_revokes_on_failure(
12651265 # Permissions must be revoked even if driver installation fails:
12661266 mock_revoke_permissions .assert_called_once_with (
12671267 exp_repo_path , f"*{ null_sid } " )
1268+
1269+ @mock .patch .object (
1270+ windows .BaseWindowsMorphingTools , "register_firstboot_script" )
1271+ def test_setup_qemu_agent_installation_local_script_from_url (
1272+ self , mock_register_firstboot_script ):
1273+ fake_msi_url = "fake-qemu-ga-msi-url"
1274+
1275+ self .morphing_tools ._setup_qemu_agent_installation_local_script (
1276+ msi_url = fake_msi_url )
1277+
1278+ exp_msi_dest_path = "C:\\ Cloudbase-Init\\ qemu-ga-x86_64.msi"
1279+ self .morphing_tools ._conn .download_file .assert_called_once_with (
1280+ fake_msi_url , exp_msi_dest_path )
1281+ self .morphing_tools ._conn .exec_ps_command .assert_not_called ()
1282+
1283+ exp_script = windows .QEMU_GUEST_AGENT_INSTALL_SCRIPT_FORMAT % {
1284+ "agent_msi_path" : exp_msi_dest_path ,
1285+ "agent_msi_log_dir" : "C:\\ Cloudbase-Init" }
1286+ mock_register_firstboot_script .assert_called_once_with (
1287+ exp_script , user_provided = False ,
1288+ script_filename = "coriolis_qemu_agent_install.ps1" )
1289+
1290+ @mock .patch .object (
1291+ windows .BaseWindowsMorphingTools , "register_firstboot_script" )
1292+ def test_setup_qemu_agent_installation_local_script_from_path (
1293+ self , mock_register_firstboot_script ):
1294+ fake_msi_source_path = "e:\\ guest-agent\\ qemu-ga-x86_64.msi"
1295+
1296+ self .morphing_tools ._setup_qemu_agent_installation_local_script (
1297+ msi_source_path = fake_msi_source_path )
1298+
1299+ exp_msi_dest_path = "C:\\ Cloudbase-Init\\ qemu-ga-x86_64.msi"
1300+ self .morphing_tools ._conn .download_file .assert_not_called ()
1301+ self .morphing_tools ._conn .exec_ps_command .assert_called_once_with (
1302+ "Copy-Item '%s' -Destination '%s'" % (
1303+ fake_msi_source_path , exp_msi_dest_path ))
1304+
1305+ exp_script = windows .QEMU_GUEST_AGENT_INSTALL_SCRIPT_FORMAT % {
1306+ "agent_msi_path" : exp_msi_dest_path ,
1307+ "agent_msi_log_dir" : "C:\\ Cloudbase-Init" }
1308+ mock_register_firstboot_script .assert_called_once_with (
1309+ exp_script , user_provided = False ,
1310+ script_filename = "coriolis_qemu_agent_install.ps1" )
1311+
1312+ @mock .patch .object (
1313+ windows .BaseWindowsMorphingTools , "register_firstboot_script" )
1314+ def test_setup_qemu_agent_installation_local_script_no_source (
1315+ self , mock_register_firstboot_script ):
1316+ self .assertRaises (
1317+ exception .CoriolisException ,
1318+ self .morphing_tools ._setup_qemu_agent_installation_local_script )
1319+
1320+ self .morphing_tools ._conn .download_file .assert_not_called ()
1321+ self .morphing_tools ._conn .exec_ps_command .assert_not_called ()
1322+ mock_register_firstboot_script .assert_not_called ()
1323+
1324+ @mock .patch .object (
1325+ windows .BaseWindowsMorphingTools , "register_firstboot_script" )
1326+ def test_setup_qemu_agent_installation_local_script_from_qemu_ga_dir (
1327+ self , mock_register_firstboot_script ):
1328+ fake_qemu_ga_source_dir = "f:\\ qemu-ga"
1329+ self .morphing_tools ._conn .test_path .return_value = True
1330+
1331+ self .morphing_tools ._setup_qemu_agent_installation_local_script (
1332+ qemu_ga_source_dir = fake_qemu_ga_source_dir )
1333+
1334+ self .morphing_tools ._conn .test_path .assert_called_once_with (
1335+ "%s\\ x64\\ qemu-ga.exe" % fake_qemu_ga_source_dir )
1336+ self .morphing_tools ._conn .download_file .assert_not_called ()
1337+ self .morphing_tools ._conn .exec_ps_command .assert_called_once_with (
1338+ "Copy-Item -Recurse -Force '%s' '%s'" % (
1339+ fake_qemu_ga_source_dir , "C:\\ Cloudbase-Init" ),
1340+ ignore_stdout = True )
1341+
1342+ exp_script = (
1343+ windows .QEMU_GUEST_AGENT_INSTALL_FROM_DIR_SCRIPT_FORMAT % {
1344+ "qemu_ga_dir" : "C:\\ Cloudbase-Init\\ qemu-ga" })
1345+ mock_register_firstboot_script .assert_called_once_with (
1346+ exp_script , user_provided = False ,
1347+ script_filename = "coriolis_qemu_agent_install.ps1" )
1348+
1349+ @mock .patch .object (
1350+ windows .BaseWindowsMorphingTools , "register_firstboot_script" )
1351+ def test_setup_qemu_agent_installation_local_script_qemu_ga_dir_missing (
1352+ self , mock_register_firstboot_script ):
1353+ self .morphing_tools ._conn .test_path .return_value = False
1354+
1355+ self .morphing_tools ._setup_qemu_agent_installation_local_script (
1356+ qemu_ga_source_dir = "f:\\ qemu-ga" )
1357+
1358+ self .morphing_tools ._conn .download_file .assert_not_called ()
1359+ self .morphing_tools ._conn .exec_ps_command .assert_not_called ()
1360+ mock_register_firstboot_script .assert_not_called ()
0 commit comments