Use os-testr and add PY35 support

masakari-monitors should use os-testr instead of testr as
it is more powerful and provide much prettier output than testr.

This patch also disables the use of PY34 and adds PY35 for in tox
as the gating on python 3.4 is restricted to <= Mitaka in OpenStack.
This is due to the change from Ubuntu Trusty to Xenial, where only
python3.5 is available. Python 3 don't have 'file' builtin method so
to make it compatible with Python 2 and 3 used 'open' builtin method.
Also fixed the failing test cases due to that.

Change-Id: Ib84b0b28a845e49eaef969d0fc995b1adbb7b29d
This commit is contained in:
Dinesh Bhor 2017-07-26 15:37:33 +05:30
parent ce5926ef0a
commit 5f59145276
6 changed files with 35 additions and 16 deletions

View File

@ -35,7 +35,7 @@ class ProcessmonitorManager(manager.Manager):
def _load_process_list(self):
try:
process_list = yaml.load(file(CONF.process.process_list_path))
process_list = yaml.load(open(CONF.process.process_list_path))
LOG.debug("Loaded process list. %s" % process_list)
return process_list

View File

@ -78,7 +78,7 @@ class TestProcessmonitorManager(testtools.TestCase):
@mock.patch.object(handle_process.HandleProcess, 'start_processes')
@mock.patch.object(handle_process.HandleProcess, 'set_process_list')
@mock.patch.object(yaml, 'load')
@mock.patch('__builtin__.file')
@mock.patch('six.moves.builtins.open')
def test_main(self,
mock_file,
mock_load,
@ -88,7 +88,6 @@ class TestProcessmonitorManager(testtools.TestCase):
mock_restart_processes,
mock_sleep):
mock_file.return_value = None
mock_load.side_effect = [self._get_mock_process_list(0),
self._get_mock_process_list(0),
self._get_mock_process_list(1)]
@ -111,7 +110,7 @@ class TestProcessmonitorManager(testtools.TestCase):
@mock.patch.object(handle_process.HandleProcess, 'start_processes')
@mock.patch.object(handle_process.HandleProcess, 'set_process_list')
@mock.patch.object(yaml, 'load')
@mock.patch('__builtin__.file')
@mock.patch('six.moves.builtins.open')
def test_main_exception(self,
mock_file,
mock_load,
@ -120,7 +119,6 @@ class TestProcessmonitorManager(testtools.TestCase):
mock_monitor_processes,
mock_restart_processes):
mock_file.return_value = None
mock_load.return_value = self._get_mock_process_list(0)
mock_set_process_list.return_value = None
mock_start_processes.side_effect = Exception("Test exception.")
@ -135,13 +133,12 @@ class TestProcessmonitorManager(testtools.TestCase):
@mock.patch.object(handle_process.HandleProcess, 'set_process_list')
@mock.patch.object(yaml, 'load')
@mock.patch('__builtin__.file')
@mock.patch('six.moves.builtins.open')
def test_load_process_list_yaml_error(self,
mock_file,
mock_load,
mock_set_process_list):
mock_file.return_value = None
mock_load.side_effect = yaml.YAMLError
obj = processmonitor_manager.ProcessmonitorManager()
@ -151,13 +148,12 @@ class TestProcessmonitorManager(testtools.TestCase):
@mock.patch.object(handle_process.HandleProcess, 'set_process_list')
@mock.patch.object(yaml, 'load')
@mock.patch('__builtin__.file')
@mock.patch('six.moves.builtins.open')
def test_load_process_list_exception(self,
mock_file,
mock_load,
mock_set_process_list):
mock_file.return_value = None
mock_load.side_effect = Exception("Test exception.")
obj = processmonitor_manager.ProcessmonitorManager()

View File

@ -14,3 +14,4 @@ oslo.utils>=3.11.0 # Apache-2.0
pbr>=1.8 # Apache-2.0
python-masakariclient>=2.0.1.dev5 # Apache-2.0
python-openstackclient>=3.3.0 # Apache-2.0
six>=1.9.0 # MIT

View File

@ -16,8 +16,7 @@ classifier =
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
[files]
packages =

View File

@ -9,6 +9,7 @@ python-subunit>=0.0.18 # Apache-2.0/BSD
sphinx>=1.2.1,!=1.3b1,<1.4 # BSD
oslosphinx>=4.7.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0
testrepository>=0.0.18 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT

32
tox.ini
View File

@ -1,16 +1,38 @@
[tox]
minversion = 2.0
envlist = py34,py27,pypy,pep8
envlist = py35,py27,pypy,pep8
skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
PYTHONWARNINGS=default::DeprecationWarning
setenv = VIRTUAL_ENV={envdir}
OS_TEST_PATH=./masakarimonitors/tests/unit
LANGUAGE=en_US
LC_ALL=en_US.utf-8
deps = -r{toxinidir}/test-requirements.txt
commands = python setup.py test --slowest --testr-args='{posargs}'
whitelist_externals = bash
find
rm
env
# By default ostestr will set concurrency
# to ncpu, to specify something else use
# the concurrency=<n> option.
# call ie: 'tox -epy27 -- --concurrency=4'
commands =
find . -type f -name "*.pyc" -delete
rm -Rf .testrepository/times.dbm
passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY OS_DEBUG GENERATE_HASHES
[testenv:py27]
commands =
{[testenv]commands}
ostestr '{posargs}'
[testenv:py35]
commands =
{[testenv]commands}
ostestr '{posargs}'
[testenv:genconfig]
commands = oslo-config-generator --config-file=etc/masakarimonitors/masakarimonitors-config-generator.conf