functional tests: don't require devstack
Now py27 bootstrap mysql and gnocchi to run tests against them.
This commit is contained in:
@@ -2,6 +2,6 @@
|
|||||||
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
|
||||||
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
|
||||||
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
|
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
|
||||||
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./gnocchiclient/tests/unit} $LISTOPT $IDOPTION
|
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./gnocchiclient/tests} $LISTOPT $IDOPTION
|
||||||
test_id_option=--load-list $IDFILE
|
test_id_option=--load-list $IDFILE
|
||||||
test_list_option=--list
|
test_list_option=--list
|
||||||
|
|||||||
@@ -11,10 +11,36 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import uuid
|
||||||
|
|
||||||
from tempest_lib.cli import base
|
from tempest_lib.cli import base
|
||||||
|
|
||||||
|
|
||||||
|
class GnocchiClient(object):
|
||||||
|
"""Gnocchi Client for tempest-lib
|
||||||
|
|
||||||
|
This client doesn't use any authentification system
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.cli_dir = os.environ.get('GNOCCHI_CLIENT_EXEC_DIR')
|
||||||
|
self.endpoint = os.environ.get('GNOCCHI_ENDPOINT')
|
||||||
|
self.user_id = uuid.uuid4()
|
||||||
|
self.project_id = uuid.uuid4()
|
||||||
|
|
||||||
|
def gnocchi(self, action, flags='', params='',
|
||||||
|
fail_ok=False, merge_stderr=False):
|
||||||
|
creds = ("--os-auth-plugin gnocchi-noauth "
|
||||||
|
"--user-id %s --project-id %s "
|
||||||
|
"--endpoint %s") % (self.user_id,
|
||||||
|
self.project_id,
|
||||||
|
self.endpoint)
|
||||||
|
|
||||||
|
flags = creds + ' ' + flags
|
||||||
|
return base.execute("gnocchi", action, flags, params, fail_ok,
|
||||||
|
merge_stderr, self.cli_dir)
|
||||||
|
|
||||||
|
|
||||||
class ClientTestBase(base.ClientTestBase):
|
class ClientTestBase(base.ClientTestBase):
|
||||||
"""Base class for gnocchiclient tests.
|
"""Base class for gnocchiclient tests.
|
||||||
|
|
||||||
@@ -23,13 +49,7 @@ class ClientTestBase(base.ClientTestBase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_clients(self):
|
def _get_clients(self):
|
||||||
cli_dir = os.environ.get('OS_GNOCCHI_CLIENT_EXEC_DIR')
|
return GnocchiClient()
|
||||||
return base.CLIClient(
|
|
||||||
username=os.environ.get('OS_USERNAME'),
|
|
||||||
password=os.environ.get('OS_PASSWORD'),
|
|
||||||
tenant_name=os.environ.get('OS_TENANT_NAME'),
|
|
||||||
uri=os.environ.get('OS_AUTH_URL'),
|
|
||||||
cli_dir=cli_dir)
|
|
||||||
|
|
||||||
def gnocchi(self, *args, **kwargs):
|
def gnocchi(self, *args, **kwargs):
|
||||||
return self.clients.cmd_with_auth('gnocchi', *args, **kwargs)
|
return self.clients.gnocchi(*args, **kwargs)
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
# 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 re
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from tempest_lib.cli import base as tempest_lib_cli_base
|
|
||||||
|
|
||||||
from gnocchiclient.tests.functional import base
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceClientTest(base.ClientTestBase):
|
|
||||||
def test_no_auth(self):
|
|
||||||
result = self.gnocchi('resource', params="list", flags="--debug",
|
|
||||||
merge_stderr=True)
|
|
||||||
endpoint = re.findall("(http://[^/]*)/v1/resource/generic",
|
|
||||||
result, re.M)[0]
|
|
||||||
|
|
||||||
result = tempest_lib_cli_base.execute(
|
|
||||||
'gnocchi', 'resource', params="list",
|
|
||||||
flags=("--os-auth-plugin gnocchi-noauth "
|
|
||||||
"--user-id %s "
|
|
||||||
"--project-id %s "
|
|
||||||
"--endpoint %s"
|
|
||||||
) % (str(uuid.uuid4()),
|
|
||||||
str(uuid.uuid4()),
|
|
||||||
endpoint),
|
|
||||||
fail_ok=True, merge_stderr=True,
|
|
||||||
cli_dir=self.clients.cli_dir)
|
|
||||||
self.assertFirstLineStartsWith(result.split('\n'),
|
|
||||||
"Unauthorized (HTTP 401)")
|
|
||||||
@@ -161,7 +161,7 @@ class ResourceManager(base.Manager):
|
|||||||
request = request or {}
|
request = request or {}
|
||||||
qs = _get_pagination_options(details, False, limit, marker, sorts)
|
qs = _get_pagination_options(details, False, limit, marker, sorts)
|
||||||
url = self.client._build_url(
|
url = self.client._build_url(
|
||||||
"/search/resource/%s?%s" % (resource_type, qs))
|
"search/resource/%s?%s" % (resource_type, qs))
|
||||||
return self.client.api.post(
|
return self.client.api.post(
|
||||||
url, headers={'Content-Type': "application/json"},
|
url, headers={'Content-Type': "application/json"},
|
||||||
data=jsonutils.dumps(request)).json()
|
data=jsonutils.dumps(request)).json()
|
||||||
|
|||||||
58
setup-tests.sh
Executable file
58
setup-tests.sh
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e -x
|
||||||
|
|
||||||
|
wait_for_line () {
|
||||||
|
while read line
|
||||||
|
do
|
||||||
|
echo "$line" | grep -q "$1" && break
|
||||||
|
done < "$2"
|
||||||
|
# Read the fifo for ever otherwise process would block
|
||||||
|
cat "$2" &
|
||||||
|
# cat "$2" >/dev/null &
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_exit (){
|
||||||
|
local error_code="$?"
|
||||||
|
kill $(jobs -p)
|
||||||
|
rm -rf "$@"
|
||||||
|
return $error_code
|
||||||
|
}
|
||||||
|
|
||||||
|
GNOCCHI_DATA=`mktemp -d /tmp/gnocchi-data-XXXXX`
|
||||||
|
MYSQL_DATA=`mktemp -d /tmp/gnocchi-mysql-XXXXX`
|
||||||
|
trap "clean_exit \"$GNOCCHI_DATA\" \"$MYSQL_DATA\"" EXIT
|
||||||
|
|
||||||
|
mkfifo ${MYSQL_DATA}/out
|
||||||
|
PATH=$PATH:/usr/libexec
|
||||||
|
mysqld --no-defaults --datadir=${MYSQL_DATA} --pid-file=${MYSQL_DATA}/mysql.pid --socket=${MYSQL_DATA}/mysql.socket --skip-networking --skip-grant-tables &> ${MYSQL_DATA}/out &
|
||||||
|
# Wait for MySQL to start listening to connections
|
||||||
|
wait_for_line "mysqld: ready for connections." ${MYSQL_DATA}/out
|
||||||
|
export GNOCCHI_TEST_INDEXER_URL="mysql+pymysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8"
|
||||||
|
mysql --no-defaults -S ${MYSQL_DATA}/mysql.socket -e 'CREATE DATABASE test;'
|
||||||
|
|
||||||
|
|
||||||
|
mkfifo ${GNOCCHI_DATA}/out
|
||||||
|
echo '{"default": ""}' > ${GNOCCHI_DATA}/policy.json
|
||||||
|
cat > ${GNOCCHI_DATA}/gnocchi.conf <<EOF
|
||||||
|
[oslo_policy]
|
||||||
|
policy_file = ${GNOCCHI_DATA}/policy.json
|
||||||
|
[api]
|
||||||
|
middlewares =
|
||||||
|
[storage]
|
||||||
|
file_basepath = ${GNOCCHI_DATA}
|
||||||
|
driver = file
|
||||||
|
coordination_url = file://${GNOCCHI_DATA}
|
||||||
|
[indexer]
|
||||||
|
url = mysql+pymysql://root@localhost/test?unix_socket=${MYSQL_DATA}/mysql.socket&charset=utf8
|
||||||
|
EOF
|
||||||
|
gnocchi-dbsync --config-file ${GNOCCHI_DATA}/gnocchi.conf
|
||||||
|
gnocchi-metricd --config-file ${GNOCCHI_DATA}/gnocchi.conf &>/dev/null &
|
||||||
|
gnocchi-api --config-file ${GNOCCHI_DATA}/gnocchi.conf &> ${GNOCCHI_DATA}/out &
|
||||||
|
# Wait for Gnocchi to start
|
||||||
|
wait_for_line "Running on http://0.0.0.0:8041/" ${GNOCCHI_DATA}/out
|
||||||
|
export GNOCCHI_ENDPOINT=http://localhost:8041/
|
||||||
|
|
||||||
|
create_archive_policy() { curl -X POST -H "X-USER-ID: $(uuidgen)" -H "X-PROJECT-ID: $(uuidgen)" -H "Content-Type: application/json" -d "$1" ${GNOCCHI_ENDPOINT}v1/archive_policy ; }
|
||||||
|
create_archive_policy '{"name":"high","definition":[{"granularity": "1s","points": 86400},{"granularity": "1m","points": 43200},{"granularity": "1h","points": 8760}]}'
|
||||||
|
|
||||||
|
$*
|
||||||
@@ -14,3 +14,6 @@ tempest-lib>=0.6.1
|
|||||||
testrepository>=0.0.18
|
testrepository>=0.0.18
|
||||||
testscenarios>=0.4
|
testscenarios>=0.4
|
||||||
testtools>=1.4.0
|
testtools>=1.4.0
|
||||||
|
http://tarballs.openstack.org/gnocchi/gnocchi-master.tar.gz#egg=gnocchi
|
||||||
|
# FIXME(sileht): should be in gnocchi ?
|
||||||
|
keystonemiddleware
|
||||||
|
|||||||
21
tox.ini
21
tox.ini
@@ -5,11 +5,14 @@ skipsdist = True
|
|||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
install_command = pip install -U {opts} {packages}
|
install_command = pip install -U --allow-external gnocchi --allow-insecure gnocchi {opts} {packages}
|
||||||
setenv =
|
setenv =
|
||||||
VIRTUAL_ENV={envdir}
|
VIRTUAL_ENV={envdir}
|
||||||
deps = -r{toxinidir}/test-requirements.txt
|
GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin
|
||||||
commands = python setup.py test --slowest --testr-args='{posargs}'
|
passenv = GNOCCHI_*
|
||||||
|
deps = -r{toxinidir}/requirements.txt
|
||||||
|
-r{toxinidir}/test-requirements.txt
|
||||||
|
commands = {toxinidir}/setup-tests.sh python setup.py test --slowest --testr-args='{posargs}'
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
commands = flake8
|
commands = flake8
|
||||||
@@ -26,18 +29,6 @@ commands = python setup.py build_sphinx
|
|||||||
[testenv:debug]
|
[testenv:debug]
|
||||||
commands = oslo_debug_helper {posargs}
|
commands = oslo_debug_helper {posargs}
|
||||||
|
|
||||||
[testenv:py27-functional]
|
|
||||||
setenv =
|
|
||||||
OS_TEST_PATH=./gnocchiclient/tests/functional
|
|
||||||
OS_GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin
|
|
||||||
passenv = OS_*
|
|
||||||
|
|
||||||
[testenv:py34-functional]
|
|
||||||
setenv =
|
|
||||||
OS_TEST_PATH=./gnocchiclient/tests/functional
|
|
||||||
OS_GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin
|
|
||||||
passenv = OS_*
|
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# E123, E125 skipped as they are invalid PEP-8.
|
# E123, E125 skipped as they are invalid PEP-8.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user