RemoteFS: Use summarize option for "du"

Only return the total from du rather than
a full listing.

The parsing code here expects du's output to
only be one line.

Closes-Bug: #1781276

Change-Id: Id398ad1ce3f30ccc029bfcfb1663654946d42c91
This commit is contained in:
Eric Harney 2018-07-11 15:39:17 -04:00
parent 7a403f5fdf
commit 48a61877ce
2 changed files with 15 additions and 1 deletions

View File

@ -692,6 +692,20 @@ class NfsDriverTestCase(test.TestCase):
provider_location=loc,
size=size)
def test_get_provisioned_capacity(self):
self._set_driver()
drv = self._driver
mock_execute = self.mock_object(drv, '_execute')
mock_execute.return_value = ("148418423\t/dir", "")
with mock.patch.object(drv, 'shares') as shares:
shares.keys.return_value = {'192.0.2.1:/srv/nfs1'}
shares.return_value = {'192.0.2.1:/srv/nfs1', ''}
ret = drv._get_provisioned_capacity()
self.assertEqual(ret, 0.14)
def test_create_sparsed_volume(self):
self._set_driver()
drv = self._driver

View File

@ -217,7 +217,7 @@ class RemoteFSDriver(driver.BaseVD):
provisioned_size = 0.0
for share in self.shares.keys():
mount_path = self._get_mount_point_for_share(share)
out, _ = self._execute('du', '--bytes', mount_path,
out, _ = self._execute('du', '--bytes', '-s', mount_path,
run_as_root=self._execute_as_root)
provisioned_size += int(out.split()[0])
return round(provisioned_size / units.Gi, 2)