@@ -89,6 +89,11 @@ def run_image_creator_test(
8989 base_ssh_config_path = IMAGECREATOR_TEST_CONFIGS_DIR .joinpath ("ssh-base-config.yaml" )
9090 customizer_config_path_obj = add_ssh_to_config (base_ssh_config_path , username , ssh_public_key , close_list )
9191
92+ # add previewFeatures section if distro is Fedora
93+ if distro .lower () == "fedora" :
94+ with open (customizer_config_path_obj , "a" ) as config_fd :
95+ config_fd .write ("\n previewFeatures:\n - fedora-42\n " ) # Assuming Fedora 42 for this test
96+
9297 run_image_customizer_binary (
9398 image_customizer_binary_path ,
9499 initial_output_image_path ,
@@ -185,36 +190,95 @@ def run_image_creator_test(
185190 logging .info (f"Attempting to connect to VM via SSH" )
186191 logging .info (f"Username: { username } " )
187192
188- with vm .create_ssh_client (ssh_private_key_path , test_temp_dir , username ) as ssh_client :
189- logging .info (f"SSH connection established successfully!" )
190- # Run the test
191- logging .info (f"Running basic checks on the VM" )
192- run_basic_checks (ssh_client , test_temp_dir )
193- logging .info (f"Basic checks completed successfully!" )
193+ try :
194+ with vm .create_ssh_client (ssh_private_key_path , test_temp_dir , username ) as ssh_client :
195+ logging .info ("SSH connection established successfully!" )
196+ # Test SSH connectivity and shell access
197+ result = ssh_client .run ("whoami" )
198+ if result .exit_code != 0 :
199+ logging .error ("Failed to execute basic SSH command" )
200+ logging .error (f"Command output: { result .stdout } " )
201+ logging .error (f"Command error: { result .stderr } " )
202+ raise RuntimeError ("SSH connection test failed" )
203+
204+ # Run the test
205+ logging .info ("Running basic checks on the VM" )
206+ run_basic_checks (ssh_client , test_temp_dir )
207+ logging .info ("Basic checks completed successfully!" )
208+ except Exception as e :
209+ logging .error (f"Failed to establish or verify SSH connection: { str (e )} " )
210+ logging .error ("VM Console output:" )
211+ with open (vm_console_log_file_path , "r" ) as f :
212+ logging .error (f .read ())
213+ raise
194214
195215
196216def run_basic_checks (
197217 ssh_client : SshClient ,
198218 test_temp_dir : Path ,
199219) -> None :
220+ """Run basic checks on the VM to verify the OS installation.
200221
222+ The checks are distro-specific based on the os-release file content.
223+ """
201224 ssh_client .run ("cat /proc/cmdline" ).check_exit_code ()
202225
203226 os_release_path = test_temp_dir .joinpath ("os-release" )
204227 ssh_client .get_file (Path ("/etc/os-release" ), os_release_path )
205228
206229 with open (os_release_path , "r" ) as os_release_fd :
207230 os_release_text = os_release_fd .read ()
208-
209- # Since imagecreator creates new images, we expect Azure Linux 3.0
210- assert "ID=azurelinux" in os_release_text
211- assert 'VERSION_ID="3.0"' in os_release_text
212-
213- # Check that essential packages are installed
214- ssh_client .run ("rpm -q kernel" ).check_exit_code ()
215- ssh_client .run ("rpm -q systemd" ).check_exit_code ()
216- ssh_client .run ("rpm -q grub2" ).check_exit_code ()
217- ssh_client .run ("rpm -q bash" ).check_exit_code ()
231+ logging .info ("OS Release content:" )
232+ logging .info (os_release_text )
233+
234+ # Determine which distro we're testing
235+ if "ID=fedora" in os_release_text :
236+ # Fedora specific checks
237+ assert "ID=fedora" in os_release_text
238+ assert 'VERSION="42 (Adams)"' in os_release_text
239+ elif "ID=azurelinux" in os_release_text :
240+ # Azure Linux specific checks
241+ assert "ID=azurelinux" in os_release_text
242+ assert 'VERSION_ID="3.0"' in os_release_text
243+ else :
244+ raise AssertionError (f"Unknown distribution found in os-release:\n { os_release_text } " )
245+
246+ # Check that essential packages are installed - common for both distros
247+ logging .info ("Checking essential packages..." )
248+
249+ # Check packages one by one with error logging
250+ packages_to_check = ["kernel" , "systemd" , "bash" ]
251+ for package in packages_to_check :
252+ logging .info (f"Checking package: { package } " )
253+ result = ssh_client .run (f"rpm -q { package } " )
254+ try :
255+ result .check_exit_code ()
256+ except Exception as e :
257+ logging .error (f"Failed to verify package { package } : { str (e )} " )
258+ logging .error (f"Command output: { result .stdout } " )
259+ logging .error (f"Command error: { result .stderr } " )
260+ raise
261+
262+ # Special handling for grub2 as package name might differ between distros
263+ logging .info ("Checking bootloader packages..." )
264+ if "ID=fedora" in os_release_text :
265+ # Fedora might use grub2-pc or grub2-efi
266+ try :
267+ result = ssh_client .run ("rpm -q grub2-efi-x64" )
268+ result .check_exit_code ()
269+ except Exception :
270+ logging .warning ("grub2-efi-x64 not found, trying grub2-pc..." )
271+ result = ssh_client .run ("rpm -q grub2-pc" )
272+ try :
273+ result .check_exit_code ()
274+ except Exception as e :
275+ logging .error (f"Failed to find any grub2 package: { str (e )} " )
276+ logging .error (f"Command error: { result .stderr } " )
277+ raise
278+ else :
279+ # Azure Linux check
280+ result = ssh_client .run ("rpm -q grub2" )
281+ result .check_exit_code ()
218282
219283
220284@pytest .mark .skipif (platform .machine () != "x86_64" , reason = "arm64 is not supported for this combination" )
0 commit comments