Merge pull request #41929 from sebastian-philipp/fix-qa-tox

qa: Various make check fixes

Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-07-21 00:36:59 +08:00 committed by GitHub
commit dc1a8a8b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 100 deletions

View File

@ -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()

View File

@ -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

View File

@ -2,11 +2,11 @@ from unittest.mock import Mock
from tasks import radosgw_admin
acl_with_version = """<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>foo</ID><DisplayName>Foo</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>foo</ID><DisplayName>Foo</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>
acl_with_version = b"""<?xml version="1.0" encoding="UTF-8"?><AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>foo</ID><DisplayName>Foo</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>foo</ID><DisplayName>Foo</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>
""" # noqa
acl_without_version = """<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>foo</ID><DisplayName>Foo</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>foo</ID><DisplayName>Foo</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>
acl_without_version = b"""<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>foo</ID><DisplayName>Foo</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>foo</ID><DisplayName>Foo</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>
""" # noqa

View File

@ -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'

View File

@ -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

View File

@ -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():