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

Regex used to validate device hostname is not strict enough #32

Open
sogloarcadius opened this issue Dec 26, 2019 · 11 comments
Open

Regex used to validate device hostname is not strict enough #32

sogloarcadius opened this issue Dec 26, 2019 · 11 comments
Assignees

Comments

@sogloarcadius
Copy link

Hello,

I am using pyats and genie connection client in a python script to parse some commands output of network devices.

I realize that the regex used to validate the device hostname is not strict enough.
In fact when the actual device hostname contains a substring of the hostname parameter the connection succeed but i am expecting it to fail.

For example when the actual device hostname is "demo-vrouter1" and i use con = Device("vrouter1").connect(), I am expecting the connection to fail because vrouter1 does not strictly match demo-vrouter1.

Do i miss a configuraton option to make hostname validation more strict ?

Thanks,

Best regards,

@simingy
Copy link
Contributor

simingy commented Dec 27, 2019

Hi

Cisco is currently on Christmas shutdown - expect most team members to return by Jan 6.
Will make sure our connection SME is on this issue when they return!

@difuhu fyi

@difuhu
Copy link

difuhu commented Jan 6, 2020

Hi @sogloarcadius ,

Could you share your testbed.yaml and/or detail attributes of Device("vrouter1")? Thanks.

@sogloarcadius
Copy link
Author

Hello @difuhu

Below the pyats version installed :

pyats : 19.12
genie : 19.12

Below the Python code i use to run the test

testbed = Testbed(hostname)
testbed.credentials=Credentials(dict(default=dict(
        username=username,
        password=password)))

dev = Device(hostname,
                 os=os,
                 custom={'abstraction': {'order': ['os']}},
                 connections={'default': dict(host=management_ip,
                                              arguments=dict(init_config_commands=[],
                                                             init_exec_commands=[]),
                                              protocol='ssh')})
testbed.add_device(dev)
dev.connect(log_stdout=False, connection_timeout=connection_timeout, learn_hostname=False)
dev.parse(command)

Thanks.
Regards.

@difuhu
Copy link

difuhu commented Jan 10, 2020

Hi @sogloarcadius ,

Thanks for the detail info and code snippet. Yes, enhancement can be made to validate hostname stricter.
Could you provide the os (plugin) you are using? We will enhance and test it.

@sogloarcadius
Copy link
Author

Hello @difuhu

I am using a cisco CSR1000v for testing (iosxe) but i think your fix should target all supported devices by the library.

Regards

Arcadius

@difuhu
Copy link

difuhu commented Jan 14, 2020

Hi @sogloarcadius ,
Thanks for the CSR1000V info.
Yes, sure, we will try our best to fix all supported platforms.

@simingy
Copy link
Contributor

simingy commented Feb 11, 2020

@sogloarcadius could you please validate if this was fixed in v20.1 release?

@mdear
Copy link

mdear commented Feb 11, 2020

@sogloarcadius could you please validate if this was fixed in v20.1 release?

Update: This request is tracked on our backlog but has not yet been released.

@tahigash tahigash self-assigned this May 21, 2020
@tahigash tahigash assigned LenzDong and karmoham and unassigned tahigash Sep 1, 2020
@karmoham
Copy link

Hi Sogloarcadius,

We currently run on v20.9, could you please upgrade your env to the latest version (better to install a fresh one) and retry?

Installation steps;
https://developer.cisco.com/docs/pyats/api/

If the issue persists, please provide the reproduce steps and we will get back to you with a solution.

I have tried with the most recent version and the issue is not reproducible;

Welcome to pyATS Interactive Shell
==================================
Python 3.8.1 (default, Feb  6 2020, 10:50:57)
[Clang 11.0.0 (clang-1100.0.33.16)]

>>> from genie.testbed import load
>>> testbed = load('testbed.yaml')
-------------------------------------------------------------------------------
>>> uut = testbed.devices['demo-asr-MIB-2']
>>> uut.connect()

2020-10-13 19:23:59,568: %UNICON-INFO: +++ demo-asr-MIB-2 logfile /tmp/demo-asr-MIB-2-cli-20201013T192359567.logtestbed:
 +++

2020-10-13 19:23:59,568: %UNICON-INFO: +++ Unicon plugin iosxe +++
Trying 1.1.1.1...


2020-10-13 19:23:59,602: %UNICON-INFO: +++ connection to spawn: telnet 1.1.1.1 2043, id: 1212121212 +++

2020-10-13 19:23:59,603: %UNICON-INFO: connection to demo-asr-MIB-2
Connected to arf-tsisg-asr-ssr.cisco.com.
Escape character is '^]'.

Location: 163_88_9

asr-MIB-2>^CTraceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/karmoham/pyats_3.8.1/pypi/genie/src/genie/conf/base/device.py", line 632, in connect
    self.connectionmgr.connect(*args, **kwargs)
  File "/Users/karmoham/pyats_3.8.1/pypi/pyats/pkgs/connections-pkg/src/pyats/connections/manager.py", line 334, in connect
    output = connection.connect()
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/bases/connection.py", line 694, in connect
    output = self.connection_provider.connect()
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/bases/routers/connection_provider.py", line 189, in connect
    output = self.establish_connection()
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/bases/routers/connection_provider.py", line 211, in establish_connection
    output = con.state_machine.go_to('any',
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/statemachine/statemachine.py", line 719, in go_to
    output = transition.do_transitions()
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/statemachine/statetransition.py", line 487, in do_transitions
    m = dialog.process(self.spawn,
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/eal/dialogs.py", line 460, in process
    return dp.process()
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/eal/dialog_processor.py", line 299, in process
    if self.expect_eval_statements(pat) is True:
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/eal/dialog_processor.py", line 218, in expect_eval_statements
    if self.spawn.read_update_buffer():
  File "/Users/karmoham/pyats_3.8.1/pypi/unicon/src/unicon/eal/backend/pty_backend.py", line 139, in read_update_buffer
    time.sleep(0.01)
KeyboardInterrupt
>>> exit()

Thanks,
Karim

@sogloarcadius
Copy link
Author

Hello,

The issue is not fixed in the latest release. As described in the issue when the configured hostname contains the string subset, the validation process with learn_hostname = False does not work.

Example: router is configured with hostname demo-vrouter1 and connecting to the device with hostname vrouter1 works which is not the expected behavior with learn_hostname=False.

Thanks,

Regards,

Arcadius.

@karmoham
Copy link

Hi Arcadius,

Thanks for reporting the issue, item has been added to our backlog and we will address it in the coming releases.

Thanks,
Karim

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

No branches or pull requests

7 participants