Skip to content

Commit

Permalink
Merge 7d63a8c into 08d4951
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthv committed Jul 17, 2015
2 parents 08d4951 + 7d63a8c commit a1dc5be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
22 changes: 11 additions & 11 deletions drivers/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def check_server_tcp(server, nfsversion=DEFAULT_NFSVERSION):
False otherwise.
"""
try:
util.ioretry(lambda: util.pread([RPCINFO_BIN, "-t",
"%s" % server, "nfs", nfsversion]),
errlist=[errno.EPERM], maxretry=2, nofail=True)
sv = get_supported_nfs_versions(server)
return (True if nfsversion in sv else False)
except util.CommandException, inst:
raise NfsException("rpcinfo failed or timed out: return code %d" %
inst.code)
Expand Down Expand Up @@ -207,14 +206,15 @@ def scan_srlist(path, dconf):

def get_supported_nfs_versions(server):
"""Return list of supported nfs versions."""
valid_versions = ['3', '4']
supported_versions = []
valid_versions = set(['3', '4'])
cv = set()
try:
ns = util.pread2([RPCINFO_BIN, "-t", "%s" % server, "nfs"])
for l in ns.strip().split("\n"):
if l.split()[3] in valid_versions:
supported_versions.append(l.split()[3])

return supported_versions
ns = util.pread2([RPCINFO_BIN, "-p", "%s" % server])
ns = ns.split("\n")
for i in range(len(ns)):
if ns[i].find("nfs") > 0:
cvi = ns[i].split()[1]
cv.add(cvi)
return list(cv & valid_versions)
except:
util.SMlog("Unable to obtain list of valid nfs versions")
6 changes: 2 additions & 4 deletions tests/test_nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ class Test_nfs(unittest.TestCase):
def test_check_server_tcp(self, pread):
nfs.check_server_tcp('aServer')

pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-t', 'aServer',
'nfs', '3'])
pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-p', 'aServer'], quiet=False)

@mock.patch('util.pread')
def test_check_server_tcp_nfsversion(self, pread):
nfs.check_server_tcp('aServer', 'aNfsversion')

pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-t', 'aServer',
'nfs', 'aNfsversion'])
pread.assert_called_once_with(['/usr/sbin/rpcinfo', '-p', 'aServer'], quiet=False)

def get_soft_mount_pread(self, binary, vers):
return ([binary, 'remoteserver:remotepath', 'mountpoint', '-o',
Expand Down

0 comments on commit a1dc5be

Please sign in to comment.