From 9a7d669911acd4a00f743bdfbe886749d9c65793 Mon Sep 17 00:00:00 2001 From: Mark Syms Date: Mon, 19 Mar 2018 15:27:49 +0000 Subject: [PATCH] CA-273731: call _testHost before trying to mount ISO SR NFS share Signed-off-by: Mark Syms Reviewed-by: Chandrika Srinivasan --- drivers/ISOSR.py | 2 ++ tests/test_ISOSR.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/ISOSR.py b/drivers/ISOSR.py index 57452a674..5bab7bd4a 100755 --- a/drivers/ISOSR.py +++ b/drivers/ISOSR.py @@ -46,6 +46,7 @@ TYPE = "iso" SMB_VERSION_1 = '1.0' SMB_VERSION_3 = '3.0' +NFSPORT = 2049 def is_image_utf8_compatible(s): regex = re.compile("\.iso$|\.img$", re.I) @@ -314,6 +315,7 @@ def attach(self, sr_uuid): # going to be r-only, a failure in nfs link can be reported back # to the process waiting. serv_path = location.split(':') + util._testHost(serv_path[0], NFSPORT, 'NFSTarget') nfs.soft_mount(self.mountpoint, serv_path[0], serv_path[1], 'tcp', useroptions=options, nfsversion=self.nfsversion) diff --git a/tests/test_ISOSR.py b/tests/test_ISOSR.py index 235edc10d..86e52931f 100644 --- a/tests/test_ISOSR.py +++ b/tests/test_ISOSR.py @@ -69,10 +69,11 @@ def test_load_validate_nfsversion_exceptionraised(self, @mock.patch('util._convertDNS', autospec=True) @mock.patch('nfs.validate_nfsversion', autospec=True) @mock.patch('util.makedirs', autospec=True) + @mock.patch('util._testHost', autospec=True) # Can't use autospec due to http://bugs.python.org/issue17826 @mock.patch('ISOSR.ISOSR._checkmount') - def test_attach_nfs(self, _checkmount, makedirs, validate_nfsversion, - convertDNS, soft_mount, gen_uuid): + def test_attach_nfs(self, _checkmount, testHost, makedirs, + validate_nfsversion, convertDNS, soft_mount, gen_uuid): validate_nfsversion.return_value = 'aNfsversionChanged' isosr = self.create_isosr(location='aServer:/aLocation', atype='nfs_iso', sr_uuid='asr_uuid') @@ -88,6 +89,29 @@ def test_attach_nfs(self, _checkmount, makedirs, validate_nfsversion, useroptions='', nfsversion='aNfsversionChanged') + @mock.patch('util.gen_uuid', autospec=True) + @mock.patch('util._convertDNS', autospec=True) + @mock.patch('nfs.validate_nfsversion', autospec=True) + @mock.patch('util.makedirs', autospec=True) + @mock.patch('util._testHost', autospec=True) + # Can't use autospec due to http://bugs.python.org/issue17826 + @mock.patch('ISOSR.ISOSR._checkmount') + def test_attach_nfs_no_server( + self, _checkmount, testHost, makedirs, validate_nfsversion, + convertDNS, gen_uuid): + + isosr = self.create_isosr(location='aServer:/aLocation', atype='nfs_iso', + sr_uuid='asr_uuid') + + _checkmount.side_effect = [False] + testHost.side_effect = SR.SROSError(140, 'Incorrect DNS name, unable to resolve.') + + with self.assertRaises(SR.SROSError) as ose: + isosr.attach(None) + + self.assertEqual(140, ose.exception.errno) + + class TestISOSR_overSMB(unittest.TestCase): def create_smbisosr(self, location='\\aServer\aLocation', atype=None,