This website requires JavaScript.
43a393587c5578aa3270b42b4b30e614c9fd0c09
nova /smoketests /novatestcase.py
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
#
# Copyright 2010 Anso Labs, LLC
# 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年06月24日 04:11:53 +01:00
import random
2010年06月23日 21:19:08 -07:00
import sys
2010年06月24日 04:11:53 +01:00
2010年06月23日 21:19:08 -07:00
from nova import vendor
2010年06月24日 04:11:53 +01:00
2010年07月08日 14:05:45 -07:00
from nova import adminclient
2010年07月08日 21:48:43 +00:00
flags.DEFINE_string('admin_access_key', 'admin', 'Access key for admin user')
flags.DEFINE_string('admin_secret_key', 'admin', 'Secret key for admin user')
flags.DEFINE_string('clc_ip', '127.0.0.1', 'IP of cloud controller API')
#flags.DEFINE_string('vpn_image_id', 'ami-CLOUDPIPE',
# 'AMI for cloudpipe vpn server')
2010年07月08日 14:05:45 -07:00
nova_admin = adminclient.NovaAdminClient(access_key=FLAGS.admin_access_key, secret_key=FLAGS.admin_secret_key, clc_ip=FLAGS.clc_ip)
2010年06月24日 04:11:53 +01:00
class NovaTestCase(unittest.TestCase):
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()
2010年06月24日 04:11:53 +01:00
client.load_system_host_keys()
2010年06月23日 21:19:08 -07:00
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年06月23日 21:19:08 -07:00
return commands.getstatusoutput('ping -c 1 %s' % ip)[0] == 0
2010年06月24日 04:11:53 +01:00
2010年06月23日 21:19:08 -07:00
return nova_admin.connection_for('admin')
2010年06月24日 04:11:53 +01:00
def connection_for(self, username):
2010年06月23日 21:19:08 -07:00
return nova_admin.connection_for(username)
2010年06月24日 04:11:53 +01:00
def create_user(self, username):
2010年06月23日 21:19:08 -07:00
return nova_admin.create_user(username)
2010年06月24日 04:11:53 +01:00
def get_user(self, username):
2010年06月23日 21:19:08 -07:00
return nova_admin.get_user(username)
2010年06月24日 04:11:53 +01:00
def delete_user(self, username):
2010年06月23日 21:19:08 -07:00
return nova_admin.delete_user(username)
2010年06月24日 04:11:53 +01:00
def get_signed_zip(self, username):
2010年06月23日 21:19:08 -07:00
return nova_admin.get_zip(username)
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)
def register_image(self, bucket_name, manifest):
2010年06月23日 21:19:08 -07:00
conn = nova_admin.connection_for('admin')
2010年06月24日 04:11:53 +01:00
return conn.register_image("%s/%s.manifest.xml" % (bucket_name, manifest))
def setUp_test_image(self, image, kernel=False):
self.bundle_image(image, kernel=kernel)
bucket = "auto_test_%s" % int(random.random() * 1000000)
self.upload_image(bucket, image)
return self.register_image(bucket, image)
def tearDown_test_image(self, conn, image_id):
conn.deregister_image(image_id)