Skip to content
67 changes: 33 additions & 34 deletions provider/v2v/v2v_vmcheck_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

RETRY_TIMES = 10

# max time we expect a single windows boot+configure cycle to take.
WIN_SINGLE_BOOT_MAX_TIME = 300


def detect_source_efi(source_xml):
"""
Expand Down Expand Up @@ -68,12 +71,18 @@ def _watch(self):
try:
self._proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
last_reboot_time = time.monotonic()
for line in self._proc.stdout:
line = line.decode('utf-8', errors='replace').strip()
if line:
now = time.monotonic()
elapsed = now - last_reboot_time
since = ('previous reboot' if self.reboot_count
else 'watcher started')
self.reboot_count += 1
LOG.warning("Guest reboot detected (#%d): %s",
self.reboot_count, line)
LOG.info("Guest reboot detected (#%d), %.1f seconds since %s: %s",
self.reboot_count, elapsed, since, line)
last_reboot_time = now
except Exception as e:
LOG.debug("Reboot watcher ended: %s", e)

Expand Down Expand Up @@ -529,7 +538,7 @@ def check_vm_xml(self):
".//*[@model='virtio-transitional']") or root.findall(".//*[@type='virtio-transitional']"):
self.log_err(err_msg)

if self.vsock_check_enabled() and self.is_vsock_supported(self.os_version):
if self.vsock_check_enabled() and self.is_vsock_supported():
self.check_xml('./devices/vsock')

def check_xml(self, xpath, existence=True):
Expand Down Expand Up @@ -589,7 +598,7 @@ def check_linux_vm(self):
"Virtio (memory|1.0) balloon"]
# Virtio RNG supports from kernel-2.6.26 — all test kernels qualify
virtio_devs.append("Virtio RNG")
if self.vsock_check_enabled() and self.is_vsock_supported(self.os_version):
if self.vsock_check_enabled() and self.is_vsock_supported():
virtio_devs.append("Virtio socket")
LOG.info("Virtio devices checking list: %s", virtio_devs)
for dev in virtio_devs:
Expand Down Expand Up @@ -641,7 +650,7 @@ def _wait_for_firstboot_complete(self):

Returns True if firstboot completed, False on timeout.
"""
total_timeout = 300
total_timeout = WIN_SINGLE_BOOT_MAX_TIME
step = 5
complete_path = r'"C:\Program Files\Guestfs\Firstboot\complete"'
cmd = 'type %s' % complete_path
Expand Down Expand Up @@ -687,6 +696,11 @@ def _check_firstboot_failures(self):
LOG.warning(
"Firstboot log.txt reports: The Plug and Play service is not available")

for message in re.findall(
r'Install failed, retrying in \d+ seconds\.\.\.|'
r'Install failed after \d+ attempts', log_content):
LOG.warning("Firstboot QEMU Guest Agent installer: %s", message)

scripts_dir = r'"C:\Program Files\Guestfs\Firstboot\scripts"'
try:
status, output = self.checker.run_cmd('dir /b %s' % scripts_dir)
Expand Down Expand Up @@ -723,7 +737,7 @@ def _perform_windows_checks(self):
'running',
self.checker.get_service_info('qemu-ga'),
re.I),
300,
WIN_SINGLE_BOOT_MAX_TIME,
step=5)
if not res:
self.log_err("qemu-guest-agent service is not running")
Expand All @@ -747,33 +761,18 @@ def _perform_windows_checks(self):

# Check Red Hat VirtIO drivers
LOG.info("Checking VirtIO drivers")
cpu_drivers = ['Intel Processor', 'AMD Processor']
expect_drivers = ["Red Hat VirtIO SCSI",
"Red Hat VirtIO Ethernet Adapte",
"VirtIO RNG",
"VirtIO Serial",
"VirtIO Balloon"]
check_drivers = expect_drivers[:]
win_dirvers = self.checker.get_driver_info()
for driver in expect_drivers:
if driver in win_dirvers:
expected_drivers = ["Red Hat VirtIO SCSI",
"Red Hat VirtIO Ethernet Adapte",
"VirtIO RNG",
"VirtIO Serial",
"VirtIO Balloon"]
win_drivers = self.checker.get_driver_info()
for driver in expected_drivers:
if driver in win_drivers:
LOG.info("Driver %s found", driver)
check_drivers.remove(driver)
else:
err_msg = "Driver %s not found" % driver
LOG.error(err_msg)
expect_drivers = check_drivers[:]
if expect_drivers:
for driver in expect_drivers:
self.log_err("Not find driver: %s" % driver)
if re.search(r"(Intel|AMD) Processor", win_dirvers):
if re.search(r"(Intel|AMD) Processor", win_dirvers).group(0) in cpu_drivers:
LOG.info("CPU driver '%s' is found" % re.search(r"(Intel|AMD) Processor", win_dirvers).group(0))
elif self.os_version == 'win2016':
LOG.info("CPU driver not found for win2016, known issue (RHEL-17685), skipping check")
else:
err_msg = "CPU driver is not found"
self.log_err(err_msg)

cpu_status = self.checker.get_cpu_status()
if not re.search(r'OK', cpu_status):
self.log_err("cpu status is abnormal")
Expand Down Expand Up @@ -901,15 +900,15 @@ def vsock_check_enabled(self):
"""
return self.params.get('enable_vsock_check', 'no') == 'yes'

def is_vsock_supported(self, os_version):
def is_vsock_supported(self):
"""
:param os_version: the guest's os version. e.g. rhel8.6, win10.
Check if vsock is supported for the guest OS version.
"""
vsock_skiplist = ['rhel6.10', 'opensuse42.\d+', 'rhel5.11']
if not os_version or self.os_type != 'linux':
if not self.os_version or self.os_type != 'linux':
return False
for i in vsock_skiplist:
if re.match(i, os_version):
if re.match(i, self.os_version):
return False
return self.target == 'libvirt'

Expand Down
14 changes: 0 additions & 14 deletions v2v/tests/cfg/function_test_esx.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@
msg_content_yes = "windows: skipping qemufwcfg stub driver in favor of fwcfg driver"
v2v_debug = force_on
- program_files_2:
os_version = 'PROGRAM_FILES_2_OS_VERSION_V2V_EXAMPLE'
main_vm = 'PROGRAM_FILES_2_VM_NAME_V2V_EXAMPLE'
expect_msg = 'no'
msg_content = 'case_sensitive_path: v2v: no file or directory'
- OGAC_balloon:
only dest_libvirt
checkpoint = "ogac_balloon"
#Not use virtio_win_path due to bug RHEL-69035
#virtio_win_path = EXPORT_VIRTIO_WIN_PATH_V2V_EXAMPLE
Expand Down Expand Up @@ -110,7 +108,6 @@
- iso_file:
checkpoint += 'iso_file'
- mac_ip:
only libvirt
checkpoint = 'mac_ip'
variants:
- 3_static_ip:
Expand Down Expand Up @@ -157,7 +154,6 @@
expect_msg = yes
v2v_debug = false
- multiple_online_disks:
only dest_libvirt
checkpoint = 'check_online_disks'
variants:
- win2022:
Expand All @@ -177,12 +173,10 @@
msg_content = "virt-v2v: error: filesystem was mounted read-only, even though we asked for it to be mounted read-write."
expect_msg = yes
- genid_xml:
only dest_libvirt
version_requried = "[libvirt-7.6.0-2,)"
checkpoint = 'genid_xml'
main_vm = VM_NAME_GENID_WIN2019_V2V_EXAMPLE
- windows_vm_with_nvme_disk:
only dest_libvirt
version_required = "[libvirt-11.5.0-1,)"
os_type = 'windows'
main_vm = VM_NAME_WIN_WITH_NVME_DISK_V2V_EXAMPLE
Expand Down Expand Up @@ -246,7 +240,6 @@
checkpoint = "virt_customize_permission_related"
password = 123456
- linux_vm_with_nvme_disk:
only dest_libvirt
version_required = "[libvirt-11.5.0-1,)"
os_type = 'linux'
main_vm = VM_NAME_RHEL_WITH_NVME_DISK_V2V_EXAMPLE
Expand All @@ -256,7 +249,6 @@
#add required version due to bug2076013
version_required = "[virt-v2v-2.0.7-1,)"
#rhv env does not allowed guest to have special characters
only libvirt
main_vm = "VM_NAME_ESX_SPECIALNAME_V2V_EXAMPLE"
checkpoint = 'special_name'
- esx_template:
Expand Down Expand Up @@ -338,7 +330,6 @@
checkpoint = 'check_boot_order'
v2v_debug = force_on
- resume_rhel7:
os_version = OS_VERSION_RESUME_RHEL7_V2V_EXAMPLE
checkpoint = resume_swap
main_vm = VM_NAME_RESUME_RHEL7_V2V_EXAMPLE
- resume_mapper:
Expand Down Expand Up @@ -366,7 +357,6 @@
main_vm = VM_NAME_DEBIAN_REPO_V2V_EXAMPLE
- sles:
main_vm = VM_NAME_SLES_INSTALL_KERNEL_SOURCE_PKG_V2V_EXAMPLE
os_version = "sles"
- opensuse:
main_vm = VM_NAME_OPENSUSE_REPO_V2V_EXAMPLE
- ubuntu-openvm-tools:
Expand Down Expand Up @@ -600,25 +590,21 @@
version_required = "[libguestfs-1.56.1-3,)"
version_required_error = "[libguestfs-fssupport-10.1-2,)"
- print_blkhash:
only libvirt
v2v_debug = force_on
version_required = "[virt-v2v-2.7.1-12,)"
checkpoint = "print_blkhash"
msg_content_yes = "nbdcopy.*--blkhash"
- log_libnbd_nbdcopy_version:
only libvirt
v2v_debug = force_on
version_required = "[virt-v2v-2.8.1-8,);[libnbd-1.22.2-2,)"
checkpoint = "log_libnbd_nbdcopy_version"
msg_content_yes = "(?:nbdcopy|libnbd)\s+[0-9]+(?:\.[0-9]+){1,2}(?:[-._][A-Za-z0-9~+]+)?"
- print_mountpoint_stats:
only libvirt
v2v_debug = force_on
version_required = "[virt-v2v-2.8.1-8,)"
checkpoint = "print_mountpoint_stats"
msg_content_yes = "mountpoint stats:\s*\n\s+Size\s+Used\s+Available\s+Use%$"
- char_slash:
only libvirt
version_required = "[virt-v2v-2.10.0-5,)"
checkpoint = "char_slash"
skip_vm_check = yes
Expand Down
17 changes: 5 additions & 12 deletions v2v/tests/src/function_test_esx.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def run(test, params, env):
src_uri_type = params.get('src_uri_type')
esxi_password = params.get('esxi_password')
os_pool = os_storage = params.get('output_storage', 'default')
os_version = params.get('os_version')
os_type = params.get('os_type')
# qemu-guest-agent path in virtio-win or rhv-guest-tools-iso
qa_path = params.get('qa_path')
Expand Down Expand Up @@ -168,13 +167,10 @@ def check_resume_swap(vmcheck):
"""
Check the content of grub files meet expectation.
"""
if os_version == 'rhel7':
chkfiles = [
'/etc/default/grub',
'/boot/grub2/grub.cfg',
'/etc/grub2.cfg']
if os_version == 'rhel6':
chkfiles = ['/boot/grub/grub.conf', '/etc/grub.conf']
chkfiles = [
'/etc/default/grub',
'/boot/grub2/grub.cfg',
'/etc/grub2.cfg']
for file_i in chkfiles:
status, content = vmcheck.run_cmd('cat %s' % file_i)
if status != 0:
Expand Down Expand Up @@ -255,10 +251,7 @@ def get_service_info():
Get qemu-guest-agent service info
"""
status_ptn = r'Active: active \((running|exited)\)|qemu-ga \(pid +[0-9]+\) is running'
if os_version == 'sles':
cmd = 'systemctl status qemu-guest-agent'
else:
cmd = 'service qemu-ga status;systemctl status qemu-guest-agent;systemctl status qemu-ga*'
cmd = 'service qemu-ga status;systemctl status qemu-guest-agent;systemctl status qemu-ga*'
_, output = vmcheck.run_cmd(cmd)
if not re.search(status_ptn, output):
return False
Expand Down