From: Royce Lv <lvroyce(a)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(a)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