In this section, you will create test cases in the Git repository.
code-server -r cxtm/verify_features_on_NXOS_via_rest.robot
verify_features_on_NXOS_via_rest.robot file in VS Code:
*** Settings ***
Library CXTA
Resource cxta.robot
Library genie.libs.robot.GenieRobot
Library genie.libs.robot.GenieRobotApis
Library Collections
Variables /tmp/parameters.yaml
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... disconnect from all devices
*** Test Cases ***
1. CONNECT TO DEVICES (VIA REST)
[Documentation] Connect to all devices in the devices list via rest.
FOR ${DEVICE} IN @{DEVICES}
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}" via "rest"
IF '${status[0]}' == 'FAIL'
Fail ++UNSUCCESSFUL++ ${DEVICE} not connected
ELSE
set test message ++SUCCESSFUL++ ${DEVICE} connected \n append=True
END
END
2. VERIFY FEATURES ARE ENABLED
[Documentation] Verify operational status of NXOS features via NX-API.
FOR ${DEVICE} IN @{DEVICES}
${resp}= nxapi method nxapi cli device=${DEVICE} action=send commands=show feature message_format=json_rpc command_type=cli alias=rest
VAR ${features_dict} ${resp.json()['result']['body']['TABLE_cfcFeatureCtrlTable']}
${features_list}= dq query data=${features_dict} filters=get_values('cfcFeatureCtrlName2')
FOR ${expected_feature} IN @{EXPECTED_FEATURES}
${feature_list_idx}= Get Index From List ${features_list} ${expected_feature}
VAR ${state} ${resp.json()['result']['body']['TABLE_cfcFeatureCtrlTable']['ROW_cfcFeatureCtrlTable'][${feature_list_idx}]['cfcFeatureCtrlOpStatus2']}
IF '${state}' == '${EXPECTED_STATE}'
Set Test Message ++SUCCESSFUL++ The "${expected_feature}" feature is "${state}" on ${DEVICE}\n append=True
ELSE
Fail ++UNSUCCESSFUL++ The "${expected_feature}" feature is "${state}" on ${DEVICE}
END
END
END
Be sure to save your file! Not saving will result in your code not executing.
code-server -r cxtm/verify_interface_state_on_NXOS_via_REST.robot
verify_interface_state_on_NXOS_via_REST.robot file in VS Code:
*** Settings ***
Library CXTA
Resource cxta.robot
Library genie.libs.robot.GenieRobot
Library genie.libs.robot.GenieRobotApis
Library Collections
Variables /tmp/parameters.yaml
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... disconnect from all devices
*** Test Cases ***
1. CONNECT TO DEVICES (VIA REST)
[Documentation] Connect to all devices in the devices list via rest.
@{DEVICES}= Get Dictionary Keys ${DEVICES_DATA}
Set Suite Variable @{DEVICES}
FOR ${DEVICE} IN @{DEVICES}
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}" via "rest"
IF '${status[0]}' == 'FAIL'
Fail ++UNSUCCESSFUL++ ${DEVICE} not connected
ELSE
Set Test Message ++SUCCESSFUL++ ${DEVICE} connected \n append=True
END
END
2. VERIFY INTERFACE STATE
[Documentation] Verify operational state of interfaces via NX-API.
FOR ${DEVICE} IN @{DEVICES}
${resp}= nxapi method nxapi cli device=${DEVICE} action=send commands=show ip interface brief message_format=json_rpc command_type=cli alias=rest
VAR ${interfaces_dict} ${resp.json()['result']['body']['TABLE_intf']}
${interfaces_list}= dq query data=${interfaces_dict} filters=get_values('intf-name')
@{expected_interfaces}= Set Variable ${DEVICES_DATA['${DEVICE}']['INTERFACES']}
FOR ${expected_interface} IN @{expected_interfaces}
IF "${expected_interface}" in @{interfaces_list}
${interface_list_idx}= Get Index From List ${interfaces_list} ${expected_interface}
VAR ${state} ${resp.json()['result']['body']['TABLE_intf']['ROW_intf'][${interface_list_idx}]['link-state']}
IF '${state}' == '${EXPECTED_STATE}'
Set Test Message ++SUCCESSFUL++ ${DEVICE} has interface ${expected_interface} in the expected ${EXPECTED_STATE} state\n append=True
ELSE
Fail ++UNSUCCESSFUL++ Expected interface state is ${EXPECTED_STATE}, but ${DEVICE} has interface ${expected_interface} in the ${state} state
END
END
END
END
Be sure to save your file! Not saving will result in your code not executing.
code-server -r cxtm/verify_BGP_neighbor_state_on_NXOS_via_REST.robot
verify_BGP_neighbor_state_on_NXOS_via_REST.robot file in VS Code:
*** Settings ***
Library CXTA
Resource cxta.robot
Library genie.libs.robot.GenieRobot
Library genie.libs.robot.GenieRobotApis
Variables /tmp/parameters.yaml
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... disconnect from all devices
*** Test Cases ***
1. CONNECT TO DEVICES (VIA REST)
[Documentation] Connect to all devices in the devices list via rest.
FOR ${DEVICE} IN @{DEVICES}
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}" via "rest"
IF '${status[0]}' == 'FAIL'
Fail ++UNSUCCESSFUL++ ${DEVICE} not connected
ELSE
set test message ++SUCCESSFUL++ ${DEVICE} connected \n append=True
END
END
2. VERIFY ALL CONFIGURED BGP NEIGHBOR STATES ESTABLISHED FOR THE GIVEN DUT
[Documentation] Verify all BGP neighbor states are as expected via NX-API.
FOR ${DEVICE} IN @{DEVICES}
${resp}= nxapi method nxapi cli device=${DEVICE} action=send commands=show bgp ipv4 unicast summary message_format=json_rpc command_type=cli alias=rest
VAR ${neighbors} ${resp.json()}[result][body][TABLE_vrf][ROW_vrf][TABLE_af][ROW_af][TABLE_saf][ROW_saf][TABLE_neighbor][ROW_neighbor]
${is_list}= Evaluate isinstance($neighbors, list)
IF ${is_list}
FOR ${neighbor} IN @{neighbors}
VAR ${state} ${neighbor}[state]
VAR ${neighbor_rtr_id} ${neighbor}[neighborid]
IF '${state}' == '${EXPECTED_STATE}'
Set Test Message ++SUCCESSFUL++ ${DEVICE} has BGP neighbor ${neighbor_rtr_id} in the expected ${EXPECTED_STATE} state\n append=True
ELSE
Fail ++UNSUCCESSFUL++ Expected BGP neighbor state ${EXPECTED_STATE}, but ${DEVICE} has BGP neighbor ${neighbor_rtr_id} in the ${state} state
END
END
ELSE
VAR ${state} ${neighbors}[state]
VAR ${neighbor_rtr_id} ${neighbors}[neighborid]
IF '${state}' == '${EXPECTED_STATE}'
Set Test Message ++SUCCESSFUL++ ${DEVICE} has BGP neighbor ${neighbor_rtr_id} in the expected ${EXPECTED_STATE} state\n append=True
ELSE
Fail ++UNSUCCESSFUL++ Expected BGP neighbor state ${EXPECTED_STATE}, but ${DEVICE} has BGP neighbor ${neighbor_rtr_id} in the ${state} state
END
END
END
Be sure to save your file! Not saving will result in your code not executing.
code-server -r cxtm/verify_route_table_state_on_NXOS_via_REST.robot
verify_route_table_state_on_NXOS_via_REST.robot file in VS Code:
*** Settings ***
Library CXTA
Resource cxta.robot
Library genie.libs.robot.GenieRobot
Library genie.libs.robot.GenieRobotApis
Library Collections
Variables /tmp/parameters.yaml
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... disconnect from all devices
*** Test Cases ***
1. CONNECT TO DEVICES (VIA REST)
[Documentation] Connect to all devices in the devices list via rest.
FOR ${DEVICE} IN @{DEVICES}
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}" via "rest"
IF '${status[0]}' == 'FAIL'
Fail ++UNSUCCESSFUL++ ${DEVICE} not connected
ELSE
set test message ++SUCCESSFUL++ ${DEVICE} connected \n append=True
END
END
2. VERIFY ROUTES ARE IN THE ROUTE TABLE
[Documentation] Verify expected routes are present in the default VRF IPv4 routing table.
FOR ${DEVICE} IN @{DEVICES}
${resp}= nxapi method nxapi cli device=${DEVICE} action=send commands=show ip route message_format=json_rpc command_type=cli alias=rest
VAR ${routes_dict} ${resp.json()['result']['body']['TABLE_vrf']['ROW_vrf']['TABLE_addrf']['ROW_addrf']['TABLE_prefix']}
${routes_list}= dq query data=${routes_dict} filters=get_values('ipprefix')
FOR ${expected_route} IN @{EXPECTED_ROUTES}
IF "${expected_route}" in @{routes_list}
Set Test Message ++SUCCESSFUL++ The "${expected_route}" route is in the default vrf IPv4 route table on ${DEVICE}\n append=True
ELSE
Fail ++UNSUCCESSFUL++ The "${expected_route}" route is NOT in the default vrf IPv4 route table on ${DEVICE}
END
END
END
Be sure to save your file! Not saving will result in your code not executing.
git add cxtm/
git commit -m "committing CXTM test cases"
git push
Continue to the next section.