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 problems in handling of CLI "exec" mode and "config" mode commands with prompts. #71

Merged

Conversation

kerry-meyer
Copy link
Collaborator

Root cause analysis:

Commands containing a "prompt/answer" sequence require
the user to specify a dictionary containing the command, prompt,
and "answer" (for the prompt). The previously existing handling enclosed the
entire command dictionary (containing the "command", "prompt",
and "answer" key/value pairs) in quotes as the value for an
unintended outer "command" key. The other items in the
dictionary input to the "send_command" API (for sending
commands to a device) were set to defaults (for exec commands)
or left unspecified (for configuration commands).

For example:

  • Ansible "module" contents from parsing a playbook that specified
    an exec command "list" containing a single command/prompt/answer sequence:

["{'command': 'image remove all', 'prompt': '\\[y/N\\]:', 'answer': 'N'}"]

  • Incorrect result of formatting the "raw" single command list shown
    above to prepare for invoking the "send_command" API:

{'command': "{'command': 'image remove all', 'prompt': '\\[y/N\\]:', 'answer': 'N'}", 'output': None, 'prompt': None, 'answer': None, 'newline': True, 'sendonly': False, 'check_all': False}

  • Instead of the incorrect dictionary shown above, the desired dictionary
    is:

{'command': 'image remove all', 'prompt': '\\[y/N\\]:', 'answer': 'N', 'newline': True, 'sendonly': False, 'check_all': False}

Fix:

- Create a utility function to generate the correct dictionary
entries from the input command list parsed from the user
playbook.
- Use the resulting dictionary instead of the "raw" list
of quoted command strings provided by the "AnsibleModule"
parsing invocation to formulate the correct arguments
for the "send_command" API.
- (sonic-config test suite only): Fix problems preventing execution of sonic-config test cases:
    - Change the names for snmp community list entries to valid names.
    - Use /tmp directory instead of /home directory to avoid a permissions failure for
        the "backup" test.
SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

sonic_command, sonic_cli

ADDITIONAL INFORMATION

Unit and Regression Test Results:

  • sonic-config test suite output comparison before and after the fix: (The Failing "prompt_test_case" was removed for the base comparison because it aborted the test suite. That test passes with the fix.)

prompt_fix_sonic_command_regression_comparison.txt

Kerry Meyer and others added 3 commits April 23, 2022 00:25
Root cause analysis:

Commands containing  a "prompt/answer" sequence require
the user to specify a dictionary containing the command, prompt,
and "answer" (for the prompt). The previously existing handling enclosed the
entire command dictionary (containing the "command", "prompt",
and "answer" key/value pairs) in quotes as the value for an
unintended outer "command" key. The other items in the
dictionary input to the "send_command" API (for sending
commands to a device) were set to defaults (for exec commands)
or left unspecified (for configuration commands).

For example:

- Ansible "module" contents from parsing a playbook that specified
an exec command "list" containing a single command/prompt/answer sequence:

-----------------------------
["{'command': 'image remove all', 'prompt': '\\\\[y/N\\\\]:', 'answer': 'N'}"]
-----------------------------

- Incorrect result of formatting the "raw" single command list shown
above to prepare for invoking the "send_command" API:

-----------------------------
{'command': "{'command': 'image remove all', 'prompt': '\\\\[y/N\\\\]:', 'answer': 'N'}", 'output': None, 'prompt': None, 'answer': None, 'newline': True, 'sendonly': False, 'check_all': False}
-----------------------------

- Instead of the incorrect dictionary shown above, the desired dictionary
is:
-----------------------------
{'command': 'image remove all', 'prompt': '\\\\[y/N\\\\]:', 'answer': 'N', 'newline': True, 'sendonly': False, 'check_all': False}
-----------------------------

Fix:

    - Create a utility function to generate the correct dictionary
    entries from the input command list parsed from the user
    playbook.
    - Use the resulting dictionary instead of the "raw" list
    of quoted command strings provided by the "AnsibleModule"
    parsing invocation to formulate the correct arguments
    for the "send_command" API.
@kerry-meyer kerry-meyer changed the title Fix problems in handling of CLI "exec" mode and "config" mode commands. Fix problems in handling of CLI "exec" mode and "config" mode commands with prompts. Apr 24, 2022
@kerry-meyer kerry-meyer requested a review from stalabi1 April 24, 2022 07:43
Copy link
Collaborator

@stalabi1 stalabi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of these changes.

@kerry-meyer kerry-meyer merged commit 54084ad into ansible-collections:1.x Apr 26, 2022
kerry-meyer added a commit to kerry-meyer/dellemc.enterprise_sonic that referenced this pull request Apr 26, 2022
kerry-meyer added a commit that referenced this pull request May 9, 2022
@kerry-meyer kerry-meyer deleted the cli_prompt_and_answer_fix_new branch September 1, 2022 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants