CiscoTestAutomation / pyats

Cisco DevNet pyATS Test Framework Bug Tracker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asyncio Error when trying to Initialise a mock device

gwoodwa1 opened this issue · comments

When trying to use --ssh option on the mock_device_cli I get a strange asyncio error. I've tried this on my local machine as well as the latest container based version of pyATS. It does seem to work fine on earlier versions of pyATS as a colleague has this working.

root@12231b0615b0:/pyats# mock_device_cli --os nxos --mock_data_dir /shared_volume/mock_test  --state connect --ssh
Traceback (most recent call last):
  File "/pyats/bin/mock_device_cli", line 8, in <module>
    sys.exit(main())
  File "src/unicon/mock/mock_device.py", line 1075, in unicon.mock.mock_device.main
  File "src/unicon/mock/mock_device.py", line 994, in unicon.mock.mock_device.MockDeviceSSHWrapper.run
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 595, in run_until_complete
    future = tasks.ensure_future(future, loop=self)
  File "/usr/local/lib/python3.8/asyncio/tasks.py", line 684, in ensure_future
    raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
TypeError: An asyncio.Future, a coroutine or an awaitable is required
root@12231b0615b0:/pyats#

Hi Gary,

Could you please ensure that all packages are the latest version? We've released a few minor versions and I'd like to make sure that this hasn't been already fixed by one of them.

In addition would it be possible for you to try one of the examples from https://github.com/CiscoTestAutomation/examples ? If this issue can be replicated on a mock device that we have access to it will be easier to troubleshoot any issues.

Hi Liam, I used the latest containerized version of pyATS so that I could prove the issue was not a local install. The state connect works fine it's only when trying to use the --ssh option does the traceback occur. I will try it with other mock devices to see if I can replicate it against specific mock files.

Hi Gary,

Any update?

Hi Liam, I haven't finished doing some further testing yet. Will update you in a couple of days with my findings.

I've updated all my packages to the latest version on my local machine plus this is the same outcome when using the latest docker image of pyATS. I have created a new mock device on Junos plus I have also used the one located here:
https://github.com/CiscoTestAutomation/examples/tree/master/blitz/config_interface/mock_device
This is one of your own and which I converted from the pickle to yaml file output using the command line conversion but still get the same TypeError: An asyncio.Future error whenever I use the --ssh argument in the command line. The --connect arguement works fine. Could you try and replicate this with the docker version of pyATS and this specific mock device on the cisco test automation examples?

For your reference this is the output when using your mock device example (same error and issue).

(mock_demo) gary@gary-MS-7B17:~/mock_demo$ mock_device_cli --os iosxe --mock_data_dir mock/iosxe_demo --state connect --ssh
Traceback (most recent call last):
  File "/home/gary/mock_demo/bin/mock_device_cli", line 8, in <module>
    sys.exit(main())
  File "src/unicon/mock/mock_device.py", line 1075, in unicon.mock.mock_device.main
  File "src/unicon/mock/mock_device.py", line 994, in unicon.mock.mock_device.MockDeviceSSHWrapper.run
  File "/usr/lib/python3.9/asyncio/base_events.py", line 621, in run_until_complete
    future = tasks.ensure_future(future, loop=self)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 680, in ensure_future
    raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
TypeError: An asyncio.Future, a coroutine or an awaitable is required

TypeError: An asyncio.Future, a coroutine or an awaitable is required

error might not be friendly. but I'm guessing you might not have asyncssh package. please check pip list | grep asyncssh

if not there, please install by pip install asyncssh

Hi Taskahi, You nailed the problem it was asyncssh being missing. All working now.

(mock_demo) gary@gary-MS-7B17:~/mock_demo$ mock_device_cli --os junos --mock_data_dir mock/iosxe_demo --state connect --ssh
Traceback (most recent call last):
  File "/home/gary/mock_demo/bin/mock_device_cli", line 8, in <module>
    sys.exit(main())
  File "src/unicon/mock/mock_device.py", line 1075, in unicon.mock.mock_device.main
  File "src/unicon/mock/mock_device.py", line 994, in unicon.mock.mock_device.MockDeviceSSHWrapper.run
  File "/usr/lib/python3.9/asyncio/base_events.py", line 621, in run_until_complete
    future = tasks.ensure_future(future, loop=self)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 680, in ensure_future
    raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
TypeError: An asyncio.Future, a coroutine or an awaitable is required
(mock_demo) gary@gary-MS-7B17:~/mock_demo$ pip install asyncssh
Collecting asyncssh
  Downloading asyncssh-2.9.0-py3-none-any.whl (334 kB)
     |████████████████████████████████| 334 kB 9.7 MB/s 
Collecting typing-extensions>=3.6
  Downloading typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Requirement already satisfied: cryptography>=2.8 in ./lib/python3.9/site-packages (from asyncssh) (36.0.1)
Requirement already satisfied: cffi>=1.12 in ./lib/python3.9/site-packages (from cryptography>=2.8->asyncssh) (1.15.0)
Requirement already satisfied: pycparser in ./lib/python3.9/site-packages (from cffi>=1.12->cryptography>=2.8->asyncssh) (2.21)
Installing collected packages: typing-extensions, asyncssh
Successfully installed asyncssh-2.9.0 typing-extensions-4.1.1
(mock_demo) gary@gary-MS-7B17:~/mock_demo$ mock_device_cli --os junos --mock_data_dir mock/iosxe_demo --state connect --ssh
2022-03-05 13:05:07,004 [    INFO]:  Creating SSH listener on 127.0.0.1, port 8266
2022-03-05 13:05:07,004 [    INFO]:  Server 0 listening on port 8266
^C2022-03-05 13:05:21,951 [    INFO]:  Shutting down.
2022-03-05 13:05:21,952 [    INFO]:  Closing server 1
(mock_demo) gary@gary-MS-7B17:~/mock_demo$

thanks @gwoodwa1 ! closing the issue. (we will see if we can improve the error to tell the issue exactly).