diff options
author | Justin Santa Barbara <justin@fathomdb.com> | 2011-03-07 14:34:02 -0800 |
---|---|---|
committer | Justin Santa Barbara <justin@fathomdb.com> | 2011-03-07 14:34:02 -0800 |
commit | f65867673eff81d649d1a43e895dfae913d83e84 (patch) | |
tree | a2fc1cd9dd8ac424fd8c014f093d8ef63bc9b406 /smoketests/base.py | |
parent | 861a7f2b53f02af2ef196411171182394edd7e17 (diff) | |
parent | 421cab431253290445608c67c14ec736c3bd2708 (diff) | |
download | nova-f65867673eff81d649d1a43e895dfae913d83e84.tar.gz nova-f65867673eff81d649d1a43e895dfae913d83e84.tar.xz nova-f65867673eff81d649d1a43e895dfae913d83e84.zip |
Merge with trunk, resolve conflicts and refactor
Diffstat (limited to 'smoketests/base.py')
-rw-r--r-- | smoketests/base.py | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/smoketests/base.py b/smoketests/base.py index 610270c5c..204b4a1eb 100644 --- a/smoketests/base.py +++ b/smoketests/base.py @@ -17,19 +17,21 @@ # under the License. import boto -import boto_v6 import commands import httplib import os import paramiko -import random import sys +import time import unittest from boto.ec2.regioninfo import RegionInfo from smoketests import flags +SUITE_NAMES = '[image, instance, volume]' FLAGS = flags.FLAGS +flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES) +boto_v6 = None class SmokeTestCase(unittest.TestCase): @@ -39,12 +41,10 @@ class SmokeTestCase(unittest.TestCase): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.WarningPolicy()) client.connect(ip, username='root', pkey=key) - stdin, stdout, stderr = client.exec_command('uptime') - print 'uptime: ', stdout.read() return client - def can_ping(self, ip): - """ Attempt to ping the specified IP, and give up after 1 second. """ + def can_ping(self, ip, command="ping"): + """Attempt to ping the specified IP, and give up after 1 second.""" # NOTE(devcamcar): ping timeout flag is different in OSX. if sys.platform == 'darwin': @@ -52,10 +52,41 @@ class SmokeTestCase(unittest.TestCase): else: timeout_flag = 'w' - status, output = commands.getstatusoutput('ping -c1 -%s1 %s' % - (timeout_flag, ip)) + status, output = commands.getstatusoutput('%s -c1 -%s1 %s' % + (command, timeout_flag, ip)) return status == 0 + def wait_for_running(self, instance, tries=60, wait=1): + """Wait for instance to be running""" + for x in xrange(tries): + instance.update() + if instance.state.startswith('running'): + return True + time.sleep(wait) + else: + return False + + def wait_for_ping(self, ip, command="ping", tries=120): + """Wait for ip to be pingable""" + for x in xrange(tries): + if self.can_ping(ip, command): + return True + else: + return False + + def wait_for_ssh(self, ip, key_name, tries=30, wait=5): + """Wait for ip to be sshable""" + for x in xrange(tries): + try: + conn = self.connect_ssh(ip, key_name) + conn.close() + except Exception, e: + time.sleep(wait) + else: + return True + else: + return False + def connection_for_env(self, **kwargs): """ Returns a boto ec2 connection for the current environment. @@ -144,8 +175,21 @@ class SmokeTestCase(unittest.TestCase): return True +TEST_DATA = {} + + +class UserSmokeTestCase(SmokeTestCase): + def setUp(self): + global TEST_DATA + self.conn = self.connection_for_env() + self.data = TEST_DATA + + def run_tests(suites): argv = FLAGS(sys.argv) + if FLAGS.use_ipv6: + global boto_v6 + boto_v6 = __import__('boto_v6') if not os.getenv('EC2_ACCESS_KEY'): print >> sys.stderr, 'Missing EC2 environment variables. Please ' \ |