Error casting value to float in lvm.py

Bug #1219963 reported by Victor Ruiz
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Medium
Haomai Wang

Bug Description

When I launch the cinder-volume service i get this error:

2013-09-02 21:34:37.310 DEBUG cinder.openstack.common.processutils [req-3901dc67-efaf-4829-8007-363074cdd4ad None None] Running cmd (subprocess): sudo cinder-rootwrap /etc/cinder/rootwrap.conf vgs --noheadings --unit=g -o name,size,free,lv_count,uuid --separator : --nosuffix stack-volumes from (pid=14201) execute /opt/stack/cinder/cinder/openstack/common/processutils.py:142

2013-09-02 21:34:37.407 ERROR cinder.service [req-3901dc67-efaf-4829-8007-363074cdd4ad None None] Unhandled exception
2013-09-02 21:34:37.407 TRACE cinder.service Traceback (most recent call last):
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/service.py", line 228, in _start_child
2013-09-02 21:34:37.407 TRACE cinder.service self._child_process(wrap.server)
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/service.py", line 205, in _child_process
2013-09-02 21:34:37.407 TRACE cinder.service launcher.run_server(server)
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/service.py", line 96, in run_server
2013-09-02 21:34:37.407 TRACE cinder.service server.start()
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/service.py", line 385, in start
2013-09-02 21:34:37.407 TRACE cinder.service self.manager.init_host()
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/volume/manager.py", line 192, in init_host
2013-09-02 21:34:37.407 TRACE cinder.service self.publish_service_capabilities(ctxt)
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/volume/manager.py", line 744, in publish_service_capabilities
2013-09-02 21:34:37.407 TRACE cinder.service self._report_driver_status(context)
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/volume/manager.py", line 736, in _report_driver_status
2013-09-02 21:34:37.407 TRACE cinder.service volume_stats = self.driver.get_volume_stats(refresh=True)
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/volume/drivers/lvm.py", line 669, in get_volume_stats
2013-09-02 21:34:37.407 TRACE cinder.service self._update_volume_stats()
2013-09-02 21:34:37.407 TRACE cinder.service File "/opt/stack/cinder/cinder/volume/drivers/lvm.py", line 690, in _update_volume_stats
2013-09-02 21:34:37.407 TRACE cinder.service data['free_capacity_gb'] = float(self.vg.vg_free_space)
2013-09-02 21:34:37.407 TRACE cinder.service ValueError: invalid literal for float(): 10,01
2013-09-02 21:34:37.407 TRACE cinder.service

I fix it change the line 691 of the file cinder/volume/drivers/lvm.py from:

-> data['free_capacity_gb'] = float(self.vg.vg_free_space.replace)

to

-> data['free_capacity_gb'] = float(self.vg.vg_free_space.replace(",","."))

I think someone forgot to parse the float before doing the casting.

Revision history for this message
Victor Ruiz (victormruizs) wrote :

Sorry, actually it was:

from:

-> data['free_capacity_gb'] = float(self.vg.vg_free_space)

to

-> data['free_capacity_gb'] = float(self.vg.vg_free_space.replace(",","."))

Revision history for this message
Eric Harney (eharney) wrote :

What locale are you using? I believe this happens because we run "vgs" without setting locale env variables.

The call to "vgs" should pass an LC_NUMERIC or LC_ALL env var so that the output looks the same regardless of system locale.

Changed in cinder:
status: New → Triaged
ugvddm (271025598-9)
Changed in cinder:
assignee: nobody → ugvddm (271025598-9)
Revision history for this message
Victor Ruiz (victormruizs) wrote :

We are using spanish locale:

victor@openstackserver:~$ locale
LANG=es_ES.UTF-8
LANGUAGE=
LC_CTYPE="es_ES.UTF-8"
LC_NUMERIC="es_ES.UTF-8"
LC_TIME="es_ES.UTF-8"
LC_COLLATE="es_ES.UTF-8"
LC_MONETARY="es_ES.UTF-8"
LC_MESSAGES="es_ES.UTF-8"
LC_PAPER="es_ES.UTF-8"
LC_NAME="es_ES.UTF-8"
LC_ADDRESS="es_ES.UTF-8"
LC_TELEPHONE="es_ES.UTF-8"
LC_MEASUREMENT="es_ES.UTF-8"
LC_IDENTIFICATION="es_ES.UTF-8"
LC_ALL=

ugvddm (271025598-9)
Changed in cinder:
assignee: ugvddm (271025598-9) → nobody
Eric Harney (eharney)
Changed in cinder:
milestone: none → havana-3
milestone: havana-3 → havana-rc1
Revision history for this message
Eric Harney (eharney) wrote :

Another option is to use "vgs --units B" instead of LC_NUMERIC=C, which may make things more clear.

$ sudo vgs
  VG #PV #LV #SN Attr VSize VFree
  vg_eharney 1 6 1 wz--n- 465.25g 12.97g
(en_US)

$ LC_NUMERIC='C' sudo vgs
  VG #PV #LV #SN Attr VSize VFree
  vg_eharney 1 6 1 wz--n- 465.25g 12.97g

$ LC_NUMERIC='es_ES.UTF-8' sudo vgs
  VG #PV #LV #SN Attr VSize VFree
  vg_eharney 1 6 1 wz--n- 465,25g 12,97g

$ sudo vgs --units B
  VG #PV #LV #SN Attr VSize VFree
  vg_eharney 1 6 1 wz--n- 499558383616B 13925089280B

Changed in cinder:
importance: Undecided → Medium
tags: added: low-hanging-fruit
Haomai Wang (haomai)
Changed in cinder:
assignee: nobody → Haomai Wang (haomai)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/45430

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/45430
Committed: http://github.com/openstack/cinder/commit/9334cc1913a997d462e784429cc491cb0d6c7f76
Submitter: Jenkins
Branch: master

commit 9334cc1913a997d462e784429cc491cb0d6c7f76
Author: Haomai Wang <email address hidden>
Date: Fri Sep 6 21:37:01 2013 +0800

    Fix error casting value to float in lvm.py

    Special locale setting may result in that "vgs" command output different
    results. Such as:

    $ LC_NUMERIC='es_ES.UTF-8' sudo vgs
    VG #PV #LV #SN Attr VSize VFree
    vg_eharney 1 6 1 wz--n- 465,25g 12,97g

    Fix bug 1219963

    Change-Id: Ibe79d5ce673738d8e37f86de9106ab347c21bd52

Eric Harney (eharney)
Changed in cinder:
status: Triaged → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: havana-rc1 → 2013.2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to cinder (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/60377

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to cinder (master)

Reviewed: https://review.openstack.org/60377
Committed: http://github.com/openstack/cinder/commit/174ebde8e6a8cddc2db615b127d7d0066dabaa31
Submitter: Jenkins
Branch: master

commit 174ebde8e6a8cddc2db615b127d7d0066dabaa31
Author: Eric Harney <email address hidden>
Date: Thu Dec 5 18:12:33 2013 -0500

    Brick LVM: Set C locale when gathering PV info

    Some locales use commas as decimal separators, which means
    that code breaks when someone expects to be able to use the
    PV size as a float.

    Change-Id: Idceb405e021ea8a0f44e19be43bad1307fbbb51c
    Related-Bug: 1219963

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.