commit 6b87d7d633dff0e73302a44f75b88de108203c7d Author: Rick Bartra Date: Thu Aug 16 14:53:30 2018 -0400 Framework for Airship Tempest Plugin This commit includes the following: - Base Classes for: * Shipyard tests * Shipyard RBAC tests - Unfinished Shipyard REST Clients for: * Document Staging API * Action API * Airflow Monitoring API * Log Retrieval API - RBAC Tests for Shipyard: * get workflows * get actions * get configdocs Future commits can follow this commit to further test Airship components. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..f028be8 --- /dev/null +++ b/README.rst @@ -0,0 +1,6 @@ +=============================================== +Tempest Integration of airship-tempest-plugin +=============================================== + +The purpose of this plugin is to provide automated tests +for all OpenStack Airship components. diff --git a/airship_tempest_plugin/README.rst b/airship_tempest_plugin/README.rst new file mode 100644 index 0000000..1a0edb4 --- /dev/null +++ b/airship_tempest_plugin/README.rst @@ -0,0 +1,6 @@ +=============================================== +Tempest Integration of airship-tempest-plugin +=============================================== + +This directory contains Tempest tests to cover the airship-tempest-plugin project. + diff --git a/airship_tempest_plugin/__init__.py b/airship_tempest_plugin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/config.py b/airship_tempest_plugin/config.py new file mode 100644 index 0000000..73287b2 --- /dev/null +++ b/airship_tempest_plugin/config.py @@ -0,0 +1,46 @@ +# Copyright 2015 +# 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. +from oslo_config import cfg + +service_available_group = cfg.OptGroup(name="service_available", + title="Available Airship Services") + +ServiceAvailableGroup = [ + cfg.BoolOpt("shipyard", + default=True, + help="Whether or not Shipyard is expected to be available."), +] + +shipyard_group = cfg.OptGroup(name='shipyard', + title='Shipyard service options') + +ShipyardGroup = [ + cfg.StrOpt('endpoint_type', + default='internal', + choices=['public', 'admin', 'internal'], + help="The endpoint type to use for the Shipyard service"), + cfg.StrOpt('catalog_type', + default='shipyard', + help="Catalog type of the Shipyard service"), +] + +def get_opt_lists(self, conf): + """ + Get a list of options for sample config generation + """ + return [ + (service_available_group, ServiceAvailableGroup), + (shipyard_group, ShipyardGroup) + ] diff --git a/airship_tempest_plugin/plugin.py b/airship_tempest_plugin/plugin.py new file mode 100644 index 0000000..d7056c0 --- /dev/null +++ b/airship_tempest_plugin/plugin.py @@ -0,0 +1,43 @@ +# Copyright 2015 +# 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. + + +import os + +from tempest import config +from tempest.test_discover import plugins + +from airship_tempest_plugin import config as project_config + + +class AirshipRbacPlugin(plugins.TempestPlugin): + def load_tests(self): + base_path = os.path.split(os.path.dirname( + os.path.abspath(__file__)))[0] + test_dir = "airship_tempest_plugin/tests" + full_test_dir = os.path.join(base_path, test_dir) + return full_test_dir, base_path + + def register_opts(self, conf): + config.register_opt_group(conf, project_config.service_available_group, + project_config.ServiceAvailableGroup) + config.register_opt_group(conf, project_config.shipyard_group, + project_config.ShipyardGroup) + def get_opt_lists(self): + return [ + (project_config.service_available_group.name, + project_config.ServiceAvailableGroup), + (project_config.shipyard_group.name, project_config.ShipyardGroup), + ] diff --git a/airship_tempest_plugin/services/__init__.py b/airship_tempest_plugin/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/services/shipyard/__init__.py b/airship_tempest_plugin/services/shipyard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/services/shipyard/json/__init__.py b/airship_tempest_plugin/services/shipyard/json/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/services/shipyard/json/actions_client.py b/airship_tempest_plugin/services/shipyard/json/actions_client.py new file mode 100644 index 0000000..f45517c --- /dev/null +++ b/airship_tempest_plugin/services/shipyard/json/actions_client.py @@ -0,0 +1,34 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +""" +http://airship-shipyard.readthedocs.io/en/latest/API.html#action-api +""" + +from oslo_serialization import jsonutils as json +from six.moves.urllib import parse as urllib + +from tempest.lib.common import rest_client + + +class ActionsClient(rest_client.RestClient): + api_version = "v1.0" + + def get_actions(self): + resp, body = self.get('actions') + self.expected_success(200, resp.status) + body = json.loads(body) + return rest_client.ResponseBody(resp, body) diff --git a/airship_tempest_plugin/services/shipyard/json/airflow_monitoring_client.py b/airship_tempest_plugin/services/shipyard/json/airflow_monitoring_client.py new file mode 100644 index 0000000..e6ec292 --- /dev/null +++ b/airship_tempest_plugin/services/shipyard/json/airflow_monitoring_client.py @@ -0,0 +1,34 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +""" +http://airship-shipyard.readthedocs.io/en/latest/API.html#airflow-monitoring-api +""" + +from oslo_serialization import jsonutils as json +from six.moves.urllib import parse as urllib + +from tempest.lib.common import rest_client + + +class AirflowMonitoringClient(rest_client.RestClient): + api_version = "v1.0" + + def get_workflows(self): + resp, body = self.get('workflows') + self.expected_success(200, resp.status) + body = json.loads(body) + return rest_client.ResponseBody(resp, body) diff --git a/airship_tempest_plugin/services/shipyard/json/document_staging_client.py b/airship_tempest_plugin/services/shipyard/json/document_staging_client.py new file mode 100644 index 0000000..80acae4 --- /dev/null +++ b/airship_tempest_plugin/services/shipyard/json/document_staging_client.py @@ -0,0 +1,34 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +""" +http://airship-shipyard.readthedocs.io/en/latest/API.html#document-staging-api +""" + +from oslo_serialization import jsonutils as json +from six.moves.urllib import parse as urllib + +from tempest.lib.common import rest_client + + +class DocumentStagingClient(rest_client.RestClient): + api_version = "v1.0" + + def get_configdocs(self): + resp, body = self.get('configdocs') + self.expected_success(200, resp.status) + body = json.loads(body) + return rest_client.ResponseBody(resp, body) diff --git a/airship_tempest_plugin/tests/__init__.py b/airship_tempest_plugin/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/tests/api/__init__.py b/airship_tempest_plugin/tests/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/tests/api/common/__init__.py b/airship_tempest_plugin/tests/api/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/tests/api/common/rbac_roles.yaml b/airship_tempest_plugin/tests/api/common/rbac_roles.yaml new file mode 100644 index 0000000..69063c7 --- /dev/null +++ b/airship_tempest_plugin/tests/api/common/rbac_roles.yaml @@ -0,0 +1,13 @@ +shipyard: + get_actions: + - admin + - admin_ucp + - admin_ucp_viewer + get_configdocs: + - admin + - admin_ucp + - admin_ucp_viewer + get_workflows: + - admin + - admin_ucp + - admin_ucp_viewer diff --git a/airship_tempest_plugin/tests/api/shipyard/__init__.py b/airship_tempest_plugin/tests/api/shipyard/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/tests/api/shipyard/base.py b/airship_tempest_plugin/tests/api/shipyard/base.py new file mode 100644 index 0000000..88f8233 --- /dev/null +++ b/airship_tempest_plugin/tests/api/shipyard/base.py @@ -0,0 +1,57 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +from airship_tempest_plugin.services.shipyard.json.actions_client import ActionsClient +from airship_tempest_plugin.services.shipyard.json.document_staging_client import DocumentStagingClient +from airship_tempest_plugin.services.shipyard.json.airflow_monitoring_client import AirflowMonitoringClient + +from tempest import config +from tempest import test + +from patrole_tempest_plugin import rbac_utils + +CONF = config.CONF + +class BaseShipyardTest(test.BaseTestCase): + """Base class for Shipyard tests.""" + credentials = ['primary', 'admin'] + + @classmethod + def skip_checks(cls): + super(BaseShipyardTest, cls).skip_checks() + if not CONF.service_available.shipyard: + raise cls.skipException("Shipyard is not enabled in the deployment") + + @classmethod + def setup_clients(cls): + super(BaseShipyardTest, cls).setup_clients() + cls.auth_provider = cls.os_primary.auth_provider + + cls.shipyard_actions_client = ActionsClient( + cls.auth_provider, + CONF.shipyard.catalog_type, + CONF.identity.region, + CONF.shipyard.endpoint_type) + cls.shipyard_document_staging_client = DocumentStagingClient( + cls.auth_provider, + CONF.shipyard.catalog_type, + CONF.identity.region, + CONF.shipyard.endpoint_type) + cls.shipyard_airflow_monitoring_client = AirflowMonitoringClient( + cls.auth_provider, + CONF.shipyard.catalog_type, + CONF.identity.region, + CONF.shipyard.endpoint_type) diff --git a/airship_tempest_plugin/tests/api/shipyard/rbac/__init__.py b/airship_tempest_plugin/tests/api/shipyard/rbac/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/airship_tempest_plugin/tests/api/shipyard/rbac/rbac_base.py b/airship_tempest_plugin/tests/api/shipyard/rbac/rbac_base.py new file mode 100644 index 0000000..655a21f --- /dev/null +++ b/airship_tempest_plugin/tests/api/shipyard/rbac/rbac_base.py @@ -0,0 +1,38 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +from airship_tempest_plugin.services.shipyard.json.actions_client import ActionsClient +from airship_tempest_plugin.tests.api.shipyard import base + +from tempest import config + +from patrole_tempest_plugin import rbac_utils + +CONF = config.CONF + +class BaseShipyardRbacTest(rbac_utils.RbacUtilsMixin, + base.BaseShipyardTest): + """Base class for Shipyard RBAC tests.""" + + @classmethod + def skip_checks(cls): + super(BaseShipyardRbacTest, cls).skip_checks() + cls.skip_rbac_checks() + + @classmethod + def setup_clients(cls): + super(BaseShipyardRbacTest, cls).setup_clients() + cls.setup_rbac_utils() diff --git a/airship_tempest_plugin/tests/api/shipyard/rbac/test_actions_rbac.py b/airship_tempest_plugin/tests/api/shipyard/rbac/test_actions_rbac.py new file mode 100644 index 0000000..84c95b1 --- /dev/null +++ b/airship_tempest_plugin/tests/api/shipyard/rbac/test_actions_rbac.py @@ -0,0 +1,35 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +from airship_tempest_plugin.tests.api.shipyard.rbac import rbac_base + +from patrole_tempest_plugin import rbac_rule_validation + +from tempest.common import utils +from tempest.lib import decorators +from tempest.lib.common.utils import data_utils +from tempest.lib.common.utils import test_utils + +from tempest.api.identity import base + +class ActionsRbacTest(rbac_base.BaseShipyardRbacTest): + + @rbac_rule_validation.action(service="shipyard", + rules=["get_actions"]) + @decorators.idempotent_id('183dd007-8a97-4070-afc3-9318401ebad7') + def test_get_actions(self): + with self.rbac_utils.override_role(self): + self.shipyard_actions_client.get_actions() diff --git a/airship_tempest_plugin/tests/api/shipyard/rbac/test_airflow_monitoring_rbac.py b/airship_tempest_plugin/tests/api/shipyard/rbac/test_airflow_monitoring_rbac.py new file mode 100644 index 0000000..74fd2d3 --- /dev/null +++ b/airship_tempest_plugin/tests/api/shipyard/rbac/test_airflow_monitoring_rbac.py @@ -0,0 +1,35 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +from airship_tempest_plugin.tests.api.shipyard.rbac import rbac_base + +from patrole_tempest_plugin import rbac_rule_validation + +from tempest.common import utils +from tempest.lib import decorators +from tempest.lib.common.utils import data_utils +from tempest.lib.common.utils import test_utils + +from tempest.api.identity import base + +class AirflowMonitoringRbacTest(rbac_base.BaseShipyardRbacTest): + + @rbac_rule_validation.action(service="shipyard", + rules=["get_configdocs"]) + @decorators.idempotent_id('0ab53b15-bce9-494f-9a11-34dd2c44d699') + def test_get_workflows(self): + with self.rbac_utils.override_role(self): + self.shipyard_airflow_monitoring_client.get_workflows() diff --git a/airship_tempest_plugin/tests/api/shipyard/rbac/test_document_staging_rbac.py b/airship_tempest_plugin/tests/api/shipyard/rbac/test_document_staging_rbac.py new file mode 100644 index 0000000..2906cda --- /dev/null +++ b/airship_tempest_plugin/tests/api/shipyard/rbac/test_document_staging_rbac.py @@ -0,0 +1,35 @@ +# Copyright 2018 AT&T Corp +# 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. +# + +from airship_tempest_plugin.tests.api.shipyard.rbac import rbac_base + +from patrole_tempest_plugin import rbac_rule_validation + +from tempest.common import utils +from tempest.lib import decorators +from tempest.lib.common.utils import data_utils +from tempest.lib.common.utils import test_utils + +from tempest.api.identity import base + +class DocumentStagingRbacTest(rbac_base.BaseShipyardRbacTest): + + @rbac_rule_validation.action(service="shipyard", + rules=["get_configdocs"]) + @decorators.idempotent_id('0ab53b15-bce9-494f-9a11-34dd2c44d699') + def test_get_configdocs(self): + with self.rbac_utils.override_role(self): + self.shipyard_document_staging_client.get_configdocs() diff --git a/airship_tempest_plugin/tests/scenario/__init__.py b/airship_tempest_plugin/tests/scenario/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..113f6b7 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,51 @@ +[metadata] +name = airship-tempest-plugin +summary = This project contains tests for Airship components +description-file = + README.rst +author = OpenStack +author-email = openstack-dev@lists.openstack.org +home-page = http://www.openstack.org/ +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.4 + +[files] +packages = + airship_tempest_plugin + +[build_sphinx] +all-files = 1 +warning-is-error = 1 +source-dir = doc/source +build-dir = doc/build + +[upload_sphinx] +upload-dir = doc/build/html + +[compile_catalog] +directory = airship-tempest-plugin/locale +domain = airship-tempest-plugin + +[update_catalog] +domain = airship-tempest-plugin +output_dir = airship-tempest-plugin/locale +input_file = airship-tempest-plugin/locale/airship-tempest-plugin.pot + +[extract_messages] +keywords = _ gettext ngettext l_ lazy_gettext +mapping_file = babel.cfg +output_file = airship-tempest-plugin/locale/airship-tempest-plugin.pot + +[entry_points] +tempest.test_plugins = + airship_rbac_tests = airship_tempest_plugin.plugin:AirshipRbacPlugin diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..056c16c --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr'], + pbr=True)