Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ASSET_n to download guest assets for virt tests #21123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion lib/virt_autotest/utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ sub is_hyperv_virtualization {

# Return 1 if it is SLES MU virt test, otherwise return 0
sub is_sles_mu_virt_test {
return is_sle && get_var('REGRESSION') =~ /xen|kvm|qemu|hyperv|vmware/ && !get_var("VIRT_AUTOTEST");
return is_sle && get_var('REGRESSION', '') =~ /xen|kvm|qemu|hyperv|vmware/ && !get_var("VIRT_AUTOTEST");
}

#return 1 if it is a fv guest judging by name
Expand Down
121 changes: 44 additions & 77 deletions tests/virt_autotest/virt_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -403,95 +403,62 @@ sub get_guest_list {
return $guest_list;
}

# Download guest image and xml from a NFS location to local
# the image and xml is coming from a guest installation testsuite
# need set SKIP_GUEST_INSTALL=1 in the test suite settings
# return the account of the guests downloaded
# only available on x86_64
# Download guest image and xml which are defined in ASSET_*
# fg. ASSET_10=guest_%-GUEST_LIST%fv-def-net_on-host_%DISTRI%-%VERSION%_build%BUILD%_%SYSTEM_ROLE%_%ARCH%.xml
# ASSET_11=guest_%-GUEST_LIST%fv-def-net_on-host_%DISTRI%-%VERSION%_build%BUILD%_%SYSTEM_ROLE%_%ARCH%.disk
# Need set SKIP_GUEST_INSTALL=1 in the test suite settings
# Return the account of the guests downloaded
# Only available on x86_64
sub download_guest_assets {

# guest_pattern is a string, like sles-11-sp4-64, may or may not with pv or fv given.
my ($expected_guests, $vm_xml_dir) = @_;

# mount the remote NFS location of guest assets
# OPENQA_URL="localhost" in local openQA instead of the IP, so the line below need to be turned on and set to the webUI IP when you are using local openQA
# Tips: Using local openQA, you need "rcnfs-server start & vi /etc/exports; exportfs -r")
# set OPENQA_URL="your_ip" on openQA web UI
my $openqa_server = get_required_var('OPENQA_URL');

# check if vm xml files have been uploaded
my @available_guests = ();
foreach my $guest (split "\n", $expected_guests) {
my $guest_asset = generate_guest_asset_name("$guest");
my $vm_disk_url = $openqa_server . "/assets/other/" . $guest_asset . '.disk';
$vm_disk_url =~ s#^(?!http://)(.*)$#http://$1#; #add 'http://' at beginning if needed.
if (head($vm_disk_url)) {
push @available_guests, $guest;
}
else {
record_info('Softfail', "$vm_disk_url not found!", result => 'softfail');
}
}
return 0 unless @available_guests;
my ($guests_list, $vm_xml_dir) = @_;

# clean up vm stuff
my $mount_point = "/tmp/remote_guest";
script_run "[ -d $mount_point ] && { if findmnt $mount_point; then umount $mount_point; rm -rf $mount_point; fi }";
script_run "mkdir -p $mount_point";
script_run "[ -d $vm_xml_dir ] && rm -rf $vm_xml_dir; mkdir -p $vm_xml_dir";
my $disk_image_dir = script_output "source /usr/share/qa/virtautolib/lib/virtlib; get_vm_disk_dir";
script_run "umount $disk_image_dir; rm -rf $disk_image_dir/*";
script_run "[ -d /tmp/prj3_guest_migration/ ] && rm -rf /tmp/prj3_guest_migration/" if get_var('VIRT_NEW_GUEST_MIGRATION_SOURCE');

# tip: nfs4 is not supported on sles12sp4, so use '-t nfs' instead of 'nfs4' here.
$openqa_server =~ s/^http:\/\///;
my $remote_export_dir = "/var/lib/openqa/factory/other/";
assert_script_run("mount -t nfs $openqa_server:$remote_export_dir $mount_point", 120);

# copy guest images and xml files to local
# test aborts if failing in copying all the guests
my $guest_count = 0;
foreach my $guest (@available_guests) {
my $guest_asset = generate_guest_asset_name("$guest");
my $remote_guest_xml_file = $guest_asset . '.xml';
my $remote_guest_disk = $guest_asset . '.disk';

# download vm xml file
my $rc = script_run("cp $mount_point/$remote_guest_xml_file $vm_xml_dir/$guest.xml", 60);
if ($rc) {
record_info('Softfail', "Failed copying: $mount_point/$remote_guest_xml_file", result => 'softfail');
next;
}
script_run("ls -l $vm_xml_dir", 10);
save_screenshot;

# download vm disk files
my $local_guest_image = script_output "grep '<source file=' $vm_xml_dir/$guest.xml | sed \"s/^\\s*<source file='\\([^']*\\)'.*\$/\\1/\"";
# put the downloded xml and disk files in the backup dir directory
# in case of being flushed up by the NFS workaround from dst job
if (get_var('VIRT_NEW_GUEST_MIGRATION_SOURCE')) {
my $backupRootDir = "/tmp/prj3_guest_migration/vm_backup";
my $backupCfgXmlDir = "$backupRootDir/vm-config-xmls";
my $backupDiskDir = "$backupRootDir/vm-disk-files";
script_run "mkdir -p $backupCfgXmlDir; mkdir -p $backupDiskDir";
script_run "cp $vm_xml_dir/$guest.xml $backupCfgXmlDir";
script_run "ls -l $backupCfgXmlDir";
$local_guest_image = $backupDiskDir . $local_guest_image;
}
script_run "[ -d `dirname $local_guest_image` ] || mkdir -p `dirname $local_guest_image`";
$rc = script_run("cp $mount_point/$remote_guest_disk $local_guest_image", 300); #it took 75 seconds copy from vh016 to vh001
script_run "ls -l $local_guest_image";
if ($rc) {
record_info('Softfail', "Failed to download: $remote_guest_disk", result => 'softfail');
next;
# check if vm xml files have been uploaded
my @guests = split "\n", $guests_list;
my @downloaded_guests;
foreach my $guest (@guests) {
my $guest_asset_name = generate_guest_asset_name("$guest");
for my $i (1 .. @guests) {
# ASSET_n0: put the guest xml file
# ASSET_n1: put the guest disk file
if (get_var("ASSET_${i}0", "") =~ /$guest_asset_name/) {

# Download the guest xml file
script_run("curl " . autoinst_url("/assets/other/" . get_var("ASSET_${i}0")) . " -o $vm_xml_dir/$guest.xml");
script_run("ls -l $vm_xml_dir");

# Download the guest disk file
my $local_guest_image = script_output "grep '<source file=' $vm_xml_dir/$guest.xml | sed \"s/^\\s*<source file='\\([^']*\\)'.*\$/\\1/\"";
# For prj3, put the downloded xml and disk files in the backup dir directory
# in case of being flushed up by the NFS workaround from dst job
if (get_var('VIRT_NEW_GUEST_MIGRATION_SOURCE')) {
my $backupRootDir = "/tmp/prj3_guest_migration/vm_backup";
my $backupCfgXmlDir = "$backupRootDir/vm-config-xmls";
my $backupDiskDir = "$backupRootDir/vm-disk-files";
script_run "mkdir -p $backupCfgXmlDir; mkdir -p $backupDiskDir";
script_run "cp $vm_xml_dir/$guest.xml $backupCfgXmlDir";
script_run "ls -l $backupCfgXmlDir";
$local_guest_image = $backupDiskDir . $local_guest_image;
}
script_run "[ -d `dirname $local_guest_image` ] || mkdir -p `dirname $local_guest_image`";
# It took 14s to download vm disk file from worker cache to SUT
script_run("curl " . autoinst_url("/assets/other/" . get_var("ASSET_${i}1")) . " -o $local_guest_image");
script_run "ls -l $local_guest_image";
push @downloaded_guests, $guest;
record_info("$guest downloaded", "$guest_asset_name");
}
}
$guest_count++;
record_info('Softfail', "$guest_asset_name not found!", result => 'softfail') unless grep $guest, @downloaded_guests;
}

# umount
script_run("umount $mount_point");

return $guest_count;
record_info("Downloaded guests", "@downloaded_guests") if @downloaded_guests;
return @downloaded_guests;
}

sub is_installed_equal_upgrade_major_release {
Expand Down