From 8ece6590c99b8a632d1941f92d7bbd5ceddf681c Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Thu, 5 Jul 2018 16:29:43 +0900 Subject: [PATCH] Adds /os-hosts api tests using gabbi This patch adds /os-host api tests using gabbi. Tests for /leases api will be added in a following patch. Depends-On: https://review.openstack.org/581939 Depends-On: https://review.openstack.org/580538 Change-Id: Ic8dc7b1942f312d6dcbe5f2ad6a73289eaf7c838 --- blazar_tempest_plugin/tests/api/__init__.py | 0 blazar_tempest_plugin/tests/api/fixtures.py | 30 +++++++++++++++++ .../tests/api/gabbits/hosts.yaml | 33 +++++++++++++++++++ .../tests/api/test_blazar_api.py | 30 +++++++++++++++++ doc/source/usage.rst | 19 +++++++++++ requirements.txt | 1 + 6 files changed, 113 insertions(+) create mode 100644 blazar_tempest_plugin/tests/api/__init__.py create mode 100644 blazar_tempest_plugin/tests/api/fixtures.py create mode 100644 blazar_tempest_plugin/tests/api/gabbits/hosts.yaml create mode 100644 blazar_tempest_plugin/tests/api/test_blazar_api.py create mode 100644 doc/source/usage.rst diff --git a/blazar_tempest_plugin/tests/api/__init__.py b/blazar_tempest_plugin/tests/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blazar_tempest_plugin/tests/api/fixtures.py b/blazar_tempest_plugin/tests/api/fixtures.py new file mode 100644 index 0000000..1ae88fa --- /dev/null +++ b/blazar_tempest_plugin/tests/api/fixtures.py @@ -0,0 +1,30 @@ +# +# 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 gabbi import fixture +from tempest import clients as tempestclients +from tempest import test + + +class AuthenticationFixture(fixture.GabbiFixture, test.BaseTestCase): + def start_fixture(self): + cred_provider = self._get_credentials_provider() + creds = cred_provider.get_credentials('admin') + auth_prov = tempestclients.get_auth_provider(creds._credentials) + + os.environ['OS_TOKEN'] = auth_prov.get_token() + + def stop_fixture(self): + pass diff --git a/blazar_tempest_plugin/tests/api/gabbits/hosts.yaml b/blazar_tempest_plugin/tests/api/gabbits/hosts.yaml new file mode 100644 index 0000000..3118cc6 --- /dev/null +++ b/blazar_tempest_plugin/tests/api/gabbits/hosts.yaml @@ -0,0 +1,33 @@ +fixtures: + - AuthenticationFixture + +defaults: + request_headers: + accept: application/json + content-type: application/json + X-Auth-Token: $ENVIRON['OS_TOKEN'] + +tests: +- name: get host name + GET: compute/v2.1/os-hypervisors + status: 200 + +- name: post new host + POST: reservation/v1/os-hosts + data: + name: $HISTORY['get host name'].$RESPONSE['$.hypervisors[0].hypervisor_hostname'] + status: 201 + +- name: get new host + GET: reservation/v1/os-hosts + response_json_paths: + $.hosts.`len`: 1 + +- name: delete new host + DELETE: reservation/v1/os-hosts/$HISTORY['get new host'].$RESPONSE['$.hosts[0].id'] + status: 204 + +- name: get no host + GET: reservation/v1/os-hosts + response_json_paths: + $.hosts.`len`: 0 diff --git a/blazar_tempest_plugin/tests/api/test_blazar_api.py b/blazar_tempest_plugin/tests/api/test_blazar_api.py new file mode 100644 index 0000000..79c3b3b --- /dev/null +++ b/blazar_tempest_plugin/tests/api/test_blazar_api.py @@ -0,0 +1,30 @@ +# +# 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 test module to exercise the Blazar API with gabbi.""" + +import os + +from blazar_tempest_plugin.tests.api import fixtures +from gabbi import driver + +TESTS_DIR = 'gabbits' + + +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, + test_loader_name=__name__, + fixture_module=fixtures, + url='http://127.0.0.1/') diff --git a/doc/source/usage.rst b/doc/source/usage.rst new file mode 100644 index 0000000..d508a86 --- /dev/null +++ b/doc/source/usage.rst @@ -0,0 +1,19 @@ +===== +Usage +===== + +The api tests are defined in .yaml files and should be executed +in the order in the file. To do this, set ``group_regex`` parameter +in ``.stestr.conf``:: + + group_regex=blazar_tempest_plugin\.tests\.api\.test_blazar_api + +or, you can also save the test order by setting the number of test +workers to one via tempest run options:: + + $ tempest run --regex blazar_tempest_plugin --serial + +or:: + + $ tempest run --regex blazar_tempest_plugin --concurrency=1 + diff --git a/requirements.txt b/requirements.txt index 78bd2cc..ae74d89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ oslo.config>=5.2.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 tempest>=17.1.0 # Apache-2.0 +gabbi>=1.42.1 # Apache-2.0