diff --git a/.gitignore b/.gitignore index b5d9fe78..e22628c0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ develop-eggs dist eggs sdist +.stestr +.ipynb_checkpoints # Sphinx documentation doc/build diff --git a/.zuul.yaml b/.zuul.yaml index b6ccb236..89bc428c 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -11,10 +11,14 @@ - openstack-tox-linters - openstack-tox-pep8 - stx-fault-build + - fault-rest-api-py27 + - fault-rest-api-py35 gate: jobs: - openstack-tox-linters - openstack-tox-pep8 + - fault-rest-api-py27 + - fault-rest-api-py35 # Perform just a build - job: @@ -48,3 +52,23 @@ fault: https://opendev.org/starlingx/fault integ: https://opendev.org/starlingx/integ update: https://opendev.org/starlingx/update + +- job: + name: fault-rest-api-py27 + parent: tox + description: | + Run py27 test for fm-rest-api + nodeset: ubuntu-xenial + vars: + tox_envlist: py27 + tox_extra_args: -c fm-rest-api/fm/tox.ini + +- job: + name: fault-rest-api-py35 + parent: tox + description: | + Run py35 test for fm-rest-api + nodeset: ubuntu-xenial + vars: + tox_envlist: py35 + tox_extra_args: -c fm-rest-api/fm/tox.ini diff --git a/fm-rest-api/fm/.stestr.conf b/fm-rest-api/fm/.stestr.conf new file mode 100644 index 00000000..cd89410f --- /dev/null +++ b/fm-rest-api/fm/.stestr.conf @@ -0,0 +1,5 @@ +[DEFAULT] +test_path=./fm/tests +top_dir=./ +#parallel_class=True + diff --git a/fm-rest-api/fm/fm/common/timeutils.py b/fm-rest-api/fm/fm/common/timeutils.py index 77d76e47..62f8e609 100644 --- a/fm-rest-api/fm/fm/common/timeutils.py +++ b/fm-rest-api/fm/fm/common/timeutils.py @@ -46,9 +46,9 @@ def parse_isotime(timestr): try: return iso8601.parse_date(timestr) except iso8601.ParseError as e: - raise ValueError(e.message) + raise ValueError(str(e)) except TypeError as e: - raise ValueError(e.message) + raise ValueError(str(e)) def strtime(at=None, fmt=PERFECT_TIME_FORMAT): diff --git a/fm-rest-api/fm/fm/tests/__init__.py b/fm-rest-api/fm/fm/tests/__init__.py new file mode 100644 index 00000000..70618e64 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/__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/base.py b/fm-rest-api/fm/fm/tests/base.py new file mode 100644 index 00000000..f846b07f --- /dev/null +++ b/fm-rest-api/fm/fm/tests/base.py @@ -0,0 +1,33 @@ +# 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 our unit tests. + +Allows overriding of config for use of fakes, and some black magic for +inline callbacks. + +""" +import testtools + + +class TestCase(testtools.TestCase): + """Test case base class for all unit tests.""" + + def setUp(self): + """Run before each test method to initialize test environment.""" + super(TestCase, self).setUp() + + def tearDown(self): + super(TestCase, self).tearDown() diff --git a/fm-rest-api/fm/fm/tests/test_common.py b/fm-rest-api/fm/fm/tests/test_common.py new file mode 100644 index 00000000..3d4563a8 --- /dev/null +++ b/fm-rest-api/fm/fm/tests/test_common.py @@ -0,0 +1,34 @@ +# 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. + +import datetime +from fm.common import timeutils + +from fm.tests import base + + +class FaultTimeUtilsTestCase(base.TestCase): + + def test_isotime(self): + isotimestr = timeutils.isotime() + isotime = timeutils.parse_isotime(isotimestr) + self.assertTrue(isinstance(isotime, datetime.datetime)) + + isotimestr = timeutils.isotime(subsecond=True) + isotime = timeutils.parse_isotime(isotimestr) + self.assertTrue(isinstance(isotime, datetime.datetime)) + + self.assertRaises(ValueError, timeutils.parse_isotime, "bad input") + self.assertRaises(ValueError, timeutils.parse_isotime, isotime) diff --git a/fm-rest-api/fm/test-requirements.txt b/fm-rest-api/fm/test-requirements.txt index bc04b496..64d4ed78 100644 --- a/fm-rest-api/fm/test-requirements.txt +++ b/fm-rest-api/fm/test-requirements.txt @@ -1 +1,10 @@ --r requirements.txt +hacking!=0.13.0,<0.14,>=0.12.0 +bashate >= 0.2 +PyYAML >= 3.1.0 +yamllint >= 0.5.2 +stestr +testtools!=1.2.0,>=0.9.36 +iso8601 +stestr +mock +cython diff --git a/fm-rest-api/fm/tox.ini b/fm-rest-api/fm/tox.ini new file mode 100644 index 00000000..c3838682 --- /dev/null +++ b/fm-rest-api/fm/tox.ini @@ -0,0 +1,33 @@ +[tox] +envlist = py27,py35 +minversion = 2.3 +skipsdist = True +stxdir = {toxinidir}/../../../ + +[testenv] +install_command = pip install -U {opts} {packages} +setenv = VIRTUAL_ENV={envdir} + OS_STDOUT_CAPTURE=1 + OS_STDERR_CAPTURE=1 + OS_TEST_TIMEOUT=60 +deps = -r{toxinidir}/test-requirements.txt + +[testenv:venv] +basepython = python3 +commands = {posargs} + +[testenv:py27] +basepython = python2.7 +commands = + stestr run {posargs} + stestr slowest + +[testenv:py35] +basepython = python3.5 +commands = + stestr run {posargs} + stestr slowest + + + + diff --git a/test-requirements.txt b/test-requirements.txt index a0833c46..8540d416 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,4 +2,10 @@ hacking!=0.13.0,<0.14,>=0.12.0 bashate >= 0.2 PyYAML >= 3.1.0 yamllint >= 0.5.2 -spec_cleaner>=1.0.9 +#spec_cleaner>=1.0.9 +stestr +testtools!=1.2.0,>=0.9.36 +iso8601 +stestr +mock +cython diff --git a/tox.ini b/tox.ini index b413aabf..875d9873 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,7 @@ envlist = linters,pep8,rpm-packaging-lint minversion = 2.3 skipsdist = True +stxdir = {toxinidir}/../ [testenv] install_command = pip install -U {opts} {packages} @@ -128,3 +129,4 @@ commands = {toxinidir}/devstack/build.sh basepython = python3 whitelist_externals = cat commands = cat /etc/fm/fm.conf +