@@ -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,113 @@ 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+ if distro .lower () == "fedora" :
207+ run_basic_checks_fedora (ssh_client , test_temp_dir )
208+ else :
209+ run_basic_checks_azurelinux (ssh_client , test_temp_dir )
210+ logging .info ("Basic checks completed successfully!" )
211+ except Exception as e :
212+ logging .error (f"Failed to establish or verify SSH connection: { str (e )} " )
213+ logging .error ("VM Console output:" )
214+ with open (vm_console_log_file_path , "r" ) as f :
215+ logging .error (f .read ())
216+ raise
217+
218+
219+ def _verify_common_packages (ssh_client : SshClient ) -> None :
220+ """Verify packages that should be present in all distributions."""
221+ packages_to_check = ["kernel" , "systemd" , "bash" ]
222+ for package in packages_to_check :
223+ logging .info (f"Checking package: { package } " )
224+ result = ssh_client .run (f"rpm -q { package } " )
225+ try :
226+ result .check_exit_code ()
227+ except Exception as e :
228+ logging .error (f"Failed to verify package { package } : { str (e )} " )
229+ logging .error (f"Command output: { result .stdout } " )
230+ logging .error (f"Command error: { result .stderr } " )
231+ raise
232+
233+
234+ def run_basic_checks_fedora (
235+ ssh_client : SshClient ,
236+ test_temp_dir : Path ,
237+ ) -> None :
238+ """Run basic checks specific to Fedora images."""
239+ ssh_client .run ("cat /proc/cmdline" ).check_exit_code ()
194240
241+ os_release_path = test_temp_dir .joinpath ("os-release" )
242+ ssh_client .get_file (Path ("/etc/os-release" ), os_release_path )
195243
196- def run_basic_checks (
244+ with open (os_release_path , "r" ) as os_release_fd :
245+ os_release_text = os_release_fd .read ()
246+ logging .info ("OS Release content:" )
247+ logging .info (os_release_text )
248+
249+ # Verify Fedora-specific os-release content
250+ assert "ID=fedora" in os_release_text
251+ assert 'VERSION="42 (Adams)"' in os_release_text
252+
253+ # Check common packages
254+ logging .info ("Checking essential packages..." )
255+ _verify_common_packages (ssh_client )
256+
257+ # Check Fedora-specific bootloader packages
258+ logging .info ("Checking bootloader packages..." )
259+ try :
260+ result = ssh_client .run ("rpm -q grub2-efi-x64" )
261+ result .check_exit_code ()
262+ except Exception :
263+ logging .warning ("grub2-efi-x64 not found, trying grub2-pc..." )
264+ result = ssh_client .run ("rpm -q grub2-pc" )
265+ try :
266+ result .check_exit_code ()
267+ except Exception as e :
268+ logging .error (f"Failed to find any grub2 package: { str (e )} " )
269+ logging .error (f"Command error: { result .stderr } " )
270+ raise
271+
272+
273+ def run_basic_checks_azurelinux (
197274 ssh_client : SshClient ,
198275 test_temp_dir : Path ,
199276) -> None :
200-
277+ """Run basic checks specific to Azure Linux images."""
201278 ssh_client .run ("cat /proc/cmdline" ).check_exit_code ()
202279
203280 os_release_path = test_temp_dir .joinpath ("os-release" )
204281 ssh_client .get_file (Path ("/etc/os-release" ), os_release_path )
205282
206283 with open (os_release_path , "r" ) as os_release_fd :
207284 os_release_text = os_release_fd .read ()
285+ logging .info ("OS Release content:" )
286+ logging .info (os_release_text )
208287
209- # Since imagecreator creates new images, we expect Azure Linux 3.0
288+ # Verify Azure Linux-specific os-release content
210289 assert "ID=azurelinux" in os_release_text
211290 assert 'VERSION_ID="3.0"' in os_release_text
212291
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 ()
292+ # Check common packages
293+ logging .info ("Checking essential packages..." )
294+ _verify_common_packages (ssh_client )
295+
296+ # Check Azure Linux bootloader package
297+ logging .info ("Checking bootloader packages..." )
298+ result = ssh_client .run ("rpm -q grub2" )
299+ result .check_exit_code ()
218300
219301
220302@pytest .mark .skipif (platform .machine () != "x86_64" , reason = "arm64 is not supported for this combination" )
0 commit comments