-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RHELPLAN-42920 - Collections - script - add tox/travis tests for coll… #45
Conversation
.travis/collection.sh
Outdated
# git clone --branch some_stable_tag https://github.com/linux-system-roles/auto-maintenance | ||
|
||
# TEMPORARY | ||
git clone --single-branch --branch role2collection https://github.com/nhosoi/auto-maintenance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to add ansible_role_parser.py to lsr_role2collection.py - that way we could just download a single file - we wouldn't have to use git clone we could just do something like
curl -L -o lsr_role2collection.py https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/master/lsr_role2collection.py
or curl -L -o lsr_role2collection.py https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/$STABLE_TAG/lsr_role2collection.py
but we can worry about that later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to add ansible_role_parser.py to lsr_role2collection.py - that way we could just download a single file - we wouldn't have to use git clone we could just do something like
curl -L -o lsr_role2collection.py https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/master/lsr_role2collection.py
orcurl -L -o lsr_role2collection.py https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/$STABLE_TAG/lsr_role2collection.py
but we can worry about that later
@richm, I've pushed another commit. Do you think it's ok to keep ansible_role_parser.py independent? Or do you think it's better be in lsr_role2collection.py?
Replacing git clone with curl following the suggestion by @richm.
https://github.com/linux-system-roles/template/pull/45#pullrequestreview-497822660
But ansible_role_parser.py is not added to lsr_role2collection.py.
I'm wondering ansible_role_parser.py is more useful to be a library to share?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's ok to keep ansible_role_parser.py independent? Or do you think it's better be in lsr_role2collection.py?
I think it would be better to have 1 file, but let's get this PR merged first.
I'm wondering ansible_role_parser.py is more useful to be a library to share?
We should have 1 file that can be imported into another python script, or run from the command line, by putting the non-reusable code in a main()
method and changing the script like this:
if __name__ == "__main__":
sys.exit(main())
but we can do that in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @richm. Do you think it's ok to merge this PR? Or do we need some more discussions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @richm. Do you think it's ok to merge this PR? Or do we need some more discussions?
I think it's ok to merge.
.travis/collection.sh
Outdated
|
||
COLLECTION_SRC_PATH=${TOPDIR}/.. COLLECTION_DEST_PATH=${toxworkdir} COLLECTION_ROLE=${role} python auto-maintenance/lsr_role2collection.py > "${toxworkdir}"/collection.out 2>&1 | ||
|
||
COLLECTION_SRC_PATH=${toxworkdir} COLLECTION_DEST_PATH=${toxworkdir} python auto-maintenance/lsr_role2collection.py --tox >> "${toxworkdir}"/collection.out 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some reason to use env. vars. here instead of e.g. --src-path
, --dest-path
, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no reasons. We can use the options.
.travis/collection.sh
Outdated
toxworkdir=${1:-${TOPDIR}/.tox} | ||
cd "${toxworkdir}" | ||
toxworkdir=$(pwd) | ||
envlist=${2:- "yamllint,py38,shellcheck,custom"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need custom
in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I could not find a way to run pylint successfully in the collections format yet.
We use runpylint.sh
and custom_pylint.py
combo for this. If not done yet, these files should be updated to match also the collections format.
"tox -e collection" resultsPASSED
FAILED
EXCEPTION
|
Don't worry about tuned network does not use setup_module_utils.sh - it actually rewrites the python import paths in python code https://github.com/linux-system-roles/network/blob/main/tests/unit/test_network_connections.py#L13-L25 - I think it would be better if network used setup_module_utils.sh or something like it - at any rate, that network unit test code will need to be edited to make it work with collections |
All right.
I see. I manually copied setup_module_utils.sh and .travis/utils.sh, which does not fit in the network design... These are the errors from pylint in the collection converted network after running setup_module_utils.sh. The first one is the code handling the basestring which is not available in python3. Since I had to use python 3.6 instead of 2.7 [0], it's newly reported. Probably, it has to be somehow ignored. The second one is in a test python script under the tests directory, which the conversion script does not process for now.
[0] The reason why python was upgraded to 3.6 for pylint is I ran into this problem pylint-dev/pylint#1470 and to workaround it. It seems pylint newer than 2.4.x has the fix. First, I tried just upgrading pylint to pylint>=2.5 with python-2.7, but it was rejected. If we keep using python-2.7 for pylint, I'd think we may need to copy the custom module_utils instead of create symlinks. |
.travis/utils.sh
Outdated
bash "$TOPDIR/tests/setup_module_utils.sh" "$srcdir" "$destdir" | ||
else | ||
setup_module_utils=$( ls "$TOPDIR"/tests/*/setup_module_utils.sh ) | ||
setup_module_util=$( echo "$setup_module_utils" | awk '{print $1}' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setup_module_util=$( ls "$TOPDIR"/tests/*/setup_module_utils.sh | head -1 )
.yamllint_defaults.yml
Outdated
@@ -13,4 +13,6 @@ rules: | |||
truthy: | |||
allowed-values: ["yes", "no", "true", "false"] | |||
level: error | |||
line-length: | |||
level: warning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this change? We want line-length to be an error for regular roles, and we want to override it to be ignored for collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, true... I'm going to revert this change and rethink about it.
tox.ini
Outdated
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:2.7} | ||
basepython = python2.7 | ||
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:3.6} | ||
basepython = python3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't use python2.7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can install pylint>=2.5 with python2.7, we can... Or instead of creating symlinks, copying the custom module_utils, it might work with python2.7...
If just switching back to python2.7 in tox.ini, it fails like this:
************* Module certificate_request
E:279, 0: Unable to import 'ansible_collections.fedora.system_roles.plugins.module_utils.certificate.providers.__init__' (import-error)
************* Module certificate.providers.certmonger
E: 5, 0: Unable to import 'ansible_collections.fedora.system_roles.plugins.module_utils.certificate.providers.base' (import-error)
************* Module certificate.providers
E: 1, 0: Unable to import 'ansible_collections.fedora.system_roles.plugins.module_utils.certificate.providers.certmonger' (import-error)
ERROR: InvocationError for command /usr/bin/bash .travis/runpylint.sh --errors-only (exited with code 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of creating symlinks, copying the custom module_utils
It doesn't like symlinks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of creating symlinks, copying the custom module_utils
It doesn't like symlinks?
That's what i'm suspecting... Let me test copying with python2.7 if we prefer 2.7. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that I prefer python2.7, but 1) I don't want to change this arbitrarily 2) we need coverage on python2.7. It would be great if we could do pylint (and pytest) on python 2 and python 3 (but we can do that later).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem is we cannot use this pylint change (using python3 + pylint>=2.5) for network due to its referring basestring (See https://github.com/linux-system-roles/network/blob/main/module_utils/network_lsr/utils.py#L17). Even if its in the else of PY3, pylint fails by the undefined variable error. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it fail if there is noqa:F821
?
EDIT: F821 is for flake8, not for pylint.
And how is it possible that lint passes for the original code in the repository?
@nhosoi , if it helps, we agreed (with @richm) to reduce the requirements on Travis tests for the converted collection:
|
Thank you, @pcahyna. I've been investigating why pylint with python 2.7 + pylint-1.9.5 does not successfully pass against the collections format.
I replaced symlinks with actual files by modifying setup_module_utils.sh to workaround this issue pylint-dev/astroid#583.
That's said I was proposing to upgrade from python 2.7 to 3.6 for pylint/pytest. But if there's no need to run them in the collections format, we could drop the part. In my investigation, one question has come up... Looking into the other collections source codes, I noticed the
|
If it doesn't help, why would we add |
Just because I saw lots of the modules in the roles have it... I thought it might be quite common and encouraged to import it. :)
|
|
Yes, we should add that |
I'm opening a task. Thanks! |
@richm, @pcahyna, let me double-check on it... |
Let's drop pylint for now. Both black and flake8 give us most of that coverage |
Indeed - I did not mean to imply that it should be added by the conversion script unless it is really needed in the resulting collection, which it apparently is not. |
This is not what I meant - my intent was to use pylint only on modules/plugins and module_utils. But if it does not help with your issue (looks like it does not) and/or is too difficult to implement and flake8 provides the same service, then dropping pylint is fine too. |
We use it like this: |
Regarding black and flake8, both have no problem running against the collection converted formats. Only an issue I ran into so far was pylint running with Python 2. I haven't tried pytest yet, but probably it'll reveal some more issues, I'd guess. In terms of the testing areas among black, flake8 and pylint, I like pylint's ability to check import paths. Since collection converter modifies the path, e.g., ansible.module_utils.some.thing to ansible_collections.NS.COLLECTION.plugins.module_utils.some.thing, it'll give us a good chance to capture the broken path/conversion quickly. |
I would not bother too much with pytest, unless it is really easy. |
FYI: RHELPLAN-56179 - Add the future boilerplate to all of the modules and module_utils code |
linux-system-roles#45 (review) But ansible_role_parser.py is not added to lsr_role2collection.py. I'm wondering ansible_role_parser.py is more useful to be a library to share?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
please rebase and squash
…ection conversion, verification Adding collection to envlist and travis in tox.ini. Adding script .travis/runcollection.sh that is invoked by "tox -e collection". Default test list specified in runcollection.sh: "black, flake8, yamllint, py38, shellcheck". yamllint: since collection conversion removes some line breaks, yamllint tends to fail with line too long. Setting the level to warning in .yamllint_defaults.yml when yamllint is executed in the collection format. utils.sh: supporting collections format path, e.g., - "$TOPDIR"/tests/ROLENAME/setup_module_utils.sh - SRC_COLL_MODULE_UTILS_DIR and DEST_COLL_MODULE_UTILS_DIR
Thank you, @richm. Merged. |
…ection conversion, verification
Adding collection to envlist in tox.ini and script .travis/collections.sh
that is invoked by "tox -e collection".
Notes:
and https://github.com/linux-system-roles/template. Once auto-maintenance pr/13
is merged, the line cloning the TEMPORARY branch should be replaced.
default. If any other tests to be run, it could added in tox.ini in each role.
For instance, this command line adds "black,flake8" to the default envlist and
they pass.
commands =
bash {toxinidir}/.travis/collection.sh {toxworkdir} "black,flake8,yamllint,py38,shellcheck,custom"