Skip to content

Commit

Permalink
If no NFS ACLs provided, assume everyone:
Browse files Browse the repository at this point in the history
Some QNAP devices do not provide ACL when fetching NFS mounts.
In this case the assumed ACL should be: "*".

This commit fixes the crash when attempting to access the non existing ACL.
Relevant issues:
- xapi-project#511
- xcp-ng/xcp#113
  • Loading branch information
benjamreis authored and stormi committed Feb 25, 2021
1 parent 327f349 commit a6b5af8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ def scan_exports(target):
textnode = dom.createTextNode(target)
subentry.appendChild(textnode)

(path, access) = val.split()
# Access is not always provided by showmount return
# If none is provided we need to assume "*"
array = val.split()
path = array[0]
access = array[1] if len(array) >= 2 else "*"
subentry = dom.createElement("Path")
entry.appendChild(subentry)
textnode = dom.createTextNode(path)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,33 @@ def test_validate_nfsversion_valid(self):
for thenfsversion in ['3', '4', '4.1']:
self.assertEquals(nfs.validate_nfsversion(thenfsversion),
thenfsversion)

# Can't use autospec due to http://bugs.python.org/issue17826
@mock.patch('util.pread2')
def test_scan_exports(self, pread2):
pread2.side_effect = ["/srv/nfs\n/srv/nfs2 *\n/srv/nfs3 127.0.0.1/24"]
res = nfs.scan_exports('aServer')

expected = """<?xml version="1.0" ?>
<nfs-exports>
\t<Export>
\t\t<Target>aServer</Target>
\t\t<Path>/srv/nfs</Path>
\t\t<Accesslist>*</Accesslist>
\t</Export>
\t<Export>
\t\t<Target>aServer</Target>
\t\t<Path>/srv/nfs2</Path>
\t\t<Accesslist>*</Accesslist>
\t</Export>
\t<Export>
\t\t<Target>aServer</Target>
\t\t<Path>/srv/nfs3</Path>
\t\t<Accesslist>127.0.0.1/24</Accesslist>
\t</Export>
</nfs-exports>
"""

self.assertEqual(res.toprettyxml(), expected)
self.assertEqual(len(pread2.mock_calls), 1)
pread2.assert_called_with(['/usr/sbin/showmount', '--no-headers', '-e', 'aServer'])

0 comments on commit a6b5af8

Please sign in to comment.