-
Notifications
You must be signed in to change notification settings - Fork 106
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
fix most ansible-test issues, suppress the rest #362
Conversation
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
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.
Please avoid at least introducing words that do not align with our conscious language initiative and it also seems that logging should be improved instead of ignoring the warning.
library/network_connections.py
Outdated
c = [] | ||
# pylint: disable=blacklisted-name |
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.
# pylint: disable=blacklisted-name | |
# disable check for bad names: | |
# pylint: disable=C0102 |
The name for the C0102 check does not match our conscious language initiative, therefore using the code with an explanation instead of the name seems to be better here. What is the bad variable name here? _
? Is there a better pattern to do something x times than a for _ in range()
? Maybe we can get rid of the warning completelely.
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 rewrote the code to avoid this issue - check it out
library/network_connections.py
Outdated
@@ -1988,6 +2015,7 @@ def _check_ethtool_setting_support(self, idx, connection): | |||
idx, "ethtool.%s specified but not supported by NM", specified | |||
) | |||
|
|||
# pylint: disable=blacklisted-name |
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.
see the other comment about this change
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 rewrote the code to avoid this issue e.g. use for option in specified.keys()
tests/get_coverage.sh
Outdated
@@ -32,10 +31,12 @@ call_ansible() { | |||
} | |||
|
|||
remote_coverage_dir="$(mktemp -d /tmp/remote_coverage-XXXXXX)" | |||
trap "rm -rf '${remote_coverage_dir}'" EXIT | |||
trap 'rm -rf "${remote_coverage_dir}"' EXIT |
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 this change correct? AFAIU, this will make $remote_coverage_dir
to be evaluated when the script exits but it should use the value it has at the time the trap is configured.
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.
shellcheck assumes that the correct thing to do is to use single quotes around the entire trap
command, and only expand it, including any variables used by the trap
command, at trap
evaulation time. https://github.com/koalaman/shellcheck/wiki/SC2064 - but we know what we're doing here, and we want the variable expanded at the point where the trap
is declared. So we follow the directions:
Exceptions
If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message.
so we will tell shellcheck to be quiet
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, I only have two comments.
2618ee1
to
e70dd1b
Compare
one thing to note - @cathay4t @liangwen12year @ffmancera - if this merges, all of your PRs will need to be rebased, and possibly there will be conflicts that will have to be fixed |
Rebase report - what effect will merging this PR have on other PRs:
|
b779577
to
1b15341
Compare
so wdyt? Can we merge this PR, and I help PR authors rebase and fixup their PRs? |
ok to merge? |
library/network_connections.py
Outdated
@@ -1408,7 +1416,8 @@ def check_mode_set(self, check_mode, connections=None): | |||
or (c == CheckMode.PRE_RUN and check_mode in [CheckMode.REAL_RUN]) | |||
or (c == CheckMode.REAL_RUN and check_mode in [CheckMode.DONE]) | |||
or (c == CheckMode.DRY_RUN and check_mode in [CheckMode.DONE]) | |||
) | |||
): | |||
raise AssertionError("check_mode value is incorrect {0}".format(c)) |
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.
should this be raise AssertionError("updating check_mode value from {0} into {1} is incorrect".format(c, check_mode))
?
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.
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
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 'type' the default 'metaclass' in python ?
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 'type' the default 'metaclass' in python ?
https://docs.ansible.com/ansible/2.9/dev_guide/testing/sanity/metaclass-boilerplate.html
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!
@richm There are 2 black formatting errors. Other than that, it looks good to me. :-) |
fixed |
@tyll have all of your requested changes been addressed? |
yes, thank you. |
module_utils/network_lsr/ethtool.py
Outdated
@@ -46,7 +50,7 @@ def get_perm_addr(ifname): | |||
res = ecmd.tobytes() | |||
except AttributeError: # tobytes() is not available in python2 | |||
res = ecmd.tostring() | |||
_, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res) | |||
dummy, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res) |
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.
The inclusive open source community orientation training at
https://training.linuxfoundation.org/training/inclusive-open-source-community-orientation-lfc102/
recommends in
to avoid the term "Dummy Value" and use "Placeholder Value" instead. I do not see an explanation for this.
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 guess I have to register to see the contents of that link? At any rate - what is the suggestion?
placeholder, size, perm_addr = struct.unpack("II%is" % MAX_ADDR_LEN, res)
?
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 do you want to replace _
in the first place? I though that is pretty common and pythonic.
An alternative name might be unused
. While I am surprised to hear "dummy" is discouraged, unused
anyway seems a better name.
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 do you want to replace
_
in the first place? I though that is pretty common and pythonic.
#362 (comment)
tl;dr - _
is also used for i18n, and Ansible wants to reserve _
for future use.
An alternative name might be
unused
. While I am surprised to hear "dummy" is discouraged,unused
anyway seems a better name.
"dummy" is a derogatory word which can be seen as non-inclusive
unused
works for me
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'll note that "dummy" is used in many places in the network role:
> git grep -c dummy
examples/dummy_simple.yml:4
library/network_connections.py:1
module_utils/network_lsr/argument_validator.py:1
pylintrc:2
tests/ensure_provider_tests.py:1
tests/playbooks/tests_dummy.yml:5
tests/tasks/create_dummy_profile.yml:1
tests/tasks/manage_test_interface.yml:9
tests/tests_dummy_nm.yml:2
tests/tests_helpers_and_asserts.yml: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.
I guess I have to register to see the contents of that link? At any rate - what is the suggestion?
You can easily login with your Red Hat Google account if you like. The course was recommended in the past and you can get a Fedora badge if you complete it.
I'll note that "dummy" is used in many places in the network role:
It is also an official network interface type, see https://developers.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces-for-virtual-networking/#dummy so we cannot get it completely removed.
> git grep -c dummy examples/dummy_simple.yml:4 library/network_connections.py:1 module_utils/network_lsr/argument_validator.py:1 pylintrc:2
This is a good find since it shwos that unused
is configured as an expectedly not used variable name, so we can use that.
tests/ensure_provider_tests.py:1
tests/playbooks/tests_dummy.yml:5
tests/tasks/create_dummy_profile.yml:1
tests/tasks/manage_test_interface.yml:9
tests/tests_dummy_nm.yml:2
tests/tests_helpers_and_asserts.yml:2
[citest] |
2 similar comments
[citest] |
[citest] |
Not sure if this is related to other changes, but there are now CI errors (Tox Python 3.6): https://github.com/linux-system-roles/network/pull/362/checks?check_run_id=2290367054
gi does not exist on Python 2.6 and is also not needed there. This is a module needed to access the NetworkManager API. Not sure where this is coming from, seems to be related to the conversion to collections. Also, there are some warnings, not sure what causes them, maybe it is related to broken 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.
Most shebang exceptions could be cleaned up.
plugins/modules/network_connections.py validate-modules:no-default-for-required-parameter | ||
plugins/modules/network_connections.py validate-modules:parameter-type-not-in-doc | ||
plugins/modules/network_connections.py validate-modules:undocumented-parameter | ||
tests/network/covstats shebang!skip |
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.
Seems this just needs the whitespace to be removed from the script to fix this.
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.
apparently not, if you are talking about the shebang
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.
This exception is about what is described in https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/shebang.html, isn't it? It states #!/bin/bash
as a valid Shebang but the file uses #! /bin/bash
. Not sure what I am missing 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.
#! /bin/bash
is valid for the Linux kernel, though.
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.
This is the error, for example:
ERROR: tests/network/covstats:1:1: unexpected non-module shebang: b'#!/bin/bash'
See documentation for help: https://docs.ansible.com/ansible/2.9/dev_guide/testing/sanity/shebang.html
I think the problem is that ansible-test doesn't understand executable files outside of the expected module/plugin directories. So it thinks that tests/covstats
is a module since it is executable and has a shebang, but it isn't in the right directory. This is because we need to have these helper scripts but there isn't a good place to keep them. There isn't a general Ansible role/collection convention for helper scripts used during build/test time. The ssh role uses .dev-tools
for this - https://github.com/linux-system-roles/ssh/tree/master/.dev-tools - I think a dotfile directory is a good idea - we used to use .travis/
for these sorts of scripts.
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.
The scripts are currently meant for a human to be used so hiding them in a dotdir seems to be wrong. I am fine with skipping them for now.
.sanity-ansible-ignore-2.9.txt
Outdated
plugins/module_utils/network_lsr/__init__.py shebang!skip | ||
plugins/module_utils/network_lsr/argument_validator.py shebang!skip | ||
plugins/module_utils/network_lsr/myerror.py shebang!skip |
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.
The shebangs can be removed from these files and then they don't need to be skipped.
The commit message is not accurate anymore since a few things were done differently, now. If you like, you can move some of the changes like the python code in a separate PR that we can merge to reduce the amount of changes piling up in this PR. |
bfd7c3e
to
1f4a0c9
Compare
Based on the recent changes, including updates to the PR description and commit message, do we still need to split this? |
I assumed the CI failures would cause more pain, I am fine with merging this as-is once the CI is finished. |
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.
👍
[citest bad] |
Automation Hub, and possibly Galaxy in the future, require the collection to be screened with `ansible-test sanity` among other checks. The role had a number of issues: * Use `AssertionError` instead of `assert` * Use of `logging` module not in accordance with standards, but these are ok and the errors were suppressed * Several import errors which are ok because they are checked elsewhere * __init__.py in the module_utils directories must be empty, so a new file myerror.py was added to move the code from __init__.py * NOTE: network_lsr/nm/__init__.py is not empty * The documentation block in the module was not properly constructed or formatted. * shellcheck issues, including removing unused files * use `unused` instead of `_` (underscore) for variables that are unused add WARNING to module docs - collection users should not use directly Signed-off-by: Rich Megginson <[email protected]>
Pull Request Test Coverage Report for Build 86f0bcd6bbd4a47245861e4100d2741dd79db24a-PR-362
💛 - Coveralls |
Automation Hub, and possibly Galaxy in the future, require the
collection to be screened with
ansible-test sanity
among otherchecks. The role had a number of issues:
AssertionError
instead ofassert
logging
module not in accordance with standards, but theseare ok and the errors were suppressed
elsewhere
new file myerror.py was added to move the code from init.py
or formatted.
unused
instead of_
(underscore) for variables that areunused