summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-09-19 00:25:39 +0000
committerGerrit Code Review <review@openstack.org>2014-09-19 00:25:39 +0000
commit857690560657bbfc5342000908bc84c918da1b11 (patch)
tree16bd1e55823fc6152e3ac7ab09837b66220f8a1f
parent954ad51698903155ba981e80e77f27984e06f4a1 (diff)
parent87d1680ccf9619644379f2419d5a1fda7501d905 (diff)
downloadironic-857690560657bbfc5342000908bc84c918da1b11.tar.gz
Merge "Use standard locale in list_partitions"
-rw-r--r--ironic/common/disk_partitioner.py7
-rw-r--r--ironic/tests/test_disk_partitioner.py8
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):