libvirt: Add option to ssh to prevent prompting
When doing migration with libvirt driver there are ssh commands that can cause prompting if ssh is not configured correctly. This patch disables the prompting by adding BatchMode=yes option to the ssh command. Closes-Bug: #1437790 Change-Id: Ib1e38f397afaac96a2e1a8717c87a4b6756419db
This commit is contained in:
parent
fc5e6315af
commit
0a6d0216dc
|
@ -218,6 +218,13 @@ class GenericUtilsTestCase(test.NoDBTestCase):
|
|||
cmd = utils._get_root_helper()
|
||||
self.assertEqual('sudo', cmd)
|
||||
|
||||
def test_ssh_execute(self):
|
||||
expected_args = ('ssh', '-o', 'BatchMode=yes',
|
||||
'remotehost', 'ls', '-l')
|
||||
with mock.patch('nova.utils.execute') as mock_method:
|
||||
utils.ssh_execute('remotehost', 'ls', '-l')
|
||||
mock_method.assert_called_once_with(*expected_args)
|
||||
|
||||
|
||||
class VPNPingTestCase(test.NoDBTestCase):
|
||||
"""Unit tests for utils.vpn_ping()."""
|
||||
|
|
|
@ -9703,21 +9703,22 @@ Active: 8381604 kB
|
|||
drvr._set_cache_mode(fake_conf)
|
||||
self.assertEqual(fake_conf.driver_cache, 'fake')
|
||||
|
||||
def _test_shared_storage_detection(self, is_same):
|
||||
@mock.patch('os.unlink')
|
||||
@mock.patch.object(os.path, 'exists')
|
||||
def _test_shared_storage_detection(self, is_same,
|
||||
mock_exists, mock_unlink):
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
|
||||
self.mox.StubOutWithMock(drvr, 'get_host_ip_addr')
|
||||
self.mox.StubOutWithMock(utils, 'execute')
|
||||
self.mox.StubOutWithMock(os.path, 'exists')
|
||||
self.mox.StubOutWithMock(os, 'unlink')
|
||||
drvr.get_host_ip_addr().AndReturn('bar')
|
||||
utils.execute('ssh', 'foo', 'touch', mox.IgnoreArg())
|
||||
os.path.exists(mox.IgnoreArg()).AndReturn(is_same)
|
||||
drvr.get_host_ip_addr = mock.MagicMock(return_value='bar')
|
||||
mock_exists.return_value = is_same
|
||||
with mock.patch('nova.utils.ssh_execute') as mock_ssh_method:
|
||||
result = drvr._is_storage_shared_with('foo', '/path')
|
||||
mock_ssh_method.assert_any_call('foo', 'touch', mock.ANY)
|
||||
if is_same:
|
||||
os.unlink(mox.IgnoreArg())
|
||||
mock_unlink.assert_called_once_with(mock.ANY)
|
||||
else:
|
||||
utils.execute('ssh', 'foo', 'rm', mox.IgnoreArg())
|
||||
self.mox.ReplayAll()
|
||||
return drvr._is_storage_shared_with('foo', '/path')
|
||||
self.assertEqual(2, mock_ssh_method.call_count)
|
||||
mock_ssh_method.assert_called_with('foo', 'rm', mock.ANY)
|
||||
return result
|
||||
|
||||
def test_shared_storage_detection_same_host(self):
|
||||
self.assertTrue(self._test_shared_storage_detection(True))
|
||||
|
|
|
@ -206,6 +206,14 @@ def execute(*cmd, **kwargs):
|
|||
return processutils.execute(*cmd, **kwargs)
|
||||
|
||||
|
||||
def ssh_execute(dest, *cmd, **kwargs):
|
||||
"""Convenience wrapper to execute ssh command."""
|
||||
ssh_cmd = ['ssh', '-o', 'BatchMode=yes']
|
||||
ssh_cmd.append(dest)
|
||||
ssh_cmd.extend(cmd)
|
||||
return execute(*ssh_cmd, **kwargs)
|
||||
|
||||
|
||||
def trycmd(*args, **kwargs):
|
||||
"""Convenience wrapper around oslo's trycmd() method."""
|
||||
if 'run_as_root' in kwargs and 'root_helper' not in kwargs:
|
||||
|
|
|
@ -6127,7 +6127,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
utils.execute('rm', '-rf', inst_base)
|
||||
utils.execute('mv', inst_base_resize, inst_base)
|
||||
if not shared_storage:
|
||||
utils.execute('ssh', dest, 'rm', '-rf', inst_base)
|
||||
utils.ssh_execute(dest, 'rm', '-rf', inst_base)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
@ -6142,12 +6142,12 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
tmp_path = os.path.join(inst_base, tmp_file)
|
||||
|
||||
try:
|
||||
utils.execute('ssh', dest, 'touch', tmp_path)
|
||||
utils.ssh_execute(dest, 'touch', tmp_path)
|
||||
if os.path.exists(tmp_path):
|
||||
shared_storage = True
|
||||
os.unlink(tmp_path)
|
||||
else:
|
||||
utils.execute('ssh', dest, 'rm', tmp_path)
|
||||
utils.ssh_execute(dest, 'rm', tmp_path)
|
||||
except Exception:
|
||||
pass
|
||||
return shared_storage
|
||||
|
@ -6199,7 +6199,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
# failures here earlier
|
||||
if not shared_storage:
|
||||
try:
|
||||
utils.execute('ssh', dest, 'mkdir', '-p', inst_base)
|
||||
utils.ssh_execute(dest, 'mkdir', '-p', inst_base)
|
||||
except processutils.ProcessExecutionError as e:
|
||||
reason = _("not able to execute ssh command: %s") % e
|
||||
raise exception.InstanceFaultRollback(
|
||||
|
|
Loading…
Reference in New Issue