summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Alvares Gomes <lucasagomes@gmail.com>2014-09-25 14:48:31 +0100
committerLucas Alvares Gomes <lucasagomes@gmail.com>2014-09-25 15:10:05 +0100
commit8ba03ed0bcd078edd7f5979b89c82a57671c95a2 (patch)
tree1b16d0dbf133749fe85d440e808afdf3b19825f8
parentffba2c5b3baff31861db55d7c0a1ca8398a69708 (diff)
downloadironic-8ba03ed0bcd078edd7f5979b89c82a57671c95a2.tar.gz
Force the SSH commands to use their default language
SSH commands often have to parse an output and do some pattern matchings (e.g using grep) that makes those commands dependent on the system language and causing it to fail on systems with a non-english locale setting. This patch forces the SSH commands to use their default language (whatever language the strings in the application was written in) for output by passing LC_ALL=C as part of the command. For virsh, vmware, vbox and prlctl the default language is english making the commands from the SSH driver to work independent of the system language. Closes-Bug: #1373671 Change-Id: I175d84fca4e10b8c9468bc4fe54ecd865725e39c
-rw-r--r--ironic/drivers/modules/ssh.py8
-rw-r--r--ironic/tests/drivers/test_ssh.py21
2 files changed, 15 insertions, 14 deletions
diff --git a/ironic/drivers/modules/ssh.py b/ironic/drivers/modules/ssh.py
index 87a968697..d6fbd774b 100644
--- a/ironic/drivers/modules/ssh.py
+++ b/ironic/drivers/modules/ssh.py
@@ -110,7 +110,7 @@ def _get_boot_device_map(virt_type):
def _get_command_sets(virt_type):
if virt_type == 'vbox':
return {
- 'base_cmd': '/usr/bin/VBoxManage',
+ 'base_cmd': 'LC_ALL=C /usr/bin/VBoxManage',
'start_cmd': 'startvm {_NodeName_}',
'stop_cmd': 'controlvm {_NodeName_} poweroff',
'reboot_cmd': 'controlvm {_NodeName_} reset',
@@ -126,7 +126,7 @@ def _get_command_sets(virt_type):
}
elif virt_type == 'vmware':
return {
- 'base_cmd': '/bin/vim-cmd',
+ 'base_cmd': 'LC_ALL=C /bin/vim-cmd',
'start_cmd': 'vmsvc/power.on {_NodeName_}',
'stop_cmd': 'vmsvc/power.off {_NodeName_}',
'reboot_cmd': 'vmsvc/power.reboot {_NodeName_}',
@@ -151,7 +151,7 @@ def _get_command_sets(virt_type):
# Change-Id: I160e4202952b7551b855dc7d91784d6a184cb0ed
# for more detail.
virsh_cmds = {
- 'base_cmd': '/usr/bin/virsh',
+ 'base_cmd': 'LC_ALL=C /usr/bin/virsh',
'start_cmd': 'start {_NodeName_}',
'stop_cmd': 'destroy {_NodeName_}',
'reboot_cmd': 'reset {_NodeName_}',
@@ -176,7 +176,7 @@ def _get_command_sets(virt_type):
return virsh_cmds
elif virt_type == 'parallels':
return {
- 'base_cmd': '/usr/bin/prlctl',
+ 'base_cmd': 'LC_ALL=C /usr/bin/prlctl',
'start_cmd': 'start {_NodeName_}',
'stop_cmd': 'stop {_NodeName_} --kill',
'reboot_cmd': 'reset {_NodeName_}',
diff --git a/ironic/tests/drivers/test_ssh.py b/ironic/tests/drivers/test_ssh.py
index d25f501d9..c96745bdc 100644
--- a/ironic/tests/drivers/test_ssh.py
+++ b/ironic/tests/drivers/test_ssh.py
@@ -171,7 +171,7 @@ class SSHValidateParametersTestCase(base.TestCase):
def test__parse_driver_info_with_custom_libvirt_uri(self):
CONF.set_override('libvirt_uri', 'qemu:///foo', 'ssh')
- expected_base_cmd = "/usr/bin/virsh --connect qemu:///foo"
+ expected_base_cmd = "LC_ALL=C /usr/bin/virsh --connect qemu:///foo"
node = obj_utils.get_test_node(
self.context,
@@ -806,7 +806,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
task.node['driver_info']['ssh_virt_type'] = 'vbox'
self.driver.management.set_boot_device(task, boot_devices.PXE)
- expected_cmd = ('/usr/bin/VBoxManage modifyvm %s '
+ expected_cmd = ('LC_ALL=C /usr/bin/VBoxManage modifyvm %s '
'--boot1 net') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@@ -822,7 +822,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
task.node['driver_info']['ssh_virt_type'] = 'parallels'
self.driver.management.set_boot_device(task, boot_devices.PXE)
- expected_cmd = ('/usr/bin/prlctl set %s '
+ expected_cmd = ('LC_ALL=C /usr/bin/prlctl set %s '
'--device-bootorder "net0"') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@@ -840,7 +840,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
self.driver.management.set_boot_device(task, boot_devices.PXE)
expected_cmd = ('EDITOR="sed -i \'/<boot \\(dev\\|order\\)=*\\>'
'/d;/<\\/os>/i\\<boot dev=\\"network\\"/>\'" '
- '/usr/bin/virsh --connect qemu:///system '
+ 'LC_ALL=C /usr/bin/virsh --connect qemu:///system '
'edit %s') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@@ -883,7 +883,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
task.node['driver_info']['ssh_virt_type'] = 'vbox'
result = self.driver.management.get_boot_device(task)
self.assertEqual(boot_devices.PXE, result['boot_device'])
- expected_cmd = ('/usr/bin/VBoxManage showvminfo --machinereadable %s '
+ expected_cmd = ('LC_ALL=C /usr/bin/VBoxManage showvminfo '
+ '--machinereadable %s '
'| awk -F \'"\' \'/boot1/{print $2}\'') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@@ -901,7 +902,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
task.node['driver_info']['ssh_virt_type'] = 'parallels'
result = self.driver.management.get_boot_device(task)
self.assertEqual(boot_devices.PXE, result['boot_device'])
- expected_cmd = ('/usr/bin/prlctl list -i %s '
+ expected_cmd = ('LC_ALL=C /usr/bin/prlctl list -i %s '
'| awk \'/^Boot order:/ {print $3}\'') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@@ -919,10 +920,10 @@ class SSHDriverTestCase(db_base.DbTestCase):
task.node['driver_info']['ssh_virt_type'] = 'virsh'
result = self.driver.management.get_boot_device(task)
self.assertEqual(boot_devices.PXE, result['boot_device'])
- expected_cmd = ('/usr/bin/virsh --connect qemu:///system dumpxml '
- '%s | awk \'/boot dev=/ { gsub( ".*dev=" Q, "" ); '
- 'gsub( Q ".*", "" ); print; }\' Q="\'" RS="[<>]" | '
- 'head -1') % fake_name
+ expected_cmd = ('LC_ALL=C /usr/bin/virsh --connect '
+ 'qemu:///system dumpxml %s | awk \'/boot dev=/ '
+ '{ gsub( ".*dev=" Q, "" ); gsub( Q ".*", "" ); '
+ 'print; }\' Q="\'" RS="[<>]" | head -1') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')