Skip to content

Commit

Permalink
Add testing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sbyrnes committed Feb 2, 2025
1 parent b1406ad commit 65f3a3a
Show file tree
Hide file tree
Showing 6 changed files with 787 additions and 3 deletions.
19 changes: 18 additions & 1 deletion internal-lab-setup-assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deploy: gen
done

deploy-lab:
# Use like `make deploy-lab num=1`
# Usage example: `make deploy-lab num=1`
containerlab deploy --reconfigure --topo workshop$(num).clab.yml

destroy:
Expand Down Expand Up @@ -48,6 +48,23 @@ docker-remove-all:
# This allows the removal of all running docker containers, regardless of if clab topology file exists
docker rm $$(docker ps -a -q)

poetry:
command -v ~/.local/bin/poetry; \
if [[ $$? -ne 0 ]]; then \
echo "Poetry is not currently installed. Installing..."; \
curl -sSL https://install.python-poetry.org | python3 -; \
else \
echo "Hooray! Poetry is installed." && ~/.local/bin/poetry --version; \
fi

test: poetry
XRD_LAB_IPS=containerlab inspect --all | grep "cisco" | rev | cut -d ' ' -f8 | rev | sort -V; \
echo "$${XRD_LAB_IPS}"; \
if [ -z "$${XRD_LAB_IPS}" ]; then echo "No labs found." && exit 1; fi; \
cd tester; \
echo "Installing dependencies..." && ~/.local/bin/poetry install --no-root; \
XRD_LAB_IPS="$${XRD_LAB_IPS}" ~/.local/bin/poetry run python lab-tester/lab-tester.py

container:
docker build -t internet2/getting_started -f Containerfile .

Expand Down
5 changes: 3 additions & 2 deletions internal-lab-setup-assets/gen-topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import jinja2

TEMPLATE_FILE = "workshop.clab.yml.j2"
NUM_LABS = 18
LAB_ID_START = 1
LAB_ID_END = 18 # inclusive

templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template(TEMPLATE_FILE)

for i in range(1, NUM_LABS + 1):
for i in range(LAB_ID_START, LAB_ID_END + 1):
with open(f"workshop{i}.clab.yml", "w") as f:
outputText = template.render(id=i)
f.write(outputText)
Empty file.
44 changes: 44 additions & 0 deletions internal-lab-setup-assets/tester/lab-tester/lab-tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
from netmiko import Netmiko

TEST_INTERFACE = "mgmtEth0/RP0/CPU0/0" # Guaranteed to exist in our XRd
XRD_LAB_IPS = os.environ.get("XRD_LAB_IPS") # Fed in by Makefile

# Lab access creds
USERNAME = "clab"
PASSWORD = "clab@123"
DEVICE_TYPE = "cisco_xr"

# Re-used constants for testing
CMD_SHOW_DESCRIPTION = f"show run int {TEST_INTERFACE} | i description"
TEST_DESCRIPTION = "Management Interface"


def test_show_version(connection):
output = connection.send_command("show version")
assert "Cisco IOS XR Software" in output


def test_configure_description(connection):
# Note: If any description existed before, it will be blanked out
connection.send_config_set(TEST_INTERFACE, f"description {TEST_DESCRIPTION}")
new_desc = connection.send_command(CMD_SHOW_DESCRIPTION)
assert new_desc == f"description {TEST_DESCRIPTION}"
connection.send_config_set(TEST_INTERFACE, "no description") # revert


lab_ips = XRD_LAB_IPS.split(" ")
print(lab_ips)

for ip in lab_ips:
# Create a variable that represents an SSH connection to our router.
connection = Netmiko(
username=USERNAME, password=PASSWORD, device_type=DEVICE_TYPE, ip=ip
)
print(f"Testing 'show version' for lab {ip}...")
test_show_version(connection)

print(f"Testing basic description configuration change for lab {ip}...")
test_configure_description(connection)

print("Complete!")
Loading

0 comments on commit 65f3a3a

Please sign in to comment.