diff --git a/.pylintrc b/.pylintrc index e88a201c..399e935d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -44,7 +44,7 @@ symbols=no # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=W,C,R +disable=W,C,R,E1002 [REPORTS] diff --git a/devstack/gate_hook.sh b/devstack/gate_hook.sh index e48e35b7..22347926 100755 --- a/devstack/gate_hook.sh +++ b/devstack/gate_hook.sh @@ -18,4 +18,5 @@ set -ex # Install freezer devstack integration export DEVSTACK_LOCAL_CONFIG="enable_plugin freezer-api https://git.openstack.org/openstack/freezer-api" +# Invoke default behavior. $BASE/new/devstack-gate/devstack-vm-gate.sh diff --git a/freezer_api/tests/freezer_api_tempest_plugin/README.rst b/freezer_api/tests/freezer_api_tempest_plugin/README.rst index 97983de1..1a68d483 100644 --- a/freezer_api/tests/freezer_api_tempest_plugin/README.rst +++ b/freezer_api/tests/freezer_api_tempest_plugin/README.rst @@ -1,6 +1,6 @@ =============================================== -Tempest Integration of Sample +Tempest Integration of Freezer API =============================================== -This directory contains Tempest tests to cover the Sample project. +This directory contains Tempest tests to cover the freezer-api project. diff --git a/freezer_api/tests/freezer_api_tempest_plugin/clients.py b/freezer_api/tests/freezer_api_tempest_plugin/clients.py new file mode 100644 index 00000000..3d8f0908 --- /dev/null +++ b/freezer_api/tests/freezer_api_tempest_plugin/clients.py @@ -0,0 +1,25 @@ +# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP +# +# 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. + +from tempest import clients + +from freezer_api.tests.freezer_api_tempest_plugin.services import \ + freezer_api_client + + +class Manager(clients.Manager): + def __init__(self, credentials=None, service=None): + super(Manager, self).__init__(credentials, service) + self.freezer_api_client = freezer_api_client.FreezerApiClient( + self.auth_provider) diff --git a/freezer_api/tests/freezer_api_tempest_plugin/config.py b/freezer_api/tests/freezer_api_tempest_plugin/config.py index 5f5602fe..240e5d89 100644 --- a/freezer_api/tests/freezer_api_tempest_plugin/config.py +++ b/freezer_api/tests/freezer_api_tempest_plugin/config.py @@ -23,4 +23,24 @@ ServiceAvailableGroup = [ cfg.BoolOpt("freezer-api", default=True, help="Whether or not Freezer API is expected to be available"), +] + +freezer_api_group = cfg.OptGroup(name="backup", + title="Freezer API Service Options") + +FreezerApiGroup = [ + cfg.StrOpt("region", + default="", + help="The freezer api region name to use. If empty, the value " + "of identity.region is used instead. If no such region " + "is found in the service catalog, the first found one is " + "used."), + cfg.StrOpt("catalog_type", + default="backup", + help="Catalog type of the freezer-api service."), + cfg.StrOpt('endpoint_type', + default='publicURL', + choices=['public', 'admin', 'internal', + 'publicURL', 'adminURL', 'internalURL'], + help="The endpoint type to use for the freezer-api service.") ] \ No newline at end of file diff --git a/freezer_api/tests/freezer_api_tempest_plugin/plugin.py b/freezer_api/tests/freezer_api_tempest_plugin/plugin.py index 96c8ea7e..203487e7 100644 --- a/freezer_api/tests/freezer_api_tempest_plugin/plugin.py +++ b/freezer_api/tests/freezer_api_tempest_plugin/plugin.py @@ -33,6 +33,9 @@ class FreezerApiTempestPlugin(plugins.TempestPlugin): config.register_opt_group( conf, freezer_api_config.service_available_group, freezer_api_config.ServiceAvailableGroup) + config.register_opt_group(conf, freezer_api_config.freezer_api_group, + freezer_api_config.FreezerApiGroup) def get_opt_lists(self): - pass \ No newline at end of file + return [(freezer_api_config.frezer_api_group.name, + freezer_api_config.FreezerApiGroup)] diff --git a/freezer_api/tests/freezer_api_tempest_plugin/services/freezer_api_client.py b/freezer_api/tests/freezer_api_tempest_plugin/services/freezer_api_client.py new file mode 100644 index 00000000..a18e9eea --- /dev/null +++ b/freezer_api/tests/freezer_api_tempest_plugin/services/freezer_api_client.py @@ -0,0 +1,34 @@ +# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP +# +# 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. + +from oslo_serialization import jsonutils as json + +from tempest import config +from tempest_lib.common import rest_client + +CONF = config.CONF + +class FreezerApiClient(rest_client.RestClient): + + def __init__(self, auth_provider): + super(FreezerApiClient, self).__init__( + auth_provider, + CONF.backup.catalog_type, + CONF.backup.region or CONF.identity.region, + endpoint_type=CONF.backup.endpoint_type + ) + + def get_version(self): + resp, response_body = self.get('/') + return resp, response_body \ No newline at end of file diff --git a/freezer_api/tests/freezer_api_tempest_plugin/tests/api/base.py b/freezer_api/tests/freezer_api_tempest_plugin/tests/api/base.py index 44005486..b8273819 100644 --- a/freezer_api/tests/freezer_api_tempest_plugin/tests/api/base.py +++ b/freezer_api/tests/freezer_api_tempest_plugin/tests/api/base.py @@ -11,8 +11,35 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from tempest import config +from tempest.common import credentials_factory import tempest.test +from freezer_api.tests.freezer_api_tempest_plugin import clients + +CONF = config.CONF + class BaseFreezerApiTest(tempest.test.BaseTestCase): - pass \ No newline at end of file + """Base test case class for all Freezer API tests.""" + + @classmethod + def skip_checks(cls): + super(BaseFreezerApiTest, cls).skip_checks() + + @classmethod + def resource_setup(cls): + super(BaseFreezerApiTest, cls).resource_setup() + auth_version = CONF.identity.auth_version + cls.cred_provider = credentials_factory.get_credentials_provider( + cls.__name__, + force_tenant_isolation=True, + identity_version=auth_version) + credentials = cls.cred_provider.get_creds_by_roles( + ['admin', 'service']) + cls.os = clients.Manager(credentials=credentials) + cls.freezer_api_client = cls.os.freezer_api_client + + @classmethod + def resource_cleanup(cls): + super(BaseFreezerApiTest, cls).resource_cleanup() + diff --git a/freezer_api/tests/freezer_api_tempest_plugin/tests/api/test_api_version.py b/freezer_api/tests/freezer_api_tempest_plugin/tests/api/test_api_version.py index 044542cd..4e0927bf 100644 --- a/freezer_api/tests/freezer_api_tempest_plugin/tests/api/test_api_version.py +++ b/freezer_api/tests/freezer_api_tempest_plugin/tests/api/test_api_version.py @@ -17,7 +17,16 @@ from tempest import test class TestFreezerApiVersion(base.BaseFreezerApiTest): + @classmethod + def resource_setup(cls): + super(TestFreezerApiVersion, cls).resource_setup() + + @classmethod + def resource_cleanup(cls): + super(TestFreezerApiVersion, cls).resource_cleanup() + @test.attr(type="gate") def test_api_version(self): - # See if tempest plugin tests run. - self.assertEqual(1, 1, 'First test case') \ No newline at end of file + + resp, response_body = self.freezer_api_client.get_version() + self.assertEqual(300, resp.status) diff --git a/freezer_api/tests/post_test_hook.sh b/freezer_api/tests/post_test_hook.sh index 861313fb..78fec491 100755 --- a/freezer_api/tests/post_test_hook.sh +++ b/freezer_api/tests/post_test_hook.sh @@ -13,12 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. +# Called by gate-freezer-api-devstack-dsvm job. + # This script is executed inside post_test_hook function in devstack gate. +echo 'Running freezer-api post_test_hook' + # Install packages from test-requirements.txt sudo pip install -r /opt/stack/new/freezer-api/test-requirements.txt cd /opt/stack/new/freezer-api/freezer_api/tests -echo 'Running freezer-api integration tests' # Here it goes the command to execute integration tests #sudo ./run_tests.sh diff --git a/freezer_api/tests/pre_test_hook.sh b/freezer_api/tests/pre_test_hook.sh new file mode 100644 index 00000000..78630a27 --- /dev/null +++ b/freezer_api/tests/pre_test_hook.sh @@ -0,0 +1,21 @@ +#!/bin/bash -xe + +# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP +# +# 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. + +# Called by gate-freezer-api-devstack-dsvm job. + +echo 'Running freezer-api pre_test_hook' + +# Nothing to do. Can be used when needed.