summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2015-09-18 13:40:10 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2015-09-18 13:40:10 +0000
commit107ebb6f62d8e5c4542be2f986d5d1632116f65b (patch)
tree8f55d02357b0b9cedd9ec5d6bbbe3149b92165e4
parentcd711c87ed3f5c16edf3e78eefb01e71c9d08c91 (diff)
downloadciat-tester-107ebb6f62d8e5c4542be2f986d5d1632116f65b.tar.gz
Revert to using cliapp/ssh to run ssh commands.
-rwxr-xr-xopenstack/tester36
1 files changed, 14 insertions, 22 deletions
diff --git a/openstack/tester b/openstack/tester
index 5ac2ffa..633e392 100755
--- a/openstack/tester
+++ b/openstack/tester
@@ -27,9 +27,7 @@ import socket
import time
import uuid
import yaml
-import select
-import paramiko
import cliapp
from novaclient import client
@@ -79,18 +77,19 @@ class DeployedSystemInstance(object):
self.deployment = deployment
self.ip_address = ip_addr
self.hostname = hostname
- self.connection = None
- def runcmd(self, cmd):
- stdin, stdout, stderr = self.connection.exec_command(cmd)
+ @property
+ def ssh_host(self):
+ # TODO: Stop assuming we ssh into test instances as root
+ return 'root@{host}'.format(host=self.ip_address)
- while not stdout.channel.exit_status_ready():
- if stdout.channel.recv_ready():
- rl, wl, xl = select.select([stdout.channel], [], [], 0.0)
- if len(rl) > 0:
- # Print data from stdout
- print stdout.channel.recv(1024),
- print stderr.read(),
+ def runcmd(self, argv, chdir='.', **kwargs):
+ ssh_cmd = ['ssh', '-o', 'StrictHostKeyChecking=no',
+ '-o', 'UserKnownHostsFile=/dev/null', self.ssh_host]
+ cmd = ['sh', '-c', 'cd "$1" && shift && exec "$@"', '-', chdir]
+ cmd += argv
+ ssh_cmd.append(' '.join(map(pipes.quote, cmd)))
+ return cliapp.runcmd(ssh_cmd, **kwargs)
def _wait_for_dhcp(self, timeout):
'''Block until given hostname resolves successfully.
@@ -117,15 +116,10 @@ class DeployedSystemInstance(object):
start_time = time.time()
while True:
try:
- # TODO: Stop assuming we ssh into test instances as root
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(self.ip_address, username='root')
- self.connection = ssh
+ self.runcmd(['true'], stdin=None, stdout=None, stderr=None)
print('SSH connection established.')
return
- except Exception as e:
- print(e)
+ except cliapp.AppException:
# TODO: Stop assuming the ssh part of the command is what failed
if time.time() > start_time + timeout:
raise TimeoutError("%s sshd did not start after %i seconds"
@@ -159,8 +153,6 @@ class DeployedSystemInstance(object):
print "Test system %s ready to run tests." % (self.hostname)
def delete(self):
- if self.connection != None:
- self.connection.close()
delete_instance_and_image(self.hostname)
@@ -283,7 +275,7 @@ class ReleaseApp(cliapp.Application):
print('Running test: ' + data['name'])
for cmd in data['commands']:
print('$ ' + cmd)
- instance.runcmd(cmd)
+ instance.runcmd(['sh', '-c', cmd])
def deploy_and_test_systems(self, tests):
"""Run the deployments and tests"""