This website requires JavaScript.
2010年06月23日 21:19:08 -07:00
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2010年06月23日 22:04:16 -07:00
2010年06月23日 21:19:08 -07:00
# Copyright 2010 United States Government as represented by the
2010年06月23日 23:15:06 -07:00
# Administrator of the National Aeronautics and Space Administration.
2010年06月23日 21:19:08 -07:00
# All Rights Reserved.
2010年06月23日 22:04:16 -07:00
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
2010年06月23日 21:19:08 -07:00
# Unless required by applicable law or agreed to in writing, software
2010年06月23日 22:04:16 -07:00
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
2010年06月23日 21:19:08 -07:00
2010年11月04日 15:50:23 -07:00
import boto
2010年06月23日 21:19:08 -07:00
import commands
2010年11月04日 15:50:23 -07:00
import httplib
2010年06月23日 21:19:08 -07:00
import os
2010年11月04日 15:50:23 -07:00
import paramiko
2010年06月24日 04:11:53 +01:00
import random
2010年06月23日 21:19:08 -07:00
import sys
2010年11月04日 15:50:23 -07:00
from boto.ec2.regioninfo import RegionInfo
2010年06月24日 04:11:53 +01:00
2010年07月09日 08:21:32 +00:00
from smoketests import flags
2010年07月08日 14:05:45 -07:00
2010年06月24日 04:11:53 +01:00
2010年11月04日 15:50:23 -07:00
class SmokeTestCase(unittest.TestCase):
2010年06月24日 04:11:53 +01:00
def connect_ssh(self, ip, key_name):
2010年06月23日 21:19:08 -07:00
# TODO(devcamcar): set a more reasonable connection timeout time
key = paramiko.RSAKey.from_private_key_file('/tmp/%s.pem' % key_name)
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
2010年06月24日 04:11:59 +01:00
client.connect(ip, username='root', pkey=key)
2010年06月24日 04:11:53 +01:00
stdin, stdout, stderr = client.exec_command('uptime')
print 'uptime: ', stdout.read()
2010年11月04日 15:50:23 -07:00
""" 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':
status, output = commands.getstatusoutput('ping -c1 -%s1 %s' %
def connection_for_env(self, **kwargs):
Returns a boto ec2 connection for the current environment.
access_key = os.getenv('EC2_ACCESS_KEY')
secret_key = os.getenv('EC2_SECRET_KEY')
clc_url = os.getenv('EC2_URL')
if not access_key or not secret_key or not clc_url:
raise Exception('Missing EC2 environment variables. Please source '
'the appropriate novarc file before running this '
parts = self.split_clc_url(clc_url)
return boto.connect_ec2(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
is_secure=parts['is_secure'],
def split_clc_url(self, clc_url):
Splits a cloud controller endpoint url.
parts = httplib.urlsplit(clc_url)
is_secure = parts.scheme == 'https'
ip, port = parts.netloc.split(':')
return {'ip': ip, 'port': int(port), 'is_secure': is_secure}
2010年06月24日 04:11:53 +01:00
def create_key_pair(self, conn, key_name):
os.remove('/tmp/%s.pem' % key_name)
key = conn.create_key_pair(key_name)
def delete_key_pair(self, conn, key_name):
conn.delete_key_pair(key_name)
os.remove('/tmp/%s.pem' % key_name)
def bundle_image(self, image, kernel=False):
cmd = 'euca-bundle-image -i %s' % image
2010年06月23日 21:19:08 -07:00
status, output = commands.getstatusoutput(cmd)
2010年06月24日 04:11:53 +01:00
if status != 0:
print '%s -> \n%s' % (cmd, output)
def upload_image(self, bucket_name, image):
cmd = 'euca-upload-bundle -b %s -m /tmp/%s.manifest.xml' % (bucket_name, image)
2010年06月23日 21:19:08 -07:00
status, output = commands.getstatusoutput(cmd)
2010年06月24日 04:11:53 +01:00
if status != 0:
print '%s -> \n%s' % (cmd, output)
def delete_bundle_bucket(self, bucket_name):
cmd = 'euca-delete-bundle --clear -b %s' % (bucket_name)
2010年06月23日 21:19:08 -07:00
status, output = commands.getstatusoutput(cmd)
2010年06月24日 04:11:53 +01:00
if status != 0:
print '%s -> \n%s' % (cmd, output)
2010年11月04日 15:50:23 -07:00
def run_tests(suites):
if not os.getenv('EC2_ACCESS_KEY'):
print >> sys.stderr, 'Missing EC2 environment variables. Please ' \
'source the appropriate novarc file before ' \
suite = suites[FLAGS.suite]
print >> sys.stderr, 'Available test suites:', \
2010年06月24日 04:11:53 +01:00
2010年11月04日 15:50:23 -07:00
unittest.TextTestRunner(verbosity=2).run(suite)
for suite in suites.itervalues():
unittest.TextTestRunner(verbosity=2).run(suite)
2010年06月24日 04:11:53 +01:00