Add files required for making this project a tempest plugin

In addition:

* Add gitignore file
* Modified client to use tempest config variables instead of env
  vars. Tempest config is what usually used in CI builds
* Modified test to use common flavor (m1.micro).

Change-Id: I5f292d7762396016a35c1895d7f6898b7dc1b417
This commit is contained in:
abregman 2018-08-16 10:22:37 +03:00
parent 47558dc83d
commit dce03ca6ea
7 changed files with 110 additions and 11 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
*.sw?
*.egg
*.egg-info
*.pyc
.test
.stestr*
etc
.testrepository
.tox
.venv
AUTHORS
build/*
ChangeLog
doc/build/*
zuul/versioninfo
dist/

View File

@ -11,8 +11,6 @@
# 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 heatclient import client as heat_client
from keystoneauth1 import loading
from keystoneauth1 import session
@ -21,7 +19,8 @@ from keystoneauth1 import session
class ClientManager(object):
"""Manages OpenStack official Python clients."""
def __init__(self):
def __init__(self, conf):
self.conf = conf
self.heat_client = self.get_heat_client()
def get_heat_client(self):
@ -30,11 +29,26 @@ class ClientManager(object):
sess = self.get_session()
return heat_client.Client('1', session=sess)
def get_username(self):
"""Returns username based on config."""
if not hasattr(self.conf.auth, 'username'):
return self.conf.auth.admin_username
else:
return self.conf.auth.username
def get_password(self):
"""Returns password based on config."""
if not hasattr(self.conf.auth, 'password'):
return self.conf.auth.admin_password
else:
return self.conf.auth.password
def get_session(self):
"""Returns keystone session."""
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url=os.environ['OS_AUTH_URL'],
username=os.environ['OS_USERNAME'],
password=os.environ['PASSWORD'],
project_id=os.environ['OS_TENANT_ID'])
auth = loader.load_from_options(
auth_url=self.conf.identity.uri,
username=self.get_username(),
password=self.get_password(),
project_name=self.conf.auth.admin_project_name)
return session.Session(auth=auth)

31
tobiko/config.py Normal file
View File

@ -0,0 +1,31 @@
# Copyright 2018 Red Hat
#
# 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 oslo_config import cfg
from tempest import config
CONF = config.CONF
TobikoGroup = [
cfg.StrOpt('floating_network_name',
default='public',
help="Floating network name "),
cfg.StrOpt('admin_username',
help="Username to use for admin API requests."),
]
tobiko_group = cfg.OptGroup(name="tobiko_plugin",
title="Tobiko Plugin Options")

37
tobiko/plugin.py Normal file
View File

@ -0,0 +1,37 @@
# Copyright 2018 Red Hat
#
# 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
from tobiko import config as tobiko_config
class TobikoTempestPlugin(plugins.TempestPlugin):
def load_tests(self):
base_path = os.path.split(os.path.dirname(
os.path.abspath(__file__)))[0]
test_dir = "tobiko"
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, tobiko_config.tobiko_group,
tobiko_config.TobikoGroup)
def get_opt_lists(self):
pass
# return [(tobiko_config.tobiko_group.name,
# tobiko_config.TobikoGroup)]

View File

@ -23,4 +23,5 @@ class TobikoTest(testtools.testcase.WithAttributes,
def setUp(self):
super(TobikoTest, self).setUp()
self.conf = config.CONF.tobiko_plugin
self.conf = config.CONF
print(self.conf)

View File

@ -27,7 +27,7 @@ class ScenarioTestsBase(base.TobikoTest):
def setUp(self):
super(ScenarioTestsBase, self).setUp()
self.clientManager = clients.ClientManager()
self.clientManager = clients.ClientManager(self.conf)
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
self.stackManager = stack.StackManager(self.clientManager,

View File

@ -22,9 +22,9 @@ class FloatingIPTest(base.ScenarioTestsBase):
"""Creates a server and checks it can reach it."""
# Defines parameters required by heat template
parameters = {'public_net': self.conf.floating_network_name,
parameters = {'public_net': self.conf.network.floating_network_name,
'image': "cirros-0.3.5-x86_64-disk.img",
'flavor': "m1.tiny"}
'flavor': "m1.micro"}
# creates stack and stores its ID
st = self.stackManager.create_stack(stack_name="fip",