summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2015-09-18 09:47:24 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2015-09-18 09:47:24 +0000
commit519f5f100fa4e711ffac9d73d6495c80c2880731 (patch)
treec999d1fb3ffeb9ad969b5ae5d3214ff15f93ce71
parentda01fffe3aaddfa953358bea59e09c58fa749349 (diff)
downloadciat-tester-519f5f100fa4e711ffac9d73d6495c80c2880731.tar.gz
Improve test commands to allow | and &&.
-rwxr-xr-xopenstack/tester36
1 files changed, 21 insertions, 15 deletions
diff --git a/openstack/tester b/openstack/tester
index fe14388..9dd4086 100755
--- a/openstack/tester
+++ b/openstack/tester
@@ -28,6 +28,7 @@ import time
import uuid
import yaml
+import paramiko
import cliapp
from novaclient import client
@@ -77,19 +78,15 @@ class DeployedSystemInstance(object):
self.deployment = deployment
self.ip_address = ip_addr
self.hostname = hostname
+ self.connection = None
- @property
- def ssh_host(self):
- # TODO: Stop assuming we ssh into test instances as root
- return 'root@{host}'.format(host=self.ip_address)
-
- 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 runcmd(self, cmd):
+ tran = self.connection.get_transport()
+ chan = tran.open_session()
+ chan.get_pty()
+ f = chan.makefile()
+ chan.exec_command(cmd)
+ print f.read()
def _wait_for_dhcp(self, timeout):
'''Block until given hostname resolves successfully.
@@ -112,12 +109,19 @@ class DeployedSystemInstance(object):
def _wait_for_ssh(self, timeout):
"""Wait until the deployed VM is responding via SSH"""
+ print('Attempting to connect to test instance via SSH:')
start_time = time.time()
while True:
try:
- self.runcmd(['true'], stdin=None, stdout=None, stderr=None)
+ # 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
+ print('SSH connection established.')
return
- except cliapp.AppException:
+ except Exception as e:
+ print(e)
# 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"
@@ -151,6 +155,8 @@ 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)
@@ -272,7 +278,7 @@ class ReleaseApp(cliapp.Application):
print('Running test: ' + data['name'])
for cmd in data['commands']:
print('$ ' + cmd)
- instance.runcmd(['sh', '-c', cmd])
+ instance.runcmd(cmd)
def deploy_and_test_systems(self, tests):
"""Run the deployments and tests"""