From edc5b7c01eb8c48e20188d01675909cb1946cc52 Mon Sep 17 00:00:00 2001 From: dimtruck Date: Thu, 19 Nov 2015 00:05:03 +0900 Subject: [PATCH] Migration to utilize tempest plugin This is a migration step to utilize tempest plugin system instead of directly calling functional api tests. This is the approach used by a number of other projects as well as an approved process by openstack-qa. The difference in execution is that we will need to execute tempest's tox instead of our own: tox -eall-plugin magnum.tests.functional.api.v1 -- --concurrency=1 Implements: blueprint magnum-tempest Change-Id: Ic3eadae7fb5d88b776f9ded9589ef25279a2e1be --- magnum/tests/functional/common/config.py | 69 ++++++++----------- magnum/tests/functional/common/datagen.py | 2 +- .../functional/tempest_tests/__init__.py | 0 .../tests/functional/tempest_tests/config.py | 46 +++++++++++++ .../tests/functional/tempest_tests/plugin.py | 39 +++++++++++ 5 files changed, 116 insertions(+), 40 deletions(-) create mode 100644 magnum/tests/functional/tempest_tests/__init__.py create mode 100644 magnum/tests/functional/tempest_tests/config.py create mode 100644 magnum/tests/functional/tempest_tests/plugin.py diff --git a/magnum/tests/functional/common/config.py b/magnum/tests/functional/common/config.py index 2cce0d5..22b36a9 100644 --- a/magnum/tests/functional/common/config.py +++ b/magnum/tests/functional/common/config.py @@ -10,7 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -import ConfigParser +from tempest import config + + +CONF = config.CONF class Config(object): @@ -19,77 +22,65 @@ class Config(object): @classmethod def set_admin_creds(cls, config): - cls.admin_user = config.get('admin', 'user') - cls.admin_passwd = config.get('admin', 'pass') - cls.admin_tenant = config.get('admin', 'tenant') + cls.admin_user = CONF.auth.admin_username + cls.admin_passwd = CONF.auth.admin_password + cls.admin_tenant = CONF.auth.admin_tenant_name @classmethod def set_user_creds(cls, config): # normal user creds - cls.user = config.get('auth', 'username') - cls.passwd = config.get('auth', 'password') - cls.tenant = config.get('auth', 'tenant_name') + cls.user = CONF.identity.username + cls.passwd = CONF.identity.password + cls.tenant = CONF.identity.tenant_name @classmethod def set_auth_version(cls, config): # auth version for client authentication - if config.has_option('auth', 'auth_version'): - cls.auth_version = config.get('auth', 'auth_version') - else: - cls.auth_version = 'v3' + cls.auth_version = CONF.identity.auth_version @classmethod def set_auth_url(cls, config): # auth_url for client authentication if cls.auth_version == 'v3': - if not config.has_option('auth', 'auth_v3_url'): - raise Exception('config missing auth_v3_url key') - cls.auth_v3_url = config.get('auth', 'auth_v3_url') + cls.auth_v3_url = CONF.identity.uri_v3 else: - if not config.has_option('auth', 'auth_url'): + if 'uri' not in CONF.identity: raise Exception('config missing auth_url key') - cls.auth_url = config.get('auth', 'auth_url') + cls.auth_url = CONF.identity.uri @classmethod def set_region(cls, config): - if config.has_option('auth', 'region'): - cls.region = config.get('auth', 'region') + if 'region' in CONF.identity: + cls.region = CONF.identity.region else: cls.region = 'RegionOne' @classmethod def set_image_id(cls, config): - cls.image_id = config.get('magnum', 'image_id') - if not config.has_option('magnum', 'image_id'): + if 'image_id' not in CONF.magnum: raise Exception('config missing image_id key') + cls.image_id = CONF.magnum.image_id @classmethod def set_nic_id(cls, config): - cls.nic_id = config.get('magnum', 'nic_id') - if not config.has_option('magnum', 'nic_id'): + if 'nic_id' not in CONF.magnum: raise Exception('config missing nic_id key') + cls.nic_id = CONF.magnum.nic_id @classmethod def set_keypair_id(cls, config): - cls.keypair_id = config.get('magnum', 'keypair_id') - if not config.has_option('magnum', 'keypair_id'): + if 'keypair_id' not in CONF.magnum: raise Exception('config missing keypair_id key') + cls.keypair_id = CONF.magnum.keypair_id @classmethod def setUp(cls): - config = ConfigParser.RawConfigParser() - if config.read('functional_creds.conf'): - cls.set_admin_creds(config) - cls.set_user_creds(config) - cls.set_auth_version(config) - cls.set_auth_url(config) + cls.set_admin_creds(config) + cls.set_user_creds(config) + cls.set_auth_version(config) + cls.set_auth_url(config) - # optional magnum bypass url - cls.magnum_url = config.get('auth', 'magnum_url') - - cls.set_region(config) - cls.set_image_id(config) - cls.set_nic_id(config) - cls.set_keypair_id(config) - else: - raise Exception('missing functional_creds.conf file') + cls.set_region(config) + cls.set_image_id(config) + cls.set_nic_id(config) + cls.set_keypair_id(config) diff --git a/magnum/tests/functional/common/datagen.py b/magnum/tests/functional/common/datagen.py index 700bc13..f110d70 100644 --- a/magnum/tests/functional/common/datagen.py +++ b/magnum/tests/functional/common/datagen.py @@ -61,7 +61,7 @@ def generate_random_port(): def generate_random_docker_volume_size(): - return random.randrange(1, 100) + return random.randrange(1, 3) def generate_fake_ssh_pubkey(): diff --git a/magnum/tests/functional/tempest_tests/__init__.py b/magnum/tests/functional/tempest_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/magnum/tests/functional/tempest_tests/config.py b/magnum/tests/functional/tempest_tests/config.py new file mode 100644 index 0000000..ac8d268 --- /dev/null +++ b/magnum/tests/functional/tempest_tests/config.py @@ -0,0 +1,46 @@ +# 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. + +from __future__ import print_function + +from oslo_config import cfg + +from tempest import config # noqa + +service_available_group = cfg.OptGroup(name="service_available", + title="Available OpenStack Services") + +ServiceAvailableGroup = [ + cfg.BoolOpt("magnum", + default=True, + help="Whether or not magnum is expected to be available"), +] + +magnum_group = cfg.OptGroup(name="magnum", title="Magnum Options") + +MagnumGroup = [ + cfg.StrOpt("image_id", + default="fedora-21-atomic-5", + help="Image id to be used for baymodel."), + + cfg.StrOpt("nic_id", + default="public", + help="NIC id."), + + cfg.StrOpt("keypair_id", + default="default", + help="Keypair id to use to log into nova instances."), + + cfg.StrOpt("flavor_id", + default="m1.magnum", + help="Flavor id to use for baymodels."), +] diff --git a/magnum/tests/functional/tempest_tests/plugin.py b/magnum/tests/functional/tempest_tests/plugin.py new file mode 100644 index 0000000..75d568c --- /dev/null +++ b/magnum/tests/functional/tempest_tests/plugin.py @@ -0,0 +1,39 @@ +# 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. + + +import os + +from tempest import config +from tempest.test_discover import plugins + +import magnum +from magnum.tests.functional.tempest_tests import config as magnum_config + + +class MagnumTempestPlugin(plugins.TempestPlugin): + def load_tests(self): + base_path = os.path.split(os.path.dirname( + os.path.abspath(magnum.__file__)))[0] + test_dir = "magnum/tests/functional/api/v1" + full_test_dir = os.path.join(base_path, test_dir) + return full_test_dir, base_path + + def register_opts(self, conf): + config.register_opt_group( + conf, magnum_config.service_available_group, + magnum_config.ServiceAvailableGroup) + config.register_opt_group(conf, magnum_config.magnum_group, + magnum_config.MagnumGroup) + + def get_opt_lists(self): + return [(magnum_config.magnum_group.name, magnum_config.MagnumGroup)]