From 87d1680ccf9619644379f2419d5a1fda7501d905 Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Thu, 18 Sep 2014 16:39:01 +0300 Subject: Use standard locale in list_partitions parted function can output values which cannot be parsed by _PARTED_PRINT_RE regexp in disk_partitioner module when using for example ukrainian locale, as comma is used to separate integer and fractional parts of float numbers. Standard 'C' locale should be used to run parted. Change-Id: Ic5b043796d548d91fb57a7ee34fe2e5a3a09088c Closes-bug: #1371079 --- ironic/common/disk_partitioner.py | 7 +++++-- ironic/tests/test_disk_partitioner.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ironic/common/disk_partitioner.py b/ironic/common/disk_partitioner.py index d2e1d8e6e..34ab49547 100644 --- a/ironic/common/disk_partitioner.py +++ b/ironic/common/disk_partitioner.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import os import re from oslo.config import cfg @@ -186,8 +187,10 @@ def list_partitions(device): :returns: list of dictionaries (one per partition) with keys: start, end, size (in MiB), filesystem, flags """ - output = utils.execute( - 'parted', '-s', '-m', device, 'unit', 'MiB', 'print')[0] + env = os.environ.copy() + env['LC_ALL'] = 'C' + output = utils.execute('parted', '-s', '-m', device, 'unit', 'MiB', + 'print', env_variables=env)[0] lines = [line for line in output.split('\n') if line.strip()][2:] # Example of line: 1:1.00MiB:501MiB:500MiB:ext4::boot fields = ('start', 'end', 'size', 'filesystem', 'flags') diff --git a/ironic/tests/test_disk_partitioner.py b/ironic/tests/test_disk_partitioner.py index 8cbf27342..494510f03 100644 --- a/ironic/tests/test_disk_partitioner.py +++ b/ironic/tests/test_disk_partitioner.py @@ -15,6 +15,7 @@ import fixtures import mock +import os from testtools.matchers import HasLength from ironic.common import disk_partitioner @@ -166,7 +167,8 @@ class DiskPartitionerTestCase(base.TestCase): @mock.patch.object(utils, 'execute') class ListPartitionsTestCase(base.TestCase): - def test_correct(self, execute_mock): + @mock.patch.object(os.environ, 'copy', return_value={}) + def test_correct(self, env_mock, execute_mock): output = """ BYT; /dev/sda:500107862016B:scsi:512:4096:msdos:ATA HGST HTS725050A7:; @@ -180,10 +182,12 @@ BYT; 'filesystem': '', 'flags': ''}, ] execute_mock.return_value = (output, '') + env = {'LC_ALL': 'C'} result = disk_partitioner.list_partitions('/dev/fake') self.assertEqual(expected, result) execute_mock.assert_called_once_with( - 'parted', '-s', '-m', '/dev/fake', 'unit', 'MiB', 'print') + 'parted', '-s', '-m', '/dev/fake', 'unit', 'MiB', 'print', + env_variables=env) @mock.patch.object(disk_partitioner.LOG, 'warn') def test_incorrect(self, log_mock, execute_mock): -- cgit v1.2.1