diff --git a/qa/CMakeLists.txt b/qa/CMakeLists.txt index 485c5b55326..884c41e4bba 100644 --- a/qa/CMakeLists.txt +++ b/qa/CMakeLists.txt @@ -5,5 +5,5 @@ endif() if(WITH_TESTS) include(AddCephTest) - add_tox_test(qa TOX_ENVS py3 flake8 import-tasks) + add_tox_test(qa TOX_ENVS py3 flake8 mypy) endif() diff --git a/qa/tasks/tests/test_cephadm.py b/qa/tasks/tests/test_cephadm.py deleted file mode 100644 index 403d1915e0f..00000000000 --- a/qa/tasks/tests/test_cephadm.py +++ /dev/null @@ -1,70 +0,0 @@ -from tasks import cephadm - -v1 = """ -[registries.search] -registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io', 'quay.io'] - -[registries.insecure] -registries = [] -""" - -v2 = """ -unqualified-search-registries = ["registry.access.redhat.com", "registry.redhat.io", "docker.io", 'quay.io'] - -[[registry]] -prefix = "registry.access.redhat.com" -location = "registry.access.redhat.com" -insecure = false -blocked = false - -[[registry]] -prefix = "registry.redhat.io" -location = "registry.redhat.io" -insecure = false -blocked = false - -[[registry]] -prefix = "docker.io" -location = "docker.io" -insecure = false -blocked = false - -[[registry.mirror]] -location = "vossi04.front.sepia.ceph.com:5000" -insecure = true - -[[registry]] -prefix = "quay.io" -location = "quay.io" -insecure = false -blocked = false -""" - -expected = { - 'unqualified-search-registries': ['registry.access.redhat.com', 'registry.redhat.io', - 'docker.io', 'quay.io'], - 'registry': [ - {'prefix': 'registry.access.redhat.com', - 'location': 'registry.access.redhat.com', - 'insecure': False, - 'blocked': False}, - {'prefix': 'registry.redhat.io', - 'location': 'registry.redhat.io', - 'insecure': False, - 'blocked': False}, - {'prefix': 'docker.io', - 'location': 'docker.io', - 'insecure': False, - 'blocked': False, - 'mirror': [{'location': 'vossi04.front.sepia.ceph.com:5000', - 'insecure': True}]}, - {'prefix': 'quay.io', - 'location': 'quay.io', - 'insecure': False, - 'blocked': False} - ] -} - -def test_add_mirror(): - assert cephadm.registries_add_mirror_to_docker_io(v1, 'vossi04.front.sepia.ceph.com:5000') == expected - assert cephadm.registries_add_mirror_to_docker_io(v2, 'vossi04.front.sepia.ceph.com:5000') == expected diff --git a/qa/tasks/tests/test_radosgw_admin.py b/qa/tasks/tests/test_radosgw_admin.py index 4e86d5c2b52..8506eda7b1b 100644 --- a/qa/tasks/tests/test_radosgw_admin.py +++ b/qa/tasks/tests/test_radosgw_admin.py @@ -2,11 +2,11 @@ from unittest.mock import Mock from tasks import radosgw_admin -acl_with_version = """fooFoofooFooFULL_CONTROL +acl_with_version = b"""fooFoofooFooFULL_CONTROL """ # noqa -acl_without_version = """fooFoofooFooFULL_CONTROL +acl_without_version = b"""fooFoofooFooFULL_CONTROL """ # noqa diff --git a/qa/test_import.py b/qa/test_import.py index fe70a1c4980..4ee59b56509 100644 --- a/qa/test_import.py +++ b/qa/test_import.py @@ -1,11 +1,10 @@ # try to import all .py files from a given directory -import argparse import glob import os import importlib import importlib.util - +import pytest def _module_name(path): task = os.path.splitext(path)[0] @@ -19,25 +18,21 @@ def _import_file(path): line = f'Importing {package}{mod_name} from {path}' print(f'{line:<80}', end='') mod_spec = importlib.util.find_spec(mod_name, package) - mod = mod_spec.loader.load_module() + mod = mod_spec.loader.load_module(f'{package}{mod_name}') if mod is None: result = 'FAIL' else: result = 'DONE' print(f'{result:>6}') mod_spec.loader.exec_module(mod) + return result -def _parser(): - parser = argparse.ArgumentParser( - description='Try to import a file', - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('path', nargs='+', help='Glob to select files') - return parser - - -if __name__ == '__main__': - parser = _parser() - args = parser.parse_args() - for g in args.path: +def get_paths(): + for g in ['tasks/**/*.py']: for p in glob.glob(g, recursive=True): - _import_file(p) + yield p + +@pytest.mark.parametrize("path", list(sorted(get_paths()))) +def test_import(path): + assert _import_file(path) == 'DONE' + diff --git a/qa/tox.ini b/qa/tox.ini index 083f5c3bf56..1046597ac16 100644 --- a/qa/tox.ini +++ b/qa/tox.ini @@ -22,14 +22,12 @@ deps = -c{toxinidir}/../src/mypy-constrains.txt commands = mypy {posargs:.} -[testenv:import-tasks] -basepython = python3 -deps = {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[coverage,orchestra,test] -commands = python test_import.py {posargs:tasks/**/*.py} - -[testenv:pytest] +[testenv:py3] basepython = python3 deps = - {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[test] + {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[coverage,orchestra,test] httplib2 -commands = pytest -vv tasks/tests +commands = + pytest --assert=plain test_import.py + pytest tasks/tests + diff --git a/qa/workunits/fs/misc/filelock_interrupt.py b/qa/workunits/fs/misc/filelock_interrupt.py index 5ebc480ba8e..b261d74fbc0 100755 --- a/qa/workunits/fs/misc/filelock_interrupt.py +++ b/qa/workunits/fs/misc/filelock_interrupt.py @@ -23,9 +23,9 @@ def timeout(seconds): """ introduced by Linux 3.15 """ -fcntl.F_OFD_GETLK = 36 -fcntl.F_OFD_SETLK = 37 -fcntl.F_OFD_SETLKW = 38 +setattr(fcntl, "F_OFD_GETLK", 36) +setattr(fcntl, "F_OFD_SETLK", 37) +setattr(fcntl, "F_OFD_SETLKW", 38) def main():