当前位置: 首页>>代码示例>>Python>>正文


Python utils_misc.umount函数代码示例

本文整理汇总了Python中virttest.utils_misc.umount函数的典型用法代码示例。如果您正苦于以下问题:Python umount函数的具体用法?Python umount怎么用?Python umount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了umount函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copy_file_from_nfs

def copy_file_from_nfs(src, dst, mount_point, image_name):
    logging.info("Test failed before the install process start."
                 " So just copy a good image from nfs for following tests.")
    utils_misc.mount(src, mount_point, "nfs", perm="ro")
    image_src = utils_misc.get_path(mount_point, image_name)
    shutil.copy(image_src, dst)
    utils_misc.umount(src, mount_point, "nfs")
开发者ID:aginies,项目名称:virt-test,代码行数:7,代码来源:unattended_install.py

示例2: cleanup

    def cleanup(self):
        """
        Clean up the host env.

        Umount NFS from the mount point. If there has some change for exported
        file system in host when setup, also clean up that.
        """
        utils_misc.umount(self.mount_src, self.mount_dir, "nfs")
        if self.nfs_setup and self.unexportfs_in_clean:
            self.exportfs.reset_export()
开发者ID:Antique,项目名称:virt-test,代码行数:10,代码来源:nfs.py

示例3: mount_hugepages

    def mount_hugepages(page_size):
        """
        To mount hugepages

        :param page_size: unit is kB, it can be 4,2048,1048576,etc
        """
        if page_size == 4:
            perm = ""
        else:
            perm = "pagesize=%dK" % page_size

        tlbfs_status = utils_misc.is_mounted("hugetlbfs", "/dev/hugepages",
                                             "hugetlbfs")
        if tlbfs_status:
            utils_misc.umount("hugetlbfs", "/dev/hugepages", "hugetlbfs")
        utils_misc.mount("hugetlbfs", "/dev/hugepages", "hugetlbfs", perm)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:16,代码来源:default_dac_check.py

示例4: test_virt_tar_out

def test_virt_tar_out(test, vm, params):
    """
    1) Write a tempfile to guest
    2) Copy file to host with tar-out
    3) Delete created file
    """
    content = "This is file for test of virt-tar-out."
    path = params.get("vt_temp_file", "/tmp/test_virt_tar_out")
    file_dir = os.path.dirname(path)
    path_on_host = os.path.join(data_dir.get_tmp_dir(),
                                "test_virt_tar_out.tar")

    vt = utils_test.libguestfs.VirtTools(vm, params)
    mountpoint = params.get("vt_mountpoint")
    if mountpoint is None:
        tmpdir = "gmount-%s" % (utils_misc.generate_random_string(6))
        mountpoint = "/tmp/%s" % tmpdir
        if not os.path.exists(mountpoint):
            os.mkdir(mountpoint)

    writes, writeo = vt.write_file_with_guestmount(mountpoint, path, content,
                                                   cleanup=False)
    if utils_misc.umount("", mountpoint, "") is False:
        logging.error("Umount vm's filesytem failed.")

    if writes is False:
        test.fail("Write file to mounted filesystem failed.")
    logging.info("Create %s successfully.", path)

    # Copy file to host
    tar_out_result = vt.tar_out(file_dir, path_on_host)
    logging.debug(tar_out_result)
    if tar_out_result.exit_status:
        test.fail("Tar out failed.")
    logging.info("Tar out successfully.")

    # uncompress file and check file in it.
    uc_result = process.run("cd %s && tar xf %s" % (file_dir, path_on_host),
                            shell=True)
    logging.debug(uc_result)
    try:
        os.remove(path_on_host)
    except IOError as detail:
        test.fail(str(detail))
    if uc_result.exit_status:
        test.fail("uncompress file on host failed.")
    logging.info("uncompress file on host successfully.")

    # Check file
    cat_result = process.run("cat %s" % path, ignore_status=True, shell=True)
    logging.debug(cat_result)
    try:
        os.remove(path)
    except IOError as detail:
        logging.error(detail)
    if cat_result.exit_status:
        test.fail("Cat file failed.")
    else:
        if not re.search(content, cat_result.stdout_text):
            test.fail("Catted file do not match.")
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:60,代码来源:virt_file_operations.py

示例5: remove

 def remove(self, name):
     info = name
     # ugly workaround for nfs which unable to umount
     #os.system('systemctl restart nfs')
     if not umount(info['src'], info['mount_point'], info['fstype'],
                   verbose=False):
         raise Exception("Failed to unmount %s" % info['mount_point'])
开发者ID:cheneydc,项目名称:virt-test-ci,代码行数:7,代码来源:ci.py

示例6: file_exists

def file_exists(params, filename_path):
    sg_uri = create_gluster_uri(params, stripped=True)
    g_uri = create_gluster_uri(params, stripped=False)
    # Using directly /tmp dir because directory should be really temporary and
    # should be deleted immediately when no longer needed and
    # created directory don't file tmp dir by any data.
    tmpdir = "gmount-%s" % (utils_misc.generate_random_string(6))
    tmpdir_path = os.path.join(data_dir.get_tmp_dir(), tmpdir)
    while os.path.exists(tmpdir_path):
        tmpdir = "gmount-%s" % (utils_misc.generate_random_string(6))
        tmpdir_path = os.path.join(data_dir.get_tmp_dir(), tmpdir)
    ret = False
    try:
        try:
            os.mkdir(tmpdir_path)
            glusterfs_mount(sg_uri, tmpdir_path)
            mount_filename_path = os.path.join(tmpdir_path,
                                               filename_path[len(g_uri):])
            if os.path.exists(mount_filename_path):
                ret = True
        except Exception as e:
            logging.error("Failed to mount gluster volume %s to"
                          " mount dir %s: %s" % (sg_uri, tmpdir_path, e))
    finally:
        if utils_misc.umount(sg_uri, tmpdir_path, "glusterfs", False,
                             "fuse.glusterfs"):
            try:
                os.rmdir(tmpdir_path)
            except OSError:
                pass
        else:
            logging.warning("Unable to unmount tmp directory %s with glusterfs"
                            " mount.", tmpdir_path)
    return ret
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:34,代码来源:gluster.py

示例7: backup_img_chain

 def backup_img_chain(image_file):
     """
     Backup whole image in a image chain;
     """
     mount_point = tempfile.mkdtemp(dir=test.resultsdir)
     qemu_img = utils_misc.get_qemu_img_binary(params)
     if enable_gluster:
         g_uri = gluster.create_gluster_uri(params)
         gluster.glusterfs_mount(g_uri, mount_point)
         image_name = os.path.basename(image_file)
         image_file = os.path.join(mount_point, image_name)
     logging.warn("backup %s to %s" % (image_file, test.resultsdir))
     shutil.copy(image_file, test.resultsdir)
     backing_file = _info(qemu_img, image_file, "backing file", None)
     if backing_file:
         backup_img_chain(backing_file)
     elif enable_gluster:
         utils_misc.umount(g_uri, mount_point, "glusterfs", False, "fuse.glusterfs")
         shutil.rmtree(mount_point)
     return None
开发者ID:uni-peter-zheng,项目名称:tp-qemu,代码行数:20,代码来源:qemu_img.py

示例8: test_virt_copy_out

def test_virt_copy_out(vm, params):
    """
    1) Write a tempfile to guest
    2) Copy file to host with copy-out
    3) Delete created file
    4) Check file on host
    """
    content = "This is file for test of virt-copy-out."
    path = params.get("vt_temp_file", "/tmp/test_virt_copy_out")
    path_dir = os.path.dirname(path)

    vt = utils_test.libguestfs.VirtTools(vm, params)
    mountpoint = params.get("vt_mountpoint")
    if mountpoint is None:
        tmpdir = "gmount-%s" % (utils_misc.generate_random_string(6))
        mountpoint = "/tmp/%s" % tmpdir
        if not os.path.exists(mountpoint):
            os.mkdir(mountpoint)

    writes, writeo = vt.write_file_with_guestmount(mountpoint, path, content,
                                                   cleanup=False)
    if utils_misc.umount("", mountpoint, "") is False:
        logging.error("Umount vm's filesytem failed.")

    if writes is False:
        raise error.TestFail("Write file to mounted filesystem failed.")
    logging.info("Create %s successfully.", path)

    # Copy file to host
    copy_out_result = vt.copy_out(path, path_dir)
    logging.debug(copy_out_result)
    if copy_out_result.exit_status:
        raise error.TestFail("Copy out failed.")
    logging.info("Copy out successfully.")

    # Check file
    cat_result = utils.run("cat %s" % path, ignore_status=True)
    logging.debug(cat_result.stdout)
    try:
        os.remove(path)
    except IOError, detail:
        logging.error(detail)
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:42,代码来源:virt_file_operations.py

示例9: recover

 def recover(self, params):
     """
     Recover test environment
     """
     abnormal_type = params.get("abnormal_type")
     cpu_enable = True if self.cpu_status else False
     utils_misc.set_cpu_status(self.cpu_num, cpu_enable)
     if virsh.domain_exists(self.vm_new_name):
         virsh.remove_domain(self.vm_new_name)
     if os.path.exists(self.new_image_file):
         os.remove(self.new_image_file)
     if self.twice_execute:
         if virsh.domain_exists(self.vm_new_name1):
             virsh.remove_domain(self.vm_new_name1)
         if os.path.exists(self.new_image_file1):
             os.remove(self.new_image_file1)
     if abnormal_type == "memory_lack":
         if 'memory_pid' in params:
             pid = params.get('memory_pid')
             utils_misc.safe_kill(pid, signal.SIGKILL)
             process.run("swapon -a", shell=True)
         tmp_c_file = params.get("tmp_c_file", "/tmp/test.c")
         tmp_exe_file = params.get("tmp_exe_file", "/tmp/test")
         if os.path.exists(tmp_c_file):
             os.remove(tmp_c_file)
         if os.path.exists(tmp_exe_file):
             os.remove(tmp_exe_file)
     elif abnormal_type in ["disk_lack", ""]:
         if self.selinux_enforcing:
             utils_selinux.set_status("enforcing")
         tmp_file = os.path.join(self.mount_dir, "tmp")
         if os.path.exists(tmp_file):
             os.remove(tmp_file)
         # Sometimes one umount action is not enough
         utils_misc.wait_for(lambda: utils_misc.umount(self.partition,
                                                       self.mount_dir,
                                                       self.fs_type), 120)
         if self.iscsi_dev:
             self.iscsi_dev.cleanup()
         os.rmdir(self.mount_dir)
     remove_machine_cgroup()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:41,代码来源:resource_abnormal.py

示例10: test_unformatted_part

def test_unformatted_part(vm, params):
    """
    1) Do some necessary check
    2) Format additional disk without filesystem type
    3) Try to mount device
    """
    add_device = params.get("gf_additional_device", "/dev/vdb")
    device_in_lgf = utils.run("echo %s | sed -e 's/vd/sd/g'" % add_device,
                              ignore_status=True).stdout.strip()

    device_part = "%s1" % device_in_lgf
    # Mount specific partition
    params['special_mountpoints'] = [device_part]
    vt = utils_test.libguestfs.VirtTools(vm, params)
    # Create a new vm with additional disk
    vt.update_vm_disk()
    # Default vm_ref is oldvm, so switch it.
    vm_ref = vt.newvm.name

    # Format disk
    format_result = vt.format_disk()
    if format_result.exit_status:
        raise error.TestFail("Format added disk failed.")
    logging.info("Format added disk successfully.")

    # List filesystems detail
    list_fs_detail = vt.get_filesystems_info(vm_ref)
    if list_fs_detail.exit_status:
        raise error.TestFail("List filesystems detail failed:"
                             "%s" % list_fs_detail)
    logging.info("List filesystems detail successfully.")

    mountpoint = params.get("vt_mountpoint", "/mnt")
    mounts, mounto = vt.guestmount(mountpoint, vm_ref)
    if utils_misc.umount("", mountpoint, "") and mounts:
        raise error.TestFail("Mount vm's filesytem successfully, "
                             "but not expected.")
    logging.info("Mount vm's filesystem failed as expected.")
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:38,代码来源:virt_part_operations.py

示例11:

                    else:
                        if shp_num == 0 and started_anon <= 0:
                            raise error.TestFail("VM doesn't use transparent"
                                                 " hugepage, while static"
                                                 " hugepage is disabled")
    finally:
        # end up session
        for session in sessions:
            session.close()

        for vm in vms:
            if vm.is_alive():
                vm.destroy()

        for vm_name in vm_names:
            if mb_enable:
                vm_xml.VMXML.del_memoryBacking_tag(vm_name)
            else:
                vm_xml.VMXML.set_memoryBacking_tag(vm_name)

        utils_libvirtd.libvirtd_restart()

        if tlbfs_enable is True:
            if tlbfs_status is not True:
                utils_misc.umount("hugetlbfs", "/dev/hugepages", "hugetlbfs")
        else:
            if tlbfs_status is True:
                utils_misc.mount("hugetlbfs", "/dev/hugepages", "hugetlbfs")
        utils_memory.set_num_huge_pages(shp_orig_num)
        utils_memory.set_transparent_hugepage(thp_orig_status)
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:30,代码来源:libvirt_hugepage.py

示例12: test_formatted_part

def test_formatted_part(test, vm, params):
    """
    1) Do some necessary check
    2) Format additional disk with specific filesystem
    3) Try to write a file to mounted device and get md5
    4) Login to check writed file and its md5
    """
    add_device = params.get("gf_additional_device", "/dev/vdb")
    device_in_lgf = process.run("echo %s | sed -e 's/vd/sd/g'" % add_device,
                                ignore_status=True, shell=True).stdout_text.strip()
    if utils_test.libguestfs.primary_disk_virtio(vm):
        device_in_vm = add_device
    else:
        device_in_vm = "/dev/vda"

    device_part = "%s1" % device_in_lgf
    device_part_in_vm = "%s1" % device_in_vm
    # Mount specific partition
    params['special_mountpoints'] = [device_part]
    vt = utils_test.libguestfs.VirtTools(vm, params)
    # Create a new vm with additional disk
    vt.update_vm_disk()
    # Default vm_ref is oldvm, so switch it.
    vm_ref = vt.newvm.name

    # Format disk
    format_result = vt.format_disk(filesystem="ext3", partition="mbr")
    if format_result.exit_status:
        test.fail("Format added disk failed.")
    logging.info("Format added disk successfully.")

    # List filesystems detail
    list_fs_detail = vt.get_filesystems_info(vm_ref)
    if list_fs_detail.exit_status:
        test.fail("List filesystems detail failed.")
    logging.info("List filesystems detail successfully.")

    content = "This is file for formatted part test."
    path = params.get("temp_file", "formatted_part")
    mountpoint = params.get("vt_mountpoint", "/mnt")

    writes, writeo = vt.write_file_with_guestmount(mountpoint, path,
                                                   content, vm_ref,
                                                   cleanup=False)
    if writes is False:
        utils_misc.umount("", mountpoint, "")
        test.fail("Write file to mounted filesystem failed.")
    logging.info("Create %s successfully.", writeo)

    # Compute new file's md5
    if os.path.isfile(writeo):
        md5s, md5o = process.getstatusoutput("md5sum %s" % writeo)
        utils_misc.umount("", mountpoint, "")
        if md5s:
            test.fail("Compute %s's md5 failed." % writeo)
        md5 = md5o.split()[0].strip()
        logging.debug("%s's md5 in newvm is:%s", writeo, md5)
    else:
        utils_misc.umount("", mountpoint, "")
        test.fail("Can not find %s." % writeo)

    attached_vm = vt.newvm
    try:
        attached_vm.start()
        session = attached_vm.wait_for_login()
    except Exception as detail:
        attached_vm.destroy()
        test.fail(str(detail))

    try:
        file_path = os.path.join(mountpoint, path)
        mounts = session.cmd_status("mount %s %s" % (device_part_in_vm,
                                                     mountpoint), timeout=10)
        if mounts:
            logging.error("Mount device in vm failed.")
        md51 = session.cmd_output("md5sum %s" % file_path)
        logging.debug(md51)
        if not re.search(md5o, md51):
            attached_vm.destroy()
            attached_vm.wait_for_shutdown()
            test.fail("Got a different md5.")
        logging.info("Got matched md5.")
        session.cmd_status("cat %s" % file_path, timeout=5)
        attached_vm.destroy()
        attached_vm.wait_for_shutdown()
    except (virt_vm.VMError, remote.LoginError, aexpect.ShellError) as detail:
        if attached_vm.is_alive():
            attached_vm.destroy()
        if not re.search(content, str(detail)):
            test.fail(str(detail))
    logging.info("Check file on guest successfully.")
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:91,代码来源:virt_part_operations.py

示例13: run


#.........这里部分代码省略.........
            pass
        else:
            v2v_options += " -v -x"

        # Prepare for libvirt unprivileged user session connection
        if "qemu:///session" in v2v_options:
            try:
                pwd.getpwnam(v2v_user)
            except KeyError:
                # create new user
                process.system("useradd %s" % v2v_user, ignore_status=True)
                new_v2v_user = True
            user_info = pwd.getpwnam(v2v_user)
            logging.info("Convert to qemu:///session by user '%s'", v2v_user)
            if input_mode == "disk":
                # Change the image owner and group
                ori_owner = os.stat(disk_img).st_uid
                ori_group = os.stat(disk_img).st_uid
                os.chown(disk_img, user_info.pw_uid, user_info.pw_gid)
                restore_image_owner = True
            else:
                raise exceptions.TestNAError("Only support convert local disk")

        # Setup ssh-agent access to xen hypervisor
        if hypervisor == 'xen':
            os.environ['LIBGUESTFS_BACKEND'] = 'direct'
            user = params.get("xen_host_user", "root")
            passwd = params.get("xen_host_passwd", "redhat")
            logging.info("set up ssh-agent access ")
            ssh_key.setup_ssh_key(remote_host, user=user,
                                  port=22, password=passwd)
            utils_misc.add_identities_into_ssh_agent()
            # If the input format is not define, we need to either define
            # the original format in the source metadata(xml) or use '-of'
            # to force the output format, see BZ#1141723 for detail.
            if '-of' not in v2v_options and checkpoint != 'xen_no_output_format':
                v2v_options += ' -of %s' % params.get("default_output_format",
                                                      "qcow2")

        # Create password file for access to ESX hypervisor
        if hypervisor == 'esx':
            os.environ['LIBGUESTFS_BACKEND'] = 'direct'
            vpx_passwd = params.get("vpx_passwd")
            vpx_passwd_file = os.path.join(test.tmpdir, "vpx_passwd")
            logging.info("Building ESX no password interactive verification.")
            pwd_f = open(vpx_passwd_file, 'w')
            pwd_f.write(vpx_passwd)
            pwd_f.close()
            output_option += " --password-file %s" % vpx_passwd_file

        # Create libvirt dir pool
        if output_mode == "libvirt":
            create_pool()

        # Running virt-v2v command
        cmd = "%s %s %s %s" % (utils_v2v.V2V_EXEC, input_option,
                               output_option, v2v_options)
        if v2v_user:
            cmd = su_cmd + "'%s'" % cmd
        cmd_result = process.run(cmd, timeout=v2v_timeout, verbose=True,
                                 ignore_status=True)
        if new_vm_name:
            vm_name = new_vm_name
            params['main_vm'] = new_vm_name
        check_result(cmd, cmd_result, status_error)
    finally:
        if hypervisor == "xen":
            process.run("ssh-agent -k")
        if hypervisor == "esx":
            process.run("rm -rf %s" % vpx_passwd_file)
        for vdsm_dir in [vdsm_domain_dir, vdsm_image_dir, vdsm_vm_dir]:
            if os.path.exists(vdsm_dir):
                shutil.rmtree(vdsm_dir)
        if os.path.exists(mnt_point):
            utils_misc.umount(nfs_storage, mnt_point, "nfs")
            os.rmdir(mnt_point)
        if output_mode == "local":
            image_name = vm_name + "-sda"
            img_file = os.path.join(output_storage, image_name)
            xml_file = img_file + ".xml"
            for local_file in [img_file, xml_file]:
                if os.path.exists(local_file):
                    os.remove(local_file)
        if output_mode == "libvirt":
            if "qemu:///session" in v2v_options:
                cmd = su_cmd + "'virsh undefine %s'" % vm_name
                process.system(cmd)
            else:
                virsh.remove_domain(vm_name)
            cleanup_pool()
        vmcheck_flag = params.get("vmcheck_flag")
        if vmcheck_flag:
            vmcheck = utils_v2v.VMCheck(test, params, env)
            vmcheck.cleanup()
        if new_v2v_user:
            process.system("userdel -f %s" % v2v_user)
        if restore_image_owner:
            os.chown(disk_img, ori_owner, ori_group)
        if backup_xml:
            backup_xml.sync()
开发者ID:chloerh,项目名称:tp-libvirt,代码行数:101,代码来源:v2v_options.py

示例14: run


#.........这里部分代码省略.........
        if output_mode == "libvirt":
            create_pool()

        # Work around till bug fixed
        os.environ['LIBGUESTFS_BACKEND'] = 'direct'

        if checkpoint in ['with_ic', 'without_ic']:
            new_v2v_user = True
            v2v_options += ' -on %s' % new_vm_name
            create_pool(user_pool=True, pool_name='src_pool', pool_target='v2v_src_pool')
            create_pool(user_pool=True)
            logging.debug(virsh.pool_list(uri='qemu:///session'))
            sh_install_vm = params.get('sh_install_vm')
            if not sh_install_vm:
                test.error('Source vm installing script missing')
            with open(sh_install_vm) as fh:
                cmd_install_vm = fh.read().strip()
            process.run('su - %s -c "%s"' % (v2v_user, cmd_install_vm),
                        timeout=10, shell=True)

        if checkpoint == 'vmx':
            mount_point = params.get('mount_point')
            if not os.path.isdir(mount_point):
                os.mkdir(mount_point)
            nfs_vmx = params.get('nfs_vmx')
            if not utils_misc.mount(nfs_vmx, mount_point, 'nfs', verbose=True):
                test.error('Mount nfs for vmx failed')
            vmx = params.get('vmx')
            input_option = '-i vmx %s' % vmx
            v2v_options += " -b %s -n %s" % (params.get("output_bridge"),
                                             params.get("output_network"))

        # Running virt-v2v command
        cmd = "%s %s %s %s" % (utils_v2v.V2V_EXEC, input_option,
                               output_option, v2v_options)
        if v2v_user:
            cmd = su_cmd + "'%s'" % cmd

        if params.get('cmd_free') == 'yes':
            cmd = params.get('check_command')

        # Set timeout to kill v2v process before conversion succeed
        if checkpoint == 'disk_not_exist':
            v2v_timeout = 30
        # Get tail content of /var/log/messages
        if checkpoint == 'tail_log':
            params['tail_log'] = os.path.join(data_dir.get_tmp_dir(), 'tail_log')
            params['tail'] = aexpect.Tail(
                    command='tail -f /var/log/messages',
                    output_func=utils_misc.log_line,
                    output_params=(params['tail_log'],)
            )
        cmd_result = process.run(cmd, timeout=v2v_timeout, verbose=True,
                                 ignore_status=True)
        if new_vm_name:
            vm_name = new_vm_name
            params['main_vm'] = new_vm_name
        check_result(cmd, cmd_result, status_error)
    finally:
        if hypervisor == "xen":
            process.run("ssh-agent -k")
        if hypervisor == "esx":
            process.run("rm -rf %s" % vpx_passwd_file)
        for vdsm_dir in [vdsm_domain_dir, vdsm_image_dir, vdsm_vm_dir]:
            if os.path.exists(vdsm_dir):
                shutil.rmtree(vdsm_dir)
        if os.path.exists(mnt_point):
            utils_misc.umount(nfs_storage, mnt_point, "nfs")
            os.rmdir(mnt_point)
        if output_mode == "local":
            image_name = vm_name + "-sda"
            img_file = os.path.join(output_storage, image_name)
            xml_file = img_file + ".xml"
            for local_file in [img_file, xml_file]:
                if os.path.exists(local_file):
                    os.remove(local_file)
        if output_mode == "libvirt":
            if "qemu:///session" in v2v_options or no_root:
                cmd = su_cmd + "'virsh undefine %s'" % vm_name
                try:
                    process.system(cmd)
                except:
                    logging.error('Undefine "%s" failed', vm_name)
                if no_root:
                    cleanup_pool(user_pool=True, pool_name='src_pool', pool_target='v2v_src_pool')
                    cleanup_pool(user_pool=True)
            else:
                virsh.remove_domain(vm_name)
            cleanup_pool()
        vmcheck_flag = params.get("vmcheck_flag")
        if vmcheck_flag:
            vmcheck = utils_v2v.VMCheck(test, params, env)
            vmcheck.cleanup()
        if new_v2v_user:
            process.system("userdel -f %s" % v2v_user)
        if backup_xml:
            backup_xml.sync()
        if checkpoint == 'vmx':
            utils_misc.umount(params['nfs_vmx'], params['mount_point'], 'nfs')
            os.rmdir(params['mount_point'])
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:101,代码来源:v2v_options.py

示例15: test_formatted_part

def test_formatted_part(vm, params):
    """
    1) Do some necessary check
    2) Format additional disk with specific filesystem
    3) Try to write a file to mounted device and get md5
    4) Login to check writed file and its md5
    """
    add_device = params.get("gf_additional_device", "/dev/vdb")
    device_in_lgf = utils.run("echo %s | sed -e 's/vd/sd/g'" % add_device,
                              ignore_status=True).stdout.strip()
    if utils_test.libguestfs.primary_disk_virtio(vm):
        device_in_vm = add_device
    else:
        device_in_vm = "/dev/vda"

    device_part = "%s1" % device_in_lgf
    device_part_in_vm = "%s1" % device_in_vm
    # Mount specific partition
    params['special_mountpoints'] = [device_part]
    vt = utils_test.libguestfs.VirtTools(vm, params)
    # Create a new vm with additional disk
    vt.update_vm_disk()
    # Default vm_ref is oldvm, so switch it.
    vm_ref = vt.newvm.name

    # Format disk
    format_result = vt.format_disk(filesystem="ext3", partition="mbr")
    if format_result.exit_status:
        raise error.TestFail("Format added disk failed.")
    logging.info("Format added disk successfully.")

    # List filesystems detail
    list_fs_detail = vt.get_filesystems_info(vm_ref)
    if list_fs_detail.exit_status:
        raise error.TestFail("List filesystems detail failed.")
    logging.info("List filesystems detail successfully.")

    content = "This is file for formatted part test."
    path = params.get("temp_file", "formatted_part")
    mountpoint = params.get("vt_mountpoint", "/mnt")

    writes, writeo = vt.write_file_with_guestmount(mountpoint, path,
                                                   content, vm_ref,
                                                   cleanup=False)
    if writes is False:
        utils_misc.umount("", mountpoint, "")
        raise error.TestFail("Write file to mounted filesystem failed.")
    logging.info("Create %s successfully.", writeo)

    # Compute new file's md5
    if os.path.isfile(writeo):
        md5s, md5o = commands.getstatusoutput("md5sum %s" % writeo)
        utils_misc.umount("", mountpoint, "")
        if md5s:
            raise error.TestFail("Compute %s's md5 failed." % writeo)
        md5 = md5o.split()[0].strip()
        logging.debug("%s's md5 in newvm is:%s", writeo, md5)
    else:
        utils_misc.umount("", mountpoint, "")
        raise error.TestFail("Can not find %s." % writeo)

    attached_vm = vt.newvm
    try:
        attached_vm.start()
        session = attached_vm.wait_for_login()
    except Exception, detail:
        attached_vm.destroy()
        raise error.TestFail(str(detail))
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:68,代码来源:virt_part_operations.py


注:本文中的virttest.utils_misc.umount函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。