Skip to content

Commit

Permalink
Merge branch '82-Sivolen' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
qaxi authored Mar 29, 2024
2 parents e66c619 + 9b76a86 commit 707202b
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 105 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/FastTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Fast Test

on:
push:
branches-ignore:
- develop
- master
pull_request:
branches-ignore:
- develop
- master

jobs:

tox_test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.11" ]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Test with tox
run: |
tox
3 changes: 2 additions & 1 deletion .github/workflows/PublishToPIP.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Publish Python Package to PyPi.org
name: Publish To PyPi.org

on:
release:
types: [created]
workflow_dispatch:

jobs:
deploy:
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/TestBeforePush.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/ThoroughTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Thorough Test

on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
- master
# check every 14 days
schedule:
- cron: '0 6 5,20 * *'
jobs:

tox_test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Test with tox
run: |
tox
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PyPi: [![Upload](https://github.com/napalm-automation-community/napalm-s350/work

## Requirements

Python 3.6+, napalm 3+
Python 3.8+, napalm 4

## Installation

Expand Down
55 changes: 14 additions & 41 deletions napalm_s350/s350.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ConnectionClosedException,
)
from napalm.base.helpers import canonical_interface_name
from napalm.base.netmiko_helpers import netmiko_args

import napalm.base.constants as C
import napalm.base.canonical_map
Expand All @@ -45,6 +46,8 @@
"te": "TengigabitEthernet",
}

from typing import List


class S350Driver(NetworkDriver):
"""Napalm driver for S350."""
Expand All @@ -63,30 +66,9 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
self._dest_file_system = optional_args.get("dest_file_system", None)

# Netmiko possible arguments
netmiko_argument_map = {
"port": None,
"secret": "",
"verbose": False,
"keepalive": 30,
"global_delay_factor": 1,
"use_keys": False,
"key_file": None,
"ssh_strict": False,
"system_host_keys": False,
"alt_host_keys": False,
"alt_key_file": "",
"ssh_config_file": None,
"allow_agent": False,
}

# Allow for passing additional Netmiko arguments
self.netmiko_optional_args = {}
for k, v in netmiko_argument_map.items():
try:
self.netmiko_optional_args[k] = optional_args[k]
except KeyError:
pass
self.netmiko_optional_args = netmiko_args(optional_args)

self.platform = "s350"
self.port = optional_args.get("port", 22)
self.device = None
self.force_no_enable = optional_args.get("force_no_enable", False)
Expand Down Expand Up @@ -118,16 +100,6 @@ def close(self):
"""Close the connection to the device."""
self.device.disconnect()

def cli(self, commands):
output = {}
try:
for cmd in commands:
output[cmd] = self.device.send_command(cmd)

return output
except (socket.error, EOFError) as e:
raise ConnectionClosedException(str(e))

def _send_command(self, command):
"""Wrapper for self.device.send.command().
Expand Down Expand Up @@ -288,7 +260,8 @@ def get_facts(self):
fqdn = "{0}.{1}".format(hostname, domainname)

# interface_list
interfaces = []

interfaces: List[str] = []
show_int_st = show_int_st.strip()
# remove the header information
show_int_st = re.sub(
Expand All @@ -309,7 +282,7 @@ def get_facts(self):
"model": str(model),
"os_version": str(os_version),
"serial_number": str(serial_number),
"uptime": uptime,
"uptime": float(uptime),
"vendor": "Cisco",
}

Expand Down Expand Up @@ -364,7 +337,7 @@ def _get_facts_uptime(self, show_sys):
return uptime_str

def _get_facts_parse_inventory(self, show_inventory):
""" inventory can list more modules/devices """
"""inventory can list more modules/devices"""
# make 1 module 1 line
show_inventory = re.sub(r"\nPID", " PID", show_inventory, re.M)
# delete empty lines
Expand Down Expand Up @@ -471,7 +444,7 @@ def get_interfaces(self):
entry = {
"is_up": is_up,
"is_enabled": is_enabled,
"speed": speed,
"speed": float(speed),
"mtu": mtu,
"last_flapped": -1.0,
"description": description,
Expand Down Expand Up @@ -523,7 +496,7 @@ def get_interfaces_ip(self):
return interfaces

def _get_ip_int_line_to_fields(self, line, fields_end):
""" dynamic fields lenghts """
"""dynamic fields lenghts"""
line_elems = {}
index = 0
f_start = 0
Expand All @@ -534,7 +507,7 @@ def _get_ip_int_line_to_fields(self, line, fields_end):
return line_elems

def _get_ip_int_fields_end(self, dashline):
""" fields length are diferent device to device, detect them on horizontal lin """
"""fields length are diferent device to device, detect them on horizontal line"""

fields_end = [m.start() for m in re.finditer(" ", dashline.strip())]
# fields_position.insert(0,0)
Expand Down Expand Up @@ -588,7 +561,7 @@ def get_lldp_neighbors(self):
return neighbors

def _get_lldp_neighbors_line_to_fields(self, line, fields_end):
""" dynamic fields lenghts """
"""dynamic fields lenghts"""
line_elems = {}
index = 0
f_start = 0
Expand All @@ -599,7 +572,7 @@ def _get_lldp_neighbors_line_to_fields(self, line, fields_end):
return line_elems

def _get_lldp_neighbors_fields_end(self, dashline):
""" fields length are diferent device to device, detect them on horizontal lin """
"""fields length are diferent device to device, detect them on horizontal line"""

fields_end = [m.start() for m in re.finditer(" ", dashline)]
fields_end.append(len(dashline))
Expand Down
28 changes: 16 additions & 12 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
black==20.8b1
coveralls==2.1.2
ddt==1.4.1
flake8-import-order==0.18.1
pytest==5.4.3
pytest-cov==2.10.1
pytest-json==0.4.0
pytest-pythonpath==0.7.3
pylama==7.7.1
mock==4.0.2
tox==3.20.1
demjson
napalm<=4.0.0
netmiko<=4.0.0
black<=24.3.0 # CVE-2024-21503
coveralls
ddt
flake8-import-order
# pytest==6.2.5
pytest
pytest-cov
pytest-json
pytest-pythonpath
pylama
# pyflakes==2.4.0 #prevent problems
pyflakes
mock
tox
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
napalm>=4.0.0
netmiko==4.1.2
netaddr
napalm<=4.0.0
netmiko<=4.0.0
netaddr<=1.2.1
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm-s350",
version="0.3.1",
version="0.4.0",
packages=find_packages(exclude=("test*",)),
author="Jasper Lievisse Adriaanse, Petr Klíma, Daniel Bacher",
author_email="[email protected], [email protected], [email protected]",
Expand All @@ -25,9 +25,12 @@
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
],
Expand Down
1 change: 1 addition & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test fixtures."""

from builtins import super

import pytest
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_getters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for getters."""

from napalm.base.test.getters import BaseTestGetters
import pytest

Expand Down
11 changes: 2 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tox]
#envlist = py3{6,7,8},black,pylama,sphinx
envlist = py3{6,7,8},pylama,black
envlist = py,pylama,black
skip_missing_interpreters = true

[testenv]
Expand All @@ -14,15 +13,9 @@ commands =

[testenv:black]
commands =
black --check --target-version py36 --line-length 100 --color --diff .
black --check --target-version py312 --line-length 100 --color --diff .

[testenv:pylama]
commands =
pylama .

[testenv:sphinx]
commands =
make doctest

whitelist_externals =
make

0 comments on commit 707202b

Please sign in to comment.