@@ -15,38 +15,60 @@ use serial_terminal qw(select_serial_terminal);
1515use Mojo::File qw( path) ;
1616use utils qw( file_content_replace) ;
1717
18- =head2 get_sysext
18+ =head2 build_installer_cmd
1919
20- get_sysext( timeout => <value> );
20+ build_installer cmd( img_filename => <value>, k8s => <value>,
21+ rootpwd => <value>, timeout => <value>,
22+ type => <value> );
2123
22- Get systemd system extensions from SYSEXT_IMAGES_TO_TEST list and
23- prepare them to be used by elemental tool .
24+ Create an OS image with `build-installer` command by using the specified
25+ containerized OS image .
2426
2527=cut
2628
27- sub get_sysext {
29+ sub build_installer_cmd {
2830 my (%args ) = @_ ;
31+ my $image = get_required_var(' CONTAINER_IMAGE_TO_TEST' );
32+ my $krnlcmdline = get_var(' KERNEL_CMD_LINE' );
33+ my $isocmdline = get_var(' ISO_CMD_LINE' );
2934 my $shared_dir = ' /root/shared' ;
30- my $overlay_dir = " $shared_dir /overlays " ;
31- my $sysext_dir = " $overlay_dir /etc/extensions " ;
32- my $ctl_oci ;
35+ my $config_file = " $shared_dir /config.sh " ;
36+ my $iso_config_file = " $shared_dir /config-iso.sh " ;
37+ my $device = get_var( ' INSTALL_DISK ' , ' /dev/vda ' ) ;
3338
34- record_info(' SYSEXT' , ' Download and configure systemd system extensions' );
39+ # Configure the systemd sysexts
40+ my ($overlay_dir , $ctl_oci ) = get_sysext(timeout => $args {timeout });
3541
36- # Create directories
37- assert_script_run(" mkdir -p $sysext_dir " );
42+ # OS configuration script
43+ assert_script_run(
44+ " curl -sf -o $config_file "
45+ . data_url(' elemental3/' . path($config_file )-> basename)
46+ );
47+ file_content_replace(
48+ $config_file ,
49+ ' --sed-modifier' => ' g' ,
50+ ' %TEST_PASSWORD%' => $args {rootpwd },
51+ ' %K8S%' => $args {k8s }
52+ );
53+ assert_script_run(" chmod 755 $config_file " );
3854
39- # Get the system extensions
40- foreach my $img (split (/ ,/ , get_required_var(' SYSEXT_IMAGES_TO_TEST' ))) {
41- assert_script_run(
42- " elemental3ctl --debug unpack-image --image ${img} --target ${sysext_dir} " ,
43- timeout => $args {timeout }
44- );
45- $ctl_oci = $img if ($img =~ / \/ elemental3ctl:/ );
46- }
55+ # ISO configuration script
56+ assert_script_run(
57+ " curl -sf -o $iso_config_file "
58+ . data_url(' elemental3/' . path($iso_config_file )-> basename)
59+ );
60+ assert_script_run(" chmod 755 $iso_config_file " );
4761
48- # Return systemd-sysexts file name
49- return ($overlay_dir , $ctl_oci );
62+ record_info(' ISO' , ' Generate and upload ISO image' );
63+
64+ # Generate OS image
65+ assert_script_run(
66+ " elemental3ctl --debug build-installer --type $args {type} --output . --name $args {img_filename} --os-image $image --cmdline '$isocmdline ' --config $iso_config_file --overlay oci://$ctl_oci --install-overlay dir://$overlay_dir --install-config $config_file --install-cmdline '$krnlcmdline ' --install-target $device " ,
67+ timeout => $args {timeout }
68+ );
69+
70+ # Return ISO image
71+ return (" $args {img_filename}.iso" );
5072}
5173
5274=head2 customize_cmd
@@ -137,64 +159,66 @@ sub customize_cmd {
137159 assert_script_run(" mv uc_image.$type '$out '" );
138160 }
139161
140- # Return HDD image
162+ # Return OS image
141163 return ($out );
142164}
143165
144- =head2 build_installer_cmd
166+ =head2 extract_iso
145167
146- build_installer cmd( img_filename => <value>, k8s => <value>,
147- rootpwd => <value>, timeout => <value>,
148- type => <value> );
168+ extract_iso( img_filename => <value>, timeout => <value> );
149169
150- Create an OS image with `build-installer` command by using the specified
151- containerized OS image.
170+ Extract ISO image from container.
152171
153172=cut
154173
155- sub build_installer_cmd {
174+ sub extract_iso {
156175 my (%args ) = @_ ;
157176 my $image = get_required_var(' CONTAINER_IMAGE_TO_TEST' );
158- my $krnlcmdline = get_var(' KERNEL_CMD_LINE' );
159- my $isocmdline = get_var(' ISO_CMD_LINE' );
160- my $shared_dir = ' /root/shared' ;
161- my $config_file = " $shared_dir /config.sh" ;
162- my $iso_config_file = " $shared_dir /config-iso.sh" ;
163- my $device = get_var(' INSTALL_DISK' , ' /dev/vda' );
177+ my $iso = get_required_var(' ISO_IMAGE_TO_TEST' );
178+ my $runtime = get_required_var(' CONTAINER_RUNTIMES' );
179+ my $out = " $args {img_filename}.iso" ;
164180
165- # Configure the systemd sysexts
166- my ($overlay_dir , $ctl_oci ) = get_sysext(timeout => $args {timeout });
181+ assert_script_run(" $runtime pull $image " );
182+ my $run_id = script_output(" $runtime run -d $image " );
183+ assert_script_run(" $runtime cp ${run_id} :/iso/${iso} ." );
184+ assert_script_run(" mv $iso '$out '" );
167185
168- # OS configuration script
169- assert_script_run(
170- " curl -sf -o $config_file "
171- . data_url(' elemental3/' . path($config_file )-> basename)
172- );
173- file_content_replace(
174- $config_file ,
175- ' --sed-modifier' => ' g' ,
176- ' %TEST_PASSWORD%' => $args {rootpwd },
177- ' %K8S%' => $args {k8s }
178- );
179- assert_script_run(" chmod 755 $config_file " );
186+ # Return OS image
187+ return ($out );
188+ }
180189
181- # ISO configuration script
182- assert_script_run(
183- " curl -sf -o $iso_config_file "
184- . data_url(' elemental3/' . path($iso_config_file )-> basename)
185- );
186- assert_script_run(" chmod 755 $iso_config_file " );
190+ =head2 get_sysext
187191
188- record_info( ' ISO ' , ' Generate and upload ISO image ' );
192+ get_sysext( timeout => <value> );
189193
190- # Generate OS image
191- assert_script_run(
192- " elemental3ctl --debug build-installer --type $args {type} --output . --name $args {img_filename} --os-image $image --cmdline '$isocmdline ' --config $iso_config_file --overlay oci://$ctl_oci --install-overlay dir://$overlay_dir --install-config $config_file --install-cmdline '$krnlcmdline ' --install-target $device " ,
193- timeout => $args {timeout }
194- );
194+ Get systemd system extensions from SYSEXT_IMAGES_TO_TEST list and
195+ prepare them to be used by elemental tool.
195196
196- # Return ISO image
197- return (" $args {img_filename}.iso" );
197+ =cut
198+
199+ sub get_sysext {
200+ my (%args ) = @_ ;
201+ my $shared_dir = ' /root/shared' ;
202+ my $overlay_dir = " $shared_dir /overlays" ;
203+ my $sysext_dir = " $overlay_dir /etc/extensions" ;
204+ my $ctl_oci ;
205+
206+ record_info(' SYSEXT' , ' Download and configure systemd system extensions' );
207+
208+ # Create directories
209+ assert_script_run(" mkdir -p $sysext_dir " );
210+
211+ # Get the system extensions
212+ foreach my $img (split (/ ,/ , get_required_var(' SYSEXT_IMAGES_TO_TEST' ))) {
213+ assert_script_run(
214+ " elemental3ctl --debug unpack-image --image ${img} --target ${sysext_dir} " ,
215+ timeout => $args {timeout }
216+ );
217+ $ctl_oci = $img if ($img =~ / \/ elemental3ctl:/ );
218+ }
219+
220+ # Return systemd-sysexts file name
221+ return ($overlay_dir , $ctl_oci );
198222}
199223
200224=head2 install_cmd
@@ -257,7 +281,6 @@ sub run {
257281 my $k8s = get_required_var(' K8S' );
258282 my $hddsize = get_var(' HDDSIZEGB' , ' 30' );
259283 my $rootpwd = get_required_var(' TEST_PASSWORD' );
260- my $build = get_required_var(' BUILD' );
261284 my $img_filename = get_required_var(' IMG_NAME' );
262285 my $tpl_file = get_var(' TEMPLATE' , ' build-tpl.tar.gz' );
263286 my $timeout = 900;
@@ -282,33 +305,35 @@ sub run {
282305 my $hashpwd = script_output(" openssl passwd -6 $rootpwd " );
283306
284307 # Create HDD image with different commands
285- $out_file = customize_cmd (
286- timeout => $timeout ,
308+ $out_file = build_installer_cmd (
309+ img_filename => $img_filename ,
287310 k8s => $k8s ,
311+ rootpwd => $hashpwd ,
312+ timeout => $timeout ,
313+ type => ' iso'
314+ ) if (check_var(' TESTED_CMD' , ' build_installer_iso' ));
315+
316+ $out_file = customize_cmd(
288317 hddsize => $hddsize ,
318+ img_filename => $img_filename ,
319+ k8s => $k8s ,
289320 rootpwd => $hashpwd ,
290321 template => $tpl_file ,
291- build => $build ,
292- img_filename => $img_filename
322+ timeout => $timeout
293323 ) if (check_var(' TESTED_CMD' , ' customize' ) || check_var(' TESTED_CMD' , ' customize_recovery' ));
294324
295- $out_file = build_installer_cmd(
296- timeout => $timeout ,
297- k8s => $k8s ,
298- type => ' iso' ,
299- rootpwd => $hashpwd ,
300- build => $build ,
301- img_filename => $img_filename
302- ) if (check_var(' TESTED_CMD' , ' build_installer_iso' ));
325+ $out_file = extract_iso(
326+ img_filename => $img_filename ,
327+ timeout => $timeout
328+ ) if (check_var(' TESTED_CMD' , ' extract_iso' ));
303329
304330 $out_file = install_cmd(
305- timeout => $timeout ,
306331 arch => $arch ,
307- k8s => $k8s ,
308332 hddsize => $hddsize ,
333+ img_filename => $img_filename ,
334+ k8s => $k8s ,
309335 rootpwd => $hashpwd ,
310- build => $build ,
311- img_filename => $img_filename
336+ timeout => $timeout ,
312337 ) if (check_var(' TESTED_CMD' , ' install' ));
313338
314339 # Upload OS image
0 commit comments