From f7742924391ed51c099a2b54d4f033ebedf64107 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Thu, 30 Sep 2021 21:50:18 +0200 Subject: [PATCH] cli - remove deprecated setting verbosity before sub command (#75840) * cli - remove deprecated setting verbosity before sub command Fixes #75823 * Fix tests --- ...-cli-remove-deprecated-verbosity-before-sub-cmd.yml | 2 ++ lib/ansible/cli/__init__.py | 10 ---------- test/units/cli/test_galaxy.py | 8 +------- test/units/cli/test_vault.py | 6 +----- 4 files changed, 4 insertions(+), 22 deletions(-) create mode 100644 changelogs/fragments/75823-cli-remove-deprecated-verbosity-before-sub-cmd.yml diff --git a/changelogs/fragments/75823-cli-remove-deprecated-verbosity-before-sub-cmd.yml b/changelogs/fragments/75823-cli-remove-deprecated-verbosity-before-sub-cmd.yml new file mode 100644 index 00000000000..c86242b84e5 --- /dev/null +++ b/changelogs/fragments/75823-cli-remove-deprecated-verbosity-before-sub-cmd.yml @@ -0,0 +1,2 @@ +bugfixes: + - cli - remove deprecated ability to set verbosity before the sub-command (https://github.com/ansible/ansible/issues/75823) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 0ffafc5a69e..515822e23ab 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -349,16 +349,6 @@ class CLI(with_metaclass(ABCMeta, object)): else: options.inventory = C.DEFAULT_HOST_LIST - # Dup args set on the root parser and sub parsers results in the root parser ignoring the args. e.g. doing - # 'ansible-galaxy -vvv init' has no verbosity set but 'ansible-galaxy init -vvv' sets a level of 3. To preserve - # back compat with pre-argparse changes we manually scan and set verbosity based on the argv values. - if self.parser.prog in ['ansible-galaxy', 'ansible-vault'] and not options.verbosity: - verbosity_arg = next(iter([arg for arg in self.args if arg.startswith('-v')]), None) - if verbosity_arg: - display.deprecated("Setting verbosity before the arg sub command is deprecated, set the verbosity " - "after the sub command", "2.13", collection_name='ansible.builtin') - options.verbosity = verbosity_arg.count('v') - return options def parse(self): diff --git a/test/units/cli/test_galaxy.py b/test/units/cli/test_galaxy.py index 804e1345d52..edf201a08b9 100644 --- a/test/units/cli/test_galaxy.py +++ b/test/units/cli/test_galaxy.py @@ -462,13 +462,7 @@ class TestGalaxyInitSkeleton(unittest.TestCase, ValidRoleTests): @pytest.mark.parametrize('cli_args, expected', [ (['ansible-galaxy', 'collection', 'init', 'abc._def'], 0), (['ansible-galaxy', 'collection', 'init', 'abc._def', '-vvv'], 3), - (['ansible-galaxy', '-vv', 'collection', 'init', 'abc._def'], 2), - # Due to our manual parsing we want to verify that -v set in the sub parser takes precedence. This behaviour is - # deprecated and tests should be removed when the code that handles it is removed - (['ansible-galaxy', '-vv', 'collection', 'init', 'abc._def', '-v'], 1), - (['ansible-galaxy', '-vv', 'collection', 'init', 'abc._def', '-vvvv'], 4), - (['ansible-galaxy', '-vvv', 'init', 'name'], 3), - (['ansible-galaxy', '-vvvvv', 'init', '-v', 'name'], 1), + (['ansible-galaxy', 'collection', 'init', 'abc._def', '-vv'], 2), ]) def test_verbosity_arguments(cli_args, expected, monkeypatch): # Mock out the functions so we don't actually execute anything diff --git a/test/units/cli/test_vault.py b/test/units/cli/test_vault.py index bb244a5ae78..e705dfe81bb 100644 --- a/test/units/cli/test_vault.py +++ b/test/units/cli/test_vault.py @@ -209,11 +209,7 @@ class TestVaultCli(unittest.TestCase): @pytest.mark.parametrize('cli_args, expected', [ (['ansible-vault', 'view', 'vault.txt'], 0), (['ansible-vault', 'view', 'vault.txt', '-vvv'], 3), - (['ansible-vault', '-vv', 'view', 'vault.txt'], 2), - # Due to our manual parsing we want to verify that -v set in the sub parser takes precedence. This behaviour is - # deprecated and tests should be removed when the code that handles it is removed - (['ansible-vault', '-vv', 'view', 'vault.txt', '-v'], 1), - (['ansible-vault', '-vv', 'view', 'vault.txt', '-vvvv'], 4), + (['ansible-vault', 'view', 'vault.txt', '-vv'], 2), ]) def test_verbosity_arguments(cli_args, expected, tmp_path_factory, monkeypatch): # Add a password file so we don't get a prompt in the test