Add initial unit testing to cgcs-patch
This update sets up the framework for unit testing in the cgcs-patch module, with some basic test cases. Change-Id: I209076449353a23bb57e0eee397e614b7e89ad88 Story: 2005939 Task: 34756 Signed-off-by: Don Penney <don.penney@windriver.com>
This commit is contained in:
parent
cd6927163f
commit
f27f1c1539
53
.zuul.yaml
53
.zuul.yaml
|
@ -9,8 +9,10 @@
|
|||
- flock-devstack-update
|
||||
- openstack-tox-linters
|
||||
- openstack-tox-pep8
|
||||
- openstack-tox-py27
|
||||
- openstack-tox-py37
|
||||
- tsconfig-tox-py27
|
||||
- tsconfig-tox-py36
|
||||
- patch-tox-py27
|
||||
- patch-tox-py36
|
||||
- stx-updates-pylint
|
||||
gate:
|
||||
jobs:
|
||||
|
@ -19,14 +21,57 @@
|
|||
- flock-devstack-update
|
||||
- openstack-tox-linters
|
||||
- openstack-tox-pep8
|
||||
- openstack-tox-py27
|
||||
- openstack-tox-py37
|
||||
- tsconfig-tox-py27
|
||||
- tsconfig-tox-py36
|
||||
- patch-tox-py27
|
||||
- patch-tox-py36
|
||||
- stx-updates-pylint
|
||||
post:
|
||||
jobs:
|
||||
- publish-stx-api-ref
|
||||
- publish-stx-tox
|
||||
- publish-stx-releasenotes
|
||||
|
||||
- job:
|
||||
name: tsconfig-tox-py27
|
||||
parent: tox
|
||||
files:
|
||||
- tsconfig/tsconfig/*
|
||||
vars:
|
||||
tox_envlist: py27
|
||||
tox_extra_args: -c tsconfig/tsconfig/tox.ini
|
||||
|
||||
- job:
|
||||
name: tsconfig-tox-py36
|
||||
parent: tox
|
||||
files:
|
||||
- tsconfig/tsconfig/*
|
||||
vars:
|
||||
tox_envlist: py36
|
||||
tox_extra_args: -c tsconfig/tsconfig/tox.ini
|
||||
|
||||
- job:
|
||||
name: patch-tox-py27
|
||||
parent: tox
|
||||
required-projects:
|
||||
- starlingx/config
|
||||
files:
|
||||
- cgcs-patch/cgcs-patch/*
|
||||
vars:
|
||||
tox_envlist: py27
|
||||
tox_extra_args: -c cgcs-patch/cgcs-patch/tox.ini
|
||||
|
||||
- job:
|
||||
name: patch-tox-py36
|
||||
parent: tox
|
||||
required-projects:
|
||||
- starlingx/config
|
||||
files:
|
||||
- cgcs-patch/cgcs-patch/*
|
||||
vars:
|
||||
tox_envlist: py36
|
||||
tox_extra_args: -c cgcs-patch/cgcs-patch/tox.ini
|
||||
|
||||
- job:
|
||||
name: stx-updates-pylint
|
||||
parent: openstack-tox-pylint
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[run]
|
||||
branch = True
|
||||
source = cgcs_patch
|
||||
omit = cgcs_patch/tests/*
|
||||
|
||||
[report]
|
||||
ignore_errors = True
|
|
@ -0,0 +1,2 @@
|
|||
[DEFAULT]
|
||||
test_path=cgcs_patch/tests
|
|
@ -641,7 +641,7 @@ class PatchController(PatchService):
|
|||
cfgfile = open(state_file, 'w')
|
||||
|
||||
config.add_section('runtime')
|
||||
config.set('runtime', 'patch_op_counter', self.patch_op_counter)
|
||||
config.set('runtime', 'patch_op_counter', str(self.patch_op_counter))
|
||||
config.write(cfgfile)
|
||||
cfgfile.close()
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2019 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
import mock
|
||||
import os
|
||||
import sys
|
||||
import testtools
|
||||
|
||||
sys.modules['rpm'] = mock.Mock()
|
||||
|
||||
import cgcs_patch.patch_functions
|
||||
|
||||
|
||||
class CgcsPatchTestCase(testtools.TestCase):
|
||||
|
||||
def test_cgcs_patch_functions_get_md5(self):
|
||||
md5testfile = os.path.join(os.path.dirname(__file__), 'md5test.txt')
|
||||
expected_result = 0x7179a07a8a5c50a3fc9f1971f1ec317f
|
||||
|
||||
md5result = cgcs_patch.patch_functions.get_md5(md5testfile)
|
||||
|
||||
self.assertEqual(expected_result, md5result)
|
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2019 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
import mock
|
||||
import six # pylint: disable=unused-import
|
||||
import sys
|
||||
import testtools
|
||||
|
||||
sys.modules['rpm'] = mock.Mock()
|
||||
sys.modules['rpmUtils'] = mock.Mock()
|
||||
sys.modules['rpmUtils.miscutils'] = mock.Mock()
|
||||
|
||||
import cgcs_patch.patch_agent
|
||||
|
||||
|
||||
class CgcsPatchAgentTestCase(testtools.TestCase):
|
||||
|
||||
def test_cgcs_patch_agent_instantiate(self):
|
||||
pc = cgcs_patch.patch_agent.PatchAgent()
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2019 Wind River Systems, Inc.
|
||||
#
|
||||
|
||||
import mock
|
||||
import six # pylint: disable=unused-import
|
||||
import sys
|
||||
import testtools
|
||||
|
||||
sys.modules['rpm'] = mock.Mock()
|
||||
sys.modules['rpmUtils'] = mock.Mock()
|
||||
sys.modules['rpmUtils.miscutils'] = mock.Mock()
|
||||
|
||||
import cgcs_patch.patch_controller
|
||||
|
||||
|
||||
class CgcsPatchControllerTestCase(testtools.TestCase):
|
||||
|
||||
@mock.patch('six.moves.builtins.open')
|
||||
def test_cgcs_patch_controller_instantiate(self, mock_open):
|
||||
pc = cgcs_patch.patch_controller.PatchController()
|
|
@ -0,0 +1,8 @@
|
|||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
keystonemiddleware
|
||||
oslo_config
|
||||
pecan
|
||||
pycryptodome;python_version=='2.7'
|
|
@ -12,6 +12,7 @@ classifier =
|
|||
Programming Language :: Python :: 2.7
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.5
|
||||
Programming Language :: Python :: 3.6
|
||||
|
||||
[files]
|
||||
packages =
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
hacking>=1.1.0 # Apache-2.0
|
||||
|
||||
coverage!=4.4,>=4.0 # Apache-2.0
|
||||
mock>=2.0.0 # BSD
|
||||
stestr>=1.0.0 # Apache-2.0
|
||||
testtools>=2.2.0 # MIT
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
[tox]
|
||||
envlist = py27,py36,cover
|
||||
minversion = 2.3.2
|
||||
|
||||
stxdir = {toxinidir}/../../..
|
||||
|
||||
[testenv]
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
LANG=en_US.UTF-8
|
||||
LANGUAGE=en_US:en
|
||||
LC_ALL=C
|
||||
OS_STDERR_CAPTURE=1
|
||||
OS_STDOUT_CAPTURE=1
|
||||
OS_TEST_PATH=./cgcs_patch/tests
|
||||
OS_TEST_TIMEOUT=60
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
PYTHONHASHSEED=0
|
||||
PYTHONWARNINGS=default::DeprecationWarning
|
||||
|
||||
sitepackages = True
|
||||
install_command = pip install \
|
||||
-v -v -v \
|
||||
-c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt} \
|
||||
{opts} {packages}
|
||||
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
-e{[tox]stxdir}/config/sysinv/sysinv/sysinv
|
||||
-e{[tox]stxdir}/update/tsconfig/tsconfig
|
||||
|
||||
commands =
|
||||
find . -name "*.pyc" -delete
|
||||
stestr run {posargs}
|
||||
stestr slowest
|
||||
|
||||
whitelist_externals = find
|
||||
sh
|
||||
|
||||
[testenv:py27]
|
||||
basepython = python2.7
|
||||
commands =
|
||||
{[testenv]commands}
|
||||
stestr run {posargs}
|
||||
stestr slowest
|
||||
|
||||
[testenv:py36]
|
||||
basepython = python3.6
|
||||
commands =
|
||||
{[testenv]commands}
|
||||
stestr run {posargs}
|
||||
stestr slowest
|
||||
|
||||
[testenv:cover]
|
||||
setenv =
|
||||
PYTHON=coverage run --parallel-mode
|
||||
PYTHONDONTWRITEBYTECODE=True
|
||||
|
||||
commands = coverage erase
|
||||
find . -name "*.pyc" -delete
|
||||
stestr run {posargs}
|
||||
coverage combine
|
||||
coverage html -d cover
|
||||
coverage xml -o cover/coverage.xml
|
||||
coverage report
|
|
@ -2,6 +2,6 @@ bashate >= 0.2
|
|||
PyYAML >= 3.1.0
|
||||
yamllint >= 0.5.2
|
||||
hacking!=0.13.0,<0.14,>=0.12.0
|
||||
# The following are for py27 and py35
|
||||
# The following are for py27 and py36
|
||||
#mock # BSD
|
||||
#nose # LGPL
|
||||
|
|
14
tox.ini
14
tox.ini
|
@ -9,7 +9,7 @@
|
|||
# test suite on all supported python versions. To use it, "pip install tox"
|
||||
# and then run "tox" from this directory.
|
||||
[tox]
|
||||
envlist = linters,pep8,py27,py37,pylint
|
||||
envlist = linters,pep8,py27,py36,pylint
|
||||
minversion = 2.3
|
||||
skipsdist = True
|
||||
|
||||
|
@ -29,9 +29,9 @@ tsconfig_src_dir = {[testenv]tsconfig_dir}/tsconfig
|
|||
commands = find {toxinidir} -type f -not -path '{toxinidir}/.tox/*' -not -path '*/__pycache__/*' -name '*.py[c|o]' -delete
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
{[testenv]cgcs_patch_dir}
|
||||
{[testenv]patch_alarm_dir}
|
||||
{[testenv]tsconfig_dir}
|
||||
-e{[testenv]cgcs_patch_dir}
|
||||
-e{[testenv]patch_alarm_dir}
|
||||
-e{[testenv]tsconfig_dir}
|
||||
|
||||
[testenv:linters]
|
||||
basepython = python3
|
||||
|
@ -100,8 +100,9 @@ whitelist_externals = cp
|
|||
recreate = True
|
||||
commands = {[testenv]commands}
|
||||
tox -c tsconfig/tsconfig -e py27
|
||||
tox -c cgcs-patch/cgcs-patch -e py27
|
||||
|
||||
[testenv:py37]
|
||||
[testenv:py36]
|
||||
basepython = python3
|
||||
deps = {[testenv]deps}
|
||||
whitelist_externals = cp
|
||||
|
@ -109,7 +110,8 @@ whitelist_externals = cp
|
|||
tox
|
||||
recreate = True
|
||||
commands = {[testenv]commands}
|
||||
tox -c tsconfig/tsconfig -e py37
|
||||
tox -c tsconfig/tsconfig -e py36
|
||||
tox -c cgcs-patch/cgcs-patch -e py36
|
||||
|
||||
[testenv:pylint]
|
||||
deps = {[testenv]deps}
|
||||
|
|
Loading…
Reference in New Issue