Refactored smoketests flags

This commit is contained in:
Devin Carlen 2010-07-09 08:21:32 +00:00
parent 43a393587c
commit 4ca5488297
3 changed files with 74 additions and 35 deletions

47
smoketests/flags.py Normal file
View File

@ -0,0 +1,47 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# 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
#
# Unless required by applicable law or agreed to in writing, software
# 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
# under the License.
"""
Package-level global flags are defined here, the rest are defined
where they're used.
"""
from nova import vendor
from gflags import *
# This keeps pylint from barfing on the imports
FLAGS = FLAGS
DEFINE_string = DEFINE_string
DEFINE_integer = DEFINE_integer
DEFINE_bool = DEFINE_bool
# __GLOBAL FLAGS ONLY__
# Define any app-specific flags in their own files, docs at:
# http://code.google.com/p/python-gflags/source/browse/trunk/gflags.py#39
DEFINE_string('admin_access_key', 'admin', 'Access key for admin user')
DEFINE_string('admin_secret_key', 'admin', 'Secret key for admin user')
DEFINE_string('clc_ip', '127.0.0.1', 'IP of cloud controller API')
DEFINE_string('bundle_kernel', 'openwrt-x86-vmlinuz',
'Local kernel file to use for bundling tests')
DEFINE_string('bundle_image', 'openwrt-x86-ext2.image',
'Local image file to use for bundling tests')
#DEFINE_string('vpn_image_id', 'ami-CLOUDPIPE',
# 'AMI for cloudpipe vpn server')

View File

@ -28,22 +28,17 @@ from nova import vendor
import paramiko
from nova import adminclient
from nova import flags
from smoketests import flags
FLAGS = flags.FLAGS
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')
nova_admin = adminclient.NovaAdminClient(access_key=FLAGS.admin_access_key, secret_key=FLAGS.admin_secret_key, clc_ip=FLAGS.clc_ip)
class NovaTestCase(unittest.TestCase):
def setUp(self):
pass
self.nova_admin = adminclient.NovaAdminClient(
access_key=FLAGS.admin_access_key,
secret_key=FLAGS.admin_secret_key,
clc_ip=FLAGS.clc_ip)
def tearDown(self):
pass
@ -64,22 +59,22 @@ class NovaTestCase(unittest.TestCase):
@property
def admin(self):
return nova_admin.connection_for('admin')
return self.nova_admin.connection_for('admin')
def connection_for(self, username):
return nova_admin.connection_for(username)
return self.nova_admin.connection_for(username)
def create_user(self, username):
return nova_admin.create_user(username)
return self.nova_admin.create_user(username)
def get_user(self, username):
return nova_admin.get_user(username)
return self.nova_admin.get_user(username)
def delete_user(self, username):
return nova_admin.delete_user(username)
return self.nova_admin.delete_user(username)
def get_signed_zip(self, username):
return nova_admin.get_zip(username)
return self.nova_admin.get_zip(username)
def create_key_pair(self, conn, key_name):
try:

View File

@ -30,15 +30,13 @@ import zipfile
from nova import vendor
import paramiko
from nova import flags
from smoketests import flags
from smoketests import novatestcase
FLAGS = flags.FLAGS
SUITE_NAMES = '[user, image, security, public_network, volume]'
flags.DEFINE_string('bundle_kernel', 'openwrt-x86-vmlinuz',
'Local kernel file to use for bundling tests')
flags.DEFINE_string('bundle_image', 'openwrt-x86-ext2.image',
'Local image file to use for bundling tests')
FLAGS = flags.FLAGS
flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES)
# TODO(devamcar): Use random tempfile
ZIP_FILENAME = '/tmp/nova-me-x509.zip'
@ -87,13 +85,13 @@ class ImageTests(novatestcase.NovaTestCase):
self.create_user(test_username)
def test_001_admin_can_bundle_image(self):
self.assertTrue(self.bundle_image(IMAGE_FILENAME))
self.assertTrue(self.bundle_image(FLAGS.bundle_image))
def test_002_admin_can_upload_image(self):
self.assertTrue(self.upload_image(test_bucket, IMAGE_FILENAME))
self.assertTrue(self.upload_image(test_bucket, FLAGS.bundle_image))
def test_003_admin_can_register_image(self):
image_id = self.register_image(test_bucket, IMAGE_FILENAME)
image_id = self.register_image(test_bucket, FLAGS.bundle_image)
self.assert_(image_id is not None)
data['image_id'] = image_id
@ -398,7 +396,7 @@ class ElasticIPTests(novatestcase.NovaTestCase):
self.create_key_pair(conn, 'mykey')
conn = self.connection_for('admin')
#data['image_id'] = self.setUp_test_image(IMAGE_FILENAME)
#data['image_id'] = self.setUp_test_image(FLAGS.bundle_image)
def test_001_me_can_launch_image_with_keypair(self):
conn = self.connection_for('me')
@ -552,20 +550,19 @@ def build_suites():
def main():
argv = FLAGS(sys.argv)
#argv = sys.argv
if len(argv) == 1:
unittest.main()
else:
suites = build_suites()
suites = build_suites()
if FLAGS.suite:
try:
suite = suites[argv[1]]
suite = suites[FLAGS.suite]
except KeyError:
print >> sys.stderr, 'Available test suites: [user, image, security, public_network, volume]'
return
print >> sys.stderr, 'Available test suites:', SUITE_NAMES
return 1
unittest.TextTestRunner(verbosity=2).run(suite)
else:
for suite in suites.itervalues():
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == "__main__":
sys.exit(main())