From 48a61877cee8665c96a16025e33b693636e9a359 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 11 Jul 2018 15:39:17 -0400 Subject: [PATCH] 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 --- cinder/tests/unit/volume/drivers/test_nfs.py | 14 ++++++++++++++ cinder/volume/drivers/remotefs.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/volume/drivers/test_nfs.py b/cinder/tests/unit/volume/drivers/test_nfs.py index da76418bc61..20ed172b424 100644 --- a/cinder/tests/unit/volume/drivers/test_nfs.py +++ b/cinder/tests/unit/volume/drivers/test_nfs.py @@ -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 diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py index f5c5b6c1e99..937041a1d15 100644 --- a/cinder/volume/drivers/remotefs.py +++ b/cinder/volume/drivers/remotefs.py @@ -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)