Skip to content
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 subprompts 'None' stringification in call to send_command #36254

Merged
merged 1 commit into from Feb 16, 2018

Conversation

bdowling
Copy link
Contributor

send_command already performs the to_bytes safely on prompts (checking for None). Without this check the literal 'None' became a subprompt trigger!

SUMMARY

The call to send_command in ios edit_config was interning prompts=None to the literal string 'None' causing any output from the device to be scanned for a subprompt None and sending 'None' back as the answer was also 'None'.

Since send_command already does a safer to_bytes() on these parameters, I removed the unneccessary calls in cliconf/ios.py

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

cliconf/ios.py
network_cli

ANSIBLE VERSION
devel
ADDITIONAL INFORMATION

Example play that triggered this bug:

---

- hosts: onerouter
  gather_facts: no
  connection: network_cli

  tasks:
  - name: Set Interfaces Descriptions

    ios_config:
      parents: "interface GigabitEthernet1"
      lines:
        - description "Interface tag triggers a prompt response [None]"

send_command already performs the to_bytes safely on prompts (checking
for None).  Without this check the literal 'None' became a subprompt trigger!
@ansibot
Copy link
Contributor

ansibot commented Feb 15, 2018

@ansibot ansibot added bugfix_pull_request needs_triage Needs a first human triage before being processed. networking Network category support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 15, 2018
@bdowling
Copy link
Contributor Author

Debug of the error (with extra local debug turned on):

CLI-SUBPROMPT: Matched 'None', sent '<answer>\r'
CLI-PROMPT: looking for prompts in [63]| description "Interface tag triggers a prompt response [None]"\r\nbd-csr1000v-00(config-if)#
CLI-PROMPT: Matched Standard Prompt '[\r\n][\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$'
CLI-RECV:
CLI-SEND: end\r
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [1]| N
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [2]| No
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [3]| Non
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [4]| None
CLI-SUBPROMPT: Matched 'None', sent '<answer>\r'
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [5]| None\r\n
cli command_timeout extended on new data
CLI-PROMPT: looking for prompts in [6]| None\r\n                            ^\r\n% Invalid input detected at '^' marker.\r\n\r\nbd-csr1000v-00(config-if)#
CLI-PROMPT: Matched Error Prompt 'invalid input'
CLI-PROMPT: Matched Standard Prompt (after error) '[\r\n][\w\+\-\.:\/\[\]]+(?:\([^\)]+\)){0,3}(?:[>#]) ?$'
done communicating
done with local.exec_command()
_low_level_execute_command() done: rc=1, stdout=, stderr=Traceback (most recent call last):
  File "/tmp/ansible_avtyI6/ansible_module_ios_config.py", line 551, in <module>    main()
  File "/tmp/ansible_avtyI6/ansible_module_ios_config.py", line 480, in main    load_config(module, commands)
  File "/tmp/ansible_avtyI6/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py", line 162, in load_config
  File "/tmp/ansible_avtyI6/ansible_modlib.zip/ansible/module_utils/connection.py", line 146, in __rpc__
ansible.module_utils.connection.ConnectionError: None
                            ^
% Invalid input detected at '^' marker.

bd-csr1000v-00(config-if)#

@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Feb 15, 2018
@bdowling
Copy link
Contributor Author

Note: I don't see other places where the caller uses to_bytes on the prompts, but there are a couple of occurrences of to_bytes on the command being sent. (Also redundant with what send_command already covers).

$ git grep 'send_command.*to_bytes'
lib/ansible/plugins/cliconf/dellos10.py:            self.send_command(to_bytes(cmd))
lib/ansible/plugins/cliconf/iosxr.py:        self.send_command(to_bytes(command))
lib/ansible/plugins/cliconf/vyos.py:            self.send_command(to_bytes(cmd))
lib/ansible/plugins/cliconf/vyos.py:        self.send_command(to_bytes(command))

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Feb 16, 2018
@Qalthos Qalthos merged commit f2818ca into ansible:devel Feb 16, 2018
@Qalthos
Copy link
Contributor

Qalthos commented Feb 16, 2018

That's what I get for forgetting how I've fixed it elsewhere. This is of course preferred, pushing the translation to the last point in common code.

Qalthos pushed a commit to Qalthos/ansible that referenced this pull request Feb 16, 2018
send_command already performs the to_bytes safely on prompts (checking
for None).  Without this check the literal 'None' became a subprompt trigger!

Fixes ansible#35662

(cherry picked from commit f2818ca)
Qalthos added a commit that referenced this pull request Feb 16, 2018
send_command already performs the to_bytes safely on prompts (checking
for None).  Without this check the literal 'None' became a subprompt trigger!

Fixes #35662

(cherry picked from commit f2818ca)
@bdowling bdowling deleted the fix_None_harmful branch February 19, 2018 15:09
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. networking Network category support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants