Skip to content

Commit

Permalink
Merge branch 'main' into ansible-firmware-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebates123 authored Jun 26, 2023
2 parents d1935b2 + a5b7263 commit 6fade81
Show file tree
Hide file tree
Showing 112 changed files with 4,866 additions and 474 deletions.
7 changes: 7 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Changelog
## [UNRELEASED]

- Update BGP to use 32 max paths
- Add CSM 1.5 configs
- Increase Dell netmiko timeout when using nornir
- added very basic integration tests via shellspec for local and github actions
- Fix storage node lag configuration in Aruba templates to prevent loop

## [1.7.3]

Expand Down
52 changes: 47 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
#
name: Python (unit tests)

on: [push]
on:
push:
workflow_dispatch:

jobs:
nox:
unit_tests:
name: Tests and Coverage
strategy:
matrix:
Expand All @@ -44,6 +46,46 @@ jobs:
env:
GIT_REPO_NAME: "${GITHUB_REPOSITORY#*/}"
run: |
pip install .[ci]
nox -e tests
nox -e cover
pip install setuptools_scm[toml] '.[test]'
make unit
integration_tests:
strategy:
matrix:
version: ['3.10', '3.9']
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }}

- if: ${{ matrix.os == 'ubuntu-latest' }}
uses: cachix/install-nix-action@v21
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
- if: ${{ matrix.os == 'ubuntu-latest' }}
name: Run shellspec
run: |
pip install setuptools_scm[toml] '.[test]'
nix-shell -p shellspec --run 'make integration'
- if: ${{ matrix.os == 'macos-latest' }}
name: Install shellspec (macOS)
run: |
brew tap shellspec/shellspec
brew update
brew install shellspec ksh93 bash
- if: ${{ matrix.os == 'macos-latest' }}
name: Run integration tests via shellspec
run: |
pip install setuptools_scm[toml] '.[test]'
make integration
12 changes: 12 additions & 0 deletions .shellspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--require spec_helper

## Default kcov (coverage) options
# --kcov-options "--include-path=. --path-strip-level=1"
# --kcov-options "--include-pattern=.sh"
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/"

## Example: Include script "myprog" with no extension
# --kcov-options "--include-pattern=.sh,myprog"

## Example: Only specified files/directories
# --kcov-options "--include-pattern=myprog,/lib/"
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ help:
clean:
rm -rf build dist

#############################################################################
# Testing targets
#############################################################################

# docs are deployed with mike, but we can build them locally with mkdocs
# mike can also serve local docs, but requires a bit more setup
# with deploy and set-default and using a specfic branch so as not to overwrite gh-pages
unit:
pip install .[ci]
nox -e tests
nox -e cover

integration:
shellspec --format tap --no-warning-as-failure --jobs 3

#############################################################################
# Doc targets
#############################################################################
Expand Down
45 changes: 37 additions & 8 deletions canu/canu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ csm:
"1.3":
aruba:
"6300":
- FL.10.09.0010
- FL.10.11.1010
"8320":
- GL.10.09.0010
- GL.10.11.1010
"8325":
- GL.10.09.0010
- GL.10.11.1010
"8360":
- LL.10.09.0010
- LL.10.11.1010
X86-64:
- Virtual.10.09.0010
dell:
Expand All @@ -108,13 +108,41 @@ csm:
"1.4":
aruba:
"6300":
- FL.10.09.0010
- FL.10.11.1010
"8320":
- GL.10.09.0010
- GL.10.11.1010
"8325":
- GL.10.09.0010
- GL.10.11.1010
"8360":
- LL.10.09.0010
- LL.10.11.1010
X86-64:
- Virtual.10.09.0010
dell:
"S3048-ON":
- "10.5.1.4"
"S4148F-ON":
- "10.5.1.4"
"S4148T-ON":
- "10.5.1.4"
"S4048-VM":
- "10.5.0.0"
"S4048T-ON":
- "10.5.1.4"
mellanox:
MSN2100:
- 3.9.3210
MSN2700:
- 3.9.3210
"1.5":
aruba:
"6300":
- FL.10.11.1010
"8320":
- GL.10.11.1010
"8325":
- GL.10.11.1010
"8360":
- LL.10.11.1010
X86-64:
- Virtual.10.09.0010
dell:
Expand All @@ -138,3 +166,4 @@ csm_versions:
- "1.2"
- "1.3"
- "1.4"
- "1.5"
6 changes: 3 additions & 3 deletions canu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ def init(ctx, sls_file, auth_token, sls_address, network, out):
)


def parse_sls_json_for_ips(csm, network="NMN"):
def parse_sls_json_for_ips(csm, network="HMN"):
"""Parse SLS JSON and return IPv4 addresses.
Defaults to the "NMN" network, but another network can be passed in. Cache the switch IP and hostname.
Defaults to the "HMN" network, but another network can be passed in. Cache the switch IP and hostname.
Args:
csm: The SLS JSON to be parsed.
network: Switch network e.g. (CAN, MTL, NMN).
network: Switch network e.g. (CAN, MTL, HMN).
Returns:
switch_addresses: A list of switch IPs.
Expand Down
Empty file modified canu/test/__init__.py
100755 → 100644
Empty file.
117 changes: 117 additions & 0 deletions canu/test/aruba/bgp_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# MIT License
#
# (C) Copyright 2022-2023 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""parse aruba bgp config and test for missing neighbors."""
from ttp import ttp


def bgp_config(result, vlan_ips):
"""Verify NCN-W IPs in SLS are BGP neighbors on the switch.
Args:
result: show run bgp
vlan_ips: list of NCN and Switch IPs
Returns:
Pass or fail
"""
# TTP template to convert switch show command to structured data.
aruba_aoscx_show_run_bgp = """
<group name="bgp_cfg.vrfs.default">
router bgp {{ asn }}
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor | _start_ }} remote-as {{ remote_asn }}
neighbor {{ neighbor }} {{ passive | macro("is_passive") }}
</group>
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor }} {{ activate | exclude("passive") | macro("is_active") }}
</group>
<group name="peers.{{ neighbor }}**.route-map">
neighbor {{ neighbor }} route-map {{ route-map-in }} in
</group>
<group name="peers.{{ neighbor }}**.route-map**">
neighbor {{ neighbor }} route-map {{ route-map-out }} out
</group>
</group>
<group name="bgp_cfg.vrfs.{{ vrf }}">
vrf {{ vrf }}
bgp router-id {{ bgp_rid }}
maximum-paths {{ max_paths }}
timers bgp {{ keepalive_timer }} {{ hold_timer }}
distance bgp {{ ebgp_distance }} {{ ibgp_distance }}
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor | _start_ }} remote-as {{ remote_asn }}
neighbor {{ neighbor }} {{ passive | macro("is_passive") }}
</group>
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor }} {{ activate | macro("is_active") }}
</group>
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor }} route-map {{ route-map-in }} in
</group>
<group name="peers.{{ neighbor }}**">
neighbor {{ neighbor }} route-map {{ route-map-out }} out
</group>
</group>
"""
# Parse the aruba "show run bgp" command
result_parsed = ttp(str(result), aruba_aoscx_show_run_bgp)
result_parsed.parse()
output = result_parsed.result()

exception = None
result = "PASS"
success = True

# Get BGP peers from switch config
bgp_peers = {}
bgp_peers.update(output[0][0]["bgp_cfg"]["vrfs"]["Customer"]["peers"])
bgp_peers.update(output[0][0]["bgp_cfg"]["vrfs"]["default"]["peers"])

# Get the worker nodes CMN and NMN IPs
# If those are not in the BGP config on the switch add them to the list.

missing_neighbors = [
data["name"]
for data in (
entry
for net, vlan_data in vlan_ips.items()
for entry in vlan_data.get("ips", [])
if "ncn-w" in entry["name"]
and any(s in entry["name"] for s in ["cmn", "nmn"])
and entry["ipv4_address"] not in bgp_peers
)
]

# Add missing neighbors to test exception message.
if missing_neighbors:
missing_neighbors_string = ", ".join(missing_neighbors)
exception = (
f"Missing BGP Neighbors: {missing_neighbors_string}\n"
"This is usually caused by changing networks used by CSM or adding worker nodes"
)
result = "FAIL"

return {
"exception": exception,
"result": result,
"success": success,
}
Loading

0 comments on commit 6fade81

Please sign in to comment.