CiscoTestAutomation / rest

pyATS | Genie REST API Connector
10 stars 23 forks source link

NXOS connection using https fails. #33

Closed jkary closed 3 years ago

jkary commented 3 years ago

Using the following testbed.yaml snippet:

devices:
  N9K-C9508-SPINE-01:
    type: switch
    connections:
      vty:
        alias: nxapi
        protocol: https
        ip: 172.31.0.61
        port: "443"
        username: admin
        password: cisco.123
        class: rest.connector.Rest
      defaults:
        via: vty
    platform: nxos
    os: nxos

I get the following error:

# python
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyats.topology import loader
d('testbeds/testbed-17_1.yaml')
device = testbed.devices['N9K-C9508-SPINE-01']
device.connect(alias='nxapi',>>> testbed = loader.load('testbeds/testbed-17_1.yaml')
 via='vty')
device.rest.connected
<stdin>:1: DeprecationWarning: Device N9K-C9508-SPINE-01 'tacacs.username' is deprecated in the testbed YAML.  This key has been moved to device 'credentials'.
<stdin>:1: DeprecationWarning: Device N9K-C9508-SPINE-01 'passwords.linux' is  deprecated in the testbed YAML.  Use 'credentials' instead.
>>> device = testbed.devices['N9K-C9508-SPINE-01']
>>> device.connect(alias='nxapi', via='vty')
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
    httplib_response = self._make_request(conn, method, url,
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 368, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/venv/lib/python3.8/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
    httplib_response = self._make_request(conn, method, url,
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/pyats/connections/manager.py", line 339, in pyats.connections.manager.ConnectionManager.connect
  File "src/pyats/async_/synchronize.py", line 117, in pyats.async_.synchronize.Lockable.locked._wrapped
  File "/venv/lib/python3.8/site-packages/rest/connector/libs/nxos/implementation.py", line 138, in connect
    response = self.session.post(login_url, data=_data, timeout=timeout)
  File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/venv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
>>> device.rest.connected
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "src/pyats/topology/device.py", line 518, in pyats.topology.device.Device.__getattr__
AttributeError: 'Device' object has no attribute 'rest'
>>>

I'm suspecting verify=false may be needed for the connection?

KamyarZiabari commented 3 years ago

@jkary what version of pyats genie and unicon are using?

jkary commented 3 years ago

I am using 21.1.

Jason

On Feb 5, 2021, at 9:35 AM, KamyarZiabari notifications@github.com wrote:

@jkary https://github.com/jkary what version of pyats genie and unicon are using?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CiscoTestAutomation/rest/issues/33#issuecomment-774069709, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGVNDPHMRSPFWUBM25IPHTS5P63JANCNFSM4WV4UV2Q.

KamyarZiabari commented 3 years ago

Based on the code lines your rest.connector version is at 20.12 but in 21.1 that verify=False is actually added to the code.

Please update rest.connector to the latest using pip install --upgrade rest.connector then try and see if it does connect.

Let me know if it helped.

Regards, Kamyar