]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat tests : functional tests add exec_sudo_command
authorSteven Hardy <shardy@redhat.com>
Thu, 20 Sep 2012 13:37:41 +0000 (14:37 +0100)
committerSteven Hardy <shardy@redhat.com>
Thu, 20 Sep 2012 16:56:41 +0000 (17:56 +0100)
Add new method in the Instance class, which uses paramiko
invoke_shell instead of exec_command, so sudo commands can
run despite requiretty being set in our sudo config

Ref #246

Change-Id: I3be691167d4c757b68e589261d6f3a1263d77e69
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/tests/functional/util.py

index 0837ba9dce298a71342ef77805b5276e6becfe5e..b9f6e06402c0c6484a5b71f558217c011b4bc67a 100644 (file)
@@ -153,6 +153,17 @@ class Instance(object):
                       (self.name, self.ip))
                 break
 
+    def exec_sudo_command(self, cmd):
+        # Force a tty or sudo commands fail
+        channel = self.ssh.invoke_shell()
+        channel.sendall("sudo %s\n" % cmd)
+        channel.sendall('exit\n')
+        time.sleep(1)  # necessary for sendall to complete
+        stdin = channel.makefile('wb')
+        stdout = channel.makefile('rb')
+        stderr = channel.makefile_stderr('rb')
+        return stdin, stdout, stderr
+
     def exec_command(self, cmd):
         return self.ssh.exec_command(cmd)