Skip to content

Commit 0d27f08

Browse files
committed
Elemental3: add ISO container test
This is to ensure that the ISO container image is validated before pushing it into the release manifest. A bsic OS boot is enough to validate the image and anyway we can't do more as installation cannot be done and user connection is not possible at this stage. Signed-off-by: Loic Devulder <ldevulder@suse.com>
1 parent cec9cdf commit 0d27f08

File tree

5 files changed

+157
-91
lines changed

5 files changed

+157
-91
lines changed

tests/elemental3/elemental_boot.pm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ sub run {
2424
wait_still_screen;
2525
}
2626

27+
# This ISO image does not install anything
28+
# It is just the basic container that should be used with 'customize' command
29+
if (check_var('TESTED_CMD', 'extract_iso')) {
30+
# Just validate that the OS boot, no more
31+
assert_screen('elemental3-tty1-selected', timeout => 120);
32+
wait_still_screen;
33+
record_info('ISO', 'ISO image booted!');
34+
return;
35+
}
36+
2737
# OS installation is done automatically as well as the reboot after installation
2838
# We just have to wait for the VM to reboot
2939
$self->wait_grub(bootloader_time => bmwqemu::scale_timeout(300));

tests/elemental3/generate_image.pm

Lines changed: 105 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,60 @@ use serial_terminal qw(select_serial_terminal);
1515
use Mojo::File qw(path);
1616
use 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

tests/elemental3/set_global_variables.pm

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ use serial_terminal qw(select_serial_terminal);
1111

1212
=head2 get_values
1313
14-
get_values( filelist => <value>, regex => <value> );
14+
get_values( txt => <value>, regex => <value> );
1515
16-
Get values from the list of files <filelist> based on defined regex.
16+
Get values from text <txt> based on defined regex.
1717
1818
=cut
1919

2020
sub get_values {
2121
my (%args) = @_;
2222

23-
return ($&, $1, $2) if ($args{filelist} =~ m/$args{regex}/);
23+
return ($&, $1, $2) if ($args{txt} =~ m/$args{regex}/);
2424
}
2525

2626
=head2 get_uri
@@ -41,10 +41,17 @@ sub get_uri {
4141
sub run {
4242
my $arch = get_required_var('ARCH');
4343
my $k8s = get_required_var('K8S');
44-
my $kernel = 'base-os-kernel-' . get_required_var('KERNEL_TYPE') . '-' . get_required_var('VERSION');
44+
my $os_version = get_required_var('VERSION');
45+
my $kernel_type = get_var('KERNEL_TYPE');
46+
my $kernel = "base-os-kernel-${kernel_type}-${os_version}";
4547
my $totest_path = get_required_var('TOTEST_PATH');
4648
my $uc_version = get_required_var('UC_VERSION');
4749

50+
# This is to test the ISO container:w
51+
if (check_var('TESTED_CMD', 'extract_iso')) {
52+
$kernel = "base-kernel-${kernel_type}-iso-${os_version}";
53+
}
54+
4855
# No GUI, easier and quicker to use the serial console
4956
select_serial_terminal();
5057

@@ -56,29 +63,45 @@ sub run {
5663

5764
# Export RELEASE_MANIFEST_URI
5865
my $manifest_regex = ".*release-manifest-${uc_version}_${k8s}_\(.*\)-\(.*\).${arch}-.*.registry.txt";
59-
my ($file, $version, $build) = get_values(filelist => ${files_list}, regex => ${manifest_regex});
66+
my ($file, $version, $build) = get_values(txt => ${files_list}, regex => ${manifest_regex});
6067
my $k8s_version = $version;
6168
my $release_manifest_uri = get_uri(file => "${totest_path}/containers/${file}", regex => "pull\\s+\(.*:${uc_version}_${k8s}_${k8s_version}-${build}\)");
6269
set_var('RELEASE_MANIFEST_URI', "$release_manifest_uri");
6370

6471
# Export SYSEXT_IMAGES_TO_TEST
6572
my $elemental3ctl_regex = ".*elemental3ctl-${uc_version}_\(.*\)-\(.*\).${arch}-.*.registry.txt";
66-
($file, $version, $build) = get_values(filelist => ${files_list}, regex => ${elemental3ctl_regex});
73+
($file, $version, $build) = get_values(txt => ${files_list}, regex => ${elemental3ctl_regex});
6774
my $elemental3ctl_uri = get_uri(file => "${totest_path}/containers/${file}", regex => "pull\\s+\(.*:${uc_version}_${version}-${build}\)");
6875

6976
my $k8s_regex = ".*${k8s}-${k8s_version}_\(.*\)-\(.*\).${arch}-.*.registry.txt";
70-
($file, $version, $build) = get_values(filelist => ${files_list}, regex => ${k8s_regex});
77+
($file, $version, $build) = get_values(txt => ${files_list}, regex => ${k8s_regex});
7178
my $k8s_uri = get_uri(file => "${totest_path}/containers/${file}", regex => "pull\\s+\(.*:${k8s_version}_${version}-${build}\)");
7279
set_var('SYSEXT_IMAGES_TO_TEST', "${elemental3ctl_uri},${k8s_uri}");
7380

7481
# Export CONTAINER_IMAGE_TO_TEST
7582
my $kernel_regex = ".*${kernel}-\(.*\).${arch}-.*.registry.txt";
76-
($file, $build) = get_values(filelist => ${files_list}, regex => ${kernel_regex});
77-
my $container_uri = get_uri(file => "${totest_path}/containers/${file}", regex => "pull\\s+\(.*:" . get_required_var('VERSION') . "-${build}\)");
83+
($file, $build) = get_values(txt => ${files_list}, regex => ${kernel_regex});
84+
my $container_uri = get_uri(file => "${totest_path}/containers/${file}", regex => "pull\\s+\(.*:${os_version}-${build}\)");
7885
set_var('CONTAINER_IMAGE_TO_TEST', "$container_uri");
7986

8087
# Export REPO_TO_TEST
8188
set_var('REPO_TO_TEST', "$totest_path/standard");
89+
90+
# Export ISO_IMAGE_TO_TEST
91+
if (check_var('TESTED_CMD', 'extract_iso')) {
92+
my $iso_regex = ".*/\(.*\):.*-\(.*\)";
93+
my (undef, $name, $build) = get_values(txt => ${container_uri}, regex => ${iso_regex});
94+
if ($name eq '' || $build eq '') {
95+
record_info('ISO_IMAGE_TO_TEST', 'Required variable cannot be set!', result => 'fail');
96+
die('Required variable not set');
97+
}
98+
set_var('ISO_IMAGE_TO_TEST', "${name}.${arch}-${os_version}-Build${build}.iso");
99+
}
100+
101+
# Logs, could be useful for debugging purporses
102+
foreach my $v ('SYSEXT_IMAGES_TO_TEST', 'RELEASE_MANIFEST_URI', 'CONTAINER_IMAGE_TO_TEST', 'REPO_TO_TEST', 'ISO_IMAGE_TO_TEST') {
103+
record_info("$v", get_var("$v"));
104+
}
82105
}
83106

84107
sub test_flags {

tests/elemental3/start_k8s.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,19 @@ sub prepare_test_framework {
224224
}
225225

226226
sub run {
227+
my ($self) = @_;
227228
my $arch = get_required_var('ARCH');
228229
my $k8s = get_required_var('K8S');
229230
my $k8s_dir = "/etc/rancher/$k8s";
230231
my $config_yaml = "$k8s_dir/config.yaml";
231232

233+
# Skip the test with simple ISO container
234+
if (check_var('TESTED_CMD', 'extract_iso')) {
235+
record_info('SKIP', 'Skip test - No K8s installed in this basic container image');
236+
$self->result('skip');
237+
return;
238+
}
239+
232240
# Set default root password
233241
$testapi::password = get_required_var('TEST_PASSWORD');
234242

tests/elemental3/validate_toolbox.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use testapi;
99
use serial_terminal qw(select_serial_terminal);
1010

1111
sub run {
12-
my $self = shift;
12+
my ($self) = @_;
1313

1414
select_serial_terminal();
1515

1616
# Skip the test in multi-machine mode
1717
if (get_var('PARALLEL_WITH')) {
18-
record_info('SKIP', 'Skip test - Network is not up at this stage', result => 'ok');
18+
record_info('SKIP', 'Skip test - Network is not up at this stage');
1919
$self->result('skip');
2020
return;
2121
}

0 commit comments

Comments
 (0)