topogen 0.2.2__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {topogen-0.2.2 → topogen-0.3.0}/.github/workflows/python-package.yml +21 -18
- topogen-0.3.0/.github/workflows/release.yml +110 -0
- {topogen-0.2.2 → topogen-0.3.0}/.gitignore +4 -0
- {topogen-0.2.2 → topogen-0.3.0}/CHANGES.md +9 -0
- topogen-0.3.0/Makefile +40 -0
- topogen-0.3.0/PKG-INFO +110 -0
- topogen-0.3.0/README.md +78 -0
- topogen-0.3.0/TESTING.md +201 -0
- {topogen-0.2.2 → topogen-0.3.0}/pyproject.toml +5 -11
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/__init__.py +10 -2
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/colorlog.py +2 -1
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/config.py +4 -4
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/dnshost.py +2 -1
- topogen-0.3.0/src/topogen/exporter.py +207 -0
- topogen-0.3.0/src/topogen/frr.py +25 -0
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/main.py +17 -36
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/models.py +2 -1
- topogen-0.3.0/src/topogen/node_definitions.py +40 -0
- topogen-0.3.0/src/topogen/offline.py +405 -0
- topogen-0.3.0/src/topogen/planner.py +83 -0
- topogen-0.3.0/src/topogen/render.py +14 -0
- topogen-0.2.2/src/topogen/templates/lxc.jinja2 → topogen-0.3.0/src/topogen/templates/frr.jinja2 +0 -1
- topogen-0.3.0/tests/data/topogen_lab_export.yaml +53 -0
- topogen-0.3.0/tests/data/topogen_reference.yaml +357 -0
- topogen-0.3.0/tests/test_colorlog.py +35 -0
- topogen-0.3.0/tests/test_config.py +34 -0
- topogen-0.3.0/tests/test_dnshost.py +52 -0
- topogen-0.3.0/tests/test_exporter.py +221 -0
- topogen-0.3.0/tests/test_fixture_export.py +22 -0
- topogen-0.3.0/tests/test_frr.py +18 -0
- topogen-0.3.0/tests/test_main.py +107 -0
- topogen-0.3.0/tests/test_models.py +38 -0
- topogen-0.3.0/tests/test_node_definitions.py +29 -0
- topogen-0.3.0/tests/test_offline.py +190 -0
- topogen-0.3.0/tests/test_reference_compare.py +23 -0
- topogen-0.3.0/tests/test_render.py +31 -0
- topogen-0.3.0/uv.lock +759 -0
- topogen-0.2.2/.github/workflows/release.yml +0 -117
- topogen-0.2.2/.images/demo.gif +0 -0
- topogen-0.2.2/PKG-INFO +0 -258
- topogen-0.2.2/README.md +0 -224
- topogen-0.2.2/src/topogen/lxcfrr.py +0 -33
- topogen-0.2.2/src/topogen/render.py +0 -543
- topogen-0.2.2/uv.lock +0 -577
- {topogen-0.2.2 → topogen-0.3.0}/.python-version +0 -0
- {topogen-0.2.2 → topogen-0.3.0}/LICENSE +0 -0
- {topogen-0.2.2 → topogen-0.3.0}/ca.pem +0 -0
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/templates/__init__.py +0 -0
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/templates/iol-xe.jinja2 +0 -0
- {topogen-0.2.2 → topogen-0.3.0}/src/topogen/templates/iosv.jinja2 +0 -0
|
@@ -13,6 +13,9 @@ name: Python package
|
|
|
13
13
|
|
|
14
14
|
on: [push]
|
|
15
15
|
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
16
19
|
jobs:
|
|
17
20
|
build:
|
|
18
21
|
name: "Build package"
|
|
@@ -21,21 +24,21 @@ jobs:
|
|
|
21
24
|
strategy:
|
|
22
25
|
fail-fast: false
|
|
23
26
|
matrix:
|
|
24
|
-
python-version: ["3.
|
|
27
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
25
28
|
|
|
26
29
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
30
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
28
31
|
with:
|
|
29
|
-
fetch-depth: 0
|
|
32
|
+
fetch-depth: 0
|
|
33
|
+
persist-credentials: false
|
|
30
34
|
|
|
31
35
|
- name: Install uv
|
|
32
|
-
uses: astral-sh/setup-uv@
|
|
36
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
33
37
|
with:
|
|
34
|
-
|
|
35
|
-
version: "0.7.9"
|
|
38
|
+
version: "0.13.9"
|
|
36
39
|
|
|
37
40
|
- name: Set up Python ${{ matrix.python-version }}
|
|
38
|
-
uses: actions/setup-python@
|
|
41
|
+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
39
42
|
with:
|
|
40
43
|
python-version: ${{ matrix.python-version }}
|
|
41
44
|
|
|
@@ -49,16 +52,16 @@ jobs:
|
|
|
49
52
|
|
|
50
53
|
- name: Check code
|
|
51
54
|
run: |
|
|
52
|
-
uv run
|
|
55
|
+
uv run ty check src
|
|
53
56
|
uv run ruff check
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
- name: Run tests with coverage
|
|
59
|
+
run: uv run pytest --cov=src/topogen --cov-report=term-missing --cov-report=xml
|
|
60
|
+
|
|
61
|
+
- name: Upload coverage to Coveralls
|
|
62
|
+
if: matrix.python-version == '3.12'
|
|
63
|
+
uses: coverallsapp/github-action@v2
|
|
64
|
+
with:
|
|
65
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
66
|
+
file: coverage.xml
|
|
67
|
+
format: cobertura
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
name: Publish Python distribution
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
name: Build distribution
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
persist-credentials: false
|
|
21
|
+
|
|
22
|
+
- name: Install uv
|
|
23
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
24
|
+
with:
|
|
25
|
+
version: "0.13.9"
|
|
26
|
+
|
|
27
|
+
- name: Set up Python
|
|
28
|
+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
29
|
+
with:
|
|
30
|
+
python-version-file: ".python-version"
|
|
31
|
+
|
|
32
|
+
- name: Verify tag matches package version
|
|
33
|
+
env:
|
|
34
|
+
RELEASE_TAG: ${{ github.ref_name }}
|
|
35
|
+
run: |
|
|
36
|
+
package_version="$(uv version --short)"
|
|
37
|
+
if [[ "$RELEASE_TAG" != "v$package_version" ]]; then
|
|
38
|
+
echo "Tag $RELEASE_TAG does not match package version v$package_version" >&2
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
- name: Build distribution
|
|
43
|
+
run: uv build
|
|
44
|
+
|
|
45
|
+
- name: Store distribution packages
|
|
46
|
+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
47
|
+
with:
|
|
48
|
+
name: python-package-distributions
|
|
49
|
+
path: dist/
|
|
50
|
+
|
|
51
|
+
publish-to-pypi:
|
|
52
|
+
name: Publish distribution to PyPI
|
|
53
|
+
needs: build
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
environment:
|
|
56
|
+
name: pypi
|
|
57
|
+
url: https://pypi.org/p/topogen
|
|
58
|
+
permissions:
|
|
59
|
+
id-token: write
|
|
60
|
+
|
|
61
|
+
steps:
|
|
62
|
+
- name: Download distributions
|
|
63
|
+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
64
|
+
with:
|
|
65
|
+
name: python-package-distributions
|
|
66
|
+
path: dist/
|
|
67
|
+
|
|
68
|
+
- name: Publish distribution
|
|
69
|
+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
|
|
70
|
+
|
|
71
|
+
github-release:
|
|
72
|
+
name: Sign distribution and create draft GitHub release
|
|
73
|
+
needs: publish-to-pypi
|
|
74
|
+
runs-on: ubuntu-latest
|
|
75
|
+
permissions:
|
|
76
|
+
contents: write
|
|
77
|
+
id-token: write
|
|
78
|
+
env:
|
|
79
|
+
RELEASE_TAG: ${{ github.ref_name }}
|
|
80
|
+
REPOSITORY: ${{ github.repository }}
|
|
81
|
+
|
|
82
|
+
steps:
|
|
83
|
+
- name: Download distributions
|
|
84
|
+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
85
|
+
with:
|
|
86
|
+
name: python-package-distributions
|
|
87
|
+
path: dist/
|
|
88
|
+
|
|
89
|
+
- name: Sign distributions with Sigstore
|
|
90
|
+
uses: sigstore/gh-action-sigstore-python@790bc6befb9d733738f18d8f895854b453640ec9 # v3.5.0
|
|
91
|
+
with:
|
|
92
|
+
inputs: >-
|
|
93
|
+
./dist/*.tar.gz
|
|
94
|
+
./dist/*.whl
|
|
95
|
+
|
|
96
|
+
- name: Create draft GitHub release
|
|
97
|
+
env:
|
|
98
|
+
GH_TOKEN: ${{ github.token }}
|
|
99
|
+
run: >-
|
|
100
|
+
gh release create "$RELEASE_TAG"
|
|
101
|
+
--repo "$REPOSITORY"
|
|
102
|
+
--draft
|
|
103
|
+
--generate-notes
|
|
104
|
+
|
|
105
|
+
- name: Upload assets to GitHub release
|
|
106
|
+
env:
|
|
107
|
+
GH_TOKEN: ${{ github.token }}
|
|
108
|
+
run: >-
|
|
109
|
+
gh release upload "$RELEASE_TAG" dist/*
|
|
110
|
+
--repo "$REPOSITORY"
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
This file lists changes.
|
|
4
4
|
|
|
5
|
+
- version 0.2.3
|
|
6
|
+
- replace the legacy LXC FRR variant with the modern CML FRR Docker node
|
|
7
|
+
- provision the FRR `node.cfg`, `boot.sh`, and `protocols` files
|
|
8
|
+
- update locked dependencies
|
|
9
|
+
- test supported Python versions 3.12 through 3.14
|
|
10
|
+
- harden and fix the release workflow
|
|
11
|
+
- enable the full Ruff rule set and resolve its findings
|
|
12
|
+
- version 0.2.2
|
|
13
|
+
- loosen dependency constraints
|
|
5
14
|
- version 0.2.1 (identical to 0.2.0, but make gh actions happy)
|
|
6
15
|
- version 0.2.0
|
|
7
16
|
- properly configure name server / domain name
|
topogen-0.3.0/Makefile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
UV ?= uv
|
|
2
|
+
|
|
3
|
+
.DEFAULT_GOAL := help
|
|
4
|
+
|
|
5
|
+
.PHONY: help sync lint format format-check typecheck check test build clean distclean
|
|
6
|
+
|
|
7
|
+
help: ## Show available targets
|
|
8
|
+
@awk 'BEGIN {FS = ":.*## "; printf "Usage: make <target>\n\nTargets:\n"} /^[a-zA-Z_-]+:.*## / {printf " %-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
|
9
|
+
|
|
10
|
+
sync: ## Install runtime and development dependencies
|
|
11
|
+
$(UV) sync --dev --locked
|
|
12
|
+
|
|
13
|
+
lint: ## Run Ruff lint checks
|
|
14
|
+
$(UV) run ruff check
|
|
15
|
+
|
|
16
|
+
format: ## Format source files with Ruff
|
|
17
|
+
$(UV) run ruff format
|
|
18
|
+
$(UV) run ruff check --fix
|
|
19
|
+
|
|
20
|
+
format-check: ## Check formatting without changing files
|
|
21
|
+
$(UV) run ruff format --check
|
|
22
|
+
|
|
23
|
+
typecheck: ## Run ty static type checks
|
|
24
|
+
$(UV) run ty check src
|
|
25
|
+
|
|
26
|
+
test: sync ## Run unit tests
|
|
27
|
+
$(UV) run pytest --cov=src/topogen --cov-report=term-missing --cov-report=xml
|
|
28
|
+
|
|
29
|
+
check: lint format-check typecheck test ## Run all static checks
|
|
30
|
+
|
|
31
|
+
build: clean ## Build source and wheel distributions
|
|
32
|
+
$(UV) build
|
|
33
|
+
|
|
34
|
+
clean: ## Remove generated build and cache files
|
|
35
|
+
rm -rf build dist .ruff_cache .pytest_cache .coverage coverage.xml htmlcov
|
|
36
|
+
find src -type d -name __pycache__ -prune -exec rm -rf {} +
|
|
37
|
+
find src -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete
|
|
38
|
+
|
|
39
|
+
distclean: clean ## Also remove the project virtual environment
|
|
40
|
+
rm -rf .venv
|
topogen-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: topogen
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Generate test topology files and configurations for CML2
|
|
5
|
+
Project-URL: Homepage, https://developer.cisco.com/modeling-labs
|
|
6
|
+
Project-URL: Repository, https://github.com/rschmied/topogen
|
|
7
|
+
Project-URL: Issues, https://github.com/rschmied/topogen/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/crschmied/topogen/blob/master/CHANGELOG.md
|
|
9
|
+
Author-email: Ralph Schmieder <rschmied@cisco.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: automation,network-programming,simulation,tools,virtualization
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Internet
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Requires-Dist: jinja2>=3
|
|
26
|
+
Requires-Dist: networkx>=3
|
|
27
|
+
Requires-Dist: numpy>=2.2.0
|
|
28
|
+
Requires-Dist: pyserde[toml]>=0.22.2
|
|
29
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
30
|
+
Requires-Dist: scipy>=1.14.1
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# TopoGen for CML/simple
|
|
34
|
+
|
|
35
|
+
TopoGen generates CML/simple YAML topologies offline. It does not connect to a
|
|
36
|
+
CML controller (the previous/legacy version did).
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- generate router topologies with `simple` or `nx` mode
|
|
41
|
+
- add an Alpine DNS host and an external connector to every generated lab
|
|
42
|
+
- assign router loopbacks and /30 point-to-point networks
|
|
43
|
+
- render day-zero configuration for IOSv, IOL-XE, and FRR
|
|
44
|
+
- write a YAML file that can be imported into CML/simple
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```shell
|
|
49
|
+
uv sync --dev --frozen
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
NumPy and SciPy are installed as normal runtime dependencies because `nx` mode
|
|
53
|
+
uses them for graph layout. Run the CLI with `uv run topogen` if the environment
|
|
54
|
+
is not active.
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
uv run topogen 3 --mode nx --template frr --output topogen_lab.yaml
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`nodes` is the router count. The generated lab also includes an Alpine DNS host
|
|
63
|
+
and an external connector.
|
|
64
|
+
|
|
65
|
+
### Modes
|
|
66
|
+
|
|
67
|
+
- `simple`: a router chain on square-spiral coordinates
|
|
68
|
+
- `nx`: a connected random-shell router graph
|
|
69
|
+
|
|
70
|
+
Both modes write offline YAML and include the DNS host and external connector.
|
|
71
|
+
|
|
72
|
+
### Router templates
|
|
73
|
+
|
|
74
|
+
Offline generation supports these CML node definitions:
|
|
75
|
+
|
|
76
|
+
- `iosv`
|
|
77
|
+
- `iol-xe`
|
|
78
|
+
- `frr`
|
|
79
|
+
|
|
80
|
+
Choose one with `--template`, for example `--template=iosv` or
|
|
81
|
+
`--template=frr`. TopoGen uses copied physical-interface maps for these
|
|
82
|
+
node definitions and rejects a topology that needs more interfaces than the
|
|
83
|
+
selected definition supports.
|
|
84
|
+
|
|
85
|
+
FRR configuration uses `node.cfg`, `boot.sh`, and `protocols`. IOSv and IOL-XE
|
|
86
|
+
configuration uses `ios_config.txt`.
|
|
87
|
+
|
|
88
|
+
### Configuration
|
|
89
|
+
|
|
90
|
+
Use `--config` to load an optional TOML file. It controls address pools, domain
|
|
91
|
+
name, and device credentials:
|
|
92
|
+
|
|
93
|
+
```toml
|
|
94
|
+
loopbacks = "10.0.0.0/8"
|
|
95
|
+
p2pnets = "172.16.0.0/12"
|
|
96
|
+
nameserver = "8.8.8.8"
|
|
97
|
+
domainname = "virl.lab"
|
|
98
|
+
username = "cisco"
|
|
99
|
+
password = "cisco"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The generated DNS host replaces `nameserver` with its router-facing address.
|
|
103
|
+
The user name and password are included in generated device configuration.
|
|
104
|
+
|
|
105
|
+
## Import and run
|
|
106
|
+
|
|
107
|
+
Import the resulting YAML file into CML/simple. TopoGen does not upload or
|
|
108
|
+
start the lab. The generated DNS host installs dnsmasq at first boot, which
|
|
109
|
+
needs Internet access. After the lab starts, configured router loopbacks and
|
|
110
|
+
interfaces resolve through that DNS host.
|
topogen-0.3.0/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# TopoGen for CML/simple
|
|
2
|
+
|
|
3
|
+
TopoGen generates CML/simple YAML topologies offline. It does not connect to a
|
|
4
|
+
CML controller (the previous/legacy version did).
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- generate router topologies with `simple` or `nx` mode
|
|
9
|
+
- add an Alpine DNS host and an external connector to every generated lab
|
|
10
|
+
- assign router loopbacks and /30 point-to-point networks
|
|
11
|
+
- render day-zero configuration for IOSv, IOL-XE, and FRR
|
|
12
|
+
- write a YAML file that can be imported into CML/simple
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```shell
|
|
17
|
+
uv sync --dev --frozen
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
NumPy and SciPy are installed as normal runtime dependencies because `nx` mode
|
|
21
|
+
uses them for graph layout. Run the CLI with `uv run topogen` if the environment
|
|
22
|
+
is not active.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
uv run topogen 3 --mode nx --template frr --output topogen_lab.yaml
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`nodes` is the router count. The generated lab also includes an Alpine DNS host
|
|
31
|
+
and an external connector.
|
|
32
|
+
|
|
33
|
+
### Modes
|
|
34
|
+
|
|
35
|
+
- `simple`: a router chain on square-spiral coordinates
|
|
36
|
+
- `nx`: a connected random-shell router graph
|
|
37
|
+
|
|
38
|
+
Both modes write offline YAML and include the DNS host and external connector.
|
|
39
|
+
|
|
40
|
+
### Router templates
|
|
41
|
+
|
|
42
|
+
Offline generation supports these CML node definitions:
|
|
43
|
+
|
|
44
|
+
- `iosv`
|
|
45
|
+
- `iol-xe`
|
|
46
|
+
- `frr`
|
|
47
|
+
|
|
48
|
+
Choose one with `--template`, for example `--template=iosv` or
|
|
49
|
+
`--template=frr`. TopoGen uses copied physical-interface maps for these
|
|
50
|
+
node definitions and rejects a topology that needs more interfaces than the
|
|
51
|
+
selected definition supports.
|
|
52
|
+
|
|
53
|
+
FRR configuration uses `node.cfg`, `boot.sh`, and `protocols`. IOSv and IOL-XE
|
|
54
|
+
configuration uses `ios_config.txt`.
|
|
55
|
+
|
|
56
|
+
### Configuration
|
|
57
|
+
|
|
58
|
+
Use `--config` to load an optional TOML file. It controls address pools, domain
|
|
59
|
+
name, and device credentials:
|
|
60
|
+
|
|
61
|
+
```toml
|
|
62
|
+
loopbacks = "10.0.0.0/8"
|
|
63
|
+
p2pnets = "172.16.0.0/12"
|
|
64
|
+
nameserver = "8.8.8.8"
|
|
65
|
+
domainname = "virl.lab"
|
|
66
|
+
username = "cisco"
|
|
67
|
+
password = "cisco"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The generated DNS host replaces `nameserver` with its router-facing address.
|
|
71
|
+
The user name and password are included in generated device configuration.
|
|
72
|
+
|
|
73
|
+
## Import and run
|
|
74
|
+
|
|
75
|
+
Import the resulting YAML file into CML/simple. TopoGen does not upload or
|
|
76
|
+
start the lab. The generated DNS host installs dnsmasq at first boot, which
|
|
77
|
+
needs Internet access. After the lab starts, configured router loopbacks and
|
|
78
|
+
interfaces resolve through that DNS host.
|
topogen-0.3.0/TESTING.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
TopoGen currently has static checks and build validation, but no automated test
|
|
4
|
+
suite. This document describes the current validation commands, the code's
|
|
5
|
+
present testability, and a practical plan for adding tests.
|
|
6
|
+
|
|
7
|
+
## Current validation
|
|
8
|
+
|
|
9
|
+
Install the locked runtime, optional, and development dependencies:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
make sync
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Run all static checks:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
make check
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This runs:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
uv run ruff check
|
|
25
|
+
uv run ruff format --check
|
|
26
|
+
uv run mypy --check-untyped-def src
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Build the source distribution and wheel:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
make build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
There is no `make test` target because the repository has no tests and does not
|
|
36
|
+
yet declare `pytest` as a development dependency.
|
|
37
|
+
|
|
38
|
+
## Testability assessment
|
|
39
|
+
|
|
40
|
+
The code is moderately testable. Pure configuration and rendering helpers can
|
|
41
|
+
be tested directly. The main `Renderer` orchestration is tightly coupled to a
|
|
42
|
+
live CML controller and requires mocks or a small design change.
|
|
43
|
+
|
|
44
|
+
### Directly testable code
|
|
45
|
+
|
|
46
|
+
The following code is deterministic or mostly free of external side effects:
|
|
47
|
+
|
|
48
|
+
- `valid_node_count()`
|
|
49
|
+
- `get_log_level()`
|
|
50
|
+
- `CoordsGenerator`
|
|
51
|
+
- `Config.load()` and `Config.save()`
|
|
52
|
+
- `frr_bootconfig()`
|
|
53
|
+
- `dnshostconfig()`
|
|
54
|
+
- Jinja templates
|
|
55
|
+
- `get_templates()`
|
|
56
|
+
- `order_iface_pair()`
|
|
57
|
+
- interface-description formatting
|
|
58
|
+
- DNS-entry formatting
|
|
59
|
+
- argument-parser defaults and validation
|
|
60
|
+
|
|
61
|
+
Tests for these functions can run without a CML controller.
|
|
62
|
+
|
|
63
|
+
### Code that is harder to test
|
|
64
|
+
|
|
65
|
+
`Renderer` creates external resources during initialization. Its constructor:
|
|
66
|
+
|
|
67
|
+
1. loads a template;
|
|
68
|
+
2. initializes `ClientLibrary`;
|
|
69
|
+
3. checks CML controller readiness; and
|
|
70
|
+
4. creates a CML lab.
|
|
71
|
+
|
|
72
|
+
This makes isolated tests for address allocation and graph generation dependent
|
|
73
|
+
on CML API mocks.
|
|
74
|
+
|
|
75
|
+
The two rendering methods also combine several responsibilities:
|
|
76
|
+
|
|
77
|
+
- topology generation;
|
|
78
|
+
- address allocation;
|
|
79
|
+
- CML node and interface creation;
|
|
80
|
+
- link creation;
|
|
81
|
+
- device configuration rendering;
|
|
82
|
+
- DNS generation; and
|
|
83
|
+
- progress reporting.
|
|
84
|
+
|
|
85
|
+
These methods can be tested with extensive mocks, but such tests are likely to
|
|
86
|
+
be brittle.
|
|
87
|
+
|
|
88
|
+
## Recommended test seam
|
|
89
|
+
|
|
90
|
+
The smallest useful design change is to allow injection of the CML client:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
class Renderer:
|
|
94
|
+
def __init__(
|
|
95
|
+
self,
|
|
96
|
+
args: Namespace,
|
|
97
|
+
cfg: Config,
|
|
98
|
+
client: ClientLibrary | None = None,
|
|
99
|
+
):
|
|
100
|
+
self.client = client or self.initialize_client()
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
A test could then provide a fake client and lab without network access.
|
|
104
|
+
|
|
105
|
+
A later refactor should separate the workflow into three layers:
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
Topology plan generation
|
|
109
|
+
↓
|
|
110
|
+
Configuration rendering
|
|
111
|
+
↓
|
|
112
|
+
CML API application
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Topology planning and configuration rendering would then use normal unit tests.
|
|
116
|
+
Only the CML API application layer would require mocks or live integration
|
|
117
|
+
tests.
|
|
118
|
+
|
|
119
|
+
## Recommended initial test suite
|
|
120
|
+
|
|
121
|
+
A focused initial suite should cover the following behavior:
|
|
122
|
+
|
|
123
|
+
1. configuration defaults;
|
|
124
|
+
2. TOML configuration save/load round trips;
|
|
125
|
+
3. valid node-count boundaries;
|
|
126
|
+
4. invalid node-count errors;
|
|
127
|
+
5. log-level mapping;
|
|
128
|
+
6. coordinate-generator sequences;
|
|
129
|
+
7. template discovery;
|
|
130
|
+
8. missing-template errors;
|
|
131
|
+
9. FRR `boot.sh` rendering;
|
|
132
|
+
10. FRR native configuration rendering;
|
|
133
|
+
11. FRR provisioning filenames and daemon list;
|
|
134
|
+
12. IOSv template rendering;
|
|
135
|
+
13. IOL-XE template rendering;
|
|
136
|
+
14. DNS host configuration rendering;
|
|
137
|
+
15. interface-pair ordering;
|
|
138
|
+
16. interface-description formatting;
|
|
139
|
+
17. DNS-name normalization;
|
|
140
|
+
18. point-to-point subnet allocation;
|
|
141
|
+
19. CML client failure mapping with mocks; and
|
|
142
|
+
20. simple topology rendering with a fake lab.
|
|
143
|
+
|
|
144
|
+
Approximately 15 to 25 focused tests should cover most pure logic and the main
|
|
145
|
+
failure-prone boundaries.
|
|
146
|
+
|
|
147
|
+
## Test levels
|
|
148
|
+
|
|
149
|
+
### Unit tests
|
|
150
|
+
|
|
151
|
+
Unit tests should not contact a CML controller. They should cover models,
|
|
152
|
+
configuration, templates, formatting helpers, and topology planning.
|
|
153
|
+
|
|
154
|
+
### Mocked integration tests
|
|
155
|
+
|
|
156
|
+
Mocked integration tests should exercise `Renderer` with fake client, lab, node,
|
|
157
|
+
interface, and link objects. They should verify the calls and generated
|
|
158
|
+
configuration payloads sent to CML.
|
|
159
|
+
|
|
160
|
+
### Live integration tests
|
|
161
|
+
|
|
162
|
+
Live tests should be optional and explicitly enabled. They should use a
|
|
163
|
+
disposable CML lab and must not run in normal CI.
|
|
164
|
+
|
|
165
|
+
Potential live checks include:
|
|
166
|
+
|
|
167
|
+
- create a two-node topology;
|
|
168
|
+
- verify expected node-definition IDs;
|
|
169
|
+
- verify provisioned configuration filenames;
|
|
170
|
+
- start nodes only when explicitly requested;
|
|
171
|
+
- verify node boot state and basic connectivity; and
|
|
172
|
+
- delete the disposable lab during cleanup.
|
|
173
|
+
|
|
174
|
+
Credentials and controller URLs must come from environment variables or a
|
|
175
|
+
secret store. They must never be committed.
|
|
176
|
+
|
|
177
|
+
## Adding pytest
|
|
178
|
+
|
|
179
|
+
When the first tests are added, add `pytest` to the development dependency
|
|
180
|
+
group:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
uv add --dev pytest
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Then add this Makefile target:
|
|
187
|
+
|
|
188
|
+
```make
|
|
189
|
+
test: ## Run unit tests
|
|
190
|
+
$(UV) run pytest
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Include it in the aggregate check target:
|
|
194
|
+
|
|
195
|
+
```make
|
|
196
|
+
check: lint format-check typecheck test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
CI should run unit tests on every supported Python version. Live integration
|
|
200
|
+
tests should use a separate manually triggered workflow or an explicitly
|
|
201
|
+
protected environment.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "topogen"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
authors = [{ name = "Ralph Schmieder", email = "rschmied@cisco.com" }]
|
|
5
5
|
description = "Generate test topology files and configurations for CML2"
|
|
6
6
|
readme = "README.md"
|
|
@@ -43,11 +43,12 @@ classifiers = [
|
|
|
43
43
|
|
|
44
44
|
requires-python = ">=3.12"
|
|
45
45
|
dependencies = [
|
|
46
|
-
"enlighten>=1",
|
|
47
46
|
"jinja2>=3",
|
|
48
47
|
"networkx>=3",
|
|
48
|
+
"numpy>=2.2.0",
|
|
49
49
|
"pyserde[toml]>=0.22.2",
|
|
50
|
-
"
|
|
50
|
+
"PyYAML>=6.0.0",
|
|
51
|
+
"scipy>=1.14.1",
|
|
51
52
|
]
|
|
52
53
|
|
|
53
54
|
[project.urls]
|
|
@@ -59,16 +60,9 @@ Changelog = "https://github.com/crschmied/topogen/blob/master/CHANGELOG.md"
|
|
|
59
60
|
[project.scripts]
|
|
60
61
|
topogen = "topogen:main"
|
|
61
62
|
|
|
62
|
-
[project.optional-dependencies]
|
|
63
|
-
all = ["numpy>=2.2.0", "scipy>=1.14.1"]
|
|
64
|
-
|
|
65
63
|
[build-system]
|
|
66
64
|
requires = ["hatchling"]
|
|
67
65
|
build-backend = "hatchling.build"
|
|
68
66
|
|
|
69
67
|
[dependency-groups]
|
|
70
|
-
dev = ["
|
|
71
|
-
|
|
72
|
-
[[tool.mypy.overrides]]
|
|
73
|
-
module = ["enlighten.*", "virl2_client.*"]
|
|
74
|
-
follow_untyped_imports = true
|
|
68
|
+
dev = ["pytest>=8.0.0", "pytest-cov>=6.0.0", "ruff>=0.8.3", "ty>=0.0.110", "types-networkx>=3.5.0.20250531", "types-PyYAML>=6.0.12.20250915"]
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import importlib.metadata as importlib_metadata
|
|
4
4
|
|
|
5
5
|
from .config import Config
|
|
6
|
-
from .
|
|
6
|
+
from .exporter import ExportLab, ExportLink, ExportNode, ExportTopology, write_yaml
|
|
7
7
|
from .main import main
|
|
8
8
|
|
|
9
9
|
_metadata = importlib_metadata.metadata("topogen")
|
|
@@ -11,4 +11,12 @@ __version__ = _metadata["Version"]
|
|
|
11
11
|
__description__ = _metadata["Summary"]
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
__all__ = [
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Config",
|
|
16
|
+
"ExportLab",
|
|
17
|
+
"ExportLink",
|
|
18
|
+
"ExportNode",
|
|
19
|
+
"ExportTopology",
|
|
20
|
+
"main",
|
|
21
|
+
"write_yaml",
|
|
22
|
+
]
|