py-junos-eznc
py-junos-eznc copied to clipboard
scp.py module is using deprecated call - Python3.11
When using Python3.11 I get the following error. This appears to be related to deprecation work done in the built in inspection module. I am using Ansible to install Junos and this happens during the scp of the software package to the router.
The full traceback is:
Traceback (most recent call last):
File "/home/user/tmp/.ansible/ansible-tmp-1677520695.0383077-3815631-40636370462949/AnsiballZ_software.py", line 107, in <module>
_ansiballz_main()
File "/home/user/tmp/.ansible/ansible-tmp-1677520695.0383077-3815631-40636370462949/AnsiballZ_software.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/user/tmp/.ansible/ansible-tmp-1677520695.0383077-3815631-40636370462949/AnsiballZ_software.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.software', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.software', _modlib_path=modlib_path),
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/tmp/ansible_juniper.device.software_payload_svyllfbp/ansible_juniper.device.software_payload.zip/ansible_collections/juniper/device/plugins/modules/software.py", line 791, in <module>
File "/tmp/ansible_juniper.device.software_payload_svyllfbp/ansible_juniper.device.software_payload.zip/ansible_collections/juniper/device/plugins/modules/software.py", line 701, in main
File "/home/user/.local/lib/python3.11/site-packages/jnpr/junos/utils/sw.py", line 929, in install
copy_ok = self.safe_copy(
^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.11/site-packages/jnpr/junos/utils/sw.py", line 666, in safe_copy
self.put(package, remote_path=remote_path, progress=progress)
File "/home/user/.local/lib/python3.11/site-packages/jnpr/junos/utils/sw.py", line 198, in put
with SCP(self._dev, progress=progress) as scp:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.11/site-packages/jnpr/junos/utils/scp.py", line 46, in __init__
spec = inspect.getargspec(self._user_progress)
^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?
I found and used a workaround from another module to get this going again.
https://github.com/pyinvoke/invoke/issues/833
I added this to the top of the /home/user/.local/lib/python3.11/site-packages/jnpr/junos/utils/scp.py file
if not hasattr(inspect, 'getargspec'):
inspect.getargspec = inspect.getfullargspec
This issue also makes the tests to fail on Python 3.11.
======================================================================
ERROR: test_scp_user_def_progress_args_2 (tests.unit.utils.test_scp.TestScp.test_scp_user_def_progress_args_2)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/nix/store/kangjsm8gwikhfnim3lpfywzdcqls7zw-python3.11-mock-4.0.3/lib/python3.11/site-packages/mock/mock.py", line 1346, in patched
return func(*newargs, **newkeywargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/build/source/tests/unit/utils/test_scp.py", line 91, in test_scp_user_def_progress_args_2
with SCP(self.dev, progress=myprogress) as scp:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/build/source/lib/jnpr/junos/utils/scp.py", line 46, in __init__
spec = inspect.getargspec(self._user_progress)
^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'
----------------------------------------------------------------------
Ran 819 tests in 46.301s
This issue was addressed.
FYI,
% python3 --version
Python 3.12.2
% nose2 tests.unit.utils.test_scp
....1.1.1.1: test: 50 / 100 (50%)
None
......
----------------------------------------------------------------------
Ran 10 tests in 0.071s