Skip to content

Commit

Permalink
CA-273731: call _testHost before trying to mount ISO SR NFS share
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <mark.syms@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
  • Loading branch information
MarkSymsCtx committed Mar 19, 2018
1 parent 8112be2 commit 9a7d669
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drivers/ISOSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 26 additions & 2 deletions tests/test_ISOSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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,
Expand Down

0 comments on commit 9a7d669

Please sign in to comment.