From dda009f4c32575925c8c42f11e6ed5d81ae78d5b Mon Sep 17 00:00:00 2001 From: Bin Qian Date: Thu, 6 Feb 2020 10:02:39 -0500 Subject: [PATCH 1/8] Adding job to upload commits to GitHub Add job to publish fault repo to GitHub Change-Id: Idf3b1f553f7126fd2c7551fa5ab5383ef445fca1 Story: 2007252 Task: 38678 Signed-off-by: Bin Qian --- .zuul.yaml | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/.zuul.yaml b/.zuul.yaml index bb18e312..e7bfdc20 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -19,6 +19,10 @@ - openstack-tox-pep8 - fault-rest-api-py27 - fault-rest-api-py35 + post: + jobs: + - stx-fault-upload-git-mirror + # Perform just a build - job: @@ -76,3 +80,95 @@ vars: tox_envlist: py35 tox_extra_args: -c fm-rest-api/fm/tox.ini + +- job: + name: stx-fault-upload-git-mirror + parent: upload-git-mirror + description: > + Mirrors opendev.org/starlingx/fault to + github.com/starlingx/fault + vars: + git_mirror_repository: starlingx/fault + secrets: + - name: git_mirror_credentials + secret: stx-fault-github-secret + pass-to-parent: true + +- secret: + name: stx-fault-github-secret + data: + user: git + host: github.com + # yamllint disable-line rule:line-length + host_key: github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== + ssh_key: !encrypted/pkcs1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QWzgPoN8KgCdQ+XzlJ+RoKNB8ZYnOoByJlG/P1z4q1ygVTFS8ZpOz1KJamUkMwAmRP + NGH7Qcn5XA+KVCKBbwfGNdNO5ruH1OyY1FDVYUu/MyiBwf1WgoyTtXtVMkocN7ISC22Xb + MD6q1jCsnOdh3nzblU8/QI+3XS1KPCoNIVbra5AkUQ7He6Z7BhXO/tuUObp0LHbowLWdn + DWevU3rEFimlKm87z1rR776oVaJhMpF7vbgvD4H1WkmM2ae7iAnqolcsxtlzwPQWgUsTr + TQFSlQtpy1j6PFfk0dfx+A4lQgCDEjWBGV2lFb9JjgeU0pW7X39JNvw67sWkGJBc0yOlv + m9Y0Ke3nQS1n7c8FBSgaglxexGOF/vq/+FoC99fp1maWj67Z9obBjD2OzMjxoXGsEZn3h + MTJ5V4+On0i9T51Dh1/+v+UGlJd3z5+3XdpOwQmgzPDMg1KEj7azFhC+xlP35Tmh3SlvT + 3d6/UYueGY1TFwwWt2Pw+uYC5cm+5zSkkqp6p2zB4LooMScOtnszy80FfoKSAE= From f63603e966a307b1942177e915a02b81a4567cdc Mon Sep 17 00:00:00 2001 From: albailey Date: Mon, 10 Feb 2020 09:19:55 -0600 Subject: [PATCH 2/8] Adding a tox coverage target for fm-rest-api. As new unit tests are being added, the coverage target helps to view their impact. Story: 2007082 Task: 38836 Change-Id: I2d57aac7c633ab358a2d31bfc8d8a8635931527f Signed-off-by: albailey --- fm-rest-api/fm/.coveragerc | 8 ++++++++ fm-rest-api/fm/tox.ini | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 fm-rest-api/fm/.coveragerc diff --git a/fm-rest-api/fm/.coveragerc b/fm-rest-api/fm/.coveragerc new file mode 100644 index 00000000..8fa459cc --- /dev/null +++ b/fm-rest-api/fm/.coveragerc @@ -0,0 +1,8 @@ +[run] +branch = True +source = fm +omit = fm/tests/* + +[report] +ignore_errors = True + diff --git a/fm-rest-api/fm/tox.ini b/fm-rest-api/fm/tox.ini index e8a7991c..58824682 100644 --- a/fm-rest-api/fm/tox.ini +++ b/fm-rest-api/fm/tox.ini @@ -29,6 +29,16 @@ commands = stestr run {posargs} stestr slowest +[testenv:cover] +deps = {[testenv]deps} + coverage +setenv = {[testenv]setenv} + PYTHON=coverage run --parallel-mode - - +commands = + coverage erase + stestr run {posargs} + coverage combine + coverage html -d cover + coverage xml -o cover/coverage.xml + coverage report From b1dfa14f0bcd6cc2460b589095d9695b794686d5 Mon Sep 17 00:00:00 2001 From: albailey Date: Mon, 2 Mar 2020 10:57:58 -0600 Subject: [PATCH 3/8] Fix py27 and py35 zuul jobs failing to setup As of March 1, when jobs run on ubuntu-xenial, they fail to run py27 and py35 jobs with an error similar to: /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python2.7 py27 ImportError: cannot import name 'ContextManager' It does not appear to impact the ubuntu-bionic nodes so updating zuul to use those nodes. bionic nodes do not support python3.5, so the py35 jobs is now converted to py36. Partial-Bug: 1865554 Change-Id: Iad13d03ced21294d1a02c82f4e1e37cac3f27ee7 Signed-off-by: albailey --- .zuul.yaml | 14 +++++++------- fm-rest-api/fm/tox.ini | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index e7bfdc20..9acdf138 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -12,13 +12,13 @@ - openstack-tox-pep8 - stx-fault-build - fault-rest-api-py27 - - fault-rest-api-py35 + - fault-rest-api-py36 gate: jobs: - openstack-tox-linters - openstack-tox-pep8 - fault-rest-api-py27 - - fault-rest-api-py35 + - fault-rest-api-py36 post: jobs: - stx-fault-upload-git-mirror @@ -62,7 +62,7 @@ parent: tox description: | Run py27 test for fm-rest-api - nodeset: ubuntu-xenial + nodeset: ubuntu-bionic required-projects: - starlingx/config vars: @@ -70,15 +70,15 @@ tox_extra_args: -c fm-rest-api/fm/tox.ini - job: - name: fault-rest-api-py35 + name: fault-rest-api-py36 parent: tox description: | - Run py35 test for fm-rest-api - nodeset: ubuntu-xenial + Run py36 test for fm-rest-api + nodeset: ubuntu-bionic required-projects: - starlingx/config vars: - tox_envlist: py35 + tox_envlist: py36 tox_extra_args: -c fm-rest-api/fm/tox.ini - job: diff --git a/fm-rest-api/fm/tox.ini b/fm-rest-api/fm/tox.ini index 58824682..8de4cc65 100644 --- a/fm-rest-api/fm/tox.ini +++ b/fm-rest-api/fm/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py35 +envlist = py27,py36 minversion = 2.3 skipsdist = True stxdir = {toxinidir}/../../../ @@ -23,8 +23,8 @@ commands = stestr run {posargs} stestr slowest -[testenv:py35] -basepython = python3.5 +[testenv:py36] +basepython = python3.6 commands = stestr run {posargs} stestr slowest From d73ba874571bdaeba24f856fb785749954a23c55 Mon Sep 17 00:00:00 2001 From: SidneyAn Date: Fri, 17 Jan 2020 13:56:12 +0800 Subject: [PATCH 4/8] add test framework for rest api tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this patch include: fake pecan app for api tests 4 test cases: bad url setup get_root get_v1_root Story: 2007082 Task: 38158 Change-Id: I3f933b43aede43f25abca3327a9638a6fa88914c Signed-off-by: SidneyAn --- fm-rest-api/fm/fm/tests/api/__init__.py | 14 +++++ fm-rest-api/fm/fm/tests/api/base.py | 79 ++++++++++++++++++++++++ fm-rest-api/fm/fm/tests/api/test_base.py | 30 +++++++++ fm-rest-api/fm/fm/tests/api/test_root.py | 40 ++++++++++++ fm-rest-api/fm/fm/tests/base.py | 5 ++ fm-rest-api/fm/test-requirements.txt | 17 ++++- fm-rest-api/fm/tox.ini | 3 + 7 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 fm-rest-api/fm/fm/tests/api/__init__.py create mode 100644 fm-rest-api/fm/fm/tests/api/base.py create mode 100644 fm-rest-api/fm/fm/tests/api/test_base.py create mode 100644 fm-rest-api/fm/fm/tests/api/test_root.py diff --git a/fm-rest-api/fm/fm/tests/api/__init__.py b/fm-rest-api/fm/fm/tests/api/__init__.py new file mode 100644 index 00000000..70618e64 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/api/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Intel Corporation. +# 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. diff --git a/fm-rest-api/fm/fm/tests/api/base.py b/fm-rest-api/fm/fm/tests/api/base.py new file mode 100644 index 00000000..d8506099 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/api/base.py @@ -0,0 +1,79 @@ +# Copyright 2020 Intel Corporation. +# 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. +"""Base classes for API tests.""" + +from oslo_config import cfg +import pecan +import pecan.testing + +from fm.tests import base +from fm.common import context as fm_context + + +PATH_PREFIX = '/v1' + + +class FunctionalTest(base.TestCase): + """Used for functional tests of Pecan controllers where you need to + test your literal application and its integration with the + framework. + """ + + SOURCE_DATA = {'test_source': {'somekey': '666'}} + + def setUp(self): + super(FunctionalTest, self).setUp() + self.context = fm_context.RequestContext(is_admin=True) + self.app = self._make_app() + + def _make_app(self): + cfg.CONF.set_override("debug", True) + + self.config = { + 'app': { + 'root': 'fm.api.controllers.root.RootController', + 'modules': ['fm.api'], + 'acl_public_routes': ['/', '/v1'], + }, + } + + return pecan.testing.load_test_app(self.config) + + def tearDown(self): + super(FunctionalTest, self).tearDown() + pecan.set_config({}, overwrite=True) + + def get_json(self, path, expect_errors=False, headers=None, + extra_environ=None, q=[], path_prefix=PATH_PREFIX, **params): + full_path = path_prefix + path + query_params = {'q.field': [], + 'q.value': [], + 'q.op': [], + } + for query in q: + for name in ['field', 'op', 'value']: + query_params['q.%s' % name].append(query.get(name, '')) + all_params = {} + all_params.update(params) + if q: + all_params.update(query_params) + response = self.app.get(full_path, + params=all_params, + headers=headers, + extra_environ=extra_environ, + expect_errors=expect_errors) + if not expect_errors: + response = response.json + return response diff --git a/fm-rest-api/fm/fm/tests/api/test_base.py b/fm-rest-api/fm/fm/tests/api/test_base.py new file mode 100644 index 00000000..179ea53a --- /dev/null +++ b/fm-rest-api/fm/fm/tests/api/test_base.py @@ -0,0 +1,30 @@ +# Copyright 2020 Intel Corporation. +# 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 fm.tests.api import base + + +class TestBase(base.FunctionalTest): + + def test_api_setup(self): + pass + + def test_bad_uri(self): + response = self.get_json('/bad/path', + expect_errors=True, + headers={"Accept": "application/json"}) + self.assertEqual(response.status_int, 404) + self.assertEqual(response.content_type, "application/json") + self.assertTrue(response.json['error_message']) diff --git a/fm-rest-api/fm/fm/tests/api/test_root.py b/fm-rest-api/fm/fm/tests/api/test_root.py new file mode 100644 index 00000000..802e41ae --- /dev/null +++ b/fm-rest-api/fm/fm/tests/api/test_root.py @@ -0,0 +1,40 @@ +# Copyright 2013 Red Hat, Inc. +# 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. +# +# Copyright 2020 Intel Corporation. +# + +from fm.tests.api import base + + +class TestRoot(base.FunctionalTest): + + def test_get_root(self): + data = self.get_json('/', path_prefix='') + self.assertEqual(data['default_version']['id'], 'v1') + # Check fields are not empty + [self.assertNotIn(f, ['', []]) for f in data.keys()] + + +class TestV1Root(base.FunctionalTest): + + def test_get_v1_root(self): + data = self.get_json('/') + self.assertEqual(data['id'], 'v1') + # Check fields are not empty + [self.assertNotIn(f, ['', []]) for f in data.keys()] + # Check if the resources are present + self.assertIn({'type': 'application/vnd.openstack.fm.v1+json', + 'base': 'application/json'}, data['media_types']) diff --git a/fm-rest-api/fm/fm/tests/base.py b/fm-rest-api/fm/fm/tests/base.py index 9a8d4678..3f5e7e71 100644 --- a/fm-rest-api/fm/fm/tests/base.py +++ b/fm-rest-api/fm/fm/tests/base.py @@ -19,7 +19,10 @@ Allows overriding of config for use of fakes, and some black magic for inline callbacks. """ +import sys + import fixtures +import mock import testtools from oslo_config import cfg @@ -27,6 +30,8 @@ from oslo_log import log as logging CONF = cfg.CONF +sys.modules['fm_core'] = mock.Mock() + class TestCase(testtools.TestCase): """Test case base class for all unit tests.""" diff --git a/fm-rest-api/fm/test-requirements.txt b/fm-rest-api/fm/test-requirements.txt index 02dc0100..d5e38037 100644 --- a/fm-rest-api/fm/test-requirements.txt +++ b/fm-rest-api/fm/test-requirements.txt @@ -9,5 +9,18 @@ stestr mock cython oslo.log -oslo.concurrency - +oslo.i18n # Apache-2.0 +oslo.config>=3.7.0 # Apache-2.0 +oslo.concurrency>=3.7.1 # Apache-2.0 +oslo.db>=4.1.0 # Apache-2.0 +oslo.service>=1.10.0 # Apache-2.0 +oslo.utils>=3.5.0 # Apache-2.0 +oslo.serialization>=1.10.0,!=2.19.1 # Apache-2.0 +oslo_policy +oslo_versionedobjects +python-keystoneclient>=3.8.0 # Apache-2.0 +keystonemiddleware>=4.12.0 # Apache-2.0 +pecan>=1.0.0 +WSME>=0.5b2 +httplib2 +keyring <= 18.0.1 diff --git a/fm-rest-api/fm/tox.ini b/fm-rest-api/fm/tox.ini index 8de4cc65..f883d69e 100644 --- a/fm-rest-api/fm/tox.ini +++ b/fm-rest-api/fm/tox.ini @@ -12,6 +12,9 @@ setenv = VIRTUAL_ENV={envdir} OS_TEST_TIMEOUT=60 deps = -r{toxinidir}/test-requirements.txt -e{[tox]stxdir}/config/tsconfig/tsconfig + -e{[tox]stxdir}/config/sysinv/cgts-client/cgts-client + -e{[tox]stxdir}/fault/fm-api + -e{[tox]stxdir}/fault/fm-rest-api/fm [testenv:venv] basepython = python3 From 170d4fefb72d3b48bc5ddeabb8daa67945b658c6 Mon Sep 17 00:00:00 2001 From: SidneyAn Date: Thu, 16 Jan 2020 16:46:44 +0800 Subject: [PATCH 5/8] Add test case to create alarm into database Add test class DbAlarmTestCase, DbTestCase Add fake database in tests/base.py. Add test case test_create_alarm Story: 2007082 Task: 38085 Depends-on: https://review.opendev.org/#/c/702175/ Depends-on: https://review.opendev.org/#/c/702347/ Change-Id: I906edc894c97fdeb8c52730e00fba765d33edc0f Signed-off-by: SidneyAn --- fm-rest-api/fm/fm/tests/base.py | 15 +++++++ fm-rest-api/fm/fm/tests/conf_fixture.py | 33 +++++++++++++++ fm-rest-api/fm/fm/tests/db/__init__.py | 14 +++++++ fm-rest-api/fm/fm/tests/db/base.py | 30 ++++++++++++++ fm-rest-api/fm/fm/tests/db/test_alarm.py | 24 +++++++++++ fm-rest-api/fm/fm/tests/db/utils.py | 53 ++++++++++++++++++++++++ 6 files changed, 169 insertions(+) create mode 100644 fm-rest-api/fm/fm/tests/conf_fixture.py create mode 100644 fm-rest-api/fm/fm/tests/db/__init__.py create mode 100644 fm-rest-api/fm/fm/tests/db/base.py create mode 100644 fm-rest-api/fm/fm/tests/db/test_alarm.py create mode 100644 fm-rest-api/fm/fm/tests/db/utils.py diff --git a/fm-rest-api/fm/fm/tests/base.py b/fm-rest-api/fm/fm/tests/base.py index 3f5e7e71..e6abb5d2 100644 --- a/fm-rest-api/fm/fm/tests/base.py +++ b/fm-rest-api/fm/fm/tests/base.py @@ -26,9 +26,15 @@ import mock import testtools from oslo_config import cfg +from oslo_db.sqlalchemy import enginefacade from oslo_log import log as logging +from fm.db import migration +from fm.tests import conf_fixture + CONF = cfg.CONF +_DB_CACHE = None +INIT_VERSION = 0 sys.modules['fm_core'] = mock.Mock() @@ -47,5 +53,14 @@ class TestCase(testtools.TestCase): fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup)) logging.register_options(CONF) + self.useFixture(conf_fixture.ConfFixture(CONF)) + + global _DB_CACHE + if not _DB_CACHE: + engine = enginefacade.get_legacy_facade().get_engine() + engine.dispose() + engine.connect() + migration.db_sync(engine=engine) + def tearDown(self): super(TestCase, self).tearDown() diff --git a/fm-rest-api/fm/fm/tests/conf_fixture.py b/fm-rest-api/fm/fm/tests/conf_fixture.py new file mode 100644 index 00000000..5440ee87 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/conf_fixture.py @@ -0,0 +1,33 @@ +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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 +from oslo_config import fixture as config_fixture + +CONF = cfg.CONF + + +class ConfFixture(config_fixture.Config): + """Fixture to manage global conf settings.""" + + def __init__(self, conf): + self.conf = conf + + def setUp(self): + super(ConfFixture, self).setUp() + + self.conf.set_default('connection', "sqlite://", group='database') + self.addCleanup(self.conf.reset) diff --git a/fm-rest-api/fm/fm/tests/db/__init__.py b/fm-rest-api/fm/fm/tests/db/__init__.py new file mode 100644 index 00000000..70618e64 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/db/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Intel Corporation. +# 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. diff --git a/fm-rest-api/fm/fm/tests/db/base.py b/fm-rest-api/fm/fm/tests/db/base.py new file mode 100644 index 00000000..43131988 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/db/base.py @@ -0,0 +1,30 @@ +# Copyright 2020 Intel Corporation. +# 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. + +"""Fault DB test base class.""" + +import abc +import six + +from fm.common import context +from fm.tests import base + + +@six.add_metaclass(abc.ABCMeta) +class DbTestCase(base.TestCase): + + def setUp(self): + super(DbTestCase, self).setUp() + self.admin_context = context.make_context(is_admin=True) diff --git a/fm-rest-api/fm/fm/tests/db/test_alarm.py b/fm-rest-api/fm/fm/tests/db/test_alarm.py new file mode 100644 index 00000000..3c64c471 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/db/test_alarm.py @@ -0,0 +1,24 @@ +# Copyright 2020 Intel Corporation. +# +# SPDX-License-Identifier: Apache-2.0 +# + + +"""Tests for Alarm via the DB API""" + +from fm.db import api as dbapi +from fm.tests.db import base +from fm.tests.db import utils + + +class DbAlarmTestCase(base.DbTestCase): + + def setUp(self): + super(DbAlarmTestCase, self).setUp() + self.dbapi = dbapi.get_instance() + + def test_create_alarm(self): + uuid = 1234567 + alarm = utils.get_test_alarm(uuid=uuid) + alarm_exist = self.dbapi.alarm_create(alarm) + self.assertEqual(uuid, alarm_exist.uuid) diff --git a/fm-rest-api/fm/fm/tests/db/utils.py b/fm-rest-api/fm/fm/tests/db/utils.py new file mode 100644 index 00000000..94153b59 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/db/utils.py @@ -0,0 +1,53 @@ +# 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. +# +# Copyright 2020 Intel Corporation. +# + +"""Fault test utilities.""" + +from fm.db import api as db_api +from fm_api import constants + + +def get_test_alarm(**kw): + alarm = { + 'uuid': kw.get('uuid'), + 'alarm_id': kw.get('alarm_id', constants.FM_ALARM_ID_VM_FAILED), + 'alarm_state': kw.get('alarm_state', constants.FM_ALARM_STATE_SET), + 'entity_type_id': kw.get('entity_type_id', constants.FM_ENTITY_TYPE_INSTANCE), + 'entity_instance_id': kw.get('entity_instance_id', + constants.FM_ENTITY_TYPE_INSTANCE + '=' + + 'a4e4cdb7-2ee6-4818-84c8-5310fcd67b5d'), + 'severity': kw.get('severity', constants.FM_ALARM_SEVERITY_CRITICAL), + 'reason_text': kw.get('reason_text', "Unknown"), + 'alarm_type': kw.get('alarm_type', constants.FM_ALARM_TYPE_5), + 'probable_cause': kw.get('probable_cause', constants.ALARM_PROBABLE_CAUSE_8), + 'proposed_repair_action': None, + 'service_affecting': False, + 'suppression': False + } + return alarm + + +def create_test_alarm(**kw): + """Create test alarm entry in DB and return alarm DB object. + Function to be used to create test alarm objects in the database. + :param kw: kwargs with overriding values for alarm's attributes. + :returns: Test alarm DB object. + """ + alarm = get_test_alarm(**kw) + # Let DB generate ID if it isn't specified explicitly + dbapi = db_api.get_instance() + return dbapi.alarm_create(alarm) From 8fcd1cbe0346d9f28e5afe79373e16551838b926 Mon Sep 17 00:00:00 2001 From: SidneyAn Date: Wed, 15 Jan 2020 09:45:53 +0800 Subject: [PATCH 6/8] add test case for migration sync and version add test class DbSyncTestCase add test case for migration database sync Story: 2007082 Task: 38152 Depends-on: https://review.opendev.org/#/c/702823/ Signed-off-by: SidneyAn Signed-off-by: chenyan Change-Id: I8121dedae7e4319a454dc128a591f74ef066c149 --- fm-rest-api/fm/fm/tests/base.py | 25 ++++++++++++++++++++- fm-rest-api/fm/fm/tests/conf_fixture.py | 2 ++ fm-rest-api/fm/fm/tests/db/base.py | 2 ++ fm-rest-api/fm/fm/tests/db/utils.py | 3 +-- fm-rest-api/fm/fm/tests/test_dbsync.py | 29 +++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 fm-rest-api/fm/fm/tests/test_dbsync.py diff --git a/fm-rest-api/fm/fm/tests/base.py b/fm-rest-api/fm/fm/tests/base.py index e6abb5d2..7c7cf4fa 100644 --- a/fm-rest-api/fm/fm/tests/base.py +++ b/fm-rest-api/fm/fm/tests/base.py @@ -20,6 +20,7 @@ inline callbacks. """ import sys +import os import fixtures import mock @@ -34,7 +35,6 @@ from fm.tests import conf_fixture CONF = cfg.CONF _DB_CACHE = None -INIT_VERSION = 0 sys.modules['fm_core'] = mock.Mock() @@ -46,11 +46,34 @@ class TestCase(testtools.TestCase): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() + test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) + try: + test_timeout = int(test_timeout) + except ValueError: + # If timeout value is invalid do not set a timeout. + test_timeout = 0 + if test_timeout > 0: + self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) + self.useFixture(fixtures.NestedTempfile()) + self.useFixture(fixtures.TempHomeDir()) + + if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or + os.environ.get('OS_STDOUT_CAPTURE') == '1'): + stdout = self.useFixture(fixtures.StringStream('stdout')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) + if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or + os.environ.get('OS_STDERR_CAPTURE') == '1'): + stderr = self.useFixture(fixtures.StringStream('stderr')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) + + self.log_fixture = self.useFixture(fixtures.FakeLogger()) + def fake_logging_setup(*args): pass self.useFixture( fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup)) + logging.register_options(CONF) self.useFixture(conf_fixture.ConfFixture(CONF)) diff --git a/fm-rest-api/fm/fm/tests/conf_fixture.py b/fm-rest-api/fm/fm/tests/conf_fixture.py index 5440ee87..83f2e809 100644 --- a/fm-rest-api/fm/fm/tests/conf_fixture.py +++ b/fm-rest-api/fm/fm/tests/conf_fixture.py @@ -13,6 +13,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +# +# Copyright 2020 Intel Corporation. from oslo_config import cfg from oslo_config import fixture as config_fixture diff --git a/fm-rest-api/fm/fm/tests/db/base.py b/fm-rest-api/fm/fm/tests/db/base.py index 43131988..2315eff6 100644 --- a/fm-rest-api/fm/fm/tests/db/base.py +++ b/fm-rest-api/fm/fm/tests/db/base.py @@ -21,6 +21,8 @@ import six from fm.common import context from fm.tests import base +INIT_VERSION = 0 + @six.add_metaclass(abc.ABCMeta) class DbTestCase(base.TestCase): diff --git a/fm-rest-api/fm/fm/tests/db/utils.py b/fm-rest-api/fm/fm/tests/db/utils.py index 94153b59..4df03dc2 100644 --- a/fm-rest-api/fm/fm/tests/db/utils.py +++ b/fm-rest-api/fm/fm/tests/db/utils.py @@ -12,8 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright 2020 Intel Corporation. -# +# Copyright 2020 Intel Corporation """Fault test utilities.""" diff --git a/fm-rest-api/fm/fm/tests/test_dbsync.py b/fm-rest-api/fm/fm/tests/test_dbsync.py new file mode 100644 index 00000000..95f63d49 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/test_dbsync.py @@ -0,0 +1,29 @@ +# Copyright 2020 Intel Corporation. +# 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 fm.db import migration +from fm.db.sqlalchemy import api as db_api +from fm.tests.db import base + + +class DbSyncTestCase(base.DbTestCase): + def setUp(self): + super(DbSyncTestCase, self).setUp() + + def test_sync_and_version(self): + migration.db_sync() + engine = db_api.get_engine() + v = migration.get_backend().db_version(engine, migration.MIGRATE_REPO_PATH, None) + self.assertTrue(v > base.INIT_VERSION) From ce56ce7ea57c06f4d1660c61221caf3fc32952da Mon Sep 17 00:00:00 2001 From: albailey Date: Tue, 10 Mar 2020 16:22:44 -0500 Subject: [PATCH 7/8] Adding pylint zuul and tox target Adding a pylint tox target which only suppresses the error codes that are currently failing. This will prevent any of the passing checks from being broken by future submissions. The currently suppressed codes can be fixed by subsequent commits. Adds a zuul pylint target to invoke the new tox target. Unified the install_command in tox.ini to ensure the upper constraints are used. Change-Id: Id2fb8cbb7ce63f844a06403410d461c601822ad6 Story: 2007082 Task: 39020 Signed-off-by: albailey --- .zuul.yaml | 12 ++ fm-api/fm_api/fm_api.py | 2 +- pylint.rc | 267 ++++++++++++++++++++++++++++++++++++++++ requirements.txt | 15 +++ test-requirements.txt | 1 + tox.ini | 26 +++- 6 files changed, 317 insertions(+), 6 deletions(-) create mode 100755 pylint.rc create mode 100644 requirements.txt diff --git a/.zuul.yaml b/.zuul.yaml index 9acdf138..4bcb0ae8 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -10,6 +10,7 @@ jobs: - openstack-tox-linters - openstack-tox-pep8 + - fault-tox-pylint - stx-fault-build - fault-rest-api-py27 - fault-rest-api-py36 @@ -17,6 +18,7 @@ jobs: - openstack-tox-linters - openstack-tox-pep8 + - fault-tox-pylint - fault-rest-api-py27 - fault-rest-api-py36 post: @@ -81,6 +83,16 @@ tox_envlist: py36 tox_extra_args: -c fm-rest-api/fm/tox.ini +- job: + name: fault-tox-pylint + parent: tox + description: | + Run pylint for python files in fault + required-projects: + - starlingx/config + vars: + tox_envlist: pylint + - job: name: stx-fault-upload-git-mirror parent: upload-git-mirror diff --git a/fm-api/fm_api/fm_api.py b/fm-api/fm_api/fm_api.py index d2cd34d8..0da0b7b6 100755 --- a/fm-api/fm_api/fm_api.py +++ b/fm-api/fm_api/fm_api.py @@ -13,7 +13,7 @@ import copy from . import constants import six -import fm_core +import fm_core # pylint: disable=import-error import threading fm_api_lock = threading.Lock() diff --git a/pylint.rc b/pylint.rc new file mode 100755 index 00000000..9acd1ce2 --- /dev/null +++ b/pylint.rc @@ -0,0 +1,267 @@ +[MASTER] +# Specify a configuration file. +rcfile=pylint.rc + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Add files or directories to the blacklist. Should be base names, not paths. +ignore= + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Use multiple processes to speed up Pylint. +jobs=4 + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist=lxml.etree,greenlet + + + +[MESSAGES CONTROL] +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). +# See "Messages Control" section of +# https://pylint.readthedocs.io/en/latest/user_guide +# We are disabling (C)onvention +# We are disabling (R)efactor +# We are selectively disabling (W)arning +# W0102 dangerous-default-value +# W0106 expression-not-assigned +# W0107 unnecessary-pass +# W0110 deprecated-lambda +# W0201 attribute-defined-outside-init +# W0212 protected-access +# W0221 arguments-differ +# W0223 abstract-method +# W0231 super-init-not-called +# W0235 useless-super-delegation +# W0311 bad-indentation +# W0403 relative-import (this needs to be fixed in py3) +# W0603 global-statement +# W0612 unused-variable +# W0613 unused-argument +# W0621 redefined-outer-name +# W0622 redefined-builtin +# W0703 broad-except +# W1401 anomalous-backslash-in-string +# E are error codes +# E0604 invalid-all-object +# E1101 no-member +# E1102 not-callable +# E1120 no-value-for-parameter +# E1121 too-many-function-args +disable=C, R, fixme, + W0102,W0106,W0107,W0110,W0201,W0212,W0221,W0223,W0231,W0235, + W0311,W0403,W0603,W0612,W0613,W0621,W0622,W0703,W1401, + E0604,E1101,E1102,E1120,E1121 + +[REPORTS] +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html +output-format=text + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + + +[SIMILARITIES] +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + + +[FORMAT] +# Maximum number of characters on a single line. +max-line-length=85 + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually 4 spaces or "\t" (1 tab). +indent-string=' ' + + +[TYPECHECK] +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis +ignored-modules=distutils,eventlet.green.subprocess,six,six.moves + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +# pylint is confused by sqlalchemy Table, as well as sqlalchemy Enum types +# ie: (unprovisioned, identity) +# LookupDict in requests library confuses pylint +ignored-classes=SQLObject, optparse.Values, thread._local, _thread._local, + Table, unprovisioned, identity, LookupDict + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[BASIC] +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression which should only match functions or classes name which do +# not require a docstring +no-docstring-rgx=__.*__ + + +[MISCELLANEOUS] +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[VARIABLES] +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the beginning of the name of dummy variables +# (i.e. not used). +dummy-variables-rgx=_|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[IMPORTS] +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,string,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[DESIGN] +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branchs=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[CLASSES] +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + + +[EXCEPTIONS] +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..ccc829ca --- /dev/null +++ b/requirements.txt @@ -0,0 +1,15 @@ +httplib2 +keystoneauth1 +keystonemiddleware +oslo.config +oslo.db +oslo.log +oslo.policy +oslo.service +oslo.utils +oslo.versionedobjects +pecan +prettytable +pyOpenSSL +SQLAlchemy +WSME diff --git a/test-requirements.txt b/test-requirements.txt index 21c49e2f..8f1b9382 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,6 @@ hacking!=0.13.0,<0.14,>=0.12.0 bashate >= 0.2 +mock PyYAML >= 3.1.0 yamllint >= 0.5.2 #spec_cleaner>=1.0.9 diff --git a/tox.ini b/tox.ini index 875d9873..17cf525c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,13 @@ [tox] -envlist = linters,pep8,rpm-packaging-lint +envlist = linters,pep8,pylint,rpm-packaging-lint minversion = 2.3 skipsdist = True stxdir = {toxinidir}/../ [testenv] -install_command = pip install -U {opts} {packages} +install_command = pip install \ + -chttps://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt \ + {opts} {packages} setenv = VIRTUAL_ENV={envdir} OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 @@ -17,9 +19,6 @@ basepython = python3 setenv = VIRTUAL_ENV={envdir} LC_ALL=en_US.utf-8 -install_command = pip install -U \ - -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt} \ - {opts} {packages} deps = -r{toxinidir}/test-requirements.txt whitelist_externals = bash commands = @@ -51,6 +50,23 @@ commands = -o -type f -name '*.yaml' \ -print0 | xargs -0 yamllint -d '\{extends: relaxed, rules: \{line-length: \{max: 260\}\}\}'" +[testenv:pylint] +basepython = python2.7 +sitepackages = False + +deps = {[testenv]deps} + -e{toxinidir}/../config/tsconfig/tsconfig + -e{toxinidir}/../config/sysinv/cgts-client/cgts-client + -r{toxinidir}/requirements.txt + pylint + +commands = pylint {posargs} --rcfile=./pylint.rc \ + fm-api/fm_api \ + fm-common/sources/fm_db_sync_event_suppression.py \ + fm-rest-api/fm/fm \ + python-fmclient/fmclient/fmclient + + #### # Add flake8 as pep8 codestyle check. [testenv:pep8] From b70b9b5220940325844f4fb19d6e8a13c5e5bb1a Mon Sep 17 00:00:00 2001 From: Gerry Kopec Date: Mon, 30 Mar 2020 14:43:36 -0400 Subject: [PATCH 8/8] Fix stestr version so py27 tox can pass stestr was upgraded to 3.0.0 on Mar. 26 and it does not support py27. Update test requirements accordingly so py27 tests will use earlier version. Change-Id: Ia481a4609d81ad4d225aeb6ec3ab0cc3a9e18ae5 Closes-Bug: 1869777 Signed-off-by: Gerry Kopec --- fm-rest-api/fm/test-requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fm-rest-api/fm/test-requirements.txt b/fm-rest-api/fm/test-requirements.txt index d5e38037..00adf991 100644 --- a/fm-rest-api/fm/test-requirements.txt +++ b/fm-rest-api/fm/test-requirements.txt @@ -2,10 +2,9 @@ hacking!=0.13.0,<0.14,>=0.12.0 bashate >= 0.2 PyYAML >= 3.1.0 yamllint >= 0.5.2 -stestr +stestr != 3.0.0 testtools!=1.2.0,>=0.9.36 iso8601 -stestr mock cython oslo.log