]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix volume capacity reporting
authorChristoph Kassen <c.kassen@telekom.de>
Wed, 6 Mar 2013 18:37:42 +0000 (19:37 +0100)
committerChristoph Kassen <c.kassen@telekom.de>
Fri, 8 Mar 2013 08:06:59 +0000 (09:06 +0100)
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

cinder/tests/test_volume.py
cinder/volume/drivers/lvm.py

index 7fef8478c4f58511baf5f12a433e52a6c0b111f8..634ddfe98756e4d791d47c5a29c93dc87d8d0bee 100644 (file)
@@ -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"""
index 084789efadde5345c5c2cae909073632a6251764..3ab5ec38efda658f195ee5e0fa57cb6dbefc50f3 100644 (file)
@@ -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