Commit 7d8aae08 authored by Chris Dent's avatar Chris Dent Committed by liusheng

Make ceilometer work correctly when hosted with a SCRIPT_NAME

In the past ceilometer was generaly hosted at / and URL generation
was relatively straightforward. It should also be possible to host
at /foobar or /telemetry and for URL generation to still work. This
changeset adds tests to confirm prefixed requests can work and fixes
the small number of issues that were found.

Note that because the ceilometer api has the temerity to not set
location headers, we can't test that those are working, because
there aren't any. In general that's the place where SCRIPT_NAME
mounting would show bugs.

But we can confirm that content-location headers are okay.

Closes-Bug: #1468796
Change-Id: I6e5cf440bc3bd8ffb4cc5c86aa19225b3c5f87ed
parent 34c6eb03
......@@ -6,4 +6,4 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
test_id_option=--load-list $IDFILE
test_list_option=--list
# NOTE(chdent): Only used/matches on gabbi-related tests.
group_regex=(gabbi\.driver\.test_gabbi_[^_]+)_
group_regex=(gabbi\.driver\.test_gabbi_(?:prefix_|)[^_]+)_
......@@ -27,7 +27,7 @@ class RootController(object):
@pecan.expose('json')
def index(self):
base_url = pecan.request.host_url
base_url = pecan.request.application_url
available = [{'tag': 'v2', 'date': '2013-02-13T00:00:00Z', }]
collected = [version_descriptor(base_url, v['tag'], v['date'])
for v in available]
......
......@@ -100,14 +100,14 @@ class ResourcesController(rest.RestController):
rel=rel_name)
def _resource_links(self, resource_id, meter_links=1):
links = [self._make_link('self', pecan.request.host_url,
links = [self._make_link('self', pecan.request.application_url,
'resources', resource_id)]
if meter_links:
for meter in pecan.request.storage_conn.get_meters(
resource=resource_id):
query = {'field': 'resource_id', 'value': resource_id}
links.append(self._make_link(meter.name,
pecan.request.host_url,
pecan.request.application_url,
'meters', meter.name,
query=query))
return links
......
# This test runs against the Events API and confirms the
# content-location header includes a prefix.
fixtures:
- ConfigFixture
- EventDataFixture
tests:
- name: get all events
url: /v2/events
response_headers:
content-type: application/json; charset=UTF-8
content-location: /$SCHEME://.*/telemetry/v2/events/
#
# Confirm root reports the right data including a prefixed URL
#
fixtures:
- ConfigFixture
tests:
# Root gives us some information on where to go from here.
- name: quick root check
url: /
response_headers:
content-type: application/json; charset=UTF-8
response_strings:
- '"base": "application/json"'
response_json_paths:
versions.values.[0].status: stable
versions.values.[0].media-types.[0].base: application/json
response_strings:
- /telemetry/
# Post a simple sample and confirm the created resource has
# reasonable URLs
fixtures:
- ConfigFixture
tests:
# POST one sample and verify its existence.
- name: post sample for meter
desc: post a single sample
url: /v2/meters/apples?direct=True
method: POST
request_headers:
content-type: application/json
data: |
[
{
"counter_name": "apples",
"project_id": "35b17138-b364-4e6a-a131-8f3099c5be68",
"user_id": "efd87807-12d2-4b38-9c70-5f5c2ac427ff",
"counter_unit": "instance",
"counter_volume": 1,
"resource_id": "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
"resource_metadata": {
"name2": "value2",
"name1": "value1"
},
"counter_type": "gauge"
}
]
response_json_paths:
$.[0].counter_name: apples
status: 201
response_headers:
content-type: application/json; charset=UTF-8
- name: get resources
desc: get the resources that exist because of the sample
url: /v2/resources
response_json_paths:
$.[0].metadata.name2: value2
- name: get resource
desc: get just one of those resources via self
url: $RESPONSE['$[0].links[0].href']
response_json_paths:
$.metadata.name2: value2
response_strings:
- /telemetry/
#
# Explore and cover resources API with gabbi tests when there are a
# small number of pre-existing resources
#
fixtures:
- ConfigFixture
- SampleDataFixture
tests:
- name: list all resources
url: /v2/resources
response_json_paths:
$[0].user_id: farmerjon
$[0].links[1].rel: livestock
response_strings:
- /telemetry/
- name: get one resource
desc: get a resource via the links in the first resource listed above
url: $RESPONSE['$[0].links[0].href']
response_json_paths:
$.resource_id: $RESPONSE['$[0].resource_id']
#
# Copyright 2015 Red Hat. All Rights Reserved.
#
# 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.
"""A module to exercise the Ceilometer API with gabbi with a URL prefix"""
import os
from gabbi import driver
from ceilometer.api import app
from ceilometer.tests.gabbi import fixtures as fixture_module
TESTS_DIR = 'gabbits_prefix'
def load_tests(loader, tests, pattern):
"""Provide a TestSuite to the discovery process."""
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
return driver.build_tests(test_dir, loader, host=None,
prefix='/telemetry',
intercept=app.VersionSelectorApplication,
fixture_module=fixture_module)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment