From 53d15d3bbe8ae5327f3c4ff1752e969afddf8d1b Mon Sep 17 00:00:00 2001 From: Goutham Pacha Ravi Date: Tue, 25 Sep 2018 17:57:50 -0700 Subject: [PATCH] [Container driver] Fix volume group data collection On different distros, the vgs command may have a different format. So, lets ask very specific questions about the total and free size, and use that response. Change-Id: I36e5e3ba7be562846687c7cc989028371efae2fc Needed-By: https://review.openstack.org/#/c/604929/ Closes-Bug: #1794402 --- manila/share/drivers/container/storage_helper.py | 16 +++++++++++++--- .../drivers/container/test_storage_helper.py | 11 ++++++----- ...-stats-container-driver-b3cb1fa2987ad4b1.yaml | 6 ++++++ 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/bug-1794402-fix-share-stats-container-driver-b3cb1fa2987ad4b1.yaml diff --git a/manila/share/drivers/container/storage_helper.py b/manila/share/drivers/container/storage_helper.py index 5db4a11086..3803359247 100644 --- a/manila/share/drivers/container/storage_helper.py +++ b/manila/share/drivers/container/storage_helper.py @@ -52,9 +52,19 @@ class LVMHelper(driver.ExecuteMixin): def get_share_server_pools(self, share_server=None): out, err = self._execute('vgs', self.configuration.container_volume_group, - '--rows', run_as_root=True) - total_size = re.findall("VSize\s[0-9.]+g", out)[0][6:-1] - free_size = re.findall("VFree\s[0-9.]+g", out)[0][6:-1] + '--options', 'vg_size,vg_free', + '--noheadings', + '--units', 'g', + run_as_root=True) + if err: + msg = _("Unable to gather size of the volume group %(vg)s to be " + "used by the driver. Error: %(err)s") + raise exception.ShareBackendException( + msg % {'vg': self.configuration.container_volume_group, + 'err': err}) + + (free_size, total_size) = sorted(re.findall("\d+\.\d+|\d+", out), + reverse=False) return [{ 'pool_name': self.configuration.container_volume_group, 'total_capacity_gb': float(total_size), diff --git a/manila/tests/share/drivers/container/test_storage_helper.py b/manila/tests/share/drivers/container/test_storage_helper.py index 5d6c674d76..d5c8db0bb6 100644 --- a/manila/tests/share/drivers/container/test_storage_helper.py +++ b/manila/tests/share/drivers/container/test_storage_helper.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. """Unit tests for the Storage helper module.""" - +import ddt import functools import mock @@ -24,6 +24,7 @@ from manila import test from manila.tests.share.drivers.container.fakes import fake_share +@ddt.ddt class LVMHelperTestCase(test.TestCase): """Tests ContainerShareDriver""" @@ -46,12 +47,12 @@ class LVMHelperTestCase(test.TestCase): storage_helper.LVMHelper, None) - def test_get_share_server_pools(self): - ret_vgs = "VSize 100g size\nVFree 100g whatever" + @ddt.data("62.50g 72.50g", " 72.50g 62.50g\n", " <62.50g <72.50g\n") + def test_get_share_server_pools(self, ret_vgs): expected_result = [{'reserved_percentage': 0, 'pool_name': 'manila_docker_volumes', - 'total_capacity_gb': 100.0, - 'free_capacity_gb': 100.0}] + 'total_capacity_gb': 72.5, + 'free_capacity_gb': 62.5}] self.mock_object(self.LVMHelper, "_execute", mock.Mock(return_value=(ret_vgs, 0))) diff --git a/releasenotes/notes/bug-1794402-fix-share-stats-container-driver-b3cb1fa2987ad4b1.yaml b/releasenotes/notes/bug-1794402-fix-share-stats-container-driver-b3cb1fa2987ad4b1.yaml new file mode 100644 index 0000000000..5cbaba1190 --- /dev/null +++ b/releasenotes/notes/bug-1794402-fix-share-stats-container-driver-b3cb1fa2987ad4b1.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Pool stats collection has been fixed in the container driver to reflect + the differences in formatting of information for the underlying volume + groups across different operating systems.