Use standard locale when executing 'dd' command

When executing 'dd' command, baremetal provisioning fails on OS with
Japanese because of ascii codec error:
 InstanceDeployFailure: Deploy failed for instance <uuid>.
 Error: 'ascii' codec can't decode byte 0xc2 in position 24:
        ordinal not in range(128)
This fixes it by using standard locale when executing 'dd'.

Change-Id: I1248adb71489a818cfe1b5218f3bb6c961e66692
Closes-Bug:#1488289
This commit is contained in:
Ruby Loo 2015-09-30 13:47:20 +00:00
parent 3bb86b2cb4
commit 618ab03b60
3 changed files with 12 additions and 11 deletions
ironic_lib
tests/ironic_lib

@ -301,9 +301,7 @@ def destroy_disk_metadata(dev, node_uuid):
LOG.debug("Start destroy disk metadata for node %(node)s.",
{'node': node_uuid})
try:
utils.execute('dd', 'if=/dev/zero', 'of=%s' % dev,
'bs=512', 'count=36', run_as_root=True,
check_exit_code=[0])
utils.dd('/dev/zero', dev, 'bs=512', 'count=36')
except processutils.ProcessExecutionError as err:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Failed to erase beginning of disk for node "
@ -326,9 +324,8 @@ def destroy_disk_metadata(dev, node_uuid):
else:
seek_value = block_sz - 36
try:
utils.execute('dd', 'if=/dev/zero', 'of=%s' % dev,
'bs=512', 'count=36', 'seek=%d' % seek_value,
run_as_root=True, check_exit_code=[0])
utils.dd('/dev/zero', dev, 'bs=512', 'count=36',
'seek=%d' % seek_value)
except processutils.ProcessExecutionError as err:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Failed to erase the end of the disk on node "

@ -146,7 +146,7 @@ def dd(src, dst, *args):
"""
LOG.debug("Starting dd process.")
execute('dd', 'if=%s' % src, 'of=%s' % dst, *args,
run_as_root=True, check_exit_code=[0])
use_standard_locale=True, run_as_root=True, check_exit_code=[0])
def is_http_url(url):

@ -318,11 +318,13 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
mock_gz.return_value = 64
expected_calls = [mock.call('dd', 'if=/dev/zero', 'of=fake-dev',
'bs=512', 'count=36', run_as_root=True,
check_exit_code=[0]),
check_exit_code=[0],
use_standard_locale=True),
mock.call('dd', 'if=/dev/zero', 'of=fake-dev',
'bs=512', 'count=36', 'seek=28',
run_as_root=True,
check_exit_code=[0])]
check_exit_code=[0],
use_standard_locale=True)]
disk_utils.destroy_disk_metadata(self.dev, self.node_uuid)
mock_exec.assert_has_calls(expected_calls)
self.assertTrue(mock_gz.called)
@ -332,7 +334,8 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
expected_call = [mock.call('dd', 'if=/dev/zero', 'of=fake-dev',
'bs=512', 'count=36', run_as_root=True,
check_exit_code=[0])]
check_exit_code=[0],
use_standard_locale=True)]
self.assertRaises(processutils.ProcessExecutionError,
disk_utils.destroy_disk_metadata,
self.dev,
@ -344,7 +347,8 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
expected_call = [mock.call('dd', 'if=/dev/zero', 'of=fake-dev',
'bs=512', 'count=36', run_as_root=True,
check_exit_code=[0])]
check_exit_code=[0],
use_standard_locale=True)]
self.assertRaises(processutils.ProcessExecutionError,
disk_utils.destroy_disk_metadata,
self.dev,