From f0cd2c46861ffdf75dec00d86aa1b8c4d4cb1e34 Mon Sep 17 00:00:00 2001 From: Julie-CAO Date: Mon, 30 Sep 2024 14:56:43 +0800 Subject: [PATCH] Wait until guest get IP in setup_dns --- data/virt_autotest/setup_dns_service.sh | 38 ++++++++++-------------- products/sle/main.pm | 2 +- tests/virt_autotest/setup_dns_service.pm | 11 ++----- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/data/virt_autotest/setup_dns_service.sh b/data/virt_autotest/setup_dns_service.sh index 3d26a55a392e..00733e16e62e 100755 --- a/data/virt_autotest/setup_dns_service.sh +++ b/data/virt_autotest/setup_dns_service.sh @@ -120,18 +120,26 @@ if [[ ${vmguest_failed} -ne 0 ]];then exit 1 fi #Wait for vm guests get assigned ip addresses -sleep 90s +sleep 60s echo -e "Virtual machines ${vm_guestnames_array[@]} have already been refreshed\n" | tee -a ${setup_log_file} #Write vm_hash_forward_ipaddr and vm_hash_reverse_ipaddr arrays for vmguest in ${vm_guestnames_array[@]};do get_vm_macaddress=`virsh domiflist --domain ${vmguest} | grep -oE "([0-9|a-z]{2}:){5}[0-9|a-z]{2}"` vm_macaddresses_array[${vm_hash_index}]=$(echo -e ${get_vm_macaddress}) + for i in {1..30} ; do + get_vm_ipaddress=`tac $dhcpd_lease_file | awk '!($0 in S) {print; S[$0]}' | tac | grep -iE "${vm_macaddresses_array[${vm_hash_index}]}" -B8 | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" | tail -1` + [[ -n "$vm_ipaddress" ]] && break + sleep 10 + done get_vm_ipaddress=`tac $dhcpd_lease_file | awk '!($0 in S) {print; S[$0]}' | tac | grep -iE "${vm_macaddresses_array[${vm_hash_index}]}" -B8 | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" | tail -1` vm_ipaddress=$(echo -e ${get_vm_ipaddress}) #missing ip will make named fail to load domain zones due to malformed zone file if [ -z "$vm_ipaddress" ]; then echo -e "Unable to get the ip of $vmguest. Abort the test!\n" | tee -a ${setup_log_file} + date >> ${setup_log_file} + echo -e "cat $dhcpd_lease_file" >> ${setup_log_file} + cat $dhcpd_lease_file >> ${setup_log_file} exit 1 fi vm_ipaddress_lastpart=$(echo -e ${vm_ipaddress} | grep -Eo "[0-9]{1,3}$") @@ -283,20 +291,10 @@ echo "" | tee -a ${setup_log_file} #Start named service. Quit if failed. dns_service_name="named" -get_os_installed_release=`lsb_release -r | grep -oE "[[:digit:]]{2}"` -os_installed_release=$(echo ${get_os_installed_release}) -get_os_installed_sp=`cat /etc/os-release | grep "SUSE Linux Enterprise Server" | grep -oE "SP[0-9]{1,}" | grep -oE "[0-9]{1,}"` -os_installed_sp=$(echo ${get_os_installed_sp}) -if [[ ${os_installed_release} -gt '11' ]];then - systemctl enable ${dns_service_name} - systemctl restart ${dns_service_name} - dns_service_failed=$(echo $?) - systemctl status ${dns_service_name} | tee -a ${setup_log_file} -else - service ${dns_service_name} restart - dns_service_failed=$(echo $?) - service ${dns_service_name} status | tee -a ${setup_log_file} -fi +systemctl enable ${dns_service_name} +systemctl restart ${dns_service_name} +dns_service_failed=$(echo $?) +systemctl status ${dns_service_name} | tee -a ${setup_log_file} if [[ ${dns_service_failed} -ne 0 ]];then echo -e "DNS service did not start up as normal. Please investigate.\n" | tee -a ${setup_log_file} echo -e "DNS resolver file content:\n" | tee -a ${setup_log_file} @@ -341,9 +339,9 @@ done echo "" | tee -a ${setup_log_file} echo "# virsh list --all" | tee -a ${setup_log_file} virsh list --all | tee -a ${setup_log_file} -ehco "" | tee -a ${setup_log_file} +echo "" | tee -a ${setup_log_file} -ehco "" | tee -a ${setup_log_file} +echo "" | tee -a ${setup_log_file} echo "the new /etc/named.conf after modified: " | tee -a ${setup_log_file} echo "cat /etc/named.conf" | tee -a ${setup_log_file} echo "---------" | tee -a ${setup_log_file} @@ -403,11 +401,7 @@ else vmguest_index=0 #Use sshpass to copy public key into vm guest for the first time and store results for vmguest in ${vm_guestnames_array[@]};do - if [[ ${os_installed_release} -ge '15' ]] || [[ ${os_installed_release} -ge '12' && ${os_installed_sp} -ge '2' ]];then - sshpass -p ${ssh_key_pass} ssh-copy-id -i ${ssh_key_path}/id_rsa.pub -f root@${vmguest} - else - sshpass -p ${ssh_key_pass} ssh-copy-id -i ${ssh_key_path}/id_rsa.pub root@${vmguest} - fi + sshpass -p ${ssh_key_pass} ssh-copy-id -i ${ssh_key_path}/id_rsa.pub -f root@${vmguest} vmguest_sshcopyid_failed[${vmguest_index}]=`echo $?` vmguest_index=$((${vmguest_index} + 1)) done diff --git a/products/sle/main.pm b/products/sle/main.pm index d8eb1ade75a3..272820e327ff 100644 --- a/products/sle/main.pm +++ b/products/sle/main.pm @@ -863,7 +863,7 @@ elsif (get_var("VIRT_AUTOTEST")) { loadtest "virt_autotest/install_package"; loadtest "virt_autotest/update_package"; # Skip reset_partition for s390x due to there just be 42Gib disk space for each s390x LPAR - loadtest "virt_autotest/reset_partition" if (!is_s390x); + loadtest "virt_autotest/reset_partition" if (!is_s390x and get_var('VIRT_PRJ1_GUEST_INSTALL')); loadtest "virt_autotest/reboot_and_wait_up_normal" if (!get_var('AUTOYAST') && get_var('REPO_0_TO_INSTALL')); loadtest "virt_autotest/download_guest_assets" if get_var("SKIP_GUEST_INSTALL") && is_x86_64; } diff --git a/tests/virt_autotest/setup_dns_service.pm b/tests/virt_autotest/setup_dns_service.pm index 92b961d1c0e6..e75c2dae74e0 100644 --- a/tests/virt_autotest/setup_dns_service.pm +++ b/tests/virt_autotest/setup_dns_service.pm @@ -42,15 +42,8 @@ sub post_fail_hook { script_run("sed -irn '/^nameserver 192\\.168\\.123\\.1/d' /etc/resolv.conf"); script_run("rm /var/lib/named/testvirt.net.zone; rm /var/lib/named/123.168.192.zone"); - my $get_os_installed_release = "lsb_release -r | grep -oE \"[[:digit:]]{2}\""; - my $os_installed_release = script_output($get_os_installed_release, 30, type_command => 0, proceed_on_failure => 0); - if ($os_installed_release gt '11') { - script_run("systemctl stop named.service"); - script_run("systemctl disable named.service"); - } - else { - script_run("service named stop"); - } + script_run("systemctl stop named.service"); + script_run("systemctl disable named.service"); my $vm_types = "sles|win"; my $get_vm_hostnames = "virsh list --all | grep -E \"${vm_types}\" | awk \'{print \$2}\'";