From 2564b52972cec752527aec091c186e965bdb3f81 Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Sun, 22 Jan 2023 13:52:54 -0500 Subject: [PATCH] Fix relative imports in nfv H304 relative imports were inline suppressed in the unit tests. This modification to the unit test setup allows those relative imports to be fixed and the suppressions removed. pylint suppressions related to imports are also removed. This change has no runtime impact. The main change required was in the setup.py files for the tests. Test Plan: PASS: tox passing for nfv PASS: build-pkgs -p nfv Story: 2010531 Task: 47204 Signed-off-by: Al Bailey Change-Id: I8d7f400f162aa9af59bcdde5377647e9c91cf58c --- nfv/.stestr.conf | 2 +- nfv/nfv-tests/nfv_scenario_tests/__init__.py | 5 ----- nfv/nfv-tests/nfv_scenario_tests/main.py | 4 ++-- nfv/nfv-tests/nfv_scenario_tests/setup.py | 9 +++++---- nfv/nfv-tests/nfv_unit_tests/__init__.py | 5 ----- nfv/nfv-tests/nfv_unit_tests/setup.py | 8 ++++---- .../nfv_unit_tests/tests/sw_update_testcase.py | 8 ++++---- .../nfv_unit_tests/tests/test_database_upgrades.py | 4 ++-- .../test_dhcp_network_rebalance_randomized.py | 14 ++++++-------- .../tests/test_fw_update_strategy.py | 2 +- .../nfv_unit_tests/tests/test_instance.py | 6 +++--- .../nfv_unit_tests/tests/test_instance_director.py | 4 ++-- .../tests/test_kube_rootca_update_strategy.py | 2 +- .../tests/test_kube_upgrade_strategy.py | 2 +- .../nfv_unit_tests/tests/test_network_rebalance.py | 3 ++- .../tests/test_network_rebalance_randomized.py | 4 ++-- .../nfv_unit_tests/tests/test_nfv_client.py | 2 +- .../tests/test_plugin_kubernetes_client.py | 2 +- .../nfv_unit_tests/tests/test_sw_patch_strategy.py | 2 +- .../tests/test_sw_upgrade_strategy.py | 2 +- nfv/pylint.rc | 7 ++----- nfv/tox.ini | 3 ++- 22 files changed, 44 insertions(+), 56 deletions(-) delete mode 100755 nfv/nfv-tests/nfv_scenario_tests/__init__.py delete mode 100755 nfv/nfv-tests/nfv_unit_tests/__init__.py diff --git a/nfv/.stestr.conf b/nfv/.stestr.conf index 1150b35a..5fa010dd 100644 --- a/nfv/.stestr.conf +++ b/nfv/.stestr.conf @@ -1,4 +1,4 @@ [DEFAULT] test_path=./nfv-tests/nfv_unit_tests/tests -top_dir=. +top_dir=./nfv-tests diff --git a/nfv/nfv-tests/nfv_scenario_tests/__init__.py b/nfv/nfv-tests/nfv_scenario_tests/__init__.py deleted file mode 100755 index 02083bd0..00000000 --- a/nfv/nfv-tests/nfv_scenario_tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -# Copyright (c) 2015-2016 Wind River Systems, Inc. -# -# SPDX-License-Identifier: Apache-2.0 -# diff --git a/nfv/nfv-tests/nfv_scenario_tests/main.py b/nfv/nfv-tests/nfv_scenario_tests/main.py index 39f69d73..748d6d99 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/main.py +++ b/nfv/nfv-tests/nfv_scenario_tests/main.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2018 Wind River Systems, Inc. +# Copyright (c) 2015-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -23,7 +23,7 @@ from nfv_common import debug from nfv_common import forensic from nfv_plugins.nfvi_plugins import config -import tests # pylint: disable=relative-import +import tests DLOG = debug.debug_get_logger('nfv_tests') diff --git a/nfv/nfv-tests/nfv_scenario_tests/setup.py b/nfv/nfv-tests/nfv_scenario_tests/setup.py index 8425735f..b10c4674 100755 --- a/nfv/nfv-tests/nfv_scenario_tests/setup.py +++ b/nfv/nfv-tests/nfv_scenario_tests/setup.py @@ -1,9 +1,8 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # -from setuptools import find_packages from setuptools import setup setup( @@ -12,7 +11,9 @@ setup( version='1.0.0', license='Apache-2.0', platforms=['any'], - provides='nfv_scenario_tests', + provides=['nfv_scenario_tests'], data_files=['./config.ini'], - packages=find_packages() + packages=['nfv_scenario_tests.tests'], + package_dir={'nfv_scenario_tests.tests': 'tests'}, + scripts=['main.py'] ) diff --git a/nfv/nfv-tests/nfv_unit_tests/__init__.py b/nfv/nfv-tests/nfv_unit_tests/__init__.py deleted file mode 100755 index 02083bd0..00000000 --- a/nfv/nfv-tests/nfv_unit_tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -# Copyright (c) 2015-2016 Wind River Systems, Inc. -# -# SPDX-License-Identifier: Apache-2.0 -# diff --git a/nfv/nfv-tests/nfv_unit_tests/setup.py b/nfv/nfv-tests/nfv_unit_tests/setup.py index 0137cf3f..475797f8 100755 --- a/nfv/nfv-tests/nfv_unit_tests/setup.py +++ b/nfv/nfv-tests/nfv_unit_tests/setup.py @@ -1,9 +1,8 @@ # -# Copyright (c) 2015-2016 Wind River Systems, Inc. +# Copyright (c) 2015-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # -from setuptools import find_packages from setuptools import setup setup( @@ -12,6 +11,7 @@ setup( version='1.0.0', license='Apache-2.0', platforms=['any'], - provides='nfv_unit_tests', - packages=find_packages() + provides=['nfv_unit_tests'], + packages=['nfv_unit_tests.tests'], + package_dir={'nfv_unit_tests.tests': 'tests'} ) diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/sw_update_testcase.py b/nfv/nfv-tests/nfv_unit_tests/tests/sw_update_testcase.py index 65b1e288..10d665d4 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/sw_update_testcase.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/sw_update_testcase.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -13,6 +13,7 @@ from nfv_vim import host_fsm from nfv_vim import nfvi from nfv_vim import objects +from nfv_vim.objects import HOST_PERSONALITY from nfv_vim.strategy._strategy import strategy_rebuild_from_dict from nfv_vim.tables._host_aggregate_table import HostAggregateTable from nfv_vim.tables._host_group_table import HostGroupTable @@ -21,10 +22,9 @@ from nfv_vim.tables._instance_group_table import InstanceGroupTable from nfv_vim.tables._instance_table import InstanceTable from nfv_vim.tables._table import Table -from . import testcase # noqa: H304 -from . import utils # noqa: H304 +from nfv_unit_tests.tests import testcase +from nfv_unit_tests.tests import utils -from nfv_vim.objects import HOST_PERSONALITY DEBUG_PRINTING = False diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_database_upgrades.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_database_upgrades.py index 876c9111..95739fcf 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_database_upgrades.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_database_upgrades.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016 Wind River Systems, Inc. +# Copyright (c) 2016-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -11,7 +11,7 @@ import tempfile from nfv_vim import database from nfv_vim import tables -from . import testcase # noqa: H304 +from nfv_unit_tests.tests import testcase class TestNFVDatabaseUpgrade(testcase.NFVTestCase): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py index 7b4f0b84..4c0f5d91 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_dhcp_network_rebalance_randomized.py @@ -16,11 +16,14 @@ from nfv_vim.network_rebalance._dhcp_rebalance import _run_state_machine from nfv_vim.network_rebalance._dhcp_rebalance import add_rebalance_work_dhcp from nfv_vim.network_rebalance._dhcp_rebalance import DHCP_REBALANCE_STATE -from . import testcase # noqa: H304 -from . import utils # noqa: H304 +from nfv_unit_tests.tests import testcase +from nfv_unit_tests.tests import utils + DEBUG_PRINTING = False -# DEBUG_PRINTING = True +MAX_AGENTS = 40 +MAX_NETWORKS = 200 +MAX_LOOPCOUNT = 2 * MAX_AGENTS * MAX_NETWORKS _fake_host_table = dict() @@ -30,11 +33,6 @@ class _fake_host(object): self.uuid = uuid -MAX_AGENTS = 40 -MAX_NETWORKS = 200 -MAX_LOOPCOUNT = 2 * MAX_AGENTS * MAX_NETWORKS - - def build_get_agents_response(): get_agents_response = dict() diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_fw_update_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_fw_update_strategy.py index 38401a42..65ac0df7 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_fw_update_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_fw_update_strategy.py @@ -16,7 +16,7 @@ from nfv_vim.objects import SW_UPDATE_ALARM_RESTRICTION from nfv_vim.objects import SW_UPDATE_APPLY_TYPE from nfv_vim.objects import SW_UPDATE_INSTANCE_ACTION -from . import sw_update_testcase # noqa: H304 +from nfv_unit_tests.tests import sw_update_testcase def create_fw_update_strategy( diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py index 1948ce94..90b97951 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2016 Wind River Systems, Inc. +# Copyright (c) 2016-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -23,8 +23,8 @@ from nfv_vim.tables._instance_table import InstanceTable from nfv_vim.tables._instance_type_table import InstanceTypeTable from nfv_vim.tables._table import Table -from . import testcase # noqa: H304 -from . import utils # noqa: H304 +from nfv_unit_tests.tests import testcase +from nfv_unit_tests.tests import utils def fake_event_issue(a, b, c, d): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py index e4e2c49a..ca71c61a 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_instance_director.py @@ -13,8 +13,8 @@ from nfv_vim.directors._instance_director import InstanceDirector from nfv_vim.tables._image_table import ImageTable from nfv_vim.tables._table import Table -from . import testcase # noqa: H304 -from . import utils # noqa: H304 +from nfv_unit_tests.tests import testcase +from nfv_unit_tests.tests import utils # Constants _audit_interval = 330 diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_rootca_update_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_rootca_update_strategy.py index 394fd0f7..06f25684 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_rootca_update_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_rootca_update_strategy.py @@ -16,7 +16,7 @@ from nfv_vim.objects import SW_UPDATE_APPLY_TYPE from nfv_vim.objects import SW_UPDATE_INSTANCE_ACTION from nfv_vim.strategy._strategy import KubeRootcaUpdateStrategy -from . import sw_update_testcase # noqa: H304 +from nfv_unit_tests.tests import sw_update_testcase @mock.patch('nfv_vim.event_log._instance._event_issue', diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_upgrade_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_upgrade_strategy.py index edddd03a..5f702e57 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_upgrade_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_kube_upgrade_strategy.py @@ -19,7 +19,7 @@ from nfv_vim.objects import SW_UPDATE_APPLY_TYPE from nfv_vim.objects import SW_UPDATE_INSTANCE_ACTION from nfv_vim.strategy._strategy import KubeUpgradeStrategy -from . import sw_update_testcase # noqa: H304 +from nfv_unit_tests.tests import sw_update_testcase FROM_KUBE_VERSION = '1.2.3' diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance.py index 637eec97..625b7ea8 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance.py @@ -11,7 +11,8 @@ from nfv_vim.network_rebalance._network_rebalance import _reschedule_down_agent from nfv_vim.network_rebalance._network_rebalance import _reschedule_new_agent from nfv_vim.network_rebalance._network_rebalance import L3_REBALANCE_STATE -from . import testcase # noqa: H304 +from nfv_unit_tests.tests import testcase + DEBUG_PRINTING = False diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py index 9534fc25..c081ae78 100644 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_network_rebalance_randomized.py @@ -18,8 +18,8 @@ from nfv_vim.network_rebalance._network_rebalance import _run_state_machine from nfv_vim.network_rebalance._network_rebalance import add_rebalance_work_l3 from nfv_vim.network_rebalance._network_rebalance import L3_REBALANCE_STATE -from . import testcase # noqa: H304 -from . import utils # noqa:H304 +from nfv_unit_tests.tests import testcase +from nfv_unit_tests.tests import utils DEBUG_PRINTING = False diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py index 214ddba7..6dec1eaa 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_nfv_client.py @@ -9,7 +9,7 @@ from unittest import mock from nfv_client import shell -from . import testcase # noqa: H304 +from nfv_unit_tests.tests import testcase class TestNFVClientShell(testcase.NFVTestCase): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_plugin_kubernetes_client.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_plugin_kubernetes_client.py index 4cd73053..ace6c329 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_plugin_kubernetes_client.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_plugin_kubernetes_client.py @@ -12,7 +12,7 @@ from unittest import mock from nfv_plugins.nfvi_plugins.clients import kubernetes_client -from . import testcase # noqa: H304 +from nfv_unit_tests.tests import testcase def mock_load_kube_config(path): diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py index d4895b54..b41f9d86 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_patch_strategy.py @@ -16,7 +16,7 @@ from nfv_vim.objects import SW_UPDATE_INSTANCE_ACTION from nfv_vim.objects import SwPatch from nfv_vim.strategy._strategy import SwPatchStrategy -from . import sw_update_testcase # noqa: H304 +from nfv_unit_tests.tests import sw_update_testcase def create_sw_patch_strategy( diff --git a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py index 2472e088..7cbb61e9 100755 --- a/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py +++ b/nfv/nfv-tests/nfv_unit_tests/tests/test_sw_upgrade_strategy.py @@ -20,7 +20,7 @@ from nfv_vim.strategy._strategy import SwUpgradeStrategy from nfv_vim.nfvi.objects.v1 import UPGRADE_STATE -from . import sw_update_testcase # noqa: H304 +from nfv_unit_tests.tests import sw_update_testcase # utility method for the formatting of unlock-hosts stage as dict diff --git a/nfv/pylint.rc b/nfv/pylint.rc index 59dc6429..e2c45890 100755 --- a/nfv/pylint.rc +++ b/nfv/pylint.rc @@ -131,19 +131,16 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652, # W1406 redundant-u-string-prefix # W1505 Using deprecated method getargspec() (deprecated-method) # W1514 unspecified-encoding -# W1618 no-absolute-import (Python3 checker) # W0237 arguments-renamed # W4904 deprecated-class # W4905 deprecated-decorator - -# E0012 pylint for python3 does not support inline deprecation # E1101 no-member # E1111 assignment-from-no-return # E1121 too-many-function-args disable=C, R, W0120, W0125, W0212, W0221, W0223, W0231, W0235, W0401, W0404, W0511, W0602, W0603, W0612, W0613, W0621, W0622, W0703, W1401, - W0107, W0706, W0707, W1310, W1406, W1505, W1514, W1618, W0237, W4904, W4905, - E0012, E1101, E1111, E1121 + W0107, W0706, W0707, W1310, W1406, W1505, W1514, W0237, W4904, W4905, + E1101, E1111, E1121 [REPORTS] # Set the output format. Available formats are text, parseable, colorized, msvs diff --git a/nfv/tox.ini b/nfv/tox.ini index c3dde994..60e1573e 100644 --- a/nfv/tox.ini +++ b/nfv/tox.ini @@ -101,13 +101,14 @@ commands = [testenv:pylint] deps = {[nfv]deps} -r{toxinidir}/test-requirements.txt + {[nfv]nfv_test_dir}/nfv_unit_tests {[nfv]nfv_test_dir}/nfv_scenario_tests jinja2 commands = pylint {[nfv]nfv_client_src_dir} \ {[nfv]nfv_common_src_dir} \ {[nfv]nfv_plugins_src_dir} \ {[nfv]nfv_vim_src_dir} \ - {[nfv]nfv_test_src_dir} \ + {[nfv]nfv_test_src_dir}/nfv_unit_tests \ --rcfile=./pylint.rc [bandit]