Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/elemental3/build-tpl.tar.gz
Binary file not shown.
Binary file added data/elemental3/build-tpl_recovery.tar.gz
Binary file not shown.
35 changes: 35 additions & 0 deletions tests/elemental3/elemental_boot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use testapi;
use lockapi;
use mm_network qw(configure_hostname setup_static_mm_network);
use serial_terminal qw(select_serial_terminal);
use power_action_utils qw(power_action);

sub run {
my ($self) = @_;
Expand All @@ -23,6 +24,16 @@ sub run {
wait_still_screen;
}

# This ISO image does not install anything
# It is just the basic container that should be used with 'customize' command
if (check_var('TESTED_CMD', 'extract_iso')) {
# Just validate that the OS boot, no more
assert_screen('elemental3-tty1-selected', timeout => 120);
wait_still_screen;
record_info('ISO', 'ISO image booted!');
return;
}

# OS installation is done automatically as well as the reboot after installation
# We just have to wait for the VM to reboot
$self->wait_grub(bootloader_time => bmwqemu::scale_timeout(300));
Expand Down Expand Up @@ -52,6 +63,30 @@ sub run {
my $sys_state = script_output('systemctl is-system-running --wait', timeout => 240, proceed_on_failure => 1);
die("Wrong OS state: $sys_state") unless ($sys_state =~ m/running/);
}

# Test reboot in recovery mode
if (check_var('TESTED_CMD', 'customize_recovery')) {
power_action('reboot', keepconsole => 1, textmode => 1);

# Select SUT for bootloader
select_console('sut');

# Wait for GRUB
$self->wait_grub();

# Choose entry to test
send_key_until_needlematch('elemental3-bootmenu-recovery', 'down');
send_key('ret', wait_screen_change => 1);
wait_still_screen(timeout => 120);

# In recovery mode we have auto-login configured on tty1
console('root-console')->set_tty(1);
select_console('root-console');

# Check for recovery boot option
assert_script_run('grep -q recovery /proc/cmdline');
record_info('RECOVERY', 'Booted in recovery mode!');
}
}

sub test_flags {
Expand Down
220 changes: 131 additions & 89 deletions tests/elemental3/generate_image.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,66 @@ use serial_terminal qw(select_serial_terminal);
use Mojo::File qw(path);
use utils qw(file_content_replace);

=head2 get_sysext
=head2 build_installer_cmd

get_sysext( timeout => <value> );
build_installer cmd( img_filename => <value>, k8s => <value>,
rootpwd => <value>, timeout => <value>,
type => <value> );

Get systemd system extensions from SYSEXT_IMAGES_TO_TEST list and
prepare them to be used by elemental tool.
Create an OS image with `build-installer` command by using the specified
containerized OS image.

=cut

sub get_sysext {
sub build_installer_cmd {
my (%args) = @_;
my $image = get_required_var('CONTAINER_IMAGE_TO_TEST');
my $krnlcmdline = get_var('KERNEL_CMD_LINE');
my $isocmdline = get_var('ISO_CMD_LINE');
my $shared_dir = '/root/shared';
my $overlay_dir = "$shared_dir/overlays";
my $sysext_dir = "$overlay_dir/etc/extensions";
my $ctl_oci;
my $config_file = "$shared_dir/config.sh";
my $iso_config_file = "$shared_dir/config-iso.sh";
my $device = get_var('INSTALL_DISK', '/dev/vda');

record_info('SYSEXT', 'Download and configure systemd system extensions');
# Configure the systemd sysexts
my ($overlay_dir, $ctl_oci) = get_sysext(timeout => $args{timeout});

# Create directories
assert_script_run("mkdir -p $sysext_dir");
# OS configuration script
assert_script_run(
"curl -sf -o $config_file "
. data_url('elemental3/' . path($config_file)->basename)
);
file_content_replace(
$config_file,
'--sed-modifier' => 'g',
'%TEST_PASSWORD%' => $args{rootpwd},
'%K8S%' => $args{k8s}
);
assert_script_run("chmod 755 $config_file");

# Get the system extensions
foreach my $img (split(/,/, get_required_var('SYSEXT_IMAGES_TO_TEST'))) {
assert_script_run(
"elemental3ctl --debug unpack-image --image ${img} --target ${sysext_dir}",
timeout => $args{timeout}
);
$ctl_oci = $img if ($img =~ /\/elemental3ctl:/);
}
# ISO configuration script
assert_script_run(
"curl -sf -o $iso_config_file "
. data_url('elemental3/' . path($iso_config_file)->basename)
);
assert_script_run("chmod 755 $iso_config_file");

# Return systemd-sysexts file name
return ($overlay_dir, $ctl_oci);
record_info('ISO', 'Generate and upload ISO image');

# Generate OS image
assert_script_run(
"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",
timeout => $args{timeout}
);

# Return ISO image
return ("$args{img_filename}.iso");
}

=head2 customize_cmd

customize_cmd( hddsize => <value>, k8s => <value>, timeout => <value>,
rootpwd => <value> );
customize_cmd( hddsize => <value>, k8s => <value>, rootpwd => <value>,
template => <value>, timeout => <value> );

Create an OS image with `customize` command by using the specified
release-manifest.
Expand All @@ -61,21 +83,22 @@ release-manifest.

sub customize_cmd {
my (%args) = @_;
my $build_dir = '/root/build';
my $crypto_policy = get_var('CRYPTO_POLICY');
my $device = get_var('INSTALL_DISK', '/dev/vda');
my $krnlcmdline = get_var('KERNEL_CMD_LINE');
my $manifest_uri = get_required_var('RELEASE_MANIFEST_URI');
my $out = "$args{img_filename}.iso";
my $tpl_tar = "$build_dir/build-tpl.tar.gz";
my $type = get_required_var('IMAGE_TYPE');
my $build_dir = '/root/build';
my $tpl_tar = "$build_dir/$args{template}";
my $initial_hddsize = '4';
my $out = "$args{img_filename}.iso";

# Create directories
assert_script_run("mkdir -p $build_dir");

# Download build configuration files
assert_script_run(
"curl -s -o $tpl_tar "
"curl -sf -o $tpl_tar "
. data_url('elemental3/' . path($tpl_tar)->basename)
);
assert_script_run("tar xzvf $tpl_tar -C $build_dir");
Expand All @@ -95,7 +118,7 @@ sub customize_cmd {
"$build_dir/install.yaml",
'--sed-modifier' => 'g',
'%CRYPTO_POLICY%' => $crypto_policy,
'%HDDSIZE%' => $args{hddsize},
'%HDDSIZE%' => $initial_hddsize,
'%INSTALL_DISK%' => $device,
'%KERNEL_CMD_LINE%' => $krnlcmdline
);
Expand All @@ -105,6 +128,13 @@ sub customize_cmd {
'%RELEASE_MANIFEST_URI%' => $manifest_uri,
'%K8S%' => $args{k8s}
);
if (check_var('TESTED_CMD', 'customize_recovery')) {
file_content_replace(
"$build_dir/custom/scripts/50-firstboot.sh",
'--sed-modifier' => 'g',
'%INSTALL_DISK%' => $device,
);
}

# Generate OS image
assert_script_run(
Expand All @@ -113,73 +143,82 @@ sub customize_cmd {
);

# Convert RAW to QCOW2 if needed
# NOTE: './' is needed in front of $out as the filename contains a ':' in it
if ($type =~ m/raw/) {
assert_script_run(
"qemu-img convert -p -f raw -O qcow2 uc_image.$type ./$out",
timeout => $args{timeout}
);

# Extend HDD image to needed size
assert_script_run(
"qemu-img resize ./$out $args{hddsize}G",
timeout => $args{timeout}
);
} elsif ($type =~ m/iso/) {
assert_script_run("mv uc_image.$type '$out'");
}

# Return HDD image
# Return OS image
return ($out);
}

=head2 build_installer_cmd
=head2 extract_iso

build_installer cmd( img_filename => <value>, k8s => <value>,
rootpwd => <value>, timeout => <value>,
type => <value> );
extract_iso( img_filename => <value>, timeout => <value> );

Create an OS image with `build-installer` command by using the specified
containerized OS image.
Extract ISO image from container.

=cut

sub build_installer_cmd {
sub extract_iso {
my (%args) = @_;
my $image = get_required_var('CONTAINER_IMAGE_TO_TEST');
my $krnlcmdline = get_var('KERNEL_CMD_LINE');
my $isocmdline = get_var('ISO_CMD_LINE');
my $shared_dir = '/root/shared';
my $config_file = "$shared_dir/config.sh";
my $iso_config_file = "$shared_dir/config-iso.sh";
my $device = get_var('INSTALL_DISK', '/dev/vda');
my $iso = get_required_var('ISO_IMAGE_TO_TEST');
my $runtime = get_required_var('CONTAINER_RUNTIMES');
my $out = "$args{img_filename}.iso";

# Configure the systemd sysexts
my ($overlay_dir, $ctl_oci) = get_sysext(timeout => $args{timeout});
assert_script_run("$runtime pull $image");
my $run_id = script_output("$runtime run -d $image");
assert_script_run("$runtime cp ${run_id}:/iso/${iso} .");
assert_script_run("mv $iso '$out'");

# OS configuration script
assert_script_run(
"curl -s -o $config_file "
. data_url('elemental3/' . path($config_file)->basename)
);
file_content_replace(
$config_file,
'--sed-modifier' => 'g',
'%TEST_PASSWORD%' => $args{rootpwd},
'%K8S%' => $args{k8s}
);
assert_script_run("chmod 755 $config_file");
# Return OS image
return ($out);
}

# ISO configuration script
assert_script_run(
"curl -s -o $iso_config_file "
. data_url('elemental3/' . path($iso_config_file)->basename)
);
assert_script_run("chmod 755 $iso_config_file");
=head2 get_sysext

record_info('ISO', 'Generate and upload ISO image');
get_sysext( timeout => <value> );

# Generate OS image
assert_script_run(
"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",
timeout => $args{timeout}
);
Get systemd system extensions from SYSEXT_IMAGES_TO_TEST list and
prepare them to be used by elemental tool.

# Return ISO image
return ("$args{img_filename}.iso");
=cut

sub get_sysext {
my (%args) = @_;
my $shared_dir = '/root/shared';
my $overlay_dir = "$shared_dir/overlays";
my $sysext_dir = "$overlay_dir/etc/extensions";
my $ctl_oci;

record_info('SYSEXT', 'Download and configure systemd system extensions');

# Create directories
assert_script_run("mkdir -p $sysext_dir");

# Get the system extensions
foreach my $img (split(/,/, get_required_var('SYSEXT_IMAGES_TO_TEST'))) {
assert_script_run(
"elemental3ctl --debug unpack-image --image ${img} --target ${sysext_dir}",
timeout => $args{timeout}
);
$ctl_oci = $img if ($img =~ /\/elemental3ctl:/);
}

# Return systemd-sysexts file name
return ($overlay_dir, $ctl_oci);
}

=head2 install_cmd
Expand Down Expand Up @@ -207,7 +246,7 @@ sub install_cmd {

# OS configuration script
assert_script_run(
"curl -s -o $config_file "
"curl -sf -o $config_file "
. data_url('elemental3/' . path($config_file)->basename)
);
file_content_replace(
Expand Down Expand Up @@ -242,8 +281,8 @@ sub run {
my $k8s = get_required_var('K8S');
my $hddsize = get_var('HDDSIZEGB', '30');
my $rootpwd = get_required_var('TEST_PASSWORD');
my $build = get_required_var('BUILD');
my $img_filename = get_required_var('IMG_NAME');
my $tpl_file = get_var('TEMPLATE', 'build-tpl.tar.gz');
my $timeout = 900;
my $out_file;

Expand All @@ -266,33 +305,36 @@ sub run {
my $hashpwd = script_output("openssl passwd -6 $rootpwd");

# Create HDD image with different commands
$out_file = customize_cmd(
timeout => $timeout,
$out_file = build_installer_cmd(
img_filename => $img_filename,
k8s => $k8s,
hddsize => $hddsize,
rootpwd => $hashpwd,
build => $build,
img_filename => $img_filename
) if check_var('TESTED_CMD', 'customize');

$out_file = build_installer_cmd(
timeout => $timeout,
type => 'iso'
) if (check_var('TESTED_CMD', 'build_installer_iso'));

$out_file = customize_cmd(
hddsize => $hddsize,
img_filename => $img_filename,
k8s => $k8s,
type => 'iso',
rootpwd => $hashpwd,
build => $build,
img_filename => $img_filename
) if check_var('TESTED_CMD', 'build_installer_iso');
template => $tpl_file,
timeout => $timeout
) if (check_var('TESTED_CMD', 'customize') || check_var('TESTED_CMD', 'customize_recovery'));

$out_file = extract_iso(
img_filename => $img_filename,
timeout => $timeout
) if (check_var('TESTED_CMD', 'extract_iso'));

$out_file = install_cmd(
timeout => $timeout,
arch => $arch,
k8s => $k8s,
hddsize => $hddsize,
img_filename => $img_filename,
k8s => $k8s,
rootpwd => $hashpwd,
build => $build,
img_filename => $img_filename
) if check_var('TESTED_CMD', 'install');
timeout => $timeout,
) if (check_var('TESTED_CMD', 'install'));

# Upload OS image
upload_asset("$out_file", 1);
Expand Down
Loading
Loading