1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
27
from boto.ec2.regioninfo import RegionInfo
29
from smoketests import flags
34
class SmokeTestCase(unittest.TestCase):
35
def connect_ssh(self, ip, key_name):
36
# TODO(devcamcar): set a more reasonable connection timeout time
37
key = paramiko.RSAKey.from_private_key_file('/tmp/%s.pem' % key_name)
38
client = paramiko.SSHClient()
39
client.set_missing_host_key_policy(paramiko.WarningPolicy())
40
client.connect(ip, username='root', pkey=key)
41
stdin, stdout, stderr = client.exec_command('uptime')
42
print 'uptime: ', stdout.read()
45
def can_ping(self, ip):
46
""" Attempt to ping the specified IP, and give up after 1 second. """
48
# NOTE(devcamcar): ping timeout flag is different in OSX.
49
if sys.platform == 'darwin':
54
status, output = commands.getstatusoutput('ping -c1 -%s1 %s' %
58
def connection_for_env(self, **kwargs):
60
Returns a boto ec2 connection for the current environment.
62
access_key = os.getenv('EC2_ACCESS_KEY')
63
secret_key = os.getenv('EC2_SECRET_KEY')
64
clc_url = os.getenv('EC2_URL')
66
if not access_key or not secret_key or not clc_url:
67
raise Exception('Missing EC2 environment variables. Please source '
68
'the appropriate novarc file before running this '
71
parts = self.split_clc_url(clc_url)
72
return boto.connect_ec2(aws_access_key_id=access_key,
73
aws_secret_access_key=secret_key,
74
is_secure=parts['is_secure'],
75
region=RegionInfo(None,
79
path='/services/Cloud',
82
def split_clc_url(self, clc_url):
84
Splits a cloud controller endpoint url.
86
parts = httplib.urlsplit(clc_url)
87
is_secure = parts.scheme == 'https'
88
ip, port = parts.netloc.split(':')
89
return {'ip': ip, 'port': int(port), 'is_secure': is_secure}
91
def create_key_pair(self, conn, key_name):
93
os.remove('/tmp/%s.pem' % key_name)
96
key = conn.create_key_pair(key_name)
100
def delete_key_pair(self, conn, key_name):
101
conn.delete_key_pair(key_name)
103
os.remove('/tmp/%s.pem' % key_name)
107
def bundle_image(self, image, kernel=False):
108
cmd = 'euca-bundle-image -i %s' % image
110
cmd += ' --kernel true'
111
status, output = commands.getstatusoutput(cmd)
113
print '%s -> \n %s' % (cmd, output)
114
raise Exception(output)
117
def upload_image(self, bucket_name, image):
118
cmd = 'euca-upload-bundle -b %s -m /tmp/%s.manifest.xml' % (bucket_name, image)
119
status, output = commands.getstatusoutput(cmd)
121
print '%s -> \n %s' % (cmd, output)
122
raise Exception(output)
125
def delete_bundle_bucket(self, bucket_name):
126
cmd = 'euca-delete-bundle --clear -b %s' % (bucket_name)
127
status, output = commands.getstatusoutput(cmd)
129
print '%s -> \n%s' % (cmd, output)
130
raise Exception(output)
133
def run_tests(suites):
134
argv = FLAGS(sys.argv)
136
if not os.getenv('EC2_ACCESS_KEY'):
137
print >> sys.stderr, 'Missing EC2 environment variables. Please ' \
138
'source the appropriate novarc file before ' \
144
suite = suites[FLAGS.suite]
146
print >> sys.stderr, 'Available test suites:', \
147
', '.join(suites.keys())
150
unittest.TextTestRunner(verbosity=2).run(suite)
152
for suite in suites.itervalues():
153
unittest.TextTestRunner(verbosity=2).run(suite)