From 9fe6a3df3676c9ab8587e8a77d4d28896dc65d07 Mon Sep 17 00:00:00 2001 From: BenjiReis Date: Thu, 25 Feb 2021 09:54:52 +0100 Subject: [PATCH] If no NFS ACLs provided, assume everyone: 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: - https://github.com/xapi-project/sm/issues/511 - https://github.com/xcp-ng/xcp/issues/113 --- drivers/nfs.py | 6 +++++- tests/test_nfs.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/nfs.py b/drivers/nfs.py index 23dca2870..80b71a52a 100644 --- a/drivers/nfs.py +++ b/drivers/nfs.py @@ -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) diff --git a/tests/test_nfs.py b/tests/test_nfs.py index 71800ab0a..cef414fe6 100644 --- a/tests/test_nfs.py +++ b/tests/test_nfs.py @@ -140,3 +140,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 = """ + +\t +\t\taServer +\t\t/srv/nfs +\t\t* +\t +\t +\t\taServer +\t\t/srv/nfs2 +\t\t* +\t +\t +\t\taServer +\t\t/srv/nfs3 +\t\t127.0.0.1/24 +\t + +""" + + self.assertEqual(res.toprettyxml(), expected) + self.assertEqual(len(pread2.mock_calls), 1) + pread2.assert_called_with(['/usr/sbin/showmount', '--no-headers', '-e', 'aServer'])