diff --git a/drivers/nfs.py b/drivers/nfs.py index 5791d55a4..91463d838 100644 --- a/drivers/nfs.py +++ b/drivers/nfs.py @@ -205,7 +205,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 b561e8eea..0e9e8911b 100644 --- a/tests/test_nfs.py +++ b/tests/test_nfs.py @@ -154,3 +154,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'])