From: Christoph Kassen Date: Wed, 6 Mar 2013 18:37:42 +0000 (+0100) Subject: Fix volume capacity reporting X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6c8d860507a66424cf47b46380478b3cc565359e;p=openstack-build%2Fcinder-build.git Fix volume capacity reporting cinder-volume crashes when the decimal point is not represented by a dot but by a comma instead. This crash happens for example with the de_DE locale. This change replaces any comma appearing in the vgs command output with a dot. Test case added. Fixes: bug #1151684 Change-Id: I831055fb7fd206a8560688ec4c25d766e92ee0f0 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 7fef8478c..634ddfe98 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -965,6 +965,21 @@ class ISCSITestCase(DriverTestCase): self.assertEquals(result["target_iqn"], "iqn:iqn") self.assertEquals(result["target_lun"], 0) + def test_get_volume_stats(self): + def _emulate_vgs_execute(_command, *_args, **_kwargs): + out = " test1-volumes 5,52 0,52" + out += " test2-volumes 5.52 0.52" + return out, None + + self.volume.driver.set_execute(_emulate_vgs_execute) + + self.volume.driver._update_volume_status() + + stats = self.volume.driver._stats + + self.assertEquals(stats['total_capacity_gb'], float('5.52')) + self.assertEquals(stats['free_capacity_gb'], float('0.52')) + class FibreChannelTestCase(DriverTestCase): """Test Case for FibreChannelDriver""" diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 084789efa..3ab5ec38e 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -578,8 +578,8 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): if out: volume = out.split() - data['total_capacity_gb'] = float(volume[1]) - data['free_capacity_gb'] = float(volume[2]) + data['total_capacity_gb'] = float(volume[1].replace(',', '.')) + data['free_capacity_gb'] = float(volume[2].replace(',', '.')) self._stats = data