def prepare(self, conn): mnt_point = tempfile.mkdtemp(dir='/tmp') export_path = "%s:%s" % (self.poolArgs['source']['host'], self.poolArgs['source']['path']) mount_cmd = [ "mount", "-o", 'soft,timeo=100,retrans=3,retry=0', export_path, mnt_point ] umount_cmd = ["umount", "-f", export_path] mounted = False # Due to an NFS bug (See Red Hat BZ 1023059), NFSv4 exports may take # 10-15 seconds to mount the first time. cmd_timeout = 15 with RollbackContext() as rollback: rollback.prependDefer(os.rmdir, mnt_point) try: run_command(mount_cmd, cmd_timeout) rollback.prependDefer(run_command, umount_cmd, cmd_timeout) except TimeoutExpired: raise InvalidParameter("KCHPOOL0012E", {'path': export_path}) with open("/proc/mounts", "rb") as f: rawMounts = f.read() output_items = ['dev_path', 'mnt_point', 'type'] mounts = parse_cmd_output(rawMounts, output_items) for item in mounts: if 'dev_path' in item and item['dev_path'] == export_path: mounted = True if not mounted: raise InvalidParameter("KCHPOOL0013E", {'path': export_path})
def prepare(self, conn): mnt_point = tempfile.mkdtemp(dir='/tmp') export_path = "%s:%s" % ( self.poolArgs['source']['host'], self.poolArgs['source']['path']) mount_cmd = ["mount", "-o", 'soft,timeo=100,retrans=3,retry=0', export_path, mnt_point] umount_cmd = ["umount", "-f", export_path] mounted = False # Due to an NFS bug (See Red Hat BZ 1023059), NFSv4 exports may take # 10-15 seconds to mount the first time. cmd_timeout = 15 with RollbackContext() as rollback: rollback.prependDefer(os.rmdir, mnt_point) try: run_command(mount_cmd, cmd_timeout) rollback.prependDefer(run_command, umount_cmd, cmd_timeout) except TimeoutExpired: raise InvalidParameter("KCHPOOL0012E", {'path': export_path}) with open("/proc/mounts", "rb") as f: rawMounts = f.read() output_items = ['dev_path', 'mnt_point', 'type'] mounts = parse_cmd_output(rawMounts, output_items) for item in mounts: if 'dev_path' in item and item['dev_path'] == export_path: mounted = True if not mounted: raise InvalidParameter("KCHPOOL0013E", {'path': export_path})