|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright (c) 2024 Cisco and/or its affiliates. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from __future__ import absolute_import, division, print_function |
| 18 | + |
| 19 | +__metaclass__ = type |
| 20 | +__copyright__ = "Copyright (c) 2024 Cisco and/or its affiliates." |
| 21 | +__author__ = "Allen Robel" |
| 22 | + |
| 23 | +import json |
| 24 | +from os import environ |
| 25 | + |
| 26 | +""" |
| 27 | +# Summary |
| 28 | +
|
| 29 | +Optional dynamic inventory for the ansible-dcnm repository |
| 30 | +integration tests. This inventory is built from environment |
| 31 | +variables. |
| 32 | +
|
| 33 | +## Usage |
| 34 | +
|
| 35 | +### Mandatory general variables |
| 36 | +
|
| 37 | +The following general environment variables are related |
| 38 | +to credentials, controller reachability, and role/testcase |
| 39 | +assignment. These should be considered mandatory; though |
| 40 | +the NXOS_* variables are not strictly needed unless called |
| 41 | +for by the specific role/testcase. |
| 42 | +
|
| 43 | +Values below are examples, and should be modified for your |
| 44 | +setup and the roles/testcases you are running. |
| 45 | +
|
| 46 | +```bash |
| 47 | +export ND_ROLE=dcnm_vrf # The role to run |
| 48 | +export ND_TESTCASE=query # The testcase to run |
| 49 | +export ND_IP4=10.1.1.1 # Controller IPv4 address |
| 50 | +export ND_PASSWORD=MyPassword # Controller password |
| 51 | +export ND_USERNAME=admin # Controller username |
| 52 | +export NXOS_PASSWORD=MyPassword # Switch password |
| 53 | +export NXOS_USERNAME=admin # Switch username |
| 54 | +``` |
| 55 | +
|
| 56 | +### Fabrics |
| 57 | +
|
| 58 | +We can add more fabrics later as the need arises... |
| 59 | +
|
| 60 | +```bash |
| 61 | +export ND_FABRIC_1=MyFabric1 # Assigned to var fabric_1 |
| 62 | +export ND_FABRIC_2=MyFabric2 # Assigned to var fabric_2 |
| 63 | +export ND_FABRIC_3=MyFabric3 # Assigned to var fabric_3 |
| 64 | +
|
| 65 | +``` |
| 66 | +
|
| 67 | +### Interfaces |
| 68 | +
|
| 69 | +Interface usage varies by testcase. See individual |
| 70 | +testcase YAML files for details regarding each test's |
| 71 | +usage. |
| 72 | +
|
| 73 | +#### Interface naming convention |
| 74 | +
|
| 75 | +##### Environment variables |
| 76 | +
|
| 77 | +ND_INTERFACE_[A][b] |
| 78 | +
|
| 79 | +Where: |
| 80 | +
|
| 81 | +A - The number of the switch to which the interface belongs |
| 82 | +b - An incrementing lower-case letter in range a-z |
| 83 | +
|
| 84 | +###### Examples: |
| 85 | +
|
| 86 | +```bash |
| 87 | +export ND_INTERFACE_1a=Ethernet1/1 |
| 88 | +export ND_INTERFACE_2a=Ethernet1/1 |
| 89 | +export ND_INTERFACE_2b=Ethernet1/2 |
| 90 | +export ND_INTERFACE_3a=Ethernet2/4 |
| 91 | +``` |
| 92 | +
|
| 93 | +Above: |
| 94 | +
|
| 95 | +- switch_1 has one interface; Ethernet1/1 |
| 96 | +- switch_2 two interfaces; Ethernet1/1 and Ethernet1/2 |
| 97 | +- switch_3 has one interface; Ethernet2/4 |
| 98 | +
|
| 99 | +##### Test case variables |
| 100 | +
|
| 101 | +Interface variables within test cases follow the same convention |
| 102 | +as above, but are lowercase, and remove the leading ND_. |
| 103 | +
|
| 104 | +###### Examples |
| 105 | +
|
| 106 | +interface_1a - 1st interface on switch_1 |
| 107 | +interface_1b - 2st interface on switch_1 |
| 108 | +etc... |
| 109 | +
|
| 110 | +""" |
| 111 | +nd_role = environ.get("ND_ROLE", "dcnm_vrf") |
| 112 | +nd_testcase = environ.get("ND_TESTCASE", "query") |
| 113 | + |
| 114 | +fabric_1 = environ.get("ND_FABRIC_1") |
| 115 | +fabric_2 = environ.get("ND_FABRIC_1") |
| 116 | +fabric_3 = environ.get("ND_FABRIC_1") |
| 117 | + |
| 118 | +nd_ip4 = environ.get("ND_IP4") |
| 119 | +nd_password = environ.get("ND_PASSWORD") |
| 120 | +nd_username = environ.get("ND_USERNAME", "admin") |
| 121 | +nxos_password = environ.get("NXOS_PASSWORD") |
| 122 | +nxos_username = environ.get("NXOS_USERNAME", "admin") |
| 123 | + |
| 124 | +# Base set of switches |
| 125 | +bgw_1 = environ.get("ND_BGW_1_IP4", "10.1.1.211") |
| 126 | +bgw_2 = environ.get("ND_BGW_2_IP4", "10.1.1.212") |
| 127 | +leaf_1 = environ.get("ND_LEAF_1_IP4", "10.1.1.106") |
| 128 | +leaf_2 = environ.get("ND_LEAF_2_IP4", "10.1.1.107") |
| 129 | +leaf_3 = environ.get("ND_LEAF_3_IP4", "10.1.1.108") |
| 130 | +leaf_4 = environ.get("ND_LEAF_4_IP4", "10.1.1.109") |
| 131 | +spine_1 = environ.get("ND_SPINE_1_IP4", "10.1.1.112") |
| 132 | +spine_2 = environ.get("ND_SPINE_2_IP4", "10.1.1.113") |
| 133 | + |
| 134 | +# Placeholders if you'd rather directly set each of |
| 135 | +# the switch vars instead of setting the switch vars |
| 136 | +# from the switch roles above. |
| 137 | +switch_1 = environ.get("ND_SWITCH_1_IP4", "10.1.1.112") |
| 138 | +switch_2 = environ.get("ND_SWITCH_2_IP4", "10.1.1.113") |
| 139 | +switch_3 = environ.get("ND_SWITCH_3_IP4", "10.1.1.108") |
| 140 | + |
| 141 | +# Base set of interfaces |
| 142 | +interface_1a = environ.get("ND_INTERFACE_1a", "Ethernet1/1") |
| 143 | +interface_2a = environ.get("ND_INTERFACE_2a", "Ethernet1/1") |
| 144 | +interface_2b = environ.get("ND_INTERFACE_2b", "Ethernet1/2") |
| 145 | +interface_3a = environ.get("ND_INTERFACE_3a", "Ethernet1/3") |
| 146 | + |
| 147 | +if nd_role == "dcnm_vrf": |
| 148 | + pass |
| 149 | + # VXLAN/EVPN Fabric Name |
| 150 | + # fabric_1 |
| 151 | + # - all tests |
| 152 | + # switch_1 |
| 153 | + # - all tests |
| 154 | + # - vrf capable |
| 155 | + # switch_2 |
| 156 | + # - all tests |
| 157 | + # - vrf-lite capable |
| 158 | + # switch_3 |
| 159 | + # - merged |
| 160 | + # - NOT vrf-lite capable |
| 161 | + # interface_1a |
| 162 | + # - no tests |
| 163 | + # interface_2a |
| 164 | + # - [deleted, merged, overridden, query, replaced, vrf_lite] |
| 165 | + # - switch_2 VRF LITE extensions |
| 166 | + # interface_2b |
| 167 | + # - [vrf_lite] |
| 168 | + # - switch_2 VRF LITE extensions |
| 169 | + # interface_3a |
| 170 | + # - [merged, vrf_lite] |
| 171 | + # - switch_3 non-vrf-lite capable switch |
| 172 | + # |
| 173 | +elif nd_role == "vrf_lite": |
| 174 | + # VXLAN/EVPN Fabric Name |
| 175 | + # Uses fabric_1 |
| 176 | + # switch_1: vrf-lite capable |
| 177 | + switch_1 = spine_1 |
| 178 | + # switch_2: vrf-lite capable |
| 179 | + switch_2 = spine_2 |
| 180 | + # switch_3: vrf capable |
| 181 | + switch_3 = bgw_1 |
| 182 | +elif nd_role == "scale": |
| 183 | + pass |
| 184 | +else: |
| 185 | + switch_1 = leaf_1 |
| 186 | + switch_2 = spine_1 |
| 187 | + switch_3 = bgw_1 |
| 188 | + |
| 189 | +# output is printed to STDOUT, where ansible-playbook -i reads it. |
| 190 | +# If you change any vars above, be sure to add them below. |
| 191 | +# We'll clean this up as the integration test vars are standardized. |
| 192 | + |
| 193 | +output = { |
| 194 | + "_meta": {"hostvars": {}}, |
| 195 | + "all": { |
| 196 | + "children": ["ungrouped", "dcnm", "ndfc", "nxos"], |
| 197 | + "vars": { |
| 198 | + "ansible_httpapi_use_ssl": "true", |
| 199 | + "ansible_httpapi_validate_certs": "false", |
| 200 | + "ansible_password": nd_password, |
| 201 | + "ansible_python_interpreter": "python", |
| 202 | + "ansible_user": nd_username, |
| 203 | + "testcase": nd_testcase, |
| 204 | + "fabric_1": fabric_1, |
| 205 | + "fabric_2": fabric_2, |
| 206 | + "fabric_3": fabric_3, |
| 207 | + "bgw1": bgw_1, |
| 208 | + "bgw2": bgw_2, |
| 209 | + "leaf1": leaf_1, |
| 210 | + "leaf2": leaf_2, |
| 211 | + "leaf_1": leaf_1, |
| 212 | + "leaf_2": leaf_2, |
| 213 | + "leaf3": leaf_3, |
| 214 | + "leaf4": leaf_4, |
| 215 | + "nxos_username": nxos_username, |
| 216 | + "nxos_password": nxos_password, |
| 217 | + "switch_password": nxos_password, |
| 218 | + "switch_username": nxos_username, |
| 219 | + "spine1": spine_1, |
| 220 | + "spine2": spine_2, |
| 221 | + "switch1": switch_1, |
| 222 | + "switch2": switch_2, |
| 223 | + "switch_1": switch_1, |
| 224 | + "switch_2": switch_2, |
| 225 | + "switch_3": switch_3, |
| 226 | + "interface_1a": interface_1a, |
| 227 | + "interface_2a": interface_2a, |
| 228 | + "interface_2b": interface_2b, |
| 229 | + "interface_3a": interface_3a, |
| 230 | + }, |
| 231 | + }, |
| 232 | + "dcnm": { |
| 233 | + "hosts": [nd_ip4], |
| 234 | + "vars": { |
| 235 | + "ansible_connection": "ansible.netcommon.httpapi", |
| 236 | + "ansible_network_os": "cisco.dcnm.dcnm", |
| 237 | + }, |
| 238 | + }, |
| 239 | + "ndfc": { |
| 240 | + "hosts": [nd_ip4], |
| 241 | + "vars": { |
| 242 | + "ansible_connection": "ansible.netcommon.httpapi", |
| 243 | + "ansible_network_os": "cisco.dcnm.dcnm", |
| 244 | + }, |
| 245 | + }, |
| 246 | + "nxos": { |
| 247 | + "children": [ |
| 248 | + "bgw1", |
| 249 | + "bgw2", |
| 250 | + "leaf_1", |
| 251 | + "leaf_2", |
| 252 | + "leaf1", |
| 253 | + "leaf2", |
| 254 | + "leaf3", |
| 255 | + "leaf4", |
| 256 | + "spine1", |
| 257 | + "spine2", |
| 258 | + "switch1", |
| 259 | + "switch2", |
| 260 | + ], |
| 261 | + "vars": { |
| 262 | + "ansible_become": "true", |
| 263 | + "ansible_become_method": "enable", |
| 264 | + "ansible_connection": "ansible.netcommon.httpapi", |
| 265 | + "ansible_network_os": "cisco.nxos.nxos", |
| 266 | + }, |
| 267 | + }, |
| 268 | + "bgw1": {"hosts": [bgw_1]}, |
| 269 | + "bgw2": {"hosts": [bgw_2]}, |
| 270 | + "leaf_1": {"hosts": [leaf_1]}, |
| 271 | + "leaf_2": {"hosts": [leaf_2]}, |
| 272 | + "leaf1": {"hosts": [leaf_1]}, |
| 273 | + "leaf2": {"hosts": [leaf_2]}, |
| 274 | + "leaf3": {"hosts": [leaf_3]}, |
| 275 | + "leaf4": {"hosts": [leaf_4]}, |
| 276 | + "spine1": {"hosts": [spine_1]}, |
| 277 | + "spine2": {"hosts": [spine_2]}, |
| 278 | + "switch1": {"hosts": [switch_1]}, |
| 279 | + "switch2": {"hosts": [switch_2]}, |
| 280 | +} |
| 281 | + |
| 282 | +print(json.dumps(output)) |
0 commit comments