From 22d74e52488aacb5643bd2c9e49d84a575bfe0ac Mon Sep 17 00:00:00 2001 From: duhow Date: Wed, 24 May 2023 17:23:17 +0200 Subject: [PATCH 01/23] Optimize Dockerfile --- Dockerfile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 51e39d030..d771c3984 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,16 @@ -FROM python:3.6-slim-stretch +# syntax=docker/dockerfile:1.4 +FROM scratch AS installer COPY ./ /var/cache/napalm/ -RUN apt-get update \ - && apt-get install -y python-dev python-cffi libxslt1-dev libssl-dev libffi-dev \ - && apt-get autoremove \ - && rm -rf /var/lib/apt/lists/* \ - && pip --no-cache-dir install -U cffi cryptography /var/cache/napalm/ \ - && rm -rf /var/cache/napalm/ +FROM python:3.9-slim + +RUN --mount=type=bind,from=installer,source=/var/cache/napalm,target=/var/cache/napalm,rw \ + apt-get update && \ + apt-get install -y \ + python3.9-dev libxslt1-dev libssl-dev libffi-dev && \ + apt-get autoremove && \ + rm -rf /var/lib/apt/lists/* && \ + pip --no-cache-dir install -U cffi cryptography /var/cache/napalm/ + + ENTRYPOINT ["napalm"] From 0cb1cfe339dab6633df6897777bcb876d4225e74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:55:57 +0000 Subject: [PATCH 02/23] Bump mock from 5.0.2 to 5.1.0 Bumps [mock](https://github.com/testing-cabal/mock) from 5.0.2 to 5.1.0. - [Changelog](https://github.com/testing-cabal/mock/blob/master/CHANGELOG.rst) - [Commits](https://github.com/testing-cabal/mock/compare/5.0.2...5.1.0) --- updated-dependencies: - dependency-name: mock dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ec60bb8cf..fc2308db7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ pytest-cov==4.1.0 pytest-json-report==1.5.0 pyflakes==3.0.1 pylama==8.4.1 -mock==5.0.2 +mock==5.1.0 mypy==0.982 types-PyYAML==6.0.12.10 types-requests==2.31.0.20240311 From dab9cdd81a237a89cb877d513c6d79271e861028 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:56:04 +0000 Subject: [PATCH 03/23] Bump ttp from 0.9.4 to 0.9.5 Bumps [ttp](https://github.com/dmulyalin/ttp) from 0.9.4 to 0.9.5. - [Release notes](https://github.com/dmulyalin/ttp/releases) - [Commits](https://github.com/dmulyalin/ttp/compare/0.9.4...0.9.5) --- updated-dependencies: - dependency-name: ttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ec60bb8cf..0507051d6 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -13,5 +13,5 @@ types-PyYAML==6.0.12.10 types-requests==2.31.0.20240311 types-six==1.16.21.8 types-setuptools==67.8.0.0 -ttp==0.9.4 +ttp==0.9.5 ttp_templates==0.3.5 From 875a1c95522e4410829bc3052f3f2e6cc53ad10b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:56:10 +0000 Subject: [PATCH 04/23] Bump types-six from 1.16.21.8 to 1.16.21.20240311 Bumps [types-six](https://github.com/python/typeshed) from 1.16.21.8 to 1.16.21.20240311. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-six dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ec60bb8cf..4a55f331d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -11,7 +11,7 @@ mock==5.0.2 mypy==0.982 types-PyYAML==6.0.12.10 types-requests==2.31.0.20240311 -types-six==1.16.21.8 +types-six==1.16.21.20240311 types-setuptools==67.8.0.0 ttp==0.9.4 ttp_templates==0.3.5 From 3beb5c689ca3e6547e0b02c7452a230be05aa8bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:28:52 +0000 Subject: [PATCH 05/23] Bump types-setuptools from 67.8.0.0 to 69.2.0.20240317 Bumps [types-setuptools](https://github.com/python/typeshed) from 67.8.0.0 to 69.2.0.20240317. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-setuptools dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 98ef25705..e5f25e53f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,6 +12,6 @@ mypy==0.982 types-PyYAML==6.0.12.10 types-requests==2.31.0.20240311 types-six==1.16.21.20240311 -types-setuptools==67.8.0.0 +types-setuptools==69.2.0.20240317 ttp==0.9.5 ttp_templates==0.3.5 From f6774e035a898c926c4cd2d74ccf2e65b2bb70c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 10:57:08 +0000 Subject: [PATCH 06/23] Bump pyflakes from 3.0.1 to 3.2.0 Bumps [pyflakes](https://github.com/PyCQA/pyflakes) from 3.0.1 to 3.2.0. - [Changelog](https://github.com/PyCQA/pyflakes/blob/main/NEWS.rst) - [Commits](https://github.com/PyCQA/pyflakes/compare/3.0.1...3.2.0) --- updated-dependencies: - dependency-name: pyflakes dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index e5f25e53f..63815be9a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,7 +5,7 @@ flake8-import-order==0.18.2 pytest==7.3.1 pytest-cov==4.1.0 pytest-json-report==1.5.0 -pyflakes==3.0.1 +pyflakes==3.2.0 pylama==8.4.1 mock==5.1.0 mypy==0.982 From df0c507bc086c289fdcb48d8e434951afa8bf680 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:25:37 +0000 Subject: [PATCH 07/23] Bump ttp-templates from 0.3.5 to 0.3.6 Bumps [ttp-templates](https://github.com/dmulyalin/ttp_templates) from 0.3.5 to 0.3.6. - [Release notes](https://github.com/dmulyalin/ttp_templates/releases) - [Commits](https://github.com/dmulyalin/ttp_templates/compare/0.3.5...0.3.6) --- updated-dependencies: - dependency-name: ttp-templates dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 63815be9a..90d0699b8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,4 +14,4 @@ types-requests==2.31.0.20240311 types-six==1.16.21.20240311 types-setuptools==69.2.0.20240317 ttp==0.9.5 -ttp_templates==0.3.5 +ttp_templates==0.3.6 From 2ad5bafdc4b298c26f7d4e486229051a0338048d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:25:43 +0000 Subject: [PATCH 08/23] Bump ddt from 1.6.0 to 1.7.2 Bumps [ddt](https://github.com/datadriventests/ddt) from 1.6.0 to 1.7.2. - [Release notes](https://github.com/datadriventests/ddt/releases) - [Commits](https://github.com/datadriventests/ddt/compare/1.6.0...1.7.2) --- updated-dependencies: - dependency-name: ddt dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 63815be9a..4909b326f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ black==24.3.0 coveralls==3.3.1 -ddt==1.6.0 +ddt==1.7.2 flake8-import-order==0.18.2 pytest==7.3.1 pytest-cov==4.1.0 From 29f86f99b1f36ea5d4dd60622a7102c0ae42e345 Mon Sep 17 00:00:00 2001 From: talves Date: Tue, 23 May 2023 13:23:11 +0100 Subject: [PATCH 09/23] fix: restrict group names inside the bgp config --- napalm/junos/junos.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py index 02ae5eec9..6c0fc6e83 100644 --- a/napalm/junos/junos.py +++ b/napalm/junos/junos.py @@ -1246,6 +1246,8 @@ def build_prefix_limit(**args): } _GROUP_FIELDS_DATATYPE_MAP_.update(_COMMON_FIELDS_DATATYPE_) + _UNWANTED_GROUP_FIELDS = ["multihop", "cluster"] + _DATATYPE_DEFAULT_ = {str: "", int: 0, bool: False, list: []} bgp_config = {} @@ -1302,6 +1304,8 @@ def build_prefix_limit(**args): is_nhs, boolean = is_nhs_list[0] nhs_policies[policy_name] = boolean if boolean is not None else False + unwanted_group_fields = dict() + for bgp_group in bgp_items: bgp_group_name = bgp_group[0] bgp_group_details = bgp_group[1] @@ -1314,6 +1318,9 @@ def build_prefix_limit(**args): # Always overwrite with the system local_as (this will either be # valid or will be zero i.e. the same as the default value). bgp_config[bgp_group_name]["local_as"] = system_bgp_asn + unwanted_group_fields[bgp_group_name] = dict( + {key: False for key in _UNWANTED_GROUP_FIELDS} + ) for key, value in bgp_group_details: if "_prefix_limit" in key or value is None: @@ -1335,6 +1342,10 @@ def build_prefix_limit(**args): if key == "neighbors": bgp_group_peers = value continue + + if key in _UNWANTED_GROUP_FIELDS: + unwanted_group_fields[bgp_group_name][key] = True + continue if datatype: bgp_config[bgp_group_name].update( {key: napalm.base.helpers.convert(datatype, value, default)} @@ -1354,9 +1365,7 @@ def build_prefix_limit(**args): bgp_config[bgp_group_name]["prefix_limit"] = build_prefix_limit( **prefix_limit_fields ) - if "multihop" in bgp_config[bgp_group_name].keys(): - # Delete 'multihop' key from the output - del bgp_config[bgp_group_name]["multihop"] + if unwanted_group_fields[bgp_group_name]["multihop"]: if bgp_config[bgp_group_name]["multihop_ttl"] == 0: # Set ttl to default value 64 bgp_config[bgp_group_name]["multihop_ttl"] = 64 @@ -1411,7 +1420,7 @@ def build_prefix_limit(**args): # we do not want cluster in the output del bgp_peer_details["cluster"] - if "cluster" in bgp_config[bgp_group_name].keys(): + if unwanted_group_fields[bgp_group_name]["cluster"]: bgp_peer_details["route_reflector_client"] = True prefix_limit_fields = {} for key, value in bgp_group_details: @@ -1434,10 +1443,6 @@ def build_prefix_limit(**args): if neighbor and bgp_peer_address == neighbor_ip: break # found the desired neighbor - if "cluster" in bgp_config[bgp_group_name].keys(): - # we do not want cluster in the output - del bgp_config[bgp_group_name]["cluster"] - return bgp_config def get_bgp_neighbors_detail(self, neighbor_address=""): From 1ea0fc416a8cb4686984969150b559acd1d772e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 09:59:33 +0000 Subject: [PATCH 10/23] Bump types-pyyaml from 6.0.12.10 to 6.0.12.20240311 Bumps [types-pyyaml](https://github.com/python/typeshed) from 6.0.12.10 to 6.0.12.20240311. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-pyyaml dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 0f4824d52..702014586 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,7 +9,7 @@ pyflakes==3.2.0 pylama==8.4.1 mock==5.1.0 mypy==0.982 -types-PyYAML==6.0.12.10 +types-PyYAML==6.0.12.20240311 types-requests==2.31.0.20240311 types-six==1.16.21.20240311 types-setuptools==69.2.0.20240317 From b850498a6db2250dd1fa97a524ce249259c3bae0 Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Mon, 25 Mar 2024 12:12:53 +0000 Subject: [PATCH 11/23] Bump version to release 5.0.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9dcd81059..a7e9fa615 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( name="napalm", - version="4.1.0", + version="5.0.0", packages=find_packages(exclude=("test*",)), test_suite="test_base", author="David Barroso, Kirk Byers, Mircea Ulinic", From 6c18bba172314555611e6eeb3c6f1ddc6eb302ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Gir=C3=B3n?= Date: Mon, 25 Mar 2024 15:10:42 +0100 Subject: [PATCH 12/23] bump to python 3.12 Co-authored-by: Mircea Ulinic --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d771c3984..2b4fc0593 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,12 @@ FROM scratch AS installer COPY ./ /var/cache/napalm/ -FROM python:3.9-slim +FROM python:3.12-slim-bookworm RUN --mount=type=bind,from=installer,source=/var/cache/napalm,target=/var/cache/napalm,rw \ apt-get update && \ apt-get install -y \ - python3.9-dev libxslt1-dev libssl-dev libffi-dev && \ + python3-dev libxslt1-dev libssl-dev libffi-dev && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* && \ pip --no-cache-dir install -U cffi cryptography /var/cache/napalm/ From e765bac1e2feb7b1b984089a118f48bf0218adee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:19:18 -0700 Subject: [PATCH 13/23] Bump pytest-cov from 4.1.0 to 5.0.0 (#2051) Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 4.1.0 to 5.0.0. - [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-cov/compare/v4.1.0...v5.0.0) --- updated-dependencies: - dependency-name: pytest-cov dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 702014586..bebae9c82 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ coveralls==3.3.1 ddt==1.7.2 flake8-import-order==0.18.2 pytest==7.3.1 -pytest-cov==4.1.0 +pytest-cov==5.0.0 pytest-json-report==1.5.0 pyflakes==3.2.0 pylama==8.4.1 From f0779ec7d1e52fbcc43cfb8a9a2ec71f190a3fa5 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 25 Mar 2024 17:26:00 -0700 Subject: [PATCH 14/23] Update docs depedencies, mypy, and gh-actions (checkout and setup-python) (#2052) * Update to newer version of mypy * Updating GH actions checkout and setup-python * Upgrading markupsafe * Upgrade Jinja2, MarkupSafe, Ansible * Upgrade Sphinx to 7.2.6 --- .github/workflows/commit.yaml | 10 +++++----- docs/requirements.txt | 11 +++++------ napalm/base/base.py | 2 +- requirements-dev.txt | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index 8494d6c4b..7449f1a22 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -14,10 +14,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -50,14 +50,14 @@ jobs: strategy: matrix: - python-version: [3.8] + python-version: [3.11] steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/docs/requirements.txt b/docs/requirements.txt index ab61ce545..c122fb3ec 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,9 +1,8 @@ urllib3==2.2.1 # https://github.com/readthedocs/readthedocs.org/issues/10290 -sphinx==1.8.6 -sphinx-rtd-theme==1.2.0 -sphinxcontrib-napoleon==0.7 +sphinx==7.2.6 +sphinx-rtd-theme==2.0.0 invoke==2.2.0 -jinja2==2.11.3 -MarkupSafe==2.0.1 +jinja2==3.1.3 +MarkupSafe==2.1.5 pytest==7.2.2 -ansible==4.10.0 +ansible==6.7.0 diff --git a/napalm/base/base.py b/napalm/base/base.py index b1b56040d..1050924e1 100644 --- a/napalm/base/base.py +++ b/napalm/base/base.py @@ -44,7 +44,7 @@ def __init__( username: str, password: str, timeout: int = 60, - optional_args: Dict = None, + optional_args: Optional[Dict] = None, ) -> None: """ This is the base class you have to inherit from when writing your own Network Driver to diff --git a/requirements-dev.txt b/requirements-dev.txt index bebae9c82..6ed09db51 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,7 +8,7 @@ pytest-json-report==1.5.0 pyflakes==3.2.0 pylama==8.4.1 mock==5.1.0 -mypy==0.982 +mypy==1.9.0 types-PyYAML==6.0.12.20240311 types-requests==2.31.0.20240311 types-six==1.16.21.20240311 From b0f44bca74756ac3eb0cbc9b667f857caf9e6d3d Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 25 Mar 2024 17:49:44 -0700 Subject: [PATCH 15/23] Roll Ansible to newer version for docs-testing (#2053) --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index c122fb3ec..443e3dd36 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,4 +5,4 @@ invoke==2.2.0 jinja2==3.1.3 MarkupSafe==2.1.5 pytest==7.2.2 -ansible==6.7.0 +ansible==9.3.0 From f0a69b467651e9c5787f729050fa558a4a74e32f Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 25 Mar 2024 18:00:35 -0700 Subject: [PATCH 16/23] Upgrade pytest to version 7.3.1 for docs-test (#2054) --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 443e3dd36..93463a5b5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,5 +4,5 @@ sphinx-rtd-theme==2.0.0 invoke==2.2.0 jinja2==3.1.3 MarkupSafe==2.1.5 -pytest==7.2.2 +pytest==7.3.1 ansible==9.3.0 From 800e8d70bba48320e970e29ee3c2219d5b7faf01 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank <94914780+decoupca@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:55:19 -0500 Subject: [PATCH 17/23] Closes #2005: Change rollback behavior (#2006) --- napalm/nxos/nxos.py | 33 +++++++++++++++++++++++++++++---- napalm/nxos_ssh/nxos_ssh.py | 33 ++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/napalm/nxos/nxos.py b/napalm/nxos/nxos.py index b975029ef..fbbffc44d 100644 --- a/napalm/nxos/nxos.py +++ b/napalm/nxos/nxos.py @@ -191,6 +191,29 @@ def _send_command( ) -> Dict[str, Union[str, Dict[str, Any]]]: raise NotImplementedError + def _check_file_exists(self, cfg_file: str) -> bool: + """ + Check that the file exists on remote device using full path. + + cfg_file can be a full path, e.g.: bootflash:rollback_config.txt + or just a filename, e.g.: rollback_config.txt + + For example + # dir rollback_config.txt + 71803 Sep 06 14:13:33 2023 rollback_config.txt + + Usage for bootflash://sup-local + 6211682304 bytes used + 110314684416 bytes free + 116526366720 bytes total + """ + cmd = f"dir {cfg_file}" + output = self._send_command(command=cmd, raw_text=True) + if "No such file or directory" in output: + return False + else: + return True + def _commit_merge(self) -> None: try: output = self._send_config(self.merge_candidate) @@ -918,10 +941,12 @@ def _load_cfg_from_checkpoint(self) -> None: def rollback(self) -> None: assert isinstance(self.device, NXOSDevice) - if self.changed: - self.device.rollback(self.rollback_cfg) - self._copy_run_start() - self.changed = False + if not self._check_file_exists(cfg_file=self.rollback_cfg): + msg = f"Rollback file '{self.rollback_cfg}' does not exist on device." + raise ReplaceConfigException(msg) + self.device.rollback(self.rollback_cfg) + self._copy_run_start() + self.changed = False def get_facts(self) -> models.FactsDict: facts: models.FactsDict = {} # type: ignore diff --git a/napalm/nxos_ssh/nxos_ssh.py b/napalm/nxos_ssh/nxos_ssh.py index 04896c9cc..3bfa46ec9 100644 --- a/napalm/nxos_ssh/nxos_ssh.py +++ b/napalm/nxos_ssh/nxos_ssh.py @@ -553,21 +553,24 @@ def _load_cfg_from_checkpoint(self): raise ReplaceConfigException(msg) def rollback(self): - if self.changed: - commands = [ - "terminal dont-ask", - "rollback running-config file {}".format(self.rollback_cfg), - "no terminal dont-ask", - ] - result = self._send_command_list( - commands, expect_string=r"[#>]", read_timeout=90 - ) - if "completed" not in result.lower(): - raise ReplaceConfigException(result) - # If hostname changes ensure Netmiko state is updated properly - self._netmiko_device.set_base_prompt() - self._copy_run_start() - self.changed = False + if not self._check_file_exists(self.rollback_cfg): + msg = f"Rollback file '{self.rollback_cfg}' does not exist on device." + raise ReplaceConfigException(msg) + + commands = [ + "terminal dont-ask", + "rollback running-config file {}".format(self.rollback_cfg), + "no terminal dont-ask", + ] + result = self._send_command_list( + commands, expect_string=r"[#>]", read_timeout=90 + ) + if "completed" not in result.lower(): + raise ReplaceConfigException(result) + # If hostname changes ensure Netmiko state is updated properly + self._netmiko_device.set_base_prompt() + self._copy_run_start() + self.changed = False def _apply_key_map(self, key_map, table): new_dict = {} From 7804a3a0a14b894dff7c351c6bbf10b169cc3d4d Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 25 Mar 2024 18:58:47 -0700 Subject: [PATCH 18/23] Remove changed attribute from nxos driver --- napalm/nxos/nxos.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/napalm/nxos/nxos.py b/napalm/nxos/nxos.py index fbbffc44d..5559c9646 100644 --- a/napalm/nxos/nxos.py +++ b/napalm/nxos/nxos.py @@ -120,7 +120,6 @@ def __init__( self.timeout = timeout self.replace = True self.loaded = False - self.changed = False self.merge_candidate = "" self.candidate_cfg = "candidate_config.txt" self.rollback_cfg = "rollback_config.txt" @@ -220,13 +219,11 @@ def _commit_merge(self) -> None: if output and "Invalid command" in output: raise MergeConfigException("Error while applying config!") except Exception as e: - self.changed = True self.rollback() err_header = "Configuration merge failed; automatic rollback attempted" merge_error = "{0}:\n{1}".format(err_header, repr(str(e))) raise MergeConfigException(merge_error) - self.changed = True # clear the merge buffer self.merge_candidate = "" @@ -920,8 +917,6 @@ def _load_cfg_from_checkpoint(self) -> None: except ConnectionError: # requests will raise an error with verbose warning output (don't fail on this). return - finally: - self.changed = True # For nx-api a list is returned so extract the result associated with the # 'rollback' command. @@ -946,7 +941,6 @@ def rollback(self) -> None: raise ReplaceConfigException(msg) self.device.rollback(self.rollback_cfg) self._copy_run_start() - self.changed = False def get_facts(self) -> models.FactsDict: facts: models.FactsDict = {} # type: ignore From 41b40814edbab6095569491cbaddeae0573454d5 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Mon, 25 Mar 2024 19:00:56 -0700 Subject: [PATCH 19/23] Adding nxos_ssh driver, changed attribute removal --- napalm/nxos_ssh/nxos_ssh.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/napalm/nxos_ssh/nxos_ssh.py b/napalm/nxos_ssh/nxos_ssh.py index 3bfa46ec9..fcec00c28 100644 --- a/napalm/nxos_ssh/nxos_ssh.py +++ b/napalm/nxos_ssh/nxos_ssh.py @@ -542,12 +542,9 @@ def _load_cfg_from_checkpoint(self): "no terminal dont-ask", ] - try: - rollback_result = self._send_command_list( - commands, expect_string=r"[#>]", read_timeout=90 - ) - finally: - self.changed = True + rollback_result = self._send_command_list( + commands, expect_string=r"[#>]", read_timeout=90 + ) msg = rollback_result if "Rollback failed." in msg: raise ReplaceConfigException(msg) @@ -570,7 +567,6 @@ def rollback(self): # If hostname changes ensure Netmiko state is updated properly self._netmiko_device.set_base_prompt() self._copy_run_start() - self.changed = False def _apply_key_map(self, key_map, table): new_dict = {} From a45a71e52cd12fdbc561af233b1525301fe81c22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:44:58 +0000 Subject: [PATCH 20/23] Bump ansible from 9.3.0 to 9.4.0 Bumps [ansible](https://github.com/ansible-community/ansible-build-data) from 9.3.0 to 9.4.0. - [Changelog](https://github.com/ansible-community/ansible-build-data/blob/main/docs/release-process.md) - [Commits](https://github.com/ansible-community/ansible-build-data/compare/9.3.0...9.4.0) --- updated-dependencies: - dependency-name: ansible dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 93463a5b5..e0ea7ee6c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,4 +5,4 @@ invoke==2.2.0 jinja2==3.1.3 MarkupSafe==2.1.5 pytest==7.3.1 -ansible==9.3.0 +ansible==9.4.0 From f253e7063d9e8831c9dba3b7a2b203f6a83a7fba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:54:54 +0000 Subject: [PATCH 21/23] Bump types-requests from 2.31.0.20240311 to 2.31.0.20240402 Bumps [types-requests](https://github.com/python/typeshed) from 2.31.0.20240311 to 2.31.0.20240402. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-requests dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6ed09db51..ca68d647c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,7 +10,7 @@ pylama==8.4.1 mock==5.1.0 mypy==1.9.0 types-PyYAML==6.0.12.20240311 -types-requests==2.31.0.20240311 +types-requests==2.31.0.20240402 types-six==1.16.21.20240311 types-setuptools==69.2.0.20240317 ttp==0.9.5 From 652a58784465dcd96ecd70e04da3d50e1f998881 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:21:57 +0000 Subject: [PATCH 22/23] Bump types-requests from 2.31.0.20240402 to 2.31.0.20240403 Bumps [types-requests](https://github.com/python/typeshed) from 2.31.0.20240402 to 2.31.0.20240403. - [Commits](https://github.com/python/typeshed/commits) --- updated-dependencies: - dependency-name: types-requests dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ca68d647c..e5dc22183 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,7 +10,7 @@ pylama==8.4.1 mock==5.1.0 mypy==1.9.0 types-PyYAML==6.0.12.20240311 -types-requests==2.31.0.20240402 +types-requests==2.31.0.20240403 types-six==1.16.21.20240311 types-setuptools==69.2.0.20240317 ttp==0.9.5 From 719b72c2ca7123c3b03dcb8f71cc954ad66bf45f Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Thu, 4 Apr 2024 10:49:06 +0200 Subject: [PATCH 23/23] Add .dockerignore file for Docker build This significantly reduces the build context from: ``` Sending build context to Docker daemon 916MB ``` to: ``` Sending build context to Docker daemon 3.713MB ``` --- .dockerignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..0675dd786 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +.git* +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +.tox +.venv +.coverage +.coverage.* +.cache +.mypy_cache +.pytest_cache +docs +test +static +vagrant +LICENSE +report.json