From f5037314e30dd6e2accf9313988c3ceb64491922 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 7 Jul 2020 21:16:28 +0530 Subject: [PATCH] sanity: remove ansible-bad-function (#70431) * Updated docs and ignore.txt * Replaced with correct function calls Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/facts/system/distribution.py | 2 +- lib/ansible/modules/file.py | 2 +- test/sanity/ignore.txt | 11 ++++------- test/units/modules/test_known_hosts.py | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index 45264df5b3c..e906a5afc45 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -136,7 +136,7 @@ class DistributionFiles: parsed, dist_file_dict = distfunc(name, dist_file_content, path, collected_facts) return parsed, dist_file_dict except AttributeError as exc: - print('exc: %s' % exc) + self.module.debug('exc: %s' % exc) # this should never happen, but if it does fail quietly and not with a traceback return False, dist_file_dict diff --git a/lib/ansible/modules/file.py b/lib/ansible/modules/file.py index 0054df06d34..d34a894f37c 100644 --- a/lib/ansible/modules/file.py +++ b/lib/ansible/modules/file.py @@ -237,7 +237,7 @@ class AnsibleModuleError(Exception): self.results = results def __repr__(self): - print('AnsibleModuleError(results={0})'.format(self.results)) + return 'AnsibleModuleError(results={0})'.format(self.results) class ParameterError(AnsibleModuleError): diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index f01616892de..9952f2c351f 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -51,7 +51,6 @@ lib/ansible/module_utils/distro/_distro.py no-assert lib/ansible/module_utils/distro/_distro.py pep8!skip # bundled code we don't want to modify lib/ansible/module_utils/facts/__init__.py empty-init # breaks namespacing, deprecate and eventually remove lib/ansible/module_utils/facts/network/linux.py pylint:blacklisted-name -lib/ansible/module_utils/facts/system/distribution.py pylint:ansible-bad-function lib/ansible/module_utils/powershell/Ansible.ModuleUtils.ArgvParser.psm1 pslint:PSUseApprovedVerbs lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 pslint:PSProvideCommentHelp # need to agree on best format for comment location lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1 pslint:PSUseApprovedVerbs @@ -84,7 +83,6 @@ lib/ansible/modules/copy.py validate-modules:doc-default-does-not-match-spec lib/ansible/modules/copy.py validate-modules:doc-type-does-not-match-spec lib/ansible/modules/copy.py validate-modules:nonexistent-parameter-documented lib/ansible/modules/copy.py validate-modules:undocumented-parameter -lib/ansible/modules/file.py pylint:ansible-bad-function lib/ansible/modules/file.py validate-modules:doc-default-does-not-match-spec lib/ansible/modules/file.py validate-modules:undocumented-parameter lib/ansible/modules/find.py use-argspec-type-path # fix needed @@ -169,7 +167,7 @@ lib/ansible/modules/user.py validate-modules:use-run-command-not-popen lib/ansible/modules/async_status.py use-argspec-type-path lib/ansible/modules/async_status.py validate-modules!skip lib/ansible/modules/async_wrapper.py ansible-doc!skip # not an actual module -lib/ansible/modules/async_wrapper.py pylint:ansible-bad-function +lib/ansible/modules/async_wrapper.py pylint:ansible-bad-function # ignore, required lib/ansible/modules/async_wrapper.py use-argspec-type-path lib/ansible/modules/wait_for.py validate-modules:parameter-list-no-elements lib/ansible/parsing/vault/__init__.py pylint:blacklisted-name @@ -183,9 +181,9 @@ lib/ansible/plugins/lookup/sequence.py pylint:blacklisted-name lib/ansible/plugins/strategy/__init__.py pylint:blacklisted-name lib/ansible/plugins/strategy/linear.py pylint:blacklisted-name lib/ansible/vars/hostvars.py pylint:blacklisted-name -test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import -test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import-from -test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-function +test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import # ignore, required for testing +test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import-from # ignore, required for testing +test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-function # ignore, required for testing test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py pylint:relative-beyond-top-level test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py pylint:relative-beyond-top-level test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py pylint:relative-beyond-top-level @@ -335,7 +333,6 @@ test/units/module_utils/urls/fixtures/multipart.txt line-endings # Fixture for test/units/module_utils/urls/test_Request.py replace-urlopen test/units/module_utils/urls/test_fetch_url.py replace-urlopen test/units/modules/test_apt.py pylint:blacklisted-name -test/units/modules/test_known_hosts.py pylint:ansible-bad-function test/units/parsing/vault/test_vault.py pylint:blacklisted-name test/units/playbook/role/test_role.py pylint:blacklisted-name test/units/plugins/test_plugins.py pylint:blacklisted-name diff --git a/test/units/modules/test_known_hosts.py b/test/units/modules/test_known_hosts.py index 3b6dfd86e41..123dd75f886 100644 --- a/test/units/modules/test_known_hosts.py +++ b/test/units/modules/test_known_hosts.py @@ -22,7 +22,7 @@ class KnownHostsDiffTestCase(unittest.TestCase): return tmp_file.name def test_no_existing_file(self): - path = tempfile.mktemp(prefix='ansible-test-', suffix='-known_hosts') + path = "/tmp/this_file_does_not_exists_known_hosts" key = 'example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=None, replace_or_add=False, state='present', key=key) self.assertEqual(diff, {