Skip to content

Commit

Permalink
Install SLES 16.0 Minimal VM as guest on SLES 16.0 system
Browse files Browse the repository at this point in the history
1.New module prepare_non_transactional_server.pm to perform all
necessary operations on non-transactional system before doing
actual work like virtual machine installation.
2.New subroutine is_reboot_needed in lib/utils.pm to determine
whether system reboot is needed after changes being made. It uses
setting NEEDS_REBOOTING or returned code of zypper needs-rebooting
to judge whether reboot is needed.
3.New guest profile sles_16_64_kvm_hvm_x86_64_qcow_ignition+combustion.xml
to represent SLES 16.0 Minimal VM for x86_64.
4.New combustion script combustion_script_all_round to perform all
necessary tasks, including adding user, setting passwords, adding
ssh public keys, starting services, doing registration and etc, in
order to have a fully up and running system.
5.Introduce new test suite level setting UNIFIED_GUEST_BUILDS for
unified guest installation because SLES 16.0 Minimal VM may have
different build than agama installer.
6.Update virtualization server patterns for SLES 16.0.
7.Use ##Authorized-Keys## and ##FQDN## in combustion_script_all_round.
8.New subroutine install_extra_packages in lib/utils.pm to wrap
up already existing similar functionality in multiple modules.
  • Loading branch information
waynechen55 committed Feb 7, 2025
1 parent 2c2f37d commit 3d289a9
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0"?>
<guest>
<guest_os_name>sles</guest_os_name>
<guest_version>16.0</guest_version>
<guest_version_major>16</guest_version_major>
<guest_version_minor>0</guest_version_minor>
<guest_os_word_length>64</guest_os_word_length>
<guest_build/>
<host_hypervisor_uri/>
<host_virt_type>kvm</host_virt_type>
<guest_virt_type>hvm</guest_virt_type>
<guest_machine_type>q35</guest_machine_type>
<guest_arch>x86_64</guest_arch>
<guest_name/>
<guest_domain_name/>
<guest_memory>2048,maxmemory=4096</guest_memory>
<guest_vcpus>2,maxvcpus=4</guest_vcpus>
<guest_cpumodel>host-model</guest_cpumodel>
<guest_metadata/>
<guest_boot_settings>loader=/usr/share/qemu/ovmf-x86_64-suse-4m-code.bin,loader.readonly=yes,loader.type=pflash,nvram.template=/usr/share/qemu/ovmf-x86_64-suse-4m-vars.bin,bootmenu.enable=yes</guest_boot_settings>
<guest_xpath/>
<guest_installation_automation_method>ignition+combustion</guest_installation_automation_method>
<guest_installation_automation_platform>metal</guest_installation_automation_platform>
<guest_installation_automation_file>ignition_config_non_encrypted_image.ign#combustion_script_all_round</guest_installation_automation_file>
<guest_installation_method>import</guest_installation_method>
<guest_installation_extra_args/>
<guest_installation_wait/>
<guest_installation_method_others/>
<guest_installation_media>http://mirror.suse.asia/ibs/SUSE:/SLFO:/Products:/SLES:/16.0:/TEST/images/SLES16-Minimal-VM.x86_64-kvm-and-xen-Build12345.qcow2</guest_installation_media>
<guest_installation_fine_grained/>
<guest_os_variant>sle15sp7</guest_os_variant>
<guest_storage_path/>
<guest_storage_type>disk</guest_storage_type>
<guest_storage_format>qcow2</guest_storage_format>
<guest_storage_label>gpt</guest_storage_label>
<guest_storage_size>40</guest_storage_size>
<guest_storage_backing_path/>
<guest_storage_backing_format/>
<guest_storage_others>driver.name=qemu,target.dev=vda,target.bus=virtio,bus=virtio,cache=none</guest_storage_others>
<guest_network_type>bridge</guest_network_type>
<guest_network_mode>bridge</guest_network_mode>
<guest_network_device/>
<guest_network_others/>
<guest_netaddr/>
<guest_ipaddr/>
<guest_ipaddr_static>false</guest_ipaddr_static>
<guest_macaddr/>
<guest_graphics>vnc</guest_graphics>
<guest_controller/>
<guest_input/>
<guest_serial>pty</guest_serial>
<guest_parallel/>
<guest_channel/>
<guest_console/>
<guest_hostdev/>
<guest_filesystem/>
<guest_sound/>
<guest_watchdog/>
<guest_video/>
<guest_smartcard/>
<guest_redirdev/>
<guest_memballoon/>
<guest_tpm/>
<guest_rng/>
<guest_panic/>
<guest_memdev/>
<guest_vsock/>
<guest_iommu/>
<guest_iothreads/>
<guest_seclabel/>
<guest_keywrap/>
<guest_cputune/>
<guest_memtune/>
<guest_blkiotune/>
<guest_memorybacking/>
<guest_features/>
<guest_clock/>
<guest_power_management>suspend_to_mem.enabled=yes,suspend_to_disk.enabled=yes</guest_power_management>
<guest_events/>
<guest_resource/>
<guest_sysinfo/>
<guest_qemu_command/>
<guest_launchSecurity/>
<guest_autostart/>
<guest_transient/>
<guest_destroy_on_exit/>
<guest_autoconsole>text</guest_autoconsole>
<guest_noautoconsole>false</guest_noautoconsole>
<guest_noreboot/>
<guest_default_target>graphical</guest_default_target>
<guest_do_registration>false</guest_do_registration>
<guest_registration_server/>
<guest_registration_username/>
<guest_registration_password/>
<guest_registration_extensions/>
</guest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
# combustion: network
#
# To be provisioned:
# 01) set localization and timezone
# 02) set root password
# 03) add new user qevirt
# 04) add ssh public keys for root and qevirt
# 05) set hostname
# 06) add customized sshd config
# 07) enable and restart sshd
# 08) test networking
# 09) do registration
# 10) refresh repositories
# 11) leave a marker

set -euxo pipefail

# Redirect output to the console
exec > >(exec tee -a /dev/console) 2>&1

### set locale, keyboard and timezone
rm -f /etc/localtime
systemd-firstboot --force --timezone=UTC --locale=en_US.UTF-8 --keymap=us
echo "FONT=eurlatgr.psfu" >> /etc/vconsole.conf

### set password for root
echo 'root:$6$LZQfIH8bS4JYwAQq$VIdGS2fnED6CSySnb5jJm8O6FUXWgjG3keN2I0c6Td4nLrwxUxratkJq0cKMuo1OMTwUYpQ7EyP2GnZ2pL.ut.' | chpasswd -e

### add new user qevirt
useradd --create-home --uid 1001 --comment "QE Virtualization Functional Test" --no-user-group --gid users qevirt
echo 'qevirt:$6$0Tcx/pXefxOSvZEi$ukUmR.j7/sTbv10LwbesHD8CurSkr/2pkstXeWuErA7TBxeB2nLQwOKFKQJnlqJuVzNWg1E6ovKl6ajAZRtKt.' | chpasswd -e

### add ssh public keys
mkdir -p /root/.ssh
echo "##Authorized-Keys##" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
mkdir -p /home/qevirt/.ssh
echo "##Authorized-Keys##" >> /home/qevirt/.ssh/authorized_keys
chmod 600 /home/qevirt/.ssh/authorized_keys

### set hostname
echo "##FQDN##" > /etc/hostname

### add customized sshd config
cat << EOF > /etc/ssh/sshd_config.d/01-qe-virt.conf
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no
EOF

### restart sshd service
systemctl enable sshd.service
systemctl stop sshd.service
systemctl start sshd.service

### test networking
curl conncheck.opensuse.org

### do registration
SUSEConnect -r ##Registration-Code## --url ##Registration-Server##

### refresh and list respositories
zypper --non-interactive --gpg-auto-import-keys refresh
zypper repos --details

### leave a marker
echo "Configured with combustion" > /etc/issue.d/combustion

# close outputs and wait for tee to finish
exec 1>&- 2>&-; wait;
1 change: 1 addition & 0 deletions lib/concurrent_guest_installations.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ sub instantiate_guests_and_profiles {
my $_guest_profile = (XML::Simple->new)->XMLin($_res->content, SuppressEmpty => '');
$_guest_profile->{guest_name} = $_element;
$_guest_profile->{guest_installation_media} = $_store_of_guests{$_element}{INSTALL_MEDIA} if ($_store_of_guests{$_element}{INSTALL_MEDIA} ne '');
$_guest_profile->{guest_build} = $_store_of_guests{$_element}{INSTALL_BUILD} if ($_store_of_guests{$_element}{INSTALL_BUILD} ne '');
$_guest_profile->{guest_registration_code} = $_store_of_guests{$_element}{REG_CODE};
$_guest_profile->{guest_registration_extensions_codes} = $_store_of_guests{$_element}{REG_EXTS_CODES};
$guest_instances_profiles{$_element} = $_guest_profile;
Expand Down
35 changes: 6 additions & 29 deletions lib/guest_installation_and_configuration_base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ sub prepare_non_transactional_environment {
zypper_call("install -y $_packages_to_check");
# There is already the highest version for kvm/xen packages on TW
if (is_sle) {
my $_patterns_to_check = 'kvm_server kvm_tools';
$_patterns_to_check = 'xen_server xen_tools' if ($self->{host_virt_type} eq 'xen');
my $_patterns_to_check = is_sle('<16') ? "$self->{host_virt_type}_server $self->{host_virt_type}_tools" : "$self->{host_virt_type}_host";
zypper_call("install -y -t pattern $_patterns_to_check");
}
}
Expand Down Expand Up @@ -1853,34 +1852,8 @@ sub config_guest_installation_media {

$self->reveal_myself;
$self->{guest_installation_media} =~ s/12345/$self->{guest_build}/g if ($self->{guest_build} ne 'gm');
#This is just auxiliary functionality to help correct and set correct installation media major and minor version if it mismatches with guest_version.It is not mandatory
#necessary and can be skipped without causing any issue.The end user should always pay attention and use meaningful and correct guest parameters and profiles.
if ($self->{guest_os_name} =~ /sles|oraclelinux/im) {
if (!($self->{guest_installation_media} =~ /-$self->{guest_version}-/im)) {
record_info("Guest $self->{guest_name} installation media $self->{guest_installation_media} does not match with version $self->{guest_version}", "Going to correct it !");
my $_guest_version_major_indicator = ($self->{guest_os_name} =~ /sles/im ? '' : 'R');
my $_guest_version_minor_indicator = ($self->{guest_os_name} =~ /sles/im ? 'SP' : 'U');
$self->{guest_installation_media} =~ /-((r)?(\d*))-((sp|u)?(\d*))?/im;
if ($self->{guest_version_minor} ne 0) {
if ($4 ne '') {
$self->{guest_installation_media} =~ s/-$1-$4/-${_guest_version_major_indicator}$self->{guest_version_major}-${_guest_version_minor_indicator}$self->{guest_version_minor}/im;
}
else {
$self->{guest_installation_media} =~ s/-$1/-${_guest_version_major_indicator}$self->{guest_version_major}-${_guest_version_minor_indicator}$self->{guest_version_minor}/im;
}
}
else {
if ($4 ne '') {
$self->{guest_installation_media} =~ s/-$1-$4/-${_guest_version_major_indicator}$self->{guest_version_major}/im;
}
else {
$self->{guest_installation_media} =~ s/-$1/-${_guest_version_major_indicator}$self->{guest_version_major}/im;
}
}
}
}

#If guest chooses to use iso installation media, then this iso media should be available on INSTALLATION_MEDIA_NFS_SHARE and mounted locally at INSTALLATION_MEDIA_LOCAL_SHARE.
# If guest chooses to use iso installation media, then this iso media should be available on INSTALLATION_MEDIA_NFS_SHARE and mounted locally at INSTALLATION_MEDIA_LOCAL_SHARE.
if ($self->{guest_installation_media} =~ /^.*\.iso$/im) {
my $_installation_media_nfs_share = get_var('INSTALLATION_MEDIA_NFS_SHARE', '');
my $_installation_media_local_share = get_var('INSTALLATION_MEDIA_LOCAL_SHARE', '');
Expand Down Expand Up @@ -2168,6 +2141,10 @@ sub config_guest_provision_combustion {
}
assert_script_run("curl -s -o $self->{guest_log_folder}/script " . data_url("virt_autotest/guest_unattended_installation_files/$_combustion_config"));
$_combustion_config = "$self->{guest_log_folder}/script";
my $_ssh_public_key = $guest_installation_and_configuration_metadata::host_params{ssh_public_key};
$_ssh_public_key =~ s/\//PLACEHOLDER/img;
assert_script_run("sed -i \'s/##Authorized-Keys##/$_ssh_public_key/g\' $_combustion_config");
assert_script_run("sed -i \'s/##FQDN##/$self->{guest_name}\\.$self->{guest_domain_name}/g\' $_combustion_config");
my $_scc_regcode = get_required_var('SCC_REGCODE');
$_scc_regcode =~ s/\//PLACEHOLDER/img;
assert_script_run("sed -i \'s/##Registration-Code##/$_scc_regcode/g\' $_combustion_config");
Expand Down
63 changes: 63 additions & 0 deletions lib/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ our @EXPORT = qw(
ensure_testuser_present
is_disk_image
is_ipxe_with_disk_image
is_reboot_needed
install_extra_packages
);

our @EXPORT_OK = qw(
Expand Down Expand Up @@ -3211,4 +3213,65 @@ sub is_ipxe_with_disk_image {
return 0;
}

=head2 is_reboot_needed
is_reboot_needed;
Identify whether test runs boots from ipxe and deploy linux disk image built by kiwi or similar programs
=cut

sub is_reboot_needed {
my %args = @_;
$args{username} //= 'root';
$args{address} //= 'localhost';

my $check_reboot_needed = "zypper needs-rebooting";
$check_reboot_needed = "ssh $args{username}\@$args{address} \"$check_reboot_needed\"" if ($args{address} ne 'localhost');
return 1 if (script_run("$check_reboot_needed") == 102 or get_var('NEEDS_REBOOTING'));
return 0;
}

=head2 install_extra_packages
install_extra_packages;
Install extra packages that are only available in extra repositories. These extra
packages and repositories are specified in test suite settings INSTALL_OTHER_REPOS
and INSTALL_OTHER_PACKAGES. It might be necessary to install some useful utilities
from other repositories to facilitate test run. At the same time, it also needs to
ensure such operations will not alter existing system. Althought user should not be
prevented from installing legitimate tools and utilities, it is expected that use
of additional packages should be limited to the minimum their impact should be paid
attention to.
=cut

sub install_extra_packages {
if (get_var("INSTALL_OTHER_REPOS")) {
my @repos_to_install = split(/,/, get_var("INSTALL_OTHER_REPOS"));
my @repos_names = ();
my $repo_name = "";
foreach (@repos_to_install) {
$repo_name = (split(/\//, $_))[-1] . "-" . bmwqemu::random_string(8);
push(@repos_names, $repo_name);
zypper_call("--gpg-auto-import-keys ar --enable --refresh $_ $repo_name");
save_screenshot;
}
zypper_call("--gpg-auto-import-keys refresh");
save_screenshot;

my $cmd = "install --no-allow-downgrade --no-allow-name-change --no-allow-vendor-change";
$cmd = $cmd . " $_" foreach (split(/,/, get_required_var("INSTALL_OTHER_PACKAGES")));
zypper_call($cmd);
save_screenshot;

$cmd = "rr";
$cmd = $cmd . " $_" foreach (@repos_names);
zypper_call($cmd);
save_screenshot;
}
else {
record_info("No other packages to be installed from empty INSTALL_OTHER_REPOS");
}
}

1;
2 changes: 2 additions & 0 deletions schedule/virt_autotest/sle16_guest_installation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ schedule:
- installation/ipxe_install
- installation/agama_reboot
- virt_autotest/login_console
- virt_autotest/prepare_non_transactional_server
- virt_autotest/unified_guest_installation
Loading

0 comments on commit 3d289a9

Please sign in to comment.