[Kimchi-devel] [PATCHv3 2/2] Integrate nfs path check before create nfs pool

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Jan 13 10:40:27 UTC 2014


From: Royce Lv <lvroyce at 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 at linux.vnet.ibm.com>
---
 src/kimchi/model.py | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index 671af02..189b2d3 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -70,7 +70,7 @@ from kimchi.isoinfo import IsoImage
 from kimchi.objectstore import ObjectStore
 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 get_enabled_plugins, is_digit, kimchi_log, parse_cmd_output
 from kimchi.vmtemplate import VMTemplate
 
 
@@ -1557,8 +1557,39 @@ 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
+        # FIXME: When run_cmd helper function is ready
+        # this needs to be re-write based on context manager and helper.
+        res = False
+        outputs = None
+        if not os.path.isdir(self.path):
+            os.mkdir(self.path)
+        export_path = "%s:%s" % (
+            self.poolArgs['source']['host'], self.poolArgs['source']['path'])
+        cmd = ["mount", "-o", 'soft,timeo=100,retrans=3,retry=0',
+               export_path, self.path]
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                stderr=subprocess.PIPE)
+        thread = threading.Thread(target = proc.communicate)
+        thread.start()
+        thread.join(30)
+
+        if thread.is_alive():
+            proc.kill()
+            thread.join()
+
+        with open("/proc/mounts" , "rb") as f:
+            outputs = f.read()
+        output_items = ['dev_path', 'mnt_point', 'type']
+        mounts = parse_cmd_output(outputs, output_items)
+        for item in mounts:
+            if 'dev_path' in item and item['dev_path'] == export_path:
+                res =  True
+        cmd = ["umount", "-f", export_path]
+        subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        if not res:
+            raise InvalidParameter(
+                "Export path %s may block during nfs mount" % export_path)
 
     @property
     def xml(self):
-- 
1.8.1.2




More information about the Kimchi-devel mailing list