Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcnm_vrf fix issues #351, #356, #357 #354

Open
wants to merge 51 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
40d93d6
Tentative fix for Issue #351
allenrobel Dec 3, 2024
0b17715
dcnm_vrf: to_bool() fix to return correct value, or call fail_json()
allenrobel Dec 3, 2024
6e32f42
dcnm_image_policy: fix for issue #347 (#348)
allenrobel Dec 3, 2024
244929b
dcnm_fabric: hardening (#349)
allenrobel Dec 3, 2024
5f67187
dcnm_vrf: remove bool() casts, more...
allenrobel Dec 4, 2024
9508840
dcnm_vrf: More refactoring and simplifying
allenrobel Dec 4, 2024
098d17f
Rename var for readability
allenrobel Dec 4, 2024
be41882
Rename var for readability
allenrobel Dec 4, 2024
13e076e
dcnm_vrf: Avoid code duplication
allenrobel Dec 5, 2024
6a6de04
Remove TODO comment
allenrobel Dec 5, 2024
12f9e53
dcnm_vrf: leverage get_vrf_lite_objects() everywhere
allenrobel Dec 5, 2024
bbbf285
Appease pylint f-string complaints, more...
allenrobel Dec 5, 2024
da54fa1
test_log_v2.py: Temporarily disable unit tests
allenrobel Dec 5, 2024
c8c578b
Appease pylint
allenrobel Dec 5, 2024
14da7d7
Fix pep8 too-many-blank-lines
allenrobel Dec 5, 2024
1e028a2
Remove python 3.9 incompatible type hint
allenrobel Dec 5, 2024
ee179b5
Re-enable test_log_v2.py unit tests and "fix" UT errors
allenrobel Dec 5, 2024
0c980b3
Appease linters
allenrobel Dec 5, 2024
5b8c1c3
Merge branch 'develop' into dcnm-vrf-fix-issue-351
allenrobel Dec 6, 2024
b401ab8
Update another conditional
allenrobel Dec 6, 2024
978b0d2
dcnm_vrf: dict_values_differ() use generic names
allenrobel Dec 6, 2024
75a24d5
dcnm_vrf: Address mwiebe review comments
allenrobel Dec 6, 2024
f747767
Address mwiebe coments part 2
allenrobel Dec 6, 2024
dbfe057
dcnm_vrf: Protect dictionary access
allenrobel Dec 6, 2024
cc804e0
dcnm_vrf: Refactor push_to_remote, validate_input
allenrobel Dec 7, 2024
78f9e0d
appease linters
allenrobel Dec 7, 2024
e861626
Appease linters
allenrobel Dec 7, 2024
3a1a514
More refactoring
allenrobel Dec 7, 2024
fed3a70
Fix typo
allenrobel Dec 7, 2024
930dbec
dcnm_vrf: fix IT files, minor cleanup
allenrobel Dec 8, 2024
d83d4fc
Fix UT failures
allenrobel Dec 8, 2024
832a3e8
Appease pylint
allenrobel Dec 8, 2024
cf27b33
Cleanup IT deleted, query, merged
allenrobel Dec 8, 2024
72bfc10
Update playbooks/roles
allenrobel Dec 8, 2024
5749eda
Move dynamic_inventory.py into playbooks/files
allenrobel Dec 8, 2024
acb3890
Appease ansible sanity
allenrobel Dec 8, 2024
0bc26be
Appease linters
allenrobel Dec 8, 2024
b78e996
dcnm_vrf: Updates to integration tests
allenrobel Dec 10, 2024
ca7bea8
Appease linters
allenrobel Dec 10, 2024
8fb0907
Fix unprotected dictionary access
allenrobel Dec 10, 2024
509c335
Update integration tests
allenrobel Dec 10, 2024
b61fd0b
dcnm_vrf/dcnm_tests.yaml - Include all vars
allenrobel Dec 11, 2024
a565a46
Update Usage section and assign additional fabric_* vars
allenrobel Dec 11, 2024
001931e
IT: interface var naming change
allenrobel Dec 11, 2024
ecd1849
IT: Update scale.yaml
allenrobel Dec 12, 2024
a0f44c3
dcnm_vrf: IT dynamic_inventory.py small modifications
allenrobel Dec 12, 2024
41a8fd7
dcnm_vrf: fix for #356, and for an undeploy case, simplify, more...
allenrobel Dec 15, 2024
c30cfd4
dcnm_vrf: Fix for issue #357
allenrobel Dec 16, 2024
d754e3e
dcnm_vrf IT: Update task titles, print results
allenrobel Dec 16, 2024
75334e0
Merge branch 'develop' into dcnm-vrf-fix-issue-351
allenrobel Dec 16, 2024
e92c1e2
IT: Update comment for workaround.
allenrobel Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 282 additions & 0 deletions playbooks/files/dynamic_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
#!/usr/bin/env python
#
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!


__metaclass__ = type
__copyright__ = "Copyright (c) 2024 Cisco and/or its affiliates."
__author__ = "Allen Robel"

import json
from os import environ

"""
# Summary

Optional dynamic inventory for the ansible-dcnm repository
integration tests. This inventory is built from environment
variables.

## Usage

### Mandatory general variables

The following general environment variables are related
to credentials, controller reachability, and role/testcase
assignment. These should be considered mandatory; though
the NXOS_* variables are not strictly needed unless called
for by the specific role/testcase.

Values below are examples, and should be modified for your
setup and the roles/testcases you are running.

```bash
export ND_ROLE=dcnm_vrf # The role to run
export ND_TESTCASE=query # The testcase to run
export ND_IP4=10.1.1.1 # Controller IPv4 address
export ND_PASSWORD=MyPassword # Controller password
export ND_USERNAME=admin # Controller username
export NXOS_PASSWORD=MyPassword # Switch password
export NXOS_USERNAME=admin # Switch username
```

### Fabrics

We can add more fabrics later as the need arises...

```bash
export ND_FABRIC_1=MyFabric1 # Assigned to var fabric_1
export ND_FABRIC_2=MyFabric2 # Assigned to var fabric_2
export ND_FABRIC_3=MyFabric3 # Assigned to var fabric_3

```

### Interfaces

Interface usage varies by testcase. See individual
testcase YAML files for details regarding each test's
usage.

#### Interface naming convention

##### Environment variables

ND_INTERFACE_[A][b]

Where:

A - The number of the switch to which the interface belongs
b - An incrementing lower-case letter in range a-z

###### Examples:

```bash
export ND_INTERFACE_1a=Ethernet1/1
export ND_INTERFACE_2a=Ethernet1/1
export ND_INTERFACE_2b=Ethernet1/2
export ND_INTERFACE_3a=Ethernet2/4
```

Above:

- switch_1 has one interface; Ethernet1/1
- switch_2 two interfaces; Ethernet1/1 and Ethernet1/2
- switch_3 has one interface; Ethernet2/4

##### Test case variables

Interface variables within test cases follow the same convention
as above, but are lowercase, and remove the leading ND_.

###### Examples

interface_1a - 1st interface on switch_1
interface_1b - 2st interface on switch_1
etc...

"""
nd_role = environ.get("ND_ROLE", "dcnm_vrf")
nd_testcase = environ.get("ND_TESTCASE", "query")

fabric_1 = environ.get("ND_FABRIC_1")
fabric_2 = environ.get("ND_FABRIC_1")
fabric_3 = environ.get("ND_FABRIC_1")

nd_ip4 = environ.get("ND_IP4")
nd_password = environ.get("ND_PASSWORD")
nd_username = environ.get("ND_USERNAME", "admin")
nxos_password = environ.get("NXOS_PASSWORD")
nxos_username = environ.get("NXOS_USERNAME", "admin")

# Base set of switches
bgw_1 = environ.get("ND_BGW_1_IP4", "10.1.1.211")
bgw_2 = environ.get("ND_BGW_2_IP4", "10.1.1.212")
leaf_1 = environ.get("ND_LEAF_1_IP4", "10.1.1.106")
leaf_2 = environ.get("ND_LEAF_2_IP4", "10.1.1.107")
leaf_3 = environ.get("ND_LEAF_3_IP4", "10.1.1.108")
leaf_4 = environ.get("ND_LEAF_4_IP4", "10.1.1.109")
spine_1 = environ.get("ND_SPINE_1_IP4", "10.1.1.112")
spine_2 = environ.get("ND_SPINE_2_IP4", "10.1.1.113")

# Placeholders if you'd rather directly set each of
# the switch vars instead of setting the switch vars
# from the switch roles above.
switch_1 = environ.get("ND_SWITCH_1_IP4", "10.1.1.112")
switch_2 = environ.get("ND_SWITCH_2_IP4", "10.1.1.113")
switch_3 = environ.get("ND_SWITCH_3_IP4", "10.1.1.108")

# Base set of interfaces
interface_1a = environ.get("ND_INTERFACE_1a", "Ethernet1/1")
interface_2a = environ.get("ND_INTERFACE_2a", "Ethernet1/1")
interface_2b = environ.get("ND_INTERFACE_2b", "Ethernet1/2")
interface_3a = environ.get("ND_INTERFACE_3a", "Ethernet1/3")

if nd_role == "dcnm_vrf":
pass
# VXLAN/EVPN Fabric Name
# fabric_1
# - all tests
# switch_1
# - all tests
# - vrf capable
# switch_2
# - all tests
# - vrf-lite capable
# switch_3
# - merged
# - NOT vrf-lite capable
# interface_1a
# - no tests
# interface_2a
# - [deleted, merged, overridden, query, replaced, vrf_lite]
# - switch_2 VRF LITE extensions
# interface_2b
# - [vrf_lite]
# - switch_2 VRF LITE extensions
# interface_3a
# - [merged, vrf_lite]
# - switch_3 non-vrf-lite capable switch
#
elif nd_role == "vrf_lite":
# VXLAN/EVPN Fabric Name
# Uses fabric_1
# switch_1: vrf-lite capable
switch_1 = spine_1
# switch_2: vrf-lite capable
switch_2 = spine_2
# switch_3: vrf capable
switch_3 = bgw_1
elif nd_role == "scale":
pass
else:
switch_1 = leaf_1
switch_2 = spine_1
switch_3 = bgw_1

# output is printed to STDOUT, where ansible-playbook -i reads it.
# If you change any vars above, be sure to add them below.
# We'll clean this up as the integration test vars are standardized.

output = {
"_meta": {"hostvars": {}},
"all": {
"children": ["ungrouped", "dcnm", "ndfc", "nxos"],
"vars": {
"ansible_httpapi_use_ssl": "true",
"ansible_httpapi_validate_certs": "false",
"ansible_password": nd_password,
"ansible_python_interpreter": "python",
"ansible_user": nd_username,
"testcase": nd_testcase,
"fabric_1": fabric_1,
"fabric_2": fabric_2,
"fabric_3": fabric_3,
"bgw1": bgw_1,
"bgw2": bgw_2,
"leaf1": leaf_1,
"leaf2": leaf_2,
"leaf_1": leaf_1,
"leaf_2": leaf_2,
"leaf3": leaf_3,
"leaf4": leaf_4,
"nxos_username": nxos_username,
"nxos_password": nxos_password,
"switch_password": nxos_password,
"switch_username": nxos_username,
"spine1": spine_1,
"spine2": spine_2,
"switch1": switch_1,
"switch2": switch_2,
"switch_1": switch_1,
"switch_2": switch_2,
"switch_3": switch_3,
"interface_1a": interface_1a,
"interface_2a": interface_2a,
"interface_2b": interface_2b,
"interface_3a": interface_3a,
},
},
"dcnm": {
"hosts": [nd_ip4],
"vars": {
"ansible_connection": "ansible.netcommon.httpapi",
"ansible_network_os": "cisco.dcnm.dcnm",
},
},
"ndfc": {
"hosts": [nd_ip4],
"vars": {
"ansible_connection": "ansible.netcommon.httpapi",
"ansible_network_os": "cisco.dcnm.dcnm",
},
},
"nxos": {
"children": [
"bgw1",
"bgw2",
"leaf_1",
"leaf_2",
"leaf1",
"leaf2",
"leaf3",
"leaf4",
"spine1",
"spine2",
"switch1",
"switch2",
],
"vars": {
"ansible_become": "true",
"ansible_become_method": "enable",
"ansible_connection": "ansible.netcommon.httpapi",
"ansible_network_os": "cisco.nxos.nxos",
},
},
"bgw1": {"hosts": [bgw_1]},
"bgw2": {"hosts": [bgw_2]},
"leaf_1": {"hosts": [leaf_1]},
"leaf_2": {"hosts": [leaf_2]},
"leaf1": {"hosts": [leaf_1]},
"leaf2": {"hosts": [leaf_2]},
"leaf3": {"hosts": [leaf_3]},
"leaf4": {"hosts": [leaf_4]},
"spine1": {"hosts": [spine_1]},
"spine2": {"hosts": [spine_2]},
"switch1": {"hosts": [switch_1]},
"switch2": {"hosts": [switch_2]},
}

print(json.dumps(output))
15 changes: 15 additions & 0 deletions playbooks/roles/dcnm_vrf/dcnm_hosts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all:
vars:
ansible_user: "admin"
ansible_password: "password-ndfc"
switch_password: "password-switch"
ansible_python_interpreter: python
ansible_httpapi_validate_certs: False
ansible_httpapi_use_ssl: True
children:
ndfc:
vars:
ansible_connection: ansible.netcommon.httpapi
ansible_network_os: cisco.dcnm.dcnm
hosts:
192.168.1.1:
51 changes: 51 additions & 0 deletions playbooks/roles/dcnm_vrf/dcnm_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# This playbook can be used to execute integration tests for
# the roles located in:
#
# REPO_ROOT/tests/integration/targets/dcnm_vrf/tests/dcnm/*.yaml
#
# Either:
#
# 1. Modify the following:
#
# - The vars section below with details for your testing setup.
# - dcnm_hosts.yaml in this directory
#
# 2. Run the tests
#
# ansible-playbook dcnm_tests.yaml -i dcnm_hosts.yaml
#
# OR:
#
# 1. Modify ../../files/dynamic_inventory.py to align with your setup
#
# This must contain the vars mentioned below and controller
# info from dcnm_hosts.yaml (modified for your setup)
#
# 2. Run the tests
#
# ansible-playbook dcnm_tests.yaml -i ../../files/dynamic_inventory.py
#
#
- hosts: dcnm
gather_facts: no
connection: ansible.netcommon.httpapi
# Uncomment and modify if not using dynamic_inventory.py
# See the individual test yaml files for a description of
# how each var below is used in each test. Some tests,
# for example, do not use interface_1.
# vars:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the full set of vars that are required by the vrf integration tests?

Copy link
Collaborator Author

@allenrobel allenrobel Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've updated it to include all the vars.

# fabric_1: f1
# switch_1: 10.1.1.2
# switch_2: 10.1.1.3
# switch_3: 10.1.1.4
# interface_1: Ethernet1/1
# interface_2: Ethernet1/2
# interface_3: Ethernet1/3
## Uncomment ONE of the following testcases
# testcase: deleted
# testcase: merged
# testcase: query

roles:
- dcnm_vrf
Loading
Loading