[PATCHv4 0/2] NFS prevalidation

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Note, this patchset depends on: [PATCH V3] add a synchronous function with timeout to execute command v1>v4, Address naming comments, integrate run_command patch and use context manager to deal with umount Royce Lv (2): utils: Add nfs prevalication Integrate nfs path check before create nfs pool src/kimchi/model.py | 30 ++++++++++++++++++++++++++++-- src/kimchi/utils.py | 8 ++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) -- 1.8.1.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Abstract a helper function to parse cmd result. Usage: (1)get cmd result with subprocess.call or subprocess.Popen (2) call pass_cmd_output to get formated outputs Example: blkid = subprocess.Popen(["cat", "/proc/mounts"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) outs = blkid.communicate()[0] output_items= ['path', 'mnt_point', 'type', 'option'] utils.parse_cmd_output(outs, output_items) Sample output: [{'path': '/dev/sda8', 'type': 'ext4', 'option': 'rw,relatime,data=ordered', 'mnt_point': '/home'}, {'path': 'localhost:/home/royce/isorepo', 'type': 'nfs4', 'option': 'rw...addr=127.0.0.1', 'mnt_point': '/mnt'}] To prevent future mount of nfs path will hang, we will try nfs path with a quick mount, if this check fails, report warning to user. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index 331da91..5d6e8ea 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -154,3 +154,11 @@ def run_command(cmd, timeout=None): finally: if timer and not timeout_flag[0]: timer.cancel() + + +def parse_cmd_output(output, output_items): + res = [] + for line in output.split("\n"): + res.append(dict(zip(output_items, line.split()))) + + return res -- 1.8.1.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Before creating nfs pool, reload the prevalidation for the path and see if it is able to complish a quick mount. If not, deny this storage pool from being created. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 671af02..ee604d5 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -68,9 +68,11 @@ from kimchi.featuretests import FeatureTests from kimchi.iscsi import TargetClient from kimchi.isoinfo import IsoImage from kimchi.objectstore import ObjectStore +from kimchi.rollbackcontext import RollbackContext from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log +from kimchi.utils import run_command, parse_cmd_output from kimchi.vmtemplate import VMTemplate @@ -1557,8 +1559,32 @@ class NetfsPoolDef(StoragePoolDef): self.path = '/var/lib/kimchi/nfs_mount/' + self.poolArgs['name'] def prepare(self, conn): - # TODO: Verify the NFS export can be actually mounted. - pass + 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, self.path] + umount_cmd = ["umount", "-f", export_path] + mounted = False + + if not os.path.isdir(self.path): + os.mkdir(self.path) + + + with RollbackContext() as rollback: + run_command(mount_cmd, 30) + rollback.prependDefer(run_command, umount_cmd) + + 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( + "Export path %s may block during nfs mount" % export_path) @property def xml(self): -- 1.8.1.2
participants (1)
-
lvroyce@linux.vnet.ibm.com