Am 7. Januar 2011 14:08 schrieb Iustin Pop <[email protected]>:
> On Fri, Jan 07, 2011 at 01:42:51PM +0100, Michael Hanselmann wrote:
>> +      result = _runcmd_fn(ssh_cmd, interactive=True)
>> +      if result.failed:
>> +        raise errors.OpExecError("Running \"%s\" as %...@%s failed: %s" %
>> +                                 (cmd, console.user, console.host,
>> +                                  result.fail_reason))
>
> I still think showing the SSH command to the user is not good.

Interdiff:

--- a/lib/client/gnt_instance.py
+++ b/lib/client/gnt_instance.py
@@ -27,6 +27,7 @@

 import itertools
 import simplejson
+import logging
 from cStringIO import StringIO

 from ganeti.cli import *
@@ -940,9 +941,12 @@ def _DoConsole(console, show_command,
cluster_name, feedback_fn=ToStdout,
     else:
       result = _runcmd_fn(ssh_cmd, interactive=True)
       if result.failed:
-        raise errors.OpExecError("Running \"%s\" as %...@%s failed: %s" %
-                                 (cmd, console.user, console.host,
-                                  result.fail_reason))
+        logging.error("Console command \"%s\" failed with reason '%s' and"
+                      " output %r", result.cmd, result.fail_reason,
+                      result.output)
+        raise errors.OpExecError("Connection to console of instance %s failed,"
+                                 " please check cluster configuration" %
+                                 console.instance)
   else:
     raise errors.GenericError("Unknown console type '%s'" % console.kind)

diff --git a/test/ganeti.client.gnt_instance_unittest.py
b/test/ganeti.client.gnt_instance_unittest.py
index 861c1c1..5141095 100755
--- a/test/ganeti.client.gnt_instance_unittest.py
+++ b/test/ganeti.client.gnt_instance_unittest.py
@@ -102,6 +102,9 @@ class TestConsole(unittest.TestCase):
     self.assertEqual(len(self._cmds), 1)
     self.assertEqual(len(self._output), 0)

+    # This is very important to prevent escapes from the console
+    self.assertTrue("-oEscapeChar=none" in self._cmds[0])
+
   def testSshRunFail(self):
     cons = objects.InstanceConsole(instance="inst31.example.com",
                                    kind=constants.CONS_SSH,


Michael

Reply via email to