Skip to content

Commit 5d36fbd

Browse files
authored
Add version change for restore task (#92)
* update gitignore * add version change for restore task (fix #38) * update readme * Increase sd-wan manager cpus to 10 * update gitignore * update delete task log * update gitignore * add pytest test * update tests * update contribution guidelines * update contributing guidelines
1 parent af931b5 commit 5d36fbd

File tree

10 files changed

+218
-31
lines changed

10 files changed

+218
-31
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,6 @@ cython_debug/
195195
# End of https://www.toptal.com/developers/gitignore/api/macos,python
196196

197197
catalyst_sdwan_lab/data/certs/rootCA.key
198-
vsdwan.sh
198+
vsdwan.sh
199+
lab.env
200+
backup/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- Fix issue where add task might fail for SD-WAN Manager 20.18 and higher
55
- In setup task, change behaviour when --list is specified, print software version and exit
66
- Update validator cloud-init to support 20.18 release
7+
- In restore task, add option to change the software version of control components and SD-WAN/SD-Routing edges during restore
8+
- Increase SD-WAN Manager CPU count from 8 to 10
79

810
# Catalyst SD-WAN Lab 2.0.15 [Feb 25, 2025]
911

CONTRIBUTING.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
11
# How to Contribute
22

3-
Thanks for your interest in contributing to Catalyst SD-WAN Lab! Please take a moment to review this document **before submitting a pull request**:
4-
* Want to add something from yourself? [Make a PR](https://github.com/cisco-open/sdwan-lab-deployment-tool/pulls).
5-
* To make a PR - fork the repository, make your changes and make the pull request. Now just wait for the review and feedback from our developers.
6-
* Make clear PR description and include doc strings in your code to make it easily understandable.
7-
* Always write a clear log message for your commits.
8-
* Before submitting PR, verify the existings SD-WAN Lab tasks works without any issues.
9-
* For CML interactions, use official [CML SDK](https://github.com/CiscoDevNet/virl2-client)
10-
* For SD-WAN interactions, use official [Catalyst WAN SDK](https://github.com/CiscoDevNet/catalystwan)
11-
* Bugs or feature requests? [Report it here](https://github.com/cisco-open/sdwan-lab-deployment-tool/issues) - remember to provide as much information as you can.
3+
Thank you for your interest in contributing to Catalyst SD-WAN Lab! Please take a moment to review this document **before submitting a pull request**:
4+
5+
- Want to add something yourself? [Make a PR](https://github.com/cisco-open/sdwan-lab-deployment-tool/pulls).
6+
- To make a PR, fork the repository, make your changes, and submit the pull request. Then, wait for review and feedback from our developers.
7+
- Write a clear PR description and include docstrings in your code to make it easily understandable.
8+
- Always write clear log messages for your commits.
9+
- Before submitting a PR, verify that the existing SD-WAN Lab tasks work without any issues (see [Testing Before Pull Requests](#testing-before-pull-requests)).
10+
- For CML interactions, use the official [CML SDK](https://github.com/CiscoDevNet/virl2-client).
11+
- For SD-WAN interactions, use the official [Catalyst WAN SDK](https://github.com/CiscoDevNet/catalystwan).
12+
- Found a bug or have a feature request? [Report it here](https://github.com/cisco-open/sdwan-lab-deployment-tool/issues) and provide as much information as possible.
13+
14+
## Testing Before Pull Requests
15+
16+
Before opening a pull request, please ensure all tests pass:
17+
18+
1. Create a virtual environment:
19+
20+
```
21+
python3 -m venv venv
22+
```
23+
24+
2. Activate the virtual environment:
25+
26+
```
27+
source venv/bin/activate
28+
```
29+
30+
The prompt will update with the virtual environment name (`venv`), indicating that it is active.
31+
32+
3. Upgrade initial virtual environment packages:
33+
34+
```
35+
pip install --upgrade pip setuptools pytest
36+
```
37+
38+
4. Install the tool from your local repository:
39+
40+
```
41+
pip install --upgrade .
42+
```
43+
44+
Alternatively, you can install the tool from your branch, for example:
45+
46+
```
47+
pip install git+https://github.com/cisco-open/sdwan-lab-deployment-tool.git@restore_version_change
48+
```
49+
50+
5. Load the environment variables used to deploy a test lab:
51+
52+
```
53+
source lab.env
54+
```
55+
56+
6. Run tests:
57+
58+
```
59+
pytest -s test_csdwan.py
60+
```
61+
62+
This will run all tasks and display real-time output. Make sure to resolve any test failures before submitting your PR. If needed, you can modify the control components and edge versions in the test_csdwan.py file.

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -303,26 +303,43 @@ This task restores Catalyst SD-WAN lab from a backup. This task will:
303303
3. Restore SD-WAN Manager templates, policies and configuration groups using [Sastre](https://github.com/CiscoDevNet/sastre).
304304
4. Verify if there are any WAN Edges in the topology (SD-WAN and SD-Routing). If yes, then generate the new OTP and automatically reonboard them to SD-WAN Manager.
305305

306-
This task has several task-specific parameters, including working directory from where backup is restored.
306+
This task has several task-specific parameters, including working directory from where backup is restored. You can also overwrite the software version for control components and SD-WAN/SD-Routing Edges (note that specifying version lower than the one in the backup is not supported).
307307

308308
sdwan-lab restore -h
309309

310310
Usage: sdwan-lab restore [OPTIONS]
311311

312-
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
313-
│ --manager <manager-ip> SD-WAN Manager IP address, can also be defined via MANAGER_IP environment │
314-
│ --muser <manager-user> SD-WAN Manager username, can also be defined via MANAGER_USER environment variable. │
315-
│ --mpassword <manager-password> SD-WAN Manager password, can also be defined via MANAGER_PASSWORD environment variable. │
316-
│ --mmask <manager-mask> Subnet mask for given SD-WAN Manager IP (e.g. /24), can also be defined via MANAGER_MASK environment variable. │
317-
│ --mgateway <manager-gateway> Gateway IP for given SD-WAN Manager IP, can also be defined via MANAGER_GATEWAY environment variable. │
318-
│ --lab <lab_name> CML Lab name, can also be defined via LAB_NAME environment variable. │
319-
│ --workdir <directory> Restore source folder │
320-
│ --deleteexisting If there is already lab running with same name and using same SD-WAN Manager IP, delete this lab before restoring. Note the all running lab data │
321-
│ will be lost! │
322-
│ --retry If for some reason your script lost connectivity during SD-WAN Manager boot, you can add --retry to continue onboarding the lab that is already │
323-
│ in CML │
324-
│ --help -h Show this message and exit. │
325-
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
312+
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────╮
313+
│ --manager <manager-ip> SD-WAN Manager IP address, can also be defined via │
314+
│ MANAGER_IP environment │
315+
│ --muser <manager-user> SD-WAN Manager username, can also be defined via │
316+
│ MANAGER_USER environment variable. │
317+
│ --mpassword <manager-password> SD-WAN Manager password, can also be defined via │
318+
│ MANAGER_PASSWORD environment variable. │
319+
│ --mmask <manager-mask> Subnet mask for given SD-WAN Manager IP (e.g. /24), can │
320+
│ also be defined via MANAGER_MASK environment variable. │
321+
│ --mgateway <manager-gateway> Gateway IP for given SD-WAN Manager IP, can also be │
322+
│ defined via MANAGER_GATEWAY environment variable. │
323+
│ --lab <lab_name> CML Lab name, can also be defined via LAB_NAME │
324+
│ environment variable. │
325+
│ --workdir <directory> Restore source folder │
326+
│ --deleteexisting If there is already lab running with same name and │
327+
│ using same SD-WAN Manager IP, delete this lab before │
328+
│ restoring. Note the all running lab data will be lost! │
329+
│ --retry If for some reason your script lost connectivity during │
330+
│ SD-WAN Manager boot, you can add --retry to continue │
331+
│ onboarding the lab that is already in CML │
332+
│ --contr_version <contr_version> Change the controller version when restoring the lab. │
333+
│ --edge_version <edge_version> Change the SD-WAN edge version when restoring the lab. │
334+
│ --help -h Show this message and exit. │
335+
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
336+
337+
Below you will find few examples of restore task:
338+
339+
sdwan-lab restore --workdir backup
340+
sdwan-lab restore --workdir backup --deleteexisting
341+
sdwan-lab restore --workdir backup --contr_version 20.16.1
342+
sdwan-lab restore --workdir backup --contr_version 20.16.1 --edge_version 17.16.01a
326343

327344
### Delete Task
328345

@@ -391,10 +408,11 @@ Once the installation is finished and you have restarted Windows you are able to
391408
You can read more about [Linux on Windows with WSL here](https://learn.microsoft.com/en-us/windows/wsl/install).
392409

393410
## FAQ
411+
394412
Q1: My devices' consoles have stopped working after I created my own configuration groups. How do I recover console access?
395413

396414
A1: Always include the `platform console serial` command in an CLI add-on feature parcel to ensure your consoles work from the CML UI. Note that after adding this command, a WAN Edge reboot is required.
397-
415+
398416
Q2: Can I SSH to my Manager instance directly?
399417

400418
A2: Yes, you can if you are using an external IP. However, if you are using PATty, you cannot, as we only map the HTTPS port.

catalyst_sdwan_lab/cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ def cli_backup(
430430
"during SD-WAN Manager boot, you can add --retry to continue "
431431
"onboarding the lab that is already in CML",
432432
)
433+
@click.option(
434+
"--contr_version",
435+
metavar="<contr_version>",
436+
default=None,
437+
help="Change the controller version when restoring the lab. Note the specified "
438+
"version cannot be older than the one used in the backup.",
439+
)
440+
@click.option(
441+
"--edge_version",
442+
metavar="<edge_version>",
443+
default=None,
444+
help="Change the SD-WAN/SD-Routing edge version when restoring the lab. Note the specified "
445+
"version cannot be older than the one used in the backup.",
446+
)
433447
@click.pass_context
434448
def cli_restore(
435449
ctx: click.Context,
@@ -442,6 +456,8 @@ def cli_restore(
442456
workdir: str,
443457
deleteexisting: bool,
444458
retry: bool,
459+
contr_version: str,
460+
edge_version: str,
445461
) -> None:
446462
cml_config = ctx.obj["CML_CONFIG"]
447463
cml_ip = cml_config.url
@@ -468,6 +484,8 @@ def cli_restore(
468484
deleteexisting,
469485
retry,
470486
loglevel,
487+
contr_version,
488+
edge_version,
471489
)
472490

473491

catalyst_sdwan_lab/data/cml_nodes_definition/cat-sdwan-manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ boot:
7070
- ': System Ready'
7171
sim:
7272
linux_native:
73-
cpus: 8
73+
cpus: 10
7474
disk_driver: ide
7575
driver: server
7676
libvirt_domain_driver: kvm

catalyst_sdwan_lab/tasks/delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main(
5050
lab.wipe()
5151
log.info("Removing the lab...")
5252
lab.remove()
53-
track_progress(log, "Delete task done")
53+
track_progress(log, "Delete task done\n")
5454

5555
else:
5656
exit("Could not find a lab with specified name.")

catalyst_sdwan_lab/tasks/restore.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def main(
5050
deleteexisitng: bool,
5151
retry: bool,
5252
loglevel: Union[int, str],
53+
contr_version: str,
54+
edge_version: str,
5355
) -> None:
5456
# Time the script execution
5557
begin_time = datetime.datetime.now()
@@ -71,14 +73,69 @@ def main(
7173

7274
cml_topology_dict = yaml.load(cml_topology)
7375

74-
# Verify if requested software version is defined in CML
7576
track_progress(log, "Preparing for restore...")
7677
log.info("Checking software version...")
78+
if contr_version:
79+
# Check if the software version requested by user is compatible with the backup
80+
# In particular, check if the requested version is not older than the backup version
81+
backup_version = next(
82+
node["image_definition"].split("-")[-1]
83+
for node in cml_topology_dict["nodes"]
84+
if node["node_definition"] == "cat-sdwan-manager"
85+
)
86+
backup_version_split = backup_version.split(".")
87+
contr_version_split = contr_version.split(".")
88+
if int(contr_version_split[0]) < int(backup_version_split[0]) or (
89+
int(contr_version_split[0]) == int(backup_version_split[0])
90+
and int(contr_version_split[1]) < int(backup_version_split[1])
91+
):
92+
exit(
93+
f"\nDowngrade of image version from {backup_version} to {contr_version} is not supported."
94+
)
95+
if edge_version:
96+
# Check if the software version requested by user is compatible with the backup
97+
# In particular, check if the requested version is not older than the backup version
98+
backup_version = next(
99+
node["image_definition"].split("-")[-1]
100+
for node in cml_topology_dict["nodes"]
101+
if node["node_definition"] == "cat-sdwan-edge"
102+
)
103+
backup_version_split = backup_version.split(".")
104+
edge_version_split = edge_version.split(".")
105+
if int(edge_version_split[0]) < int(backup_version_split[0]) or (
106+
int(edge_version_split[0]) == int(backup_version_split[0])
107+
and int(edge_version_split[1]) < int(backup_version_split[1])
108+
):
109+
exit(
110+
f"\nDowngrade of image version from {backup_version} to {edge_version} is not supported."
111+
)
112+
113+
# Verify if requested software version is defined in CML
77114
cml_image_definitions = cml.definitions.image_definitions()
78115
defined_images = set(image["id"] for image in cml_image_definitions)
79116
missing_images = []
80117
for node in cml_topology_dict["nodes"]:
81-
if node["image_definition"] and node["image_definition"] not in defined_images:
118+
if (
119+
node["node_definition"]
120+
in ["cat-sdwan-controller", "cat-sdwan-manager", "cat-sdwan-validator"]
121+
and contr_version
122+
):
123+
if (
124+
f'{node["node_definition"]}-{contr_version}' not in defined_images
125+
and f'{node["node_definition"]}-{contr_version}' not in missing_images
126+
):
127+
missing_images.append(f'{node["node_definition"]}-{contr_version}')
128+
elif node["node_definition"] == "cat-sdwan-edge" and edge_version:
129+
if (
130+
f'{node["node_definition"]}-{edge_version}' not in defined_images
131+
and f'{node["node_definition"]}-{edge_version}' not in missing_images
132+
):
133+
missing_images.append(f'{node["node_definition"]}-{edge_version}')
134+
elif (
135+
node["image_definition"]
136+
and node["image_definition"] not in defined_images
137+
and node["image_definition"] not in missing_images
138+
):
82139
missing_images.append(node["image_definition"])
83140
if missing_images:
84141
sys.exit(
@@ -178,6 +235,24 @@ def main(
178235
if patty_used:
179236
manager_node["tags"] = [f"pat:{manager_port}:443"]
180237

238+
if contr_version:
239+
# Overwrite the image definition for control components
240+
for node in cml_topology_dict["nodes"]:
241+
if node["node_definition"] in [
242+
"cat-sdwan-controller",
243+
"cat-sdwan-manager",
244+
"cat-sdwan-validator",
245+
]:
246+
node["image_definition"] = (
247+
f'{node["node_definition"]}-{contr_version}'
248+
)
249+
if edge_version:
250+
# Overwrite the image definition for control components
251+
for node in cml_topology_dict["nodes"]:
252+
if node["node_definition"] == "cat-sdwan-edge":
253+
node["image_definition"] = (
254+
f'{node["node_definition"]}-{edge_version}'
255+
)
181256
stream = io.StringIO()
182257
yaml.dump(cml_topology_dict, stream)
183258
track_progress(log, "Importing the lab...")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "catalyst-sdwan-lab"
3-
version = "2.0.16dev3"
3+
version = "2.0.16dev4"
44
description = "Catalyst SD-WAN Lab Deployment Tool - Automation Tool for managing Cisco Catalyst SD-WAN labs inside Cisco Modeling Labs"
55
license = "BSD-3-Clause"
66
authors = ["Tomasz Zarski <tzarski@cisco.com>"]

test_csdwan.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import subprocess
3+
4+
def test_csdwan():
5+
commands = [
6+
['csdwan', '--version'],
7+
['csdwan', 'setup'],
8+
['csdwan', 'deploy', '20.16.1'],
9+
['csdwan', 'add', '2', 'edges', '17.16.01a'],
10+
['csdwan', 'add', '1', 'validator', '20.16.1'],
11+
['csdwan', 'add', '1', 'controller', '20.16.1'],
12+
['csdwan', 'backup', '--workdir', 'backup'],
13+
['csdwan', 'delete', '--force'],
14+
['csdwan', 'restore', '--workdir', 'backup'],
15+
['csdwan', 'delete', '--force'],
16+
]
17+
print()
18+
for cmd in commands:
19+
print(f"==== {' '.join(cmd)} ====")
20+
result = subprocess.run(cmd, env=os.environ)
21+
assert result.returncode == 0, f"Command {' '.join(cmd)} failed"

0 commit comments

Comments
 (0)