Beispiel #1
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if status_error:
         if checkpoint in ['running', 'paused']:
             check_v2v_log(output, 'not_shutdown')
         else:
             check_v2v_log(output, checkpoint)
     else:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 raise exceptions.TestFail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 raise exceptions.TestFail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         if checkpoint in ['multi_kernel', 'debug_kernel']:
             default_kernel = params.get('defaultkernel')
             check_boot_kernel(vmchecker.checker, default_kernel,
                               debug_kernel)
             if checkpoint == 'multi_kernel':
                 check_vmlinuz_initramfs(output)
         elif checkpoint == 'floppy':
             check_floppy_exist(vmchecker.checker)
         elif checkpoint == 'multi_disks':
             check_disks(vmchecker.checker)
         elif checkpoint == 'multi_netcards':
             check_multi_netcards(params['mac_address'],
                                  vmchecker.virsh_instance)
         elif checkpoint.startswith('spice'):
             vmchecker.check_graphics({'type': 'spice'})
             if checkpoint == 'spice_encrypt':
                 vmchecker.check_graphics(params[checkpoint])
         elif checkpoint.startswith('selinux'):
             status = vmchecker.checker.session.cmd(
                 'getenforce').strip().lower()
             logging.info('Selinux status after v2v:%s', status)
             if status != checkpoint[8:]:
                 log_fail('Selinux status not match')
         elif checkpoint == 'guest_firewalld_status':
             check_firewalld_status(vmchecker.checker, params[checkpoint])
         elif checkpoint in ['ntpd_on', 'sync_ntp']:
             check_time_keep(vmchecker.checker)
         check_v2v_log(output, checkpoint)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
         if len(error_list):
             log_fail('%d checkpoints failed: %s' %
                      (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if not utils_v2v.import_vm_to_ovirt(
                 params, address_cache, timeout=v2v_timeout):
             raise exceptions.TestFail('Import VM failed')
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
         if len(error_list):
             raise exceptions.TestFail(
                 '%d checkpoints failed: %s' % len(error_list), error_list)
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                             timeout=v2v_timeout):
             raise exceptions.TestFail('Import VM failed')
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
         if len(error_list):
             raise exceptions.TestFail('%d checkpoints failed: %s' %
                                       len(error_list), error_list)
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if skip_check:
         logging.info('Skip checking vm after conversion')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 test.fail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if params.get('skip_vm_check') != 'yes':
             if checkpoint != 'win2008r2_ostk':
                 ret = vmchecker.run()
                 if len(ret) == 0:
                     logging.info("All common checkpoints passed")
             if checkpoint == 'win2008r2_ostk':
                 check_BSOD()
             # Merge 2 error lists
             error_list.extend(vmchecker.errors)
        def vm_check():
            """
            Checking the VM
            """
            if output_mode == 'json' and not check_json_output(params):
                test.fail('check json output failed')
            if output_mode == 'local' and not check_local_output(params):
                test.fail('check local output failed')
            if output_mode in ['null', 'json', 'local']:
                return

            # Create vmchecker before virsh.start so that the vm can be undefined
            # if started failed.
            vmchecker = VMChecker(test, params, env)
            params['vmchecker'] = vmchecker
            if output_mode == 'rhev':
                if not utils_v2v.import_vm_to_ovirt(
                        params, address_cache, timeout=v2v_timeout):
                    test.fail('Import VM failed')
            if output_mode == 'libvirt':
                try:
                    virsh.start(vm_name, debug=True, ignore_status=False)
                except Exception as e:
                    test.fail('Start vm failed: %s' % str(e))
            # Check guest following the checkpoint document after convertion
            if params.get('skip_vm_check') != 'yes':
                if checkpoint != 'win2008r2_ostk':
                    ret = vmchecker.run()
                    if len(ret) == 0:
                        logging.info("All common checkpoints passed")
                if checkpoint == 'win2008r2_ostk':
                    check_BSOD()
                # Merge 2 error lists
                error_list.extend(vmchecker.errors)
Beispiel #6
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if skip_check:
         logging.info('Skip checking vm after conversion')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 test.fail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if params.get('skip_vm_check') != 'yes':
             if checkpoint != 'win2008r2_ostk':
                 ret = vmchecker.run()
                 if len(ret) == 0:
                     logging.info("All common checkpoints passed")
             if checkpoint == 'win2008r2_ostk':
                 check_BSOD()
             # Merge 2 error lists
             error_list.extend(vmchecker.errors)
Beispiel #7
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout_text + result.stderr_text
     if checkpoint == 'empty_cdrom':
         if status_error:
             log_fail('Virsh dumpxml failed for empty cdrom image')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             virsh.start(vm_name, debug=True)
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if skip_vm_check != 'yes':
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         else:
             logging.info(
                 'Skip checking vm after conversion: %s' %
                 skip_reason)
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
             virsh_session.close()
         if checkpoint.startswith('vmtools'):
             check_vmtools(vmchecker.checker, checkpoint)
         if checkpoint == 'modprobe':
             check_modprobe(vmchecker.checker)
         if checkpoint == 'device_map':
             check_device_map(vmchecker.checker)
         if checkpoint == 'resume_swap':
             check_resume_swap(vmchecker.checker)
         if checkpoint == 'rhev_file':
             check_rhev_file_exist(vmchecker.checker)
         if checkpoint == 'file_architecture':
             check_file_architecture(vmchecker.checker)
         if checkpoint == 'ogac':
             check_ogac(vmchecker.checker)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout_text + result.stderr_text
     if not status_error and checkpoint != 'vdsm':
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception as e:
                 test.fail('Start vm failed: %s', str(e))
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         if params.get('skip_vm_check') != 'yes':
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         else:
             logging.info(
                 'Skip checking vm after conversion: %s' %
                 skip_reason)
         # Check specific checkpoints
         if checkpoint == 'console_xvc0':
             check_grub_file(vmchecker.checker, 'console_xvc0')
         if checkpoint in ('vnc_autoport', 'vnc_encrypt'):
             vmchecker.check_graphics(params[checkpoint])
         if checkpoint == 'sdl':
             if output_mode == 'libvirt':
                 vmchecker.check_graphics({'type': 'vnc'})
             elif output_mode == 'rhev':
                 vmchecker.check_graphics({'type': 'spice'})
         if checkpoint == 'pv_with_regular_kernel':
             check_kernel(vmchecker.checker)
         if checkpoint in ['sound', 'pcspk']:
             check_sound_card(vmchecker.checker, checkpoint)
         if checkpoint == 'multidisk':
             check_disk(vmchecker.checker, params['disk_count'])
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     # Merge 2 error lists
     if params.get('vmchecker'):
         error_list.extend(params['vmchecker'].errors)
     if len(error_list):
         test.fail(
             '%d checkpoints failed: %s' %
             (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                             timeout=v2v_timeout):
             raise exceptions.TestFail('Import VM failed')
         if checkpoint:
             if checkpoint == 'cdrom':
                 virsh_session = utils_sasl.VirshSessionSASL(params)
                 virsh_session_id = virsh_session.get_id()
                 check_device_exist('cdrom', virsh_session_id)
Beispiel #10
0
def run(test, params, env):
    """
    Test convert vm to ovirt
    """
    args_dict = get_args_dict(params)
    hypervisor = args_dict.get('hypervisor')
    xen_ip = args_dict.get('xen_ip')
    xen_pwd = args_dict.get('xen_pwd')
    remote_node_user = args_dict.get('remote_node_user', 'root')
    vpx_pwd = args_dict.get('vpx_pwd')
    vpx_pwd_file = args_dict.get('vpx_pwd_file')
    address_cache = env.get('address_cache')
    if hypervisor == 'xen':
        # Set up ssh access using ssh-agent and authorized_keys
        ssh_key.setup_ssh_key(xen_ip,
                              user=remote_node_user,
                              port=22,
                              password=xen_pwd)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except:
            utils.run("ssh-agent -k")
            raise error.TestError("Failed to start 'ssh-agent'")

    if hypervisor == 'esx':
        fp = open(vpx_pwd_file, 'w')
        fp.write(vpx_pwd)
        fp.close()

    try:
        # Set libguestfs environment variable
        os.environ['LIBGUESTFS_BACKEND'] = 'direct'

        # Run virt-v2v command
        ret = utils_v2v.v2v_cmd(args_dict)
        logging.debug("virt-v2v verbose messages:\n%s", ret)
        if ret.exit_status != 0:
            raise error.TestFail("Convert VM failed")

        # Import the VM to oVirt Data Center from export domain
        if not utils_v2v.import_vm_to_ovirt(params, address_cache):
            raise error.TestFail("Import VM failed")
    finally:
        if hypervisor == "xen":
            utils.run("ssh-agent -k")
        if hypervisor == "esx":
            utils.run("rm -rf %s" % vpx_pwd_file)
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if checkpoint == 'empty_cdrom':
         if status_error:
             log_fail('Virsh dumpxml failed for empty cdrom image')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             virsh.start(vm_name)
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if checkpoint not in ['GPO_AV', 'ovmf']:
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
         if checkpoint == 'vmtools':
             check_vmtools(vmchecker.checker)
         if checkpoint == 'modprobe':
             check_modprobe(vmchecker.checker)
         if checkpoint == 'device_map':
             check_device_map(vmchecker.checker)
         if checkpoint == 'snapshot':
             check_snapshot_file(vmchecker.checker)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if checkpoint == 'empty_cdrom':
         if status_error:
             log_fail('Virsh dumpxml failed for empty cdrom image')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             virsh.start(vm_name, debug=True)
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if checkpoint not in ['GPO_AV', 'ovmf']:
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
         if checkpoint.startswith('vmtools'):
             check_vmtools(vmchecker.checker, checkpoint)
         if checkpoint == 'modprobe':
             check_modprobe(vmchecker.checker)
         if checkpoint == 'device_map':
             check_device_map(vmchecker.checker)
         if checkpoint == 'resume_swap':
             check_resume_swap(vmchecker.checker)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if checkpoint == 'empty_cdrom':
         if status_error:
             log_fail('Virsh dumpxml failed for empty cdrom image')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 raise exceptions.TestFail('Import VM failed')
         elif output_mode == 'libvirt':
             virsh.start(vm_name)
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if checkpoint not in ['GPO_AV', 'ovmf']:
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
         if checkpoint == 'vmtools':
             check_vmtools(vmchecker.checker)
         if checkpoint == 'GPO_AV':
             msg_list = [
                 'virt-v2v: warning: this guest has Windows Group Policy Objects',
                 'virt-v2v: warning: this guest has Anti-Virus \(AV\) software'
             ]
             for msg in msg_list:
                 if not utils_v2v.check_log(output, [msg]):
                     log_fail('Not found error message:"%s"' % msg)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     check_v2v_log(output, checkpoint)
     if len(error_list):
         raise exceptions.TestFail('%d checkpoints failed: %s' %
                                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error and checkpoint != 'vdsm':
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 test.fail('Start vm failed: %s', str(e))
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'rhev_file':
             check_rhev_file_exist(vmchecker.checker)
         if checkpoint == 'console_xvc0':
             check_grub_file(vmchecker.checker, 'console_xvc0')
         if checkpoint in ('vnc_autoport', 'vnc_encrypt'):
             vmchecker.check_graphics(params[checkpoint])
         if checkpoint == 'sdl':
             if output_mode == 'libvirt':
                 vmchecker.check_graphics({'type': 'vnc'})
             elif output_mode == 'rhev':
                 vmchecker.check_graphics({'type': 'spice'})
         if checkpoint == 'pv_with_regular_kernel':
             check_kernel(vmchecker.checker)
         if checkpoint in ['sound', 'pcspk']:
             check_sound_card(vmchecker.checker, checkpoint)
         if checkpoint == 'rhsrvany_md5':
             check_rhsrvany_md5(vmchecker.checker)
         if checkpoint == 'multidisk':
             check_disk(vmchecker.checker, params['disk_count'])
Beispiel #15
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error and checkpoint != 'vdsm':
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 test.fail('Start vm failed: %s', str(e))
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'rhev_file':
             check_rhev_file_exist(vmchecker.checker)
         if checkpoint == 'console_xvc0':
             check_grub_file(vmchecker.checker, 'console_xvc0')
         if checkpoint in ('vnc_autoport', 'vnc_encrypt'):
             vmchecker.check_graphics(params[checkpoint])
         if checkpoint == 'sdl':
             if output_mode == 'libvirt':
                 vmchecker.check_graphics({'type': 'vnc'})
             elif output_mode == 'rhev':
                 vmchecker.check_graphics({'type': 'spice'})
         if checkpoint == 'pv_with_regular_kernel':
             check_kernel(vmchecker.checker)
         if checkpoint in ['sound', 'pcspk']:
             check_sound_card(vmchecker.checker, checkpoint)
         if checkpoint == 'rhsrvany_md5':
             check_rhsrvany_md5(vmchecker.checker)
         if checkpoint == 'multidisk':
             check_disk(vmchecker.checker, params['disk_count'])
Beispiel #16
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if status_error:
         if checkpoint in ['running', 'paused']:
             check_v2v_log(output, 'not_shutdown')
         else:
             check_v2v_log(output, checkpoint)
     else:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 raise exceptions.TestFail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 raise exceptions.TestFail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if ret == 0:
             logging.info("All checkpoints passed")
         else:
             raise exceptions.TestFail("%s checkpoints failed" % ret)
         if checkpoint in ['multi_kernel', 'debug_kernel']:
             default_kernel = params.get('defaultkernel')
             check_boot_kernel(default_kernel, debug_kernel)
             if checkpoint == 'multi_kernel':
                 check_vmlinuz_initramfs(output)
         elif checkpoint == 'floppy':
             check_floppy_exist()
         elif checkpoint == 'multi_disks':
             check_disks()
         elif checkpoint == 'multi_netcards':
             check_multi_netcards(params['mac_address'],
                                  vmchecker.virsh_session_id)
         check_v2v_log(output, checkpoint)
Beispiel #17
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 raise exceptions.TestFail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 raise exceptions.TestFail('Start vm failed: %s', str(e))
         if checkpoint:
             if checkpoint == 'rhev_file':
                 check_rhev_file_exist()
             elif checkpoint == 'console_xvc0':
                 check_grub_file('console_xvc0')
             check_v2v_log(output, checkpoint)
Beispiel #18
0
 def check_result(cmd, result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if output_mode == "rhev":
             ovf = get_ovf_content(output)
             logging.debug("ovf content: %s", ovf)
             if '--vmtype' in cmd:
                 expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                 check_vmtype(ovf, expected_vmtype)
         if '-oa' in cmd and '--no-copy' not in cmd:
             expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "allocation", expected_mode)
         if '-of' in cmd and '--no-copy' not in cmd:
             expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "format", expected_format)
         if '-on' in cmd:
             expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
             check_new_name(output, expected_name)
         if '--no-copy' in cmd:
             check_nocopy(output)
         if '-oc' in cmd:
             expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
             check_connection(output, expected_uri)
         if output_mode == "rhev":
             if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                 raise error.TestFail("Import VM failed")
             else:
                 params['vmcheck'] = utils_v2v.VMCheck(test, params, env)
                 if attach_disks:
                     check_disks(params.get("ori_disks"))
         if output_mode == "libvirt":
             if "qemu:///session" not in v2v_options:
                 virsh.start(vm_name, debug=True, ignore_status=False)
Beispiel #19
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 raise exceptions.TestFail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 raise exceptions.TestFail('Start vm failed: %s', str(e))
         if checkpoint:
             if checkpoint == 'rhev_file':
                 check_rhev_file_exist()
             elif checkpoint == 'console_xvc0':
                 check_grub_file('console_xvc0')
             check_v2v_log(output, checkpoint)
Beispiel #20
0
 def check_result(cmd, result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error:
         if output_mode == "rhev":
             ovf = get_ovf_content(output)
             logging.debug("ovf content: %s", ovf)
             if '--vmtype' in cmd:
                 expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                 check_vmtype(ovf, expected_vmtype)
         if '-oa' in cmd and '--no-copy' not in cmd:
             expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "allocation", expected_mode)
         if '-of' in cmd and '--no-copy' not in cmd:
             expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "format", expected_format)
         if '-on' in cmd:
             expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
             check_new_name(output, expected_name)
         if '--no-copy' in cmd:
             check_nocopy(output)
         if '-oc' in cmd:
             expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
             check_connection(output, expected_uri)
         if output_mode == "rhev":
             if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                 raise error.TestFail("Import VM failed")
             else:
                 params['vmcheck'] = utils_v2v.VMCheck(test, params, env)
                 if attach_disks:
                     check_disks(params.get("ori_disks"))
         if output_mode == "libvirt":
             if "qemu:///session" not in v2v_options:
                 virsh.start(vm_name, debug=True, ignore_status=False)
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout_text + result.stderr_text
     if not status_error:
         # Create vmchecker before virsh.start so that the vm can be undefined
         # if started failed.
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception as e:
                 test.fail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         if params.get('skip_vm_check') != 'yes':
             if checkpoint != 'win2008r2_ostk':
                 ret = vmchecker.run()
                 if len(ret) == 0:
                     logging.info("All common checkpoints passed")
             if checkpoint == 'win2008r2_ostk':
                 check_BSOD()
             # Merge 2 error lists
             error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
def run(test, params, env):
    """
    Convert a remote vm to remote ovirt node.
    """
    for v in list(params.values()):
        if "V2V_EXAMPLE" in v:
            test.cancel("Please set real value for %s" % v)

    vm_name = params.get("main_vm")
    target = params.get("target")
    hypervisor = params.get("hypervisor")
    input_mode = params.get("input_mode")
    storage = params.get('storage')
    storage_name = params.get('storage_name')
    network = params.get('network')
    bridge = params.get('bridge')
    source_user = params.get("username", "root")
    xen_ip = params.get("xen_hostname")
    xen_pwd = params.get("xen_pwd")
    vpx_ip = params.get("vpx_hostname")
    vpx_pwd = params.get("vpx_pwd")
    vpx_passwd_file = params.get("vpx_passwd_file")
    vpx_dc = params.get("vpx_dc")
    esx_ip = params.get("esx_hostname")
    address_cache = env.get('address_cache')
    v2v_opts = params.get("v2v_opts")
    v2v_timeout = int(params.get('v2v_timeout', 1200))
    # for construct rhv-upload option in v2v cmd
    output_method = params.get("output_method")
    rhv_upload_opts = params.get("rhv_upload_opts")
    # for get ca.crt file from ovirt engine
    rhv_passwd = params.get("rhv_upload_passwd")
    rhv_passwd_file = params.get("rhv_upload_passwd_file")
    ovirt_engine_passwd = params.get("ovirt_engine_password")
    ovirt_hostname = params.get("ovirt_engine_url").split('/')[2]
    ovirt_ca_file_path = params.get("ovirt_ca_file_path")
    local_ca_file_path = params.get("local_ca_file_path")

    # create different sasl_user name for different job
    params.update({
        'sasl_user':
        params.get("sasl_user") + utils_misc.generate_random_string(3)
    })
    logging.info('sals user name is %s' % params.get("sasl_user"))

    # Prepare step for different hypervisor
    if hypervisor == "esx":
        source_ip = vpx_ip
        source_pwd = vpx_pwd
        # Create password file to access ESX hypervisor
        with open(vpx_passwd_file, 'w') as f:
            f.write(vpx_pwd)
    elif hypervisor == "xen":
        source_ip = xen_ip
        source_pwd = xen_pwd
        # Set up ssh access using ssh-agent and authorized_keys
        ssh_key.setup_ssh_key(source_ip, source_user, source_pwd)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except:
            process.run("ssh-agent -k")
            test.error("Fail to setup ssh-agent")
    elif hypervisor == "kvm":
        source_ip = None
        source_pwd = None
    else:
        test.cancel("Unspported hypervisor: %s" % hypervisor)

    if output_method == 'rhv_upload':
        # Create password file for '-o rhv_upload' to connect to ovirt
        with open(rhv_passwd_file, 'w') as f:
            f.write(rhv_passwd)
        # Copy ca file from ovirt to local
        remote.scp_from_remote(ovirt_hostname, 22, 'root', ovirt_engine_passwd,
                               ovirt_ca_file_path, local_ca_file_path)

    # Create libvirt URI
    v2v_uri = utils_v2v.Uri(hypervisor)
    remote_uri = v2v_uri.get_uri(source_ip, vpx_dc, esx_ip)
    logging.debug("libvirt URI for converting: %s", remote_uri)

    # Make sure the VM exist before convert
    v2v_virsh = None
    close_virsh = False
    if hypervisor == 'kvm':
        v2v_virsh = virsh
    else:
        virsh_dargs = {
            'uri': remote_uri,
            'remote_ip': source_ip,
            'remote_user': source_user,
            'remote_pwd': source_pwd,
            'debug': True
        }
        v2v_virsh = virsh.VirshPersistent(**virsh_dargs)
        close_virsh = True
    try:
        if not v2v_virsh.domain_exists(vm_name):
            test.error("VM '%s' not exist" % vm_name)
    finally:
        if close_virsh:
            v2v_virsh.close_session()

    # Create SASL user on the ovirt host
    user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
                                   params.get("sasl_pwd"))
    v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
    v2v_sasl.server_ip = params.get("remote_ip")
    v2v_sasl.server_user = params.get('remote_user')
    v2v_sasl.server_pwd = params.get('remote_pwd')
    v2v_sasl.setup(remote=True)

    # Maintain a single params for v2v to avoid duplicate parameters
    v2v_params = {
        'target': target,
        'hypervisor': hypervisor,
        'main_vm': vm_name,
        'input_mode': input_mode,
        'network': network,
        'bridge': bridge,
        'storage': storage,
        'hostname': source_ip,
        'new_name': vm_name + utils_misc.generate_random_string(3),
        'output_method': output_method,
        'storage_name': storage_name
    }
    if vpx_dc:
        v2v_params.update({"vpx_dc": vpx_dc})
    if esx_ip:
        v2v_params.update({"esx_ip": esx_ip})
    if v2v_opts:
        v2v_params.update({"v2v_opts": v2v_opts})
    if rhv_upload_opts:
        v2v_params.update({"rhv_upload_opts": rhv_upload_opts})
    output_format = params.get('output_format')
    # output_format will be set to 'raw' in utils_v2v.v2v_cmd if it's None
    if output_format:
        v2v_params.update({'output_format': output_format})

    # Set libguestfs environment variable
    if hypervisor in ('xen', 'kvm'):
        os.environ['LIBGUESTFS_BACKEND'] = 'direct'
    try:
        # Execute virt-v2v command
        v2v_ret = utils_v2v.v2v_cmd(v2v_params)
        logging.debug("virt-v2v verbose messages:\n%s", v2v_ret)
        if v2v_ret.exit_status != 0:
            test.fail("Convert VM failed")

        params['main_vm'] = v2v_params['new_name']

        logging.info("output_method is %s" % output_method)
        # Import the VM to oVirt Data Center from export domain, and start it
        if not utils_v2v.import_vm_to_ovirt(
                params, address_cache, timeout=v2v_timeout):
            test.error("Import VM failed")

        # Check all checkpoints after convert
        vmchecker = VMChecker(test, params, env)
        ret = vmchecker.run()

        # Other checks
        err_list = []
        os_list = [
            'win8', 'win8.1', 'win10', 'win2012', 'win2012r2', 'win2008'
        ]
        win_version = ['6.2', '6.3', '10.0', '6.2', '6.3']
        os_map = dict(list(zip(os_list, win_version)))
        vm_arch = params.get('vm_arch')
        os_ver = params.get('os_version')

        if os_ver in os_list:
            vga_log = 'The guest will be configured to use a basic VGA ' \
                      'display driver'
            if re.search(vga_log, v2v_ret.stdout):
                logging.debug('Found vga log')
            else:
                err_list.append('Not find vga log')
            if os_ver != 'win2008':
                qxl_warn = 'virt-v2v: warning: there is no QXL driver for ' \
                           'this version of Windows \(%s[.\s]*?%s\)' %\
                           (os_map[os_ver], vm_arch)
                if re.search(qxl_warn, v2v_ret.stdout):
                    logging.debug('Found QXL warning')
                else:
                    err_list.append('Not find QXL warning')

        ret.extend(err_list)

        if len(ret) == 0:
            logging.info("All checkpoints passed")
        else:
            test.fail("%d checkpoints failed: %s" % (len(ret), ret))
    finally:
        vmcheck = utils_v2v.VMCheck(test, params, env)
        vmcheck.cleanup()
        if v2v_sasl:
            v2v_sasl.cleanup()
        if hypervisor == "xen":
            process.run("ssh-agent -k")
        # Cleanup constant files
        utils_v2v.cleanup_constant_files(params)
Beispiel #23
0
    def check_result(cmd, result, status_error):
        """
        Check virt-v2v command result
        """
        utils_v2v.check_exit_status(result, status_error, error_flag)
        output = to_text(result.stdout + result.stderr, errors=error_flag)
        output_stdout = to_text(result.stdout, errors=error_flag)
        if status_error:
            if checkpoint == 'length_of_error':
                log_lines = output.split('\n')
                v2v_start = False
                for line in log_lines:
                    if line.startswith('virt-v2v:'):
                        v2v_start = True
                    if line.startswith('libvirt:'):
                        v2v_start = False
                    if v2v_start and len(line) > 72:
                        test.fail('Error log longer than 72 charactors: %s' %
                                  line)
            if checkpoint == 'disk_not_exist':
                vol_list = virsh.vol_list(pool_name)
                logging.info(vol_list)
                if vm_name in vol_list.stdout:
                    test.fail('Disk exists for vm %s' % vm_name)
        else:
            if output_mode == "rhev" and checkpoint != 'quiet':
                ovf = get_ovf_content(output)
                logging.debug("ovf content: %s", ovf)
                check_ovf_snapshot_id(ovf)
                if '--vmtype' in cmd:
                    expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                    check_vmtype(ovf, expected_vmtype)
            if '-oa' in cmd and '--no-copy' not in cmd:
                expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
                img_path = get_img_path(output)

                def check_alloc():
                    try:
                        check_image(img_path, "allocation", expected_mode)
                        return True
                    except exceptions.TestFail:
                        pass

                if not utils_misc.wait_for(check_alloc, timeout=600,
                                           step=10.0):
                    test.fail('Allocation check failed.')
            if '-of' in cmd and '--no-copy' not in cmd and '--print-source' not in cmd and checkpoint != 'quiet':
                expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
                img_path = get_img_path(output)
                check_image(img_path, "format", expected_format)
            if '-on' in cmd:
                expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
                check_new_name(output, expected_name)
            if '--no-copy' in cmd:
                check_nocopy(output)
            if '-oc' in cmd:
                expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
                check_connection(output, expected_uri)
            if output_mode == "rhev":
                if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                    test.fail("Import VM failed")
                else:
                    params['vmcheck_flag'] = True
            if output_mode == "libvirt":
                if "qemu:///session" not in v2v_options and not no_root:
                    virsh.start(vm_name, debug=True, ignore_status=False)
            if checkpoint == ['vmx', 'vmx_ssh']:
                vmchecker = VMChecker(test, params, env)
                params['vmchecker'] = vmchecker
                params['vmcheck_flag'] = True
                ret = vmchecker.run()
                if len(ret) == 0:
                    logging.info("All common checkpoints passed")
            if checkpoint == 'quiet':
                if len(output.strip().splitlines()) > 10:
                    test.fail('Output is not empty in quiet mode')
            if checkpoint == 'dependency':
                if 'libguestfs-winsupport' not in output:
                    test.fail('libguestfs-winsupport not in dependency')
                if all(pkg_pattern not in output
                       for pkg_pattern in ['VMF', 'edk2-ovmf']):
                    test.fail('OVMF/AAVMF not in dependency')
                if 'qemu-kvm-rhev' in output:
                    test.fail('qemu-kvm-rhev is in dependency')
                if 'libX11' in output:
                    test.fail('libX11 is in dependency')
                if 'kernel-rt' in output:
                    test.fail('kernel-rt is in dependency')
                win_img = params.get('win_image')
                command = 'guestfish -a %s -i'
                if process.run(command % win_img,
                               ignore_status=True).exit_status == 0:
                    test.fail('Command "%s" success' % command % win_img)
            if checkpoint == 'no_dcpath':
                if '--dcpath' in output:
                    test.fail('"--dcpath" is not removed')
            if checkpoint == 'debug_overlays':
                search = re.search('Overlay saved as(.*)', output)
                if not search:
                    test.fail('Not find log of saving overlays')
                overlay_path = search.group(1).strip()
                logging.debug('Overlay file location: %s' % overlay_path)
                if os.path.isfile(overlay_path):
                    logging.info('Found overlay file: %s' % overlay_path)
                else:
                    test.fail('Overlay file not saved')
            if checkpoint.startswith('empty_nic_source'):
                target_str = '%s "eth0" mac: %s' % (params[checkpoint][0],
                                                    params[checkpoint][1])
                logging.info('Expect log: %s', target_str)
                if target_str not in output_stdout.lower():
                    test.fail('Expect log not found: %s' % target_str)
            if checkpoint == 'print_source':
                check_source(output_stdout)
            if checkpoint == 'machine_readable':
                if os.path.exists(params.get('example_file', '')):
                    # Checking items in example_file exist in latest
                    # output regardless of the orders and new items.
                    with open(params['example_file']) as f:
                        for line in f:
                            if line.strip() not in output_stdout.strip():
                                test.fail(
                                    '%s not in --machine-readable output' %
                                    line.strip())
                else:
                    test.error('No content to compare with')
            if checkpoint == 'compress':
                img_path = get_img_path(output)
                logging.info('Image path: %s', img_path)

                qemu_img_cmd = 'qemu-img check %s' % img_path
                qemu_img_locking_feature_support = libvirt_storage.check_qemu_image_lock_support(
                )
                if qemu_img_locking_feature_support:
                    qemu_img_cmd = 'qemu-img check %s -U' % img_path

                disk_check = process.run(qemu_img_cmd).stdout_text
                logging.info(disk_check)
                compress_info = disk_check.split(',')[-1].split('%')[0].strip()
                compress_rate = float(compress_info)
                logging.info('%s%% compressed', compress_rate)
                if compress_rate < 0.1:
                    test.fail('Disk image NOT compressed')
            if checkpoint == 'tail_log':
                messages = params['tail'].get_output()
                logging.info('Content of /var/log/messages during conversion:')
                logging.info(messages)
                msg_content = params['msg_content']
                if msg_content in messages:
                    test.fail('Found "%s" in /var/log/messages' % msg_content)
        log_check = utils_v2v.check_log(params, output)
        if log_check:
            test.fail(log_check)
        check_man_page(params.get('in_man'), params.get('not_in_man'))
 def check_result(cmd, result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if status_error:
         if checkpoint == 'length_of_error':
             log_lines = output.split('\n')
             v2v_start = False
             for line in log_lines:
                 if line.startswith('virt-v2v:'):
                     v2v_start = True
                 if line.startswith('libvirt:'):
                     v2v_start = False
                 if v2v_start and line > 72:
                     raise exceptions.TestFail('Error log longer than 72 '
                                               'charactors: %s', line)
         else:
             error_map = {
                 'conflict_options': ['option used more than once'],
                 'xen_no_output_format': ['The input metadata did not define'
                                          ' the disk format']
             }
             if not utils_v2v.check_log(output, error_map[checkpoint]):
                 raise exceptions.TestFail('Not found error message %s' %
                                           error_map[checkpoint])
     else:
         if output_mode == "rhev" and checkpoint != 'quiet':
             ovf = get_ovf_content(output)
             logging.debug("ovf content: %s", ovf)
             if '--vmtype' in cmd:
                 expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                 check_vmtype(ovf, expected_vmtype)
         if '-oa' in cmd and '--no-copy' not in cmd:
             expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "allocation", expected_mode)
         if '-of' in cmd and '--no-copy' not in cmd and checkpoint != 'quiet':
             expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
             img_path = get_img_path(output)
             check_image(img_path, "format", expected_format)
         if '-on' in cmd:
             expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
             check_new_name(output, expected_name)
         if '--no-copy' in cmd:
             check_nocopy(output)
         if '-oc' in cmd:
             expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
             check_connection(output, expected_uri)
         if output_mode == "rhev":
             if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                 raise exceptions.TestFail("Import VM failed")
             else:
                 params['vmcheck_flag'] = True
         if output_mode == "libvirt":
             if "qemu:///session" not in v2v_options:
                 virsh.start(vm_name, debug=True, ignore_status=False)
         if checkpoint == 'quiet':
             if len(output.strip()) != 0:
                 raise exceptions.TestFail('Output is not empty in quiet mode')
Beispiel #25
0
    def check_result(cmd, result, status_error):
        """
        Check virt-v2v command result
        """
        utlv.check_exit_status(result, status_error)
        output = result.stdout + result.stderr
        if status_error:
            if checkpoint == 'length_of_error':
                log_lines = output.split('\n')
                v2v_start = False
                for line in log_lines:
                    if line.startswith('virt-v2v:'):
                        v2v_start = True
                    if line.startswith('libvirt:'):
                        v2v_start = False
                    if v2v_start and len(line) > 72:
                        test.fail('Error log longer than 72 charactors: %s' %
                                  line)
            if checkpoint == 'disk_not_exist':
                vol_list = virsh.vol_list(pool_name)
                logging.info(vol_list)
                if vm_name in vol_list.stdout:
                    test.fail('Disk exists for vm %s' % vm_name)
        else:
            if output_mode == "rhev" and checkpoint != 'quiet':
                ovf = get_ovf_content(output)
                logging.debug("ovf content: %s", ovf)
                check_ovf_snapshot_id(ovf)
                if '--vmtype' in cmd:
                    expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                    check_vmtype(ovf, expected_vmtype)
            if '-oa' in cmd and '--no-copy' not in cmd:
                expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
                img_path = get_img_path(output)

                def check_alloc():
                    try:
                        check_image(img_path, "allocation", expected_mode)
                        return True
                    except exceptions.TestFail:
                        pass
                if not utils_misc.wait_for(check_alloc, timeout=600, step=10.0):
                    test.fail('Allocation check failed.')
            if '-of' in cmd and '--no-copy' not in cmd and checkpoint != 'quiet':
                expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
                img_path = get_img_path(output)
                check_image(img_path, "format", expected_format)
            if '-on' in cmd:
                expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
                check_new_name(output, expected_name)
            if '--no-copy' in cmd:
                check_nocopy(output)
            if '-oc' in cmd:
                expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
                check_connection(output, expected_uri)
            if output_mode == "rhev":
                if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                    test.fail("Import VM failed")
                else:
                    params['vmcheck_flag'] = True
            if output_mode == "libvirt":
                if "qemu:///session" not in v2v_options and not no_root:
                    virsh.start(vm_name, debug=True, ignore_status=False)
            if checkpoint == 'vmx':
                vmchecker = VMChecker(test, params, env)
                params['vmchecker'] = vmchecker
                params['vmcheck_flag'] = True
                ret = vmchecker.run()
                if len(ret) == 0:
                    logging.info("All common checkpoints passed")
            if checkpoint == 'quiet':
                if len(output.strip()) != 0:
                    test.fail('Output is not empty in quiet mode')
            if checkpoint == 'dependency':
                if 'libguestfs-winsupport' not in output:
                    test.fail('libguestfs-winsupport not in dependency')
                if 'VMF' not in output:
                    test.fail('OVMF/AAVMF not in dependency')
                if 'qemu-kvm-rhev' in output:
                    test.fail('qemu-kvm-rhev is in dependency')
                if 'libX11' in output:
                    test.fail('libX11 is in dependency')
                win_img = params.get('win_image')
                command = 'guestfish -a %s -i'
                if process.run(command % win_img, ignore_status=True).exit_status == 0:
                    test.fail('Command "%s" success' % command % win_img)
            if checkpoint == 'no_dcpath':
                if '--dcpath' in output:
                    test.fail('"--dcpath" is not removed')
            if checkpoint == 'debug_overlays':
                search = re.search('Overlay saved as(.*)', output)
                if not search:
                    test.fail('Not find log of saving overlays')
                overlay_path = search.group(1).strip()
                logging.debug('Overlay file location: %s' % overlay_path)
                if os.path.isfile(overlay_path):
                    logging.info('Found overlay file: %s' % overlay_path)
                else:
                    test.fail('Overlay file not saved')
            if checkpoint.startswith('empty_nic_source'):
                target_str = '%s "eth0" mac: %s' % (params[checkpoint][0], params[checkpoint][1])
                logging.info('Expect log: %s', target_str)
                if target_str not in result.stdout.lower():
                    test.fail('Expect log not found: %s' % target_str)
            if checkpoint == 'print_source':
                check_source(result.stdout)
            if checkpoint == 'machine_readable':
                if os.path.exists(params.get('example_file', '')):
                    expect_output = open(params['example_file']).read().strip()
                    logging.debug(expect_output)
                    if expect_output != result.stdout.strip():
                        test.fail('machine readable content not correct')
                else:
                    test.error('No content to compare with')
            if checkpoint == 'compress':
                img_path = get_img_path(output)
                logging.info('Image path: %s', img_path)
                disk_check = process.run('qemu-img check %s' % img_path).stdout
                logging.info(disk_check)
                compress_info = disk_check.split(',')[-1].split('%')[0].strip()
                compress_rate = float(compress_info)
                logging.info('%s%% compressed', compress_rate)
                if compress_rate < 0.1:
                    test.fail('Disk image NOT compressed')
            if checkpoint == 'tail_log':
                messages = params['tail'].get_output()
                logging.info('Content of /var/log/messages during conversion:')
                logging.info(messages)
                msg_content = params['msg_content']
                if msg_content in messages:
                    test.fail('Found "%s" in /var/log/messages' % msg_content)
        log_check = utils_v2v.check_log(params, output)
        if log_check:
            test.fail(log_check)
        check_man_page(params.get('in_man'), params.get('not_in_man'))
Beispiel #26
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if skip_check:
         logging.info('Skip checking vm after conversion')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception as e:
                 test.fail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if params.get('skip_check') != 'yes':
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(
             vm_name, virsh_instance=vmchecker.virsh_instance)
         logging.debug(vmxml)
         if checkpoint == 'multi_kernel':
             check_boot_kernel(vmchecker.checker)
         if checkpoint == 'floppy':
             check_floppy_exist(vmchecker.checker)
         if checkpoint == 'multi_disks':
             check_disks(vmchecker.checker)
         if checkpoint == 'multi_netcards':
             check_multi_netcards(params['mac_address'],
                                  vmchecker.virsh_instance)
         if checkpoint.startswith(('spice', 'vnc')):
             if checkpoint == 'spice_encrypt':
                 vmchecker.check_graphics(params[checkpoint])
             else:
                 graph_type = checkpoint.split('_')[0]
                 vmchecker.check_graphics({'type': graph_type})
                 video_type = vmxml.get_devices('video')[0].model_type
                 if video_type.lower() != 'qxl':
                     log_fail('Video expect QXL, actual %s' % video_type)
         if checkpoint.startswith('listen'):
             listen_type = vmxml.get_devices('graphics')[0].listen_type
             logging.info('listen type is: %s', listen_type)
             if listen_type != checkpoint.split('_')[-1]:
                 log_fail('listen type changed after conversion')
         if checkpoint.startswith('selinux'):
             status = vmchecker.checker.session.cmd(
                 'getenforce').strip().lower()
             logging.info('Selinux status after v2v:%s', status)
             if status != checkpoint[8:]:
                 log_fail('Selinux status not match')
         if checkpoint == 'guest_firewalld_status':
             check_firewalld_status(vmchecker.checker, params[checkpoint])
         if checkpoint in ['ntpd_on', 'sync_ntp']:
             check_time_keep(vmchecker.checker)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
def run(test, params, env):
    """
    Convert a remote vm to remote ovirt node.
    """
    for v in params.itervalues():
        if "V2V_EXAMPLE" in v:
            raise exceptions.TestSkipError("Please set real value for %s" % v)

    vm_name = params.get("main_vm")
    target = params.get("target")
    hypervisor = params.get("hypervisor")
    input_mode = params.get("input_mode")
    storage = params.get('storage')
    network = params.get('network')
    bridge = params.get('bridge')
    source_user = params.get("username", "root")
    xen_ip = params.get("xen_ip")
    xen_pwd = params.get("xen_pwd")
    vpx_ip = params.get("vpx_ip")
    vpx_pwd = params.get("vpx_pwd")
    vpx_pwd_file = params.get("vpx_pwd_file")
    vpx_dc = params.get("vpx_dc")
    esx_ip = params.get("esx_ip")
    address_cache = env.get('address_cache')
    v2v_opts = params.get("v2v_opts")
    v2v_timeout = int(params.get('v2v_timeout', 1200))

    # Prepare step for different hypervisor
    if hypervisor == "esx":
        source_ip = vpx_ip
        source_pwd = vpx_pwd
        # Create password file to access ESX hypervisor
        with open(vpx_pwd_file, 'w') as f:
            f.write(vpx_pwd)
    elif hypervisor == "xen":
        source_ip = xen_ip
        source_pwd = xen_pwd
        # Set up ssh access using ssh-agent and authorized_keys
        ssh_key.setup_ssh_key(source_ip, source_user, source_pwd)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except:
            process.run("ssh-agent -k")
            raise exceptions.TestError("Fail to setup ssh-agent")
    elif hypervisor == "kvm":
        source_ip = None
        source_pwd = None
    else:
        raise exceptions.TestSkipError("Unspported hypervisor: %s" % hypervisor)

    # Create libvirt URI
    v2v_uri = utils_v2v.Uri(hypervisor)
    remote_uri = v2v_uri.get_uri(source_ip, vpx_dc, esx_ip)
    logging.debug("libvirt URI for converting: %s", remote_uri)

    # Make sure the VM exist before convert
    v2v_virsh = None
    close_virsh = False
    if hypervisor == 'kvm':
        v2v_virsh = virsh
    else:
        virsh_dargs = {'uri': remote_uri, 'remote_ip': source_ip,
                       'remote_user': source_user, 'remote_pwd': source_pwd,
                       'debug': True}
        v2v_virsh = virsh.VirshPersistent(**virsh_dargs)
        close_virsh = True
    try:
        if not v2v_virsh.domain_exists(vm_name):
            raise exceptions.TestError("VM '%s' not exist" % vm_name)
    finally:
        if close_virsh:
            v2v_virsh.close_session()

    # Create SASL user on the ovirt host
    user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
                                   params.get("sasl_pwd"))
    v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
    v2v_sasl.server_ip = params.get("remote_ip")
    v2v_sasl.server_user = params.get('remote_user')
    v2v_sasl.server_pwd = params.get('remote_pwd')
    v2v_sasl.setup(remote=True)

    # Maintain a single params for v2v to avoid duplicate parameters
    v2v_params = {'target': target, 'hypervisor': hypervisor,
                  'main_vm': vm_name, 'input_mode': input_mode,
                  'network': network, 'bridge': bridge,
                  'storage': storage, 'hostname': source_ip}
    if vpx_dc:
        v2v_params.update({"vpx_dc": vpx_dc})
    if esx_ip:
        v2v_params.update({"esx_ip": esx_ip})
    if v2v_opts:
        v2v_params.update({"v2v_opts": v2v_opts})
    output_format = params.get('output_format')
    if output_format:
        v2v_params.update({'output_format': 'qcow2'})

    # Set libguestfs environment variable
    os.environ['LIBGUESTFS_BACKEND'] = 'direct'
    try:
        # Execute virt-v2v command
        ret = utils_v2v.v2v_cmd(v2v_params)
        logging.debug("virt-v2v verbose messages:\n%s", ret)
        if ret.exit_status != 0:
            raise exceptions.TestFail("Convert VM failed")

        # Import the VM to oVirt Data Center from export domain, and start it
        if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                            timeout=v2v_timeout):
            raise exceptions.TestError("Import VM failed")

        # Check all checkpoints after convert
        vmchecker = VMChecker(test, params, env)
        ret = vmchecker.run()
        if len(ret) == 0:
            logging.info("All checkpoints passed")
        else:
            raise exceptions.TestFail("%d checkpoints failed: %s" % (len(ret), ret))
    finally:
        vmcheck = utils_v2v.VMCheck(test, params, env)
        vmcheck.cleanup()
        if v2v_sasl:
            v2v_sasl.cleanup()
        if hypervisor == "esx":
            os.remove(vpx_pwd_file)
        if hypervisor == "xen":
            process.run("ssh-agent -k")
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if skip_check:
         logging.info('Skip checking vm after conversion: %s' % skip_reason)
     elif not status_error and checkpoint != 'vdsm':
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(
                     params, address_cache, timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception as e:
                 test.fail('Start vm failed: %s', str(e))
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'console_xvc0':
             check_grub_file(vmchecker.checker, 'console_xvc0')
         if checkpoint in ('vnc_autoport', 'vnc_encrypt'):
             vmchecker.check_graphics(params[checkpoint])
         if checkpoint == 'sdl':
             if output_mode == 'libvirt':
                 vmchecker.check_graphics({'type': 'vnc'})
             elif output_mode == 'rhev':
                 vmchecker.check_graphics({'type': 'spice'})
         if checkpoint == 'pv_with_regular_kernel':
             check_kernel(vmchecker.checker)
         if checkpoint in ['sound', 'pcspk']:
             check_sound_card(vmchecker.checker, checkpoint)
         if checkpoint == 'rhsrvany_md5':
             check_rhsrvany_md5(vmchecker.checker)
         if checkpoint == 'multidisk':
             check_disk(vmchecker.checker, params['disk_count'])
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     # Merge 2 error lists
     if params.get('vmchecker'):
         error_list.extend(params['vmchecker'].errors)
     # Virtio drivers will not be installed without virtio-win setup
     if checkpoint == 'virtio_win_unset':
         missing_list = params.get('missing').split(',')
         expect_errors = ['Not find driver: ' + x for x in missing_list]
         logging.debug('Expect errors: %s' % expect_errors)
         logging.debug('Actual errors: %s' % error_list)
         if set(error_list) == set(expect_errors):
             error_list[:] = []
         else:
             logging.error('Virtio drivers not meet expectation')
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout_text + result.stderr_text
     if checkpoint == 'empty_cdrom':
         if status_error:
             log_fail('Virsh dumpxml failed for empty cdrom image')
     elif not status_error:
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             virsh.start(vm_name, debug=True)
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         if skip_vm_check != 'yes':
             if checkpoint == 'ogac':
                 # windows guests will reboot at any time after qemu-ga is
                 # installed. The process cannot be controled. In order to
                 # don't break vmchecker.run() process, It's better to put
                 # check_windows_ogac before vmchecker.run(). Because in
                 # check_windows_ogac, it waits until rebooting completes.
                 vmchecker.checker.create_session()
                 if os_type == 'windows':
                     check_windows_ogac(vmchecker.checker)
                 else:
                     check_linux_ogac(vmchecker.checker)
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         else:
             logging.info(
                 'Skip checking vm after conversion: %s' %
                 skip_reason)
         # Check specific checkpoints
         if checkpoint == 'cdrom':
             virsh_session = utils_sasl.VirshSessionSASL(params)
             virsh_session_id = virsh_session.get_id()
             check_device_exist('cdrom', virsh_session_id)
             virsh_session.close()
         if checkpoint.startswith('vmtools'):
             check_vmtools(vmchecker.checker, checkpoint)
         if checkpoint == 'modprobe':
             check_modprobe(vmchecker.checker)
         if checkpoint == 'device_map':
             check_device_map(vmchecker.checker)
         if checkpoint == 'resume_swap':
             check_resume_swap(vmchecker.checker)
         if checkpoint == 'rhev_file':
             check_rhev_file_exist(vmchecker.checker)
         if checkpoint == 'file_architecture':
             check_file_architecture(vmchecker.checker)
         if checkpoint == 'ubuntu_tools':
             check_ubuntools(vmchecker.checker)
         if checkpoint == 'without_default_net':
             if virsh.net_state_dict()[net_name]['active']:
                 log_fail("Bridge virbr0 already started during conversion")
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     if len(error_list):
         test.fail('%d checkpoints failed: %s' %
                   (len(error_list), error_list))
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     libvirt.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if not status_error and checkpoint != 'vdsm':
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         elif output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception as e:
                 test.fail('Start vm failed: %s', str(e))
         # Check guest following the checkpoint document after convertion
         logging.info('Checking common checkpoints for v2v')
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         ret = vmchecker.run()
         if len(ret) == 0:
             logging.info("All common checkpoints passed")
         # Check specific checkpoints
         if checkpoint == 'rhev_file':
             check_rhev_file_exist(vmchecker.checker)
         if checkpoint == 'console_xvc0':
             check_grub_file(vmchecker.checker, 'console_xvc0')
         if checkpoint in ('vnc_autoport', 'vnc_encrypt'):
             vmchecker.check_graphics(params[checkpoint])
         if checkpoint == 'sdl':
             if output_mode == 'libvirt':
                 vmchecker.check_graphics({'type': 'vnc'})
             elif output_mode == 'rhev':
                 vmchecker.check_graphics({'type': 'spice'})
         if checkpoint == 'pv_with_regular_kernel':
             check_kernel(vmchecker.checker)
         if checkpoint in ['sound', 'pcspk']:
             check_sound_card(vmchecker.checker, checkpoint)
         if checkpoint == 'rhsrvany_md5':
             check_rhsrvany_md5(vmchecker.checker)
         if checkpoint == 'multidisk':
             check_disk(vmchecker.checker, params['disk_count'])
     log_check = utils_v2v.check_log(params, output)
     if log_check:
         log_fail(log_check)
     # Merge 2 error lists
     if params.get('vmchecker'):
         error_list.extend(params['vmchecker'].errors)
     # Virtio drivers will not be installed without virtio-win setup
     if checkpoint == 'virtio_win_unset':
         missing_list = params.get('missing').split(',')
         expect_errors = ['Not find driver: ' + x for x in missing_list]
         logging.debug('Expect errors: %s' % expect_errors)
         logging.debug('Actual errors: %s' % error_list)
         if set(error_list) == set(expect_errors):
             error_list[:] = []
         else:
             logging.error('Virtio drivers not meet expectation')
     if len(error_list):
         test.fail('%d checkpoints failed: %s' % (len(error_list), error_list))
Beispiel #31
0
    def check_result(cmd, result, status_error):
        """
        Check virt-v2v command result
        """
        utlv.check_exit_status(result, status_error)
        output = result.stdout + result.stderr
        if status_error:
            if checkpoint == 'length_of_error':
                log_lines = output.split('\n')
                v2v_start = False
                for line in log_lines:
                    if line.startswith('virt-v2v:'):
                        v2v_start = True
                    if line.startswith('libvirt:'):
                        v2v_start = False
                    if v2v_start and len(line) > 72:
                        raise exceptions.TestFail(
                            'Error log longer than 72 '
                            'charactors: %s', line)
            if checkpoint == 'disk_not_exist':
                vol_list = virsh.vol_list(pool_name)
                logging.info(vol_list)
                if vm_name in vol_list.stdout:
                    raise exceptions.TestFail('Disk exists for vm %s' %
                                              vm_name)
            else:
                error_map = {
                    'conflict_options': ['option used more than once'],
                    'xen_no_output_format':
                    ['The input metadata did not define'
                     ' the disk format'],
                    'in_place':
                    ['virt-v2v: error: --in-place cannot be used in RHEL 7']
                }
                if error_map.has_key(checkpoint) and not utils_v2v.check_log(
                        output, error_map[checkpoint]):
                    raise exceptions.TestFail('Not found error message %s' %
                                              error_map[checkpoint])
        else:
            if output_mode == "rhev" and checkpoint != 'quiet':
                ovf = get_ovf_content(output)
                logging.debug("ovf content: %s", ovf)
                check_ovf_snapshot_id(ovf)
                if '--vmtype' in cmd:
                    expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                    check_vmtype(ovf, expected_vmtype)
            if '-oa' in cmd and '--no-copy' not in cmd:
                expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
                img_path = get_img_path(output)

                def check_alloc():
                    try:
                        check_image(img_path, "allocation", expected_mode)
                        return True
                    except exceptions.TestFail:
                        pass

                if not utils_misc.wait_for(check_alloc, timeout=600,
                                           step=10.0):
                    raise exceptions.TestFail('Allocation check failed.')
            if '-of' in cmd and '--no-copy' not in cmd and checkpoint != 'quiet':
                expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
                img_path = get_img_path(output)
                check_image(img_path, "format", expected_format)
            if '-on' in cmd:
                expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
                check_new_name(output, expected_name)
            if '--no-copy' in cmd:
                check_nocopy(output)
            if '-oc' in cmd:
                expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
                check_connection(output, expected_uri)
            if output_mode == "rhev":
                if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                    raise exceptions.TestFail("Import VM failed")
                else:
                    params['vmcheck_flag'] = True
            if output_mode == "libvirt":
                if "qemu:///session" not in v2v_options and not no_root:
                    virsh.start(vm_name, debug=True, ignore_status=False)
            if checkpoint == 'quiet':
                if len(output.strip()) != 0:
                    raise exceptions.TestFail(
                        'Output is not empty in quiet mode')
            if checkpoint == 'dependency':
                if 'libguestfs-winsupport' not in output:
                    raise exceptions.TestFail(
                        'libguestfs-winsupport not in dependency')
                if 'qemu-kvm-rhev' in output:
                    raise exceptions.TestFail('qemu-kvm-rhev is in dependency')
                win_img = params.get('win_image')
                command = 'guestfish -a %s -i'
                if process.run(command % win_img,
                               ignore_status=True).exit_status == 0:
                    raise exceptions.TestFail('Command "%s" success' %
                                              command % win_img)
            if checkpoint == 'no_dcpath':
                if not utils_v2v.check_log(output, ['--dcpath'], expect=False):
                    raise exceptions.TestFail('"--dcpath" is not removed')
            if checkpoint == 'debug_overlays':
                search = re.search('Overlay saved as(.*)', output)
                if not search:
                    raise exceptions.TestFail(
                        'Not find log of saving overlays')
                overlay_path = search.group(1).strip()
                logging.debug('Overlay file location: %s' % overlay_path)
                if os.path.isfile(overlay_path):
                    logging.info('Found overlay file: %s' % overlay_path)
                else:
                    raise exceptions.TestFail('Overlay file not saved')
            if checkpoint.startswith('empty_nic_source'):
                target_str = '%s "eth0" mac: %s' % (params[checkpoint][0],
                                                    params[checkpoint][1])
                logging.info('Expect log: %s', target_str)
                if target_str not in result.stdout.lower():
                    raise exceptions.TestFail('Expect log not found: %s' %
                                              target_str)
            if checkpoint == 'print_source':
                check_source(result.stdout)
            if checkpoint == 'machine_readable':
                if os.path.exists(params.get('example_file', '')):
                    expect_output = open(params['example_file']).read().strip()
                    logging.debug(expect_output)
                    logging.debug(expect_output == result.stdout.strip())
                else:
                    raise exceptions.TestError('No content to compare with')
            if checkpoint == 'compress':
                img_path = get_img_path(output)
                logging.info('Image path: %s', img_path)
                disk_check = process.run('qemu-img check %s' % img_path).stdout
                logging.info(disk_check)
                compress_info = disk_check.split(',')[-1].split('%')[0].strip()
                compress_rate = float(compress_info)
                logging.info('%s%% compressed', compress_rate)
                if compress_rate < 0.1:
                    raise exceptions.TestFail('Disk image NOT compressed')
            if checkpoint == 'tail_log':
                messages = params['tail'].get_output()
                logging.info('Content of /var/log/messages during conversion:')
                logging.info(messages)
                msg_content = params['msg_content']
                if not utils_v2v.check_log(messages, [msg_content],
                                           expect=False):
                    raise exceptions.TestFail(
                        'Found "%s" in /var/log/messages' % msg_content)
Beispiel #32
0
    def check_result(cmd, result, status_error):
        """
        Check virt-v2v command result
        """
        utlv.check_exit_status(result, status_error)
        output = result.stdout + result.stderr
        if status_error:
            if checkpoint == 'length_of_error':
                log_lines = output.split('\n')
                v2v_start = False
                for line in log_lines:
                    if line.startswith('virt-v2v:'):
                        v2v_start = True
                    if line.startswith('libvirt:'):
                        v2v_start = False
                    if v2v_start and len(line) > 72:
                        raise exceptions.TestFail(
                            'Error log longer than 72 '
                            'charactors: %s', line)
            else:
                error_map = {
                    'conflict_options': ['option used more than once'],
                    'xen_no_output_format':
                    ['The input metadata did not define'
                     ' the disk format']
                }
                if not utils_v2v.check_log(output, error_map[checkpoint]):
                    raise exceptions.TestFail('Not found error message %s' %
                                              error_map[checkpoint])
        else:
            if output_mode == "rhev" and checkpoint != 'quiet':
                ovf = get_ovf_content(output)
                logging.debug("ovf content: %s", ovf)
                check_ovf_snapshot_id(ovf)
                if '--vmtype' in cmd:
                    expected_vmtype = re.findall(r"--vmtype\s(\w+)", cmd)[0]
                    check_vmtype(ovf, expected_vmtype)
            if '-oa' in cmd and '--no-copy' not in cmd:
                expected_mode = re.findall(r"-oa\s(\w+)", cmd)[0]
                img_path = get_img_path(output)

                def check_alloc():
                    try:
                        check_image(img_path, "allocation", expected_mode)
                        return True
                    except exceptions.TestFail:
                        pass

                if not utils_misc.wait_for(check_alloc, timeout=600,
                                           step=10.0):
                    raise exceptions.TestFail('Allocation check failed.')
            if '-of' in cmd and '--no-copy' not in cmd and checkpoint != 'quiet':
                expected_format = re.findall(r"-of\s(\w+)", cmd)[0]
                img_path = get_img_path(output)
                check_image(img_path, "format", expected_format)
            if '-on' in cmd:
                expected_name = re.findall(r"-on\s(\w+)", cmd)[0]
                check_new_name(output, expected_name)
            if '--no-copy' in cmd:
                check_nocopy(output)
            if '-oc' in cmd:
                expected_uri = re.findall(r"-oc\s(\S+)", cmd)[0]
                check_connection(output, expected_uri)
            if output_mode == "rhev":
                if not utils_v2v.import_vm_to_ovirt(params, address_cache):
                    raise exceptions.TestFail("Import VM failed")
                else:
                    params['vmcheck_flag'] = True
            if output_mode == "libvirt":
                if "qemu:///session" not in v2v_options:
                    virsh.start(vm_name, debug=True, ignore_status=False)
            if checkpoint == 'quiet':
                if len(output.strip()) != 0:
                    raise exceptions.TestFail(
                        'Output is not empty in quiet mode')
            if checkpoint == 'dependency':
                if 'libguestfs-winsupport' not in output:
                    raise exceptions.TestFail(
                        'libguestfs-winsupport not in dependency')
                if 'qemu-kvm-rhev' in output:
                    raise exceptions.TestFail('qemu-kvm-rhev is in dependency')
                win_img = params.get('win_image')
                command = 'guestfish -a %s -i'
                if process.run(command % win_img,
                               ignore_status=True).exit_status == 0:
                    raise exceptions.TestFail('Command "%s" success' %
                                              command % win_img)
            if checkpoint == 'no_dcpath':
                if not utils_v2v.check_log(output, ['--dcpath'], expect=False):
                    raise exceptions.TestFail('"--dcpath" is not removed')
def run(test, params, env):
    """
    Convert a remote vm to remote ovirt node.
    """
    for v in params.itervalues():
        if "V2V_EXAMPLE" in v:
            raise exceptions.TestSkipError("Please set real value for %s" % v)

    vm_name = params.get("main_vm")
    target = params.get("target")
    hypervisor = params.get("hypervisor")
    input_mode = params.get("input_mode")
    storage = params.get('storage')
    network = params.get('network')
    bridge = params.get('bridge')
    source_user = params.get("username", "root")
    xen_ip = params.get("xen_hostname")
    xen_pwd = params.get("xen_pwd")
    vpx_ip = params.get("vpx_hostname")
    vpx_pwd = params.get("vpx_pwd")
    vpx_passwd_file = params.get("vpx_passwd_file")
    vpx_dc = params.get("vpx_dc")
    esx_ip = params.get("esx_hostname")
    address_cache = env.get('address_cache')
    v2v_opts = params.get("v2v_opts")
    v2v_timeout = int(params.get('v2v_timeout', 1200))

    # Prepare step for different hypervisor
    if hypervisor == "esx":
        source_ip = vpx_ip
        source_pwd = vpx_pwd
        # Create password file to access ESX hypervisor
        with open(vpx_passwd_file, 'w') as f:
            f.write(vpx_pwd)
    elif hypervisor == "xen":
        source_ip = xen_ip
        source_pwd = xen_pwd
        # Set up ssh access using ssh-agent and authorized_keys
        ssh_key.setup_ssh_key(source_ip, source_user, source_pwd)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except:
            process.run("ssh-agent -k")
            raise exceptions.TestError("Fail to setup ssh-agent")
    elif hypervisor == "kvm":
        source_ip = None
        source_pwd = None
    else:
        raise exceptions.TestSkipError("Unspported hypervisor: %s" % hypervisor)

    # Create libvirt URI
    v2v_uri = utils_v2v.Uri(hypervisor)
    remote_uri = v2v_uri.get_uri(source_ip, vpx_dc, esx_ip)
    logging.debug("libvirt URI for converting: %s", remote_uri)

    # Make sure the VM exist before convert
    v2v_virsh = None
    close_virsh = False
    if hypervisor == 'kvm':
        v2v_virsh = virsh
    else:
        virsh_dargs = {'uri': remote_uri, 'remote_ip': source_ip,
                       'remote_user': source_user, 'remote_pwd': source_pwd,
                       'debug': True}
        v2v_virsh = virsh.VirshPersistent(**virsh_dargs)
        close_virsh = True
    try:
        if not v2v_virsh.domain_exists(vm_name):
            raise exceptions.TestError("VM '%s' not exist" % vm_name)
    finally:
        if close_virsh:
            v2v_virsh.close_session()

    # Create SASL user on the ovirt host
    user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
                                   params.get("sasl_pwd"))
    v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
    v2v_sasl.server_ip = params.get("remote_ip")
    v2v_sasl.server_user = params.get('remote_user')
    v2v_sasl.server_pwd = params.get('remote_pwd')
    v2v_sasl.setup(remote=True)

    # Maintain a single params for v2v to avoid duplicate parameters
    v2v_params = {'target': target, 'hypervisor': hypervisor,
                  'main_vm': vm_name, 'input_mode': input_mode,
                  'network': network, 'bridge': bridge,
                  'storage': storage, 'hostname': source_ip}
    if vpx_dc:
        v2v_params.update({"vpx_dc": vpx_dc})
    if esx_ip:
        v2v_params.update({"esx_ip": esx_ip})
    if v2v_opts:
        v2v_params.update({"v2v_opts": v2v_opts})
    output_format = params.get('output_format')
    if output_format:
        v2v_params.update({'output_format': 'qcow2'})

    # Set libguestfs environment variable
    os.environ['LIBGUESTFS_BACKEND'] = 'direct'
    try:
        # Execute virt-v2v command
        ret = utils_v2v.v2v_cmd(v2v_params)
        logging.debug("virt-v2v verbose messages:\n%s", ret)
        if ret.exit_status != 0:
            raise exceptions.TestFail("Convert VM failed")

        # Import the VM to oVirt Data Center from export domain, and start it
        if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                            timeout=v2v_timeout):
            raise exceptions.TestError("Import VM failed")

        # Check all checkpoints after convert
        vmchecker = VMChecker(test, params, env)
        ret = vmchecker.run()
        if len(ret) == 0:
            logging.info("All checkpoints passed")
        else:
            raise exceptions.TestFail("%d checkpoints failed: %s" % (len(ret), ret))
    finally:
        vmcheck = utils_v2v.VMCheck(test, params, env)
        vmcheck.cleanup()
        if v2v_sasl:
            v2v_sasl.cleanup()
        if hypervisor == "esx":
            os.remove(vpx_passwd_file)
        if hypervisor == "xen":
            process.run("ssh-agent -k")
Beispiel #34
0
    def check_result(result, status_error):
        """
        Check virt-v2v command result
        """
        utlv.check_exit_status(result, status_error)
        output = result.stdout_text + result.stderr_text
        if not status_error:
            if output_mode == 'json' and not check_json_output(params):
                test.fail('check json output failed')
            if output_mode == 'local' and not check_local_output(params):
                test.fail('check local output failed')
            if output_mode in ['null', 'json', 'local']:
                return

            vmchecker = VMChecker(test, params, env)
            params['vmchecker'] = vmchecker
            if output_mode == 'rhev':
                if not utils_v2v.import_vm_to_ovirt(
                        params, address_cache, timeout=v2v_timeout):
                    test.fail('Import VM failed')
            if output_mode == 'libvirt':
                try:
                    virsh.start(vm_name, debug=True, ignore_status=False)
                except Exception as e:
                    test.fail('Start vm failed: %s' % str(e))
            # Check guest following the checkpoint document after conversion
            if params.get('skip_vm_check') != 'yes':
                ret = vmchecker.run()
                if len(ret) == 0:
                    LOG.info("All common checkpoints passed")
            LOG.debug(vmchecker.vmxml)
            if checkpoint == 'multi_kernel':
                check_boot_kernel(vmchecker.checker)
                check_vmlinuz_initramfs(output)
            if checkpoint == 'floppy':
                # Convert to rhv will remove all removable devices(floppy,
                # cdrom)
                if output_mode in ['local', 'libvirt']:
                    check_floppy_exist(vmchecker.checker)
            if checkpoint == 'multi_disks':
                check_disks(vmchecker.checker)
            if checkpoint == 'multi_netcards':
                check_multi_netcards(params['mac_address'], vmchecker.vmxml)
            if checkpoint.startswith(('spice', 'vnc')):
                if checkpoint == 'spice_encrypt':
                    vmchecker.check_graphics(params[checkpoint])
                else:
                    graph_type = checkpoint.split('_')[0]
                    vmchecker.check_graphics({'type': graph_type})
                    video_type = vmchecker.xmltree.find(
                        './devices/video/model').get('type')
                    if utils_v2v.multiple_versions_compare(
                            V2V_ADAPTE_SPICE_REMOVAL_VER):
                        expect_video_type = 'vga'
                    else:
                        expect_video_type = 'qxl'

                    if video_type.lower() != expect_video_type:
                        log_fail('Video expect %s, actual %s' %
                                 (expect_video_type, video_type))
            if checkpoint.startswith('listen'):
                listen_type = vmchecker.xmltree.find(
                    './devices/graphics/listen').get('type')
                LOG.info('listen type is: %s', listen_type)
                if listen_type != checkpoint.split('_')[-1]:
                    log_fail('listen type changed after conversion')
            if checkpoint.startswith('selinux'):
                status = vmchecker.checker.session.cmd(
                    'getenforce').strip().lower()
                LOG.info('Selinux status after v2v:%s', status)
                if status != checkpoint[8:]:
                    log_fail('Selinux status not match')
            if checkpoint == 'check_selinuxtype':
                expect_output = vmchecker.checker.session.cmd(
                    'cat /etc/selinux/config')
                expect_selinuxtype = re.search(r'^SELINUXTYPE=\s*(\S+)$',
                                               expect_output,
                                               re.MULTILINE).group(1)
                actual_output = vmchecker.checker.session.cmd('sestatus')
                actual_selinuxtype = re.search(
                    r'^Loaded policy name:\s*(\S+)$', actual_output,
                    re.MULTILINE).group(1)
                if actual_selinuxtype != expect_selinuxtype:
                    log_fail('Seliunx type not match')
            if checkpoint == 'guest_firewalld_status':
                check_firewalld_status(vmchecker.checker, params[checkpoint])
            if checkpoint in ['ntpd_on', 'sync_ntp']:
                check_time_keep(vmchecker.checker)
            # Merge 2 error lists
            error_list.extend(vmchecker.errors)
        log_check = utils_v2v.check_log(params, output)
        if log_check:
            log_fail(log_check)
        if len(error_list):
            test.fail('%d checkpoints failed: %s' %
                      (len(error_list), error_list))
Beispiel #35
0
 def check_result(result, status_error):
     """
     Check virt-v2v command result
     """
     utlv.check_exit_status(result, status_error)
     output = result.stdout + result.stderr
     if skip_check:
         logging.info('Skip checking vm after conversion')
     elif not status_error:
         if output_mode == 'rhev':
             if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                                 timeout=v2v_timeout):
                 test.fail('Import VM failed')
         if output_mode == 'libvirt':
             try:
                 virsh.start(vm_name, debug=True, ignore_status=False)
             except Exception, e:
                 test.fail('Start vm failed: %s' % str(e))
         # Check guest following the checkpoint document after convertion
         vmchecker = VMChecker(test, params, env)
         params['vmchecker'] = vmchecker
         if params.get('skip_check') != 'yes':
             ret = vmchecker.run()
             if len(ret) == 0:
                 logging.info("All common checkpoints passed")
         vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(
                 vm_name, virsh_instance=vmchecker.virsh_instance)
         logging.debug(vmxml)
         if checkpoint in ['multi_kernel', 'debug_kernel']:
             default_kernel = params.get('defaultkernel')
             check_boot_kernel(vmchecker.checker, default_kernel, debug_kernel)
             if checkpoint == 'multi_kernel':
                 check_vmlinuz_initramfs(output)
         if checkpoint == 'floppy':
             check_floppy_exist(vmchecker.checker)
         if checkpoint == 'multi_disks':
             check_disks(vmchecker.checker)
         if checkpoint == 'multi_netcards':
             check_multi_netcards(params['mac_address'],
                                  vmchecker.virsh_instance)
         if checkpoint.startswith(('spice', 'vnc')):
             if checkpoint == 'spice_encrypt':
                 vmchecker.check_graphics(params[checkpoint])
             else:
                 graph_type = checkpoint.split('_')[0]
                 vmchecker.check_graphics({'type': graph_type})
                 video_type = vmxml.get_devices('video')[0].model_type
                 if video_type.lower() != 'qxl':
                     log_fail('Video expect QXL, actual %s' % video_type)
         if checkpoint.startswith('listen'):
             listen_type = vmxml.get_devices('graphics')[0].listen_type
             logging.info('listen type is: %s', listen_type)
             if listen_type != checkpoint.split('_')[-1]:
                 log_fail('listen type changed after conversion')
         if checkpoint.startswith('selinux'):
             status = vmchecker.checker.session.cmd('getenforce').strip().lower()
             logging.info('Selinux status after v2v:%s', status)
             if status != checkpoint[8:]:
                 log_fail('Selinux status not match')
         if checkpoint == 'guest_firewalld_status':
             check_firewalld_status(vmchecker.checker, params[checkpoint])
         if checkpoint in ['ntpd_on', 'sync_ntp']:
             check_time_keep(vmchecker.checker)
         # Merge 2 error lists
         error_list.extend(vmchecker.errors)
Beispiel #36
0
        def vm_check(status_error):
            """
            Checking the VM
            """
            if status_error:
                return

            if output_mode == 'json' and not check_json_output(params):
                test.fail('check json output failed')
            if output_mode == 'local' and not check_local_output(params):
                test.fail('check local output failed')
            if output_mode in ['null', 'json', 'local']:
                return

            # vmchecker must be put before skip_vm_check in order to clean up
            # the VM.
            vmchecker = VMChecker(test, params, env)
            params['vmchecker'] = vmchecker
            if skip_vm_check == 'yes':
                logging.info('Skip checking vm after conversion: %s' %
                             skip_reason)
                return

            if output_mode == 'rhev':
                if not utils_v2v.import_vm_to_ovirt(
                        params, address_cache, timeout=v2v_timeout):
                    test.fail('Import VM failed')
            elif output_mode == 'libvirt':
                virsh.start(vm_name, debug=True)

            # Check guest following the checkpoint document after conversion
            logging.info('Checking common checkpoints for v2v')
            if 'ogac' in checkpoint:
                # windows guests will reboot at any time after qemu-ga is
                # installed. The process cannot be controlled. In order to
                # don't break vmchecker.run() process, It's better to put
                # check_windows_ogac before vmchecker.run(). Because in
                # check_windows_ogac, it waits until rebooting completes.
                vmchecker.checker.create_session()
                if os_type == 'windows':
                    services = ['qemu-ga']
                    if not utils_v2v.multiple_versions_compare(
                            V2V_UNSUPPORT_RHEV_APT_VER):
                        services.append('rhev-apt')
                    if 'rhv-guest-tools' in os.getenv('VIRTIO_WIN'):
                        services.append('spice-ga')
                    for ser in services:
                        check_windows_service(vmchecker.checker, ser)
                else:
                    check_linux_ogac(vmchecker.checker)
            if 'mac_ip' in checkpoint:
                check_static_ip_conf(vmchecker.checker)
            ret = vmchecker.run()
            if len(ret) == 0:
                logging.info("All common checkpoints passed")
            # Check specific checkpoints
            if 'ogac' in checkpoint and 'signature' in checkpoint:
                if not utils_v2v.multiple_versions_compare(
                        V2V_UNSUPPORT_RHEV_APT_VER):
                    check_windows_signature(vmchecker.checker,
                                            r'c:\rhev-apt.exe')
            if 'cdrom' in checkpoint and "device='cdrom'" not in vmchecker.vmxml:
                test.fail('CDROM no longer exists')
            if 'vmtools' in checkpoint:
                check_vmtools(vmchecker.checker, checkpoint)
            if 'modprobe' in checkpoint:
                check_modprobe(vmchecker.checker)
            if 'device_map' in checkpoint:
                check_device_map(vmchecker.checker)
            if 'resume_swap' in checkpoint:
                check_resume_swap(vmchecker.checker)
            if 'rhev_file' in checkpoint:
                check_rhev_file_exist(vmchecker.checker)
            if 'file_architecture' in checkpoint:
                check_file_architecture(vmchecker.checker)
            if 'ubuntu_tools' in checkpoint:
                check_ubuntools(vmchecker.checker)
            if 'vmware_tools' in checkpoint:
                check_windows_vmware_tools(vmchecker.checker)
            if 'without_default_net' in checkpoint:
                if virsh.net_state_dict()[net_name]['active']:
                    log_fail("Bridge virbr0 already started during conversion")
            if 'rhsrvany_checksum' in checkpoint:
                check_rhsrvany_checksums(vmchecker.checker)
            if 'block_dev' in checkpoint and not os.path.exists(blk_dev_link):
                test.fail("checkpoint '%s' failed" % checkpoint)
            # Merge 2 error lists
            error_list.extend(vmchecker.errors)
            # Virtio drivers will not be installed without virtio-win setup
            if 'virtio_win_unset' in checkpoint:
                missing_list = params.get('missing').split(',')
                expect_errors = ['Not find driver: ' + x for x in missing_list]
                logging.debug('Expect errors: %s' % expect_errors)
                logging.debug('Actual errors: %s' % error_list)
                if set(error_list) == set(expect_errors):
                    error_list[:] = []
                else:
                    logging.error('Virtio drivers not meet expectation')
def run(test, params, env):
    """
    Convert a remote vm to remote ovirt node.
    """
    for v in list(params.values()):
        if "V2V_EXAMPLE" in v:
            test.cancel("Please set real value for %s" % v)

    vm_name = params.get("main_vm")
    target = params.get("target")
    hypervisor = params.get("hypervisor")
    input_mode = params.get("input_mode")
    input_transport = params.get("input_transport")
    vddk_libdir = params.get('vddk_libdir')
    # nfs mount source
    vddk_libdir_src = params.get('vddk_libdir_src')
    vddk_thumbprint = params.get('vddk_thumbprint')
    storage = params.get('storage')
    storage_name = params.get('storage_name')
    network = params.get('network')
    bridge = params.get('bridge')
    source_user = params.get("username", "root")
    xen_ip = params.get("xen_hostname")
    xen_pwd = params.get("xen_pwd")
    vpx_ip = params.get("vpx_hostname")
    vpx_pwd = params.get("vpx_pwd")
    vpx_passwd_file = params.get("vpx_passwd_file")
    vpx_dc = params.get("vpx_dc")
    esx_ip = params.get("esx_hostname")
    address_cache = env.get('address_cache')
    v2v_opts = params.get("v2v_opts")
    v2v_timeout = int(params.get('v2v_timeout', 1200))
    # for construct rhv-upload option in v2v cmd
    output_method = params.get("output_method")
    rhv_upload_opts = params.get("rhv_upload_opts")
    # for get ca.crt file from ovirt engine
    rhv_passwd = params.get("rhv_upload_passwd")
    rhv_passwd_file = params.get("rhv_upload_passwd_file")
    ovirt_engine_passwd = params.get("ovirt_engine_password")
    ovirt_hostname = params.get("ovirt_engine_url").split('/')[2]
    ovirt_ca_file_path = params.get("ovirt_ca_file_path")
    local_ca_file_path = params.get("local_ca_file_path")

    # create different sasl_user name for different job
    params.update({'sasl_user': params.get("sasl_user") +
                   utils_misc.generate_random_string(3)})
    logging.info('sals user name is %s' % params.get("sasl_user"))

    # Prepare step for different hypervisor
    if hypervisor == "esx":
        source_ip = vpx_ip
        source_pwd = vpx_pwd
        # Create password file to access ESX hypervisor
        with open(vpx_passwd_file, 'w') as f:
            f.write(vpx_pwd)
    elif hypervisor == "xen":
        source_ip = xen_ip
        source_pwd = xen_pwd
        # Set up ssh access using ssh-agent and authorized_keys
        ssh_key.setup_ssh_key(source_ip, source_user, source_pwd)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except:
            process.run("ssh-agent -k")
            test.error("Fail to setup ssh-agent")
    elif hypervisor == "kvm":
        source_ip = None
        source_pwd = None
    else:
        test.cancel("Unspported hypervisor: %s" % hypervisor)

    if output_method == 'rhv_upload':
        # Create password file for '-o rhv_upload' to connect to ovirt
        with open(rhv_passwd_file, 'w') as f:
            f.write(rhv_passwd)
        # Copy ca file from ovirt to local
        remote.scp_from_remote(ovirt_hostname, 22, 'root',
                               ovirt_engine_passwd,
                               ovirt_ca_file_path,
                               local_ca_file_path)

    # Create libvirt URI
    v2v_uri = utils_v2v.Uri(hypervisor)
    remote_uri = v2v_uri.get_uri(source_ip, vpx_dc, esx_ip)
    logging.debug("libvirt URI for converting: %s", remote_uri)

    # Make sure the VM exist before convert
    v2v_virsh = None
    close_virsh = False
    if hypervisor == 'kvm':
        v2v_virsh = virsh
    else:
        virsh_dargs = {'uri': remote_uri, 'remote_ip': source_ip,
                       'remote_user': source_user, 'remote_pwd': source_pwd,
                       'debug': True}
        v2v_virsh = virsh.VirshPersistent(**virsh_dargs)
        close_virsh = True
    try:
        if not v2v_virsh.domain_exists(vm_name):
            test.error("VM '%s' not exist" % vm_name)
    finally:
        if close_virsh:
            v2v_virsh.close_session()

    # Create SASL user on the ovirt host
    user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
                                   params.get("sasl_pwd"))
    v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
    v2v_sasl.server_ip = params.get("remote_ip")
    v2v_sasl.server_user = params.get('remote_user')
    v2v_sasl.server_pwd = params.get('remote_pwd')
    v2v_sasl.setup(remote=True)

    # Maintain a single params for v2v to avoid duplicate parameters
    v2v_params = {'target': target, 'hypervisor': hypervisor,
                  'main_vm': vm_name, 'input_mode': input_mode,
                  'network': network, 'bridge': bridge,
                  'storage': storage, 'hostname': source_ip,
                  'new_name': vm_name + utils_misc.generate_random_string(3),
                  'output_method': output_method, 'storage_name': storage_name,
                  'input_transport': input_transport, 'vcenter_host': vpx_ip,
                  'vcenter_password': vpx_pwd,
                  'vddk_thumbprint': vddk_thumbprint,
                  'vddk_libdir': vddk_libdir,
                  'vddk_libdir_src': vddk_libdir_src,
                  }
    if vpx_dc:
        v2v_params.update({"vpx_dc": vpx_dc})
    if esx_ip:
        v2v_params.update({"esx_ip": esx_ip})
    if v2v_opts:
        v2v_params.update({"v2v_opts": v2v_opts})
    if rhv_upload_opts:
        v2v_params.update({"rhv_upload_opts": rhv_upload_opts})
    output_format = params.get('output_format')
    # output_format will be set to 'raw' in utils_v2v.v2v_cmd if it's None
    if output_format:
        v2v_params.update({'output_format': output_format})

    # Set libguestfs environment variable
    if hypervisor in ('xen', 'kvm'):
        os.environ['LIBGUESTFS_BACKEND'] = 'direct'
    try:
        # Execute virt-v2v command
        v2v_ret = utils_v2v.v2v_cmd(v2v_params)
        if v2v_ret.exit_status != 0:
            test.fail("Convert VM failed")

        params['main_vm'] = v2v_params['new_name']

        logging.info("output_method is %s" % output_method)
        # Import the VM to oVirt Data Center from export domain, and start it
        if not utils_v2v.import_vm_to_ovirt(params, address_cache,
                                            timeout=v2v_timeout):
            test.error("Import VM failed")

        # Check all checkpoints after convert
        vmchecker = VMChecker(test, params, env)
        ret = vmchecker.run()

        # Other checks
        err_list = []
        os_list = [
            'win8',
            'win8.1',
            'win10',
            'win2012',
            'win2012r2',
            'win2008',
            'win2016',
            'win2019']
        win_version = ['6.2', '6.3', '10.0', '6.2', '6.3', '6.0', '10.0', '10.0']
        os_map = dict(list(zip(os_list, win_version)))
        vm_arch = params.get('vm_arch')
        os_ver = params.get('os_version')

        if os_ver in os_list:
            vga_log = 'The guest will be configured to use a basic VGA ' \
                      'display driver'
            if re.search(vga_log, v2v_ret.stdout):
                logging.debug('Found vga log')
            else:
                err_list.append('Not find vga log')
            if os_ver != 'win2008':
                qxl_warn = 'virt-v2v: warning: there is no QXL driver for ' \
                           'this version of Windows \(%s[.\s]*?%s\)' %\
                           (os_map[os_ver], vm_arch)
                if re.search(qxl_warn, v2v_ret.stdout):
                    logging.debug('Found QXL warning')
                else:
                    err_list.append('Not find QXL warning')

        ret.extend(err_list)

        if len(ret) == 0:
            logging.info("All checkpoints passed")
        else:
            test.fail("%d checkpoints failed: %s" % (len(ret), ret))
    finally:
        vmcheck = utils_v2v.VMCheck(test, params, env)
        vmcheck.cleanup()
        if v2v_sasl:
            v2v_sasl.cleanup()
        if hypervisor == "xen":
            process.run("ssh-agent -k")
        # Cleanup constant files
        utils_v2v.cleanup_constant_files(params)
Beispiel #38
0
        def vm_check(status_error):
            """
            Checking the VM
            """
            if status_error:
                return

            if output_mode == 'json' and not check_json_output(params):
                test.fail('check json output failed')
            if output_mode == 'local' and not check_local_output(params):
                test.fail('check local output failed')
            if output_mode in ['null', 'json', 'local']:
                return

            # vmchecker must be put before skip_vm_check in order to clean up
            # the VM.
            vmchecker = VMChecker(test, params, env)
            params['vmchecker'] = vmchecker
            if skip_vm_check == 'yes':
                logging.info('Skip checking vm after conversion: %s' %
                             skip_reason)
                return

            if output_mode == 'rhev':
                if not utils_v2v.import_vm_to_ovirt(
                        params, address_cache, timeout=v2v_timeout):
                    test.fail('Import VM failed')
            elif output_mode == 'libvirt':
                virsh.start(vm_name, debug=True)

            # Check guest following the checkpoint document after convertion
            logging.info('Checking common checkpoints for v2v')
            if checkpoint == 'ogac':
                # windows guests will reboot at any time after qemu-ga is
                # installed. The process cannot be controled. In order to
                # don't break vmchecker.run() process, It's better to put
                # check_windows_ogac before vmchecker.run(). Because in
                # check_windows_ogac, it waits until rebooting completes.
                vmchecker.checker.create_session()
                if os_type == 'windows':
                    check_windows_ogac(vmchecker.checker)
                else:
                    check_linux_ogac(vmchecker.checker)
            ret = vmchecker.run()
            if len(ret) == 0:
                logging.info("All common checkpoints passed")
            # Check specific checkpoints
            if checkpoint == 'cdrom':
                virsh_session = utils_sasl.VirshSessionSASL(params)
                virsh_session_id = virsh_session.get_id()
                check_device_exist('cdrom', virsh_session_id)
                virsh_session.close()
            if checkpoint.startswith('vmtools'):
                check_vmtools(vmchecker.checker, checkpoint)
            if checkpoint == 'modprobe':
                check_modprobe(vmchecker.checker)
            if checkpoint == 'device_map':
                check_device_map(vmchecker.checker)
            if checkpoint == 'resume_swap':
                check_resume_swap(vmchecker.checker)
            if checkpoint == 'rhev_file':
                check_rhev_file_exist(vmchecker.checker)
            if checkpoint == 'file_architecture':
                check_file_architecture(vmchecker.checker)
            if checkpoint == 'ubuntu_tools':
                check_ubuntools(vmchecker.checker)
            if checkpoint == 'without_default_net':
                if virsh.net_state_dict()[net_name]['active']:
                    log_fail("Bridge virbr0 already started during conversion")
            # Merge 2 error lists
            error_list.extend(vmchecker.errors)
Beispiel #39
0
def run(test, params, env):
    """
    Convert a remote vm to remote ovirt node.
    """
    for v in list(params.values()):
        if "V2V_EXAMPLE" in v:
            test.cancel("Please set real value for %s" % v)

    vm_name = params.get("main_vm")
    target = params.get("target")
    hypervisor = params.get("hypervisor")
    input_mode = params.get("input_mode")
    input_transport = params.get("input_transport")
    vddk_libdir = params.get('vddk_libdir')
    # nfs mount source
    vddk_libdir_src = params.get('vddk_libdir_src')
    vddk_thumbprint = params.get('vddk_thumbprint')
    os_pool = storage = params.get('storage')
    storage_name = params.get('storage_name')
    network = params.get('network')
    bridge = params.get('bridge')
    source_user = params.get("username", "root")
    xen_ip = params.get("xen_hostname")
    xen_pwd = params.get("xen_pwd")
    vpx_ip = params.get("vpx_hostname")
    vpx_pwd = params.get("vpx_pwd")
    vpx_passwd_file = params.get("vpx_passwd_file")
    vpx_dc = params.get("vpx_dc")
    esx_ip = params.get("esx_hostname")
    address_cache = env.get('address_cache')
    v2v_opts = '-v -x' if params.get('v2v_debug', 'on') == 'on' else ''
    if params.get("v2v_opts"):
        # Add a blank by force
        v2v_opts += ' ' + params.get("v2v_opts")
    v2v_timeout = int(params.get('v2v_timeout', 1200))
    # for construct rhv-upload option in v2v cmd
    output_method = params.get("output_method")
    rhv_upload_opts = params.get("rhv_upload_opts")
    # for get ca.crt file from ovirt engine
    rhv_passwd = params.get("rhv_upload_passwd")
    rhv_passwd_file = params.get("rhv_upload_passwd_file")
    ovirt_engine_passwd = params.get("ovirt_engine_password")
    ovirt_hostname = params.get("ovirt_engine_url").split('/')[2]
    ovirt_ca_file_path = params.get("ovirt_ca_file_path")
    local_ca_file_path = params.get("local_ca_file_path")
    skip_vm_check = params.get('skip_vm_check', 'no')
    os_version = params.get('os_version')
    os_type = params.get('os_type')

    # create different sasl_user name for different job
    params.update({
        'sasl_user':
        params.get("sasl_user") + utils_misc.generate_random_string(3)
    })
    LOG.info('sals user name is %s' % params.get("sasl_user"))

    # Prepare step for different hypervisor
    if hypervisor == "xen":
        # See man virt-v2v-input-xen(1)
        process.run('update-crypto-policies --set LEGACY',
                    verbose=True,
                    ignore_status=True,
                    shell=True)

    if hypervisor == "esx":
        source_ip = vpx_ip
        source_pwd = vpx_pwd
        # Create password file to access ESX hypervisor
        with open(vpx_passwd_file, 'w') as f:
            f.write(vpx_pwd)
    elif hypervisor == "xen":
        source_ip = xen_ip
        source_pwd = xen_pwd
        # Set up ssh access using ssh-agent and authorized_keys
        xen_pubkey, xen_session = utils_v2v.v2v_setup_ssh_key(source_ip,
                                                              source_user,
                                                              source_pwd,
                                                              auto_close=False)
        try:
            utils_misc.add_identities_into_ssh_agent()
        except Exception:
            process.run("ssh-agent -k")
            test.error("Fail to setup ssh-agent")
    elif hypervisor == "kvm":
        source_ip = None
        source_pwd = None
    else:
        test.cancel("Unsupported hypervisor: %s" % hypervisor)

    if output_method == 'rhv_upload':
        # Create password file for '-o rhv_upload' to connect to ovirt
        with open(rhv_passwd_file, 'w') as f:
            f.write(rhv_passwd)
        # Copy ca file from ovirt to local
        remote.scp_from_remote(ovirt_hostname, 22, 'root', ovirt_engine_passwd,
                               ovirt_ca_file_path, local_ca_file_path)

    # Create libvirt URI
    v2v_uri = utils_v2v.Uri(hypervisor)
    remote_uri = v2v_uri.get_uri(source_ip, vpx_dc, esx_ip)
    LOG.debug("libvirt URI for converting: %s", remote_uri)

    # Make sure the VM exist before convert
    v2v_virsh = None
    close_virsh = False
    if hypervisor == 'kvm':
        v2v_virsh = virsh
    else:
        virsh_dargs = {
            'uri': remote_uri,
            'remote_ip': source_ip,
            'remote_user': source_user,
            'remote_pwd': source_pwd,
            'auto_close': True,
            'debug': True
        }
        v2v_virsh = virsh.VirshPersistent(**virsh_dargs)
        close_virsh = True
    try:
        if not v2v_virsh.domain_exists(vm_name):
            test.error("VM '%s' not exist" % vm_name)
    finally:
        if close_virsh:
            v2v_virsh.close_session()

    # Create SASL user on the ovirt host
    user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
                                   params.get("sasl_pwd"))
    v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
    v2v_sasl.server_ip = params.get("remote_ip")
    v2v_sasl.server_user = params.get('remote_user')
    v2v_sasl.server_pwd = params.get('remote_pwd')
    v2v_sasl.setup(remote=True)

    # Maintain a single params for v2v to avoid duplicate parameters
    v2v_params = {
        'target': target,
        'hypervisor': hypervisor,
        'main_vm': vm_name,
        'input_mode': input_mode,
        'network': network,
        'bridge': bridge,
        'os_storage': storage,
        'hostname': source_ip,
        # For virsh connection
        'password': source_pwd,
        'new_name': vm_name + utils_misc.generate_random_string(3),
        'output_method': output_method,
        'os_storage_name': storage_name,
        'input_transport': input_transport,
        'vcenter_host': vpx_ip,
        'vcenter_password': vpx_pwd,
        'vddk_thumbprint': vddk_thumbprint,
        'vddk_libdir': vddk_libdir,
        'vddk_libdir_src': vddk_libdir_src,
        'params': params
    }
    if vpx_dc:
        v2v_params.update({"vpx_dc": vpx_dc})
    if esx_ip:
        v2v_params.update({"esx_ip": esx_ip})
    if v2v_opts:
        v2v_params.update({"v2v_opts": v2v_opts})
    if rhv_upload_opts:
        v2v_params.update({"rhv_upload_opts": rhv_upload_opts})
    output_format = params.get('output_format')
    # output_format will be set to 'raw' in utils_v2v.v2v_cmd if it's None
    if output_format:
        v2v_params.update({'of_format': output_format})

    # Set libguestfs environment variable
    if hypervisor in ('xen', 'kvm'):
        os.environ['LIBGUESTFS_BACKEND'] = 'direct'
    try:
        # Execute virt-v2v command
        v2v_ret = utils_v2v.v2v_cmd(v2v_params)
        if v2v_ret.exit_status != 0:
            test.fail("Convert VM failed")

        params['main_vm'] = v2v_params['new_name']

        LOG.info("output_method is %s" % output_method)
        # Check all checkpoints after convert
        params['vmchecker'] = vmchecker = VMChecker(test, params, env)
        # Import the VM to oVirt Data Center from export domain, and start it
        if not utils_v2v.import_vm_to_ovirt(
                params, address_cache, timeout=v2v_timeout):
            test.error("Import VM failed")

        # When VM is on OSP, it can't obtain IP address, therefore
        # skipping the VM checking.
        if skip_vm_check == 'yes':
            LOG.debug("skip vm checking")
            return

        ret = vmchecker.run()
        ret.extend(check_qxl_warning(v2v_ret.stdout_text, os_type, os_version))

        if len(ret) == 0:
            LOG.info("All checkpoints passed")
        else:
            test.fail("%d checkpoints failed: %s" % (len(ret), ret))
    finally:
        if params.get('vmchecker'):
            params['vmchecker'].cleanup()
        if v2v_sasl:
            v2v_sasl.cleanup()
            v2v_sasl.close_session()
        if hypervisor == "xen":
            # Restore crypto-policies to DEFAULT, the setting is impossible to be
            # other values by default in testing environment.
            process.run('update-crypto-policies --set DEFAULT',
                        verbose=True,
                        ignore_status=True,
                        shell=True)
            utils_v2v.v2v_setup_ssh_key_cleanup(xen_session, xen_pubkey)
            process.run("ssh-agent -k")
        # Cleanup constant files
        utils_v2v.cleanup_constant_files(params)