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

Calling jsnapy without username and password causes exception instead of prompt #400

Closed
ddivins opened this issue Jun 9, 2022 · 3 comments
Labels
Milestone

Comments

@ddivins
Copy link
Contributor

ddivins commented Jun 9, 2022

Description of Issue/Question

When running snap and not providing username or password in config.yml or command line, snap will prompt for username and then error out with exceptions and tracebacks and never as for a password, ending with:

Exception: ConnectAuthError(172.25.92.59)

Setup

config_check.yml:

hosts:
      - device: 172.25.92.59

    tests:
       - test_chassis.yml

Command:
jsnapy --snap pre -f config_check.yml -v

Note, no username/password is provided

Steps to Reproduce Issue

Run the above and the below is the output:

ddivins@ddivins-mbp jsnap % jsnapy --snap pre -f config_check.yml -v
jsnapy.cfg file location used : /Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/etc/jsnapy
Configuration file location used : /etc/jsnapy
Connecting to device 172.25.92.59 ................

Enter User name: lab

ERROR occurred ConnectAuthError(172.25.92.59)
Exception in thread Thread-1 (connect):
Traceback (most recent call last):
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/jnpr/junos/device.py", line 1347, in open
    self._conn = netconf_ssh.connect(
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/ncclient/manager.py", line 168, in connect
    return connect_ssh(*args, **kwds)
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/ncclient/manager.py", line 135, in connect_ssh
    session.connect(*args, **kwds)
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/ncclient/transport/ssh.py", line 362, in connect
    self._auth(username, password, key_filenames, allow_agent, look_for_keys)
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/ncclient/transport/ssh.py", line 466, in _auth
    raise AuthenticationError("No authentication methods available")
ncclient.transport.errors.AuthenticationError: No authentication methods available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/jnpr/jsnapy/jsnapy.py", line 667, in connect
    dev.open()
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/jnpr/junos/device.py", line 1366, in open
    raise EzErrors.ConnectAuthError(self)
jnpr.junos.exception.ConnectAuthError: ConnectAuthError(172.25.92.59)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/ddivins/Library/CloudStorage/OneDrive-JuniperNetworks,Inc/Documents/PycharmProjects/jsnap/venv/lib/python3.10/site-packages/jnpr/jsnapy/jsnapy.py", line 689, in connect
    raise Exception(ex)
Exception: ConnectAuthError(172.25.92.59)

Versions Report

ddivins@ddivins-mbp jsnap % jsnapy --version                                                         
JSNAPy version: 1.3.7
ddivins@ddivins-mbp jsnap % python --version
Python 3.10.4
@ddivins
Copy link
Contributor Author

ddivins commented Jun 9, 2022

Problem is in snappy.py line 669:

if password is None and action is None:

This if statement is not met, if we remove "and action is None" this solves my issue, snippet:

 except ConnectAuthError as ex:
                #if password is None and action is None:
                if password is None:
                    password = getpass.getpass(
                        "\nEnter Password for username <%s> : " % username
                    )
                    return self.connect(
                        hostname,
                        username,
                        password,
                        output_file,
                        config_data,
                        action,
                        post_snap,
                        **kwargs
                    )

Problem is I have no idea what that "and action is None" is there for or doing so I do not know the safety of removing it.

ddivins added a commit to ddivins/jsnapy that referenced this issue Jun 9, 2022
Issue Juniper#400 fix, line 669 remove "and action None" from else statement to allow password prompt to appear
Note, I do not know if this has implications outside my scenarios but all my tests are working as expected
@ydnath ydnath added this to the Release 1.3.8 milestone Jun 24, 2022
@chidanandpujar
Copy link
Collaborator

issue is fixed #402

jsnapy --snap pre -f common_config.yml -v
jsnapy.cfg file location used : /root/jsnapy_test1/venv/etc/jsnapy
Configuration file location used : /root/jsnapy_test1/venv/etc/jsnapy
Connecting to device x.x.x.x ................

Enter User name: xyz

Enter Password for username :
Connecting to device x.x.x.x................
Tests Included: test_chassis_hardware
Taking snapshot of COMMAND: show chassis hardware

/jsnapy_test1/jsnapy# jsnapy --version
JSNAPy version: 1.3.8.dev0

@chidanandpujar
Copy link
Collaborator

issue is fixed #402 , hence closing this issue for now,
Please feel free to re-open, if the issue is reproducible in the latest jsnapy master branch.

Thanks
Chidanand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants