Initial pass at allowing multiple services

Previously, the host was the endpoint of the service being tested.
This is limiting if what's really desired is testing multiple
services. So now we move towards setting environmen variable that
are the endpoints for any of the services that are going to be used.

Then these can be made available from any test.

Right now it is not like that. Right now it builds environments
based on the requested types. Better to just set them all and then
allow the host either be a primary service type endpoint, or a stub
if it really is going to be lots.

Committing now because tests are mostly passing (except for the
phantom failures). Cleanup to come.
This commit is contained in:
Chris Dent 2017-07-30 19:25:50 +00:00
parent 0525a268fa
commit ead5d0d51a
4 changed files with 38 additions and 35 deletions

View File

@ -14,6 +14,7 @@ import os
import unittest
from gabbi import driver
from gabbi.handlers import jsonhandler
import six.moves.urllib.parse as urlparse
from tempest import config
import tempest.test
@ -39,23 +40,20 @@ class GenericGabbiTest(tempest.test.BaseTestCase):
@classmethod
def resource_setup(cls):
super(GenericGabbiTest, cls).resource_setup()
url, token = cls._get_service_auth()
parsed_url = urlparse.urlsplit(url)
prefix = parsed_url.path.rstrip('/') # turn it into a prefix
port = 443 if parsed_url.scheme == 'https' else 80
host = parsed_url.hostname
if parsed_url.port:
port = parsed_url.port
endpoints, token = cls._get_service_auth([cls.service_type])
for service_type, url in endpoints.items():
name = '%s_SERVICE' % service_type.upper()
os.environ[name] = url
test_dir = os.path.join(os.path.dirname(__file__), 'gabbits',
cls.service_type)
cls.tests = driver.build_tests(
test_dir, unittest.TestLoader(),
host=host, port=port, prefix=prefix,
test_dir, unittest.TestLoader(), host='stub',
test_loader_name='tempest.scenario.%s.%s' % (
cls.__name__, cls.service_type))
os.environ["SERVICE_TOKEN"] = token
os.environ['SERVICE_TOKEN'] = token
@classmethod
def clear_credentials(cls):
@ -74,15 +72,20 @@ class GenericGabbiTest(tempest.test.BaseTestCase):
self.tearDown()
@classmethod
def _get_service_auth(cls):
endpoint_type = 'publicURL'
def _get_service_auth(cls, service_types):
interface = 'public'
auth = cls.os_admin.auth_provider.get_auth()
endpoints = [e for e in auth[1]['serviceCatalog']
if e['type'] == cls.service_type]
if not endpoints:
raise Exception("%s endpoint not found" % cls.service_type)
return endpoints[0]['endpoints'][0][endpoint_type], auth[0]
token = auth[0]
catalog = auth[1]['catalog']
endpoints = {}
for service_type in service_types:
result = jsonhandler.JSONHandler.extract_json_path_value(catalog,
'$[?type = "%s"].endpoints[?interface = "%s"].url' %
(service_type, interface))
endpoints[service_type] = result
return endpoints, token
def test_fake(self):
# NOTE(sileht): A fake test is needed to have the class loaded

View File

@ -9,21 +9,21 @@ defaults:
tests:
- name: retrieve root
GET: /
GET: $ENVIRON['COMPUTE_SERVICE']/
response_json_paths:
# $NETLOC contains the /v2.1 prefix
$.version.links[?rel = "self"].href: $SCHEME://$NETLOC/
$.version.links[?rel = "self"].href: /$ENVIRON['COMPUTE_SERVICE']/
$.version.status: CURRENT
- name: retrieve empty servers
GET: /servers
GET: $ENVIRON['COMPUTE_SERVICE']/servers
response_json_paths:
$.servers: []
- name: try bad accept
desc: https://bugs.launchpad.net/nova/+bug/1567966
xfail: True
GET: /servers
GET: $ENVIRON['COMPUTE_SERVICE']/servers
request_headers:
accept: text/plain
status: 406
@ -31,20 +31,20 @@ tests:
- name: try bad method
desc: https://bugs.launchpad.net/nova/+bug/1567970
xfail: True
DELETE: /servers
DELETE: $ENVIRON['COMPUTE_SERVICE']/servers
status: 405
- name: post bad content-type
desc: https://bugs.launchpad.net/nova/+bug/1567977
xfail: True
POST: /servers
POST: $ENVIRON['COMPUTE_SERVICE']/servers
request_headers:
content-type: text/plain
data: I want a server so badly
status: 415
- name: create server
POST: /servers
POST: $ENVIRON['COMPUTE_SERVICE']/servers
request_headers:
content-type: application/json
data:
@ -66,11 +66,11 @@ tests:
response_json_paths:
$.server.status: ACTIVE
- name: get bookmark
GET: $RESPONSE['$.server.links[?rel = "bookmark"].href']
status: 300
# bookmark link, whatever it is, is busted. Goes to bad version
# - name: get bookmark
# GET: $ENVIRON['COMPUTE_SERVICE']/$RESPONSE['$.server.links[?rel = "bookmark"].href']
- name: get 2.1 server via bookmark
GET: $RESPONSE['$.choices[?status = "CURRENT"].links[?rel = "self"].href']
- name: get server
GET: $RESPONSE['$.server.links[?rel = "self"].href']
response_json_paths:
$.server.name: new-server-one

View File

@ -9,7 +9,7 @@ defaults:
tests:
- name: retrieve root
GET: /
GET: $ENVIRON['IMAGE_SERVICE']/
status: 300
- name: choose current api
@ -18,16 +18,16 @@ tests:
GET: $RESPONSE['$.versions[?status = "CURRENT"].links[?rel = "self"].href']
- name: get images
GET: /v2/images
GET: $ENVIRON['IMAGE_SERVICE']/v2/images
- name: get one image
GET: $RESPONSE['$.images[0].self']
GET: $ENVIRON['IMAGE_SERVICE']$RESPONSE['$.images[0].self']
response_json_paths:
$.status: active
$.schema: /v2/schemas/image
- name: get the schema
GET: $RESPONSE['$.schema']
GET: $ENVIRON['IMAGE_SERVICE']$RESPONSE['$.schema']
response_json_paths:
$.name: image

View File

@ -30,4 +30,4 @@ source-dir = docs/source
[entry_points]
tempest.test_plugins =
plugin_name = gabbi_tempest.plugin:GabbiTempestPlugin
gabbi = gabbi_tempest.plugin:GabbiTempestPlugin