]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: Add a tox env that can test importing files 33949/head
authorThomas Bechtold <tbechtold@suse.com>
Fri, 13 Mar 2020 11:38:10 +0000 (12:38 +0100)
committerKefu Chai <kchai@redhat.com>
Thu, 26 Mar 2020 08:16:31 +0000 (16:16 +0800)
While switching to python3, we need to make sure that we can import
the qa/tasks (and others, but this starts with qa/tasks) on a python3
environment.
To test this, we need to install teuthology into the test
venv. Currently, teuthology is not py3 ready so this will fail.

To test the current state of the qa/tasks directory with the ongoing
work for python3 within teuthology, you can now do:

TEUTHOLOGY_GIT=git+https://github.com/kshtsk/teuthology.git@wip-py3-compat \
    tox -eimport-tasks

This is using the current branch from
https://github.com/ceph/teuthology/pull/1362 which does the work to
make teuthology python3 ready.

NOTE: This tox env is not activated by default. It's currently failing
but it provides a way to iterate over the failures and once we have
them fixed, we can activate the tox env during make-check.

Signed-off-by: Thomas Bechtold <tbechtold@suse.com>
qa/test_import.py [new file with mode: 0644]
qa/tox.ini

diff --git a/qa/test_import.py b/qa/test_import.py
new file mode 100644 (file)
index 0000000..fe70a1c
--- /dev/null
@@ -0,0 +1,43 @@
+# try to import all .py files from a given directory
+
+import argparse
+import glob
+import os
+import importlib
+import importlib.util
+
+
+def _module_name(path):
+    task = os.path.splitext(path)[0]
+    parts = task.split(os.path.sep)
+    package = parts[0]
+    name = ''.join('.' + c for c in parts[1:])
+    return package, name
+
+def _import_file(path):
+    package, mod_name = _module_name(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()
+    if mod is None:
+        result = 'FAIL'
+    else:
+        result = 'DONE'
+    print(f'{result:>6}')
+    mod_spec.loader.exec_module(mod)
+
+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:
+        for p in glob.glob(g, recursive=True):
+            _import_file(p)
index 746cd1b4f44d0084d0be1aed11fb1f06fe869a5c..7ca4130c0ccb518f5eb0323f4bf291924346f943 100644 (file)
@@ -18,3 +18,8 @@ commands=flake8 --select=F,E9 --exclude=venv,.tox
 basepython = python3
 deps = mypy==0.770
 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}