diff --git a/.testr.conf b/.testr.conf index 2476587..a3c4d9d 100644 --- a/.testr.conf +++ b/.testr.conf @@ -2,6 +2,6 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ 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_list_option=--list diff --git a/gnocchiclient/tests/functional/base.py b/gnocchiclient/tests/functional/base.py index 233e258..ba2ab28 100644 --- a/gnocchiclient/tests/functional/base.py +++ b/gnocchiclient/tests/functional/base.py @@ -11,10 +11,36 @@ # under the License. import os +import uuid 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): """Base class for gnocchiclient tests. @@ -23,13 +49,7 @@ class ClientTestBase(base.ClientTestBase): """ def _get_clients(self): - cli_dir = os.environ.get('OS_GNOCCHI_CLIENT_EXEC_DIR') - 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) + return GnocchiClient() def gnocchi(self, *args, **kwargs): - return self.clients.cmd_with_auth('gnocchi', *args, **kwargs) + return self.clients.gnocchi(*args, **kwargs) diff --git a/gnocchiclient/tests/functional/test_shell.py b/gnocchiclient/tests/functional/test_shell.py deleted file mode 100644 index 1f8124d..0000000 --- a/gnocchiclient/tests/functional/test_shell.py +++ /dev/null @@ -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)") diff --git a/gnocchiclient/v1/resource.py b/gnocchiclient/v1/resource.py index f37c35f..9d4a00e 100644 --- a/gnocchiclient/v1/resource.py +++ b/gnocchiclient/v1/resource.py @@ -161,7 +161,7 @@ class ResourceManager(base.Manager): request = request or {} qs = _get_pagination_options(details, False, limit, marker, sorts) url = self.client._build_url( - "/search/resource/%s?%s" % (resource_type, qs)) + "search/resource/%s?%s" % (resource_type, qs)) return self.client.api.post( url, headers={'Content-Type': "application/json"}, data=jsonutils.dumps(request)).json() diff --git a/setup-tests.sh b/setup-tests.sh new file mode 100755 index 0000000..923ffc6 --- /dev/null +++ b/setup-tests.sh @@ -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 </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}]}' + +$* diff --git a/test-requirements.txt b/test-requirements.txt index 485d2ec..2ed2e03 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,3 +14,6 @@ tempest-lib>=0.6.1 testrepository>=0.0.18 testscenarios>=0.4 testtools>=1.4.0 +http://tarballs.openstack.org/gnocchi/gnocchi-master.tar.gz#egg=gnocchi +# FIXME(sileht): should be in gnocchi ? +keystonemiddleware diff --git a/tox.ini b/tox.ini index 97a364f..e0cdeda 100644 --- a/tox.ini +++ b/tox.ini @@ -5,11 +5,14 @@ skipsdist = True [testenv] usedevelop = True -install_command = pip install -U {opts} {packages} +install_command = pip install -U --allow-external gnocchi --allow-insecure gnocchi {opts} {packages} setenv = VIRTUAL_ENV={envdir} -deps = -r{toxinidir}/test-requirements.txt -commands = python setup.py test --slowest --testr-args='{posargs}' + GNOCCHI_CLIENT_EXEC_DIR={envdir}/bin +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] commands = flake8 @@ -26,18 +29,6 @@ commands = python setup.py build_sphinx [testenv:debug] 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] # E123, E125 skipped as they are invalid PEP-8.