In the next steps, you will create test cases that verify that the expected interfaces are up on the IOS-XE, IOS-XR, and NX-OS devices in your testbed. In the first Job File you created, you connected to all the devices via ssh and verified that they are running the expected software release using Genie parsers. In the following test cases, you will continue to verify output via the CLI on the IOS-XE devices, but you will also use NETCONF and REST APIs to verify the state of your IOS-XR and NX-OS devices, respectively.
From your project home page:
*** Settings ***
Library CXTA
Resource cxta.robot
Library BuiltIn
Library Collections
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... Disconnect From All Devices
*** Test Cases ***
1. CONNECT TO DEVICES
@{DEVICES}= Get Dictionary Keys ${DEVICES_DATA}
Set Suite Variable @{DEVICES}
FOR ${DEVICE} IN @{DEVICES}
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}"
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
FOR ${DEVICE} IN @{DEVICES}
${output}= parse "show ip interface brief" on device "${DEVICE}"
@{expected_interfaces}= Set Variable ${DEVICES_DATA['${DEVICE}']['INTERFACES']}
Log ${expected_interfaces}
@{interfaces_list}= Get Dictionary Keys ${output['interface']}
Log ${interfaces_list}
FOR ${expected_interface} IN @{expected_interfaces}
IF "${expected_interface}" in @{interfaces_list}
${int_status}= Get From Dictionary ${output['interface']['${expected_interface}']} status
${int_protocol}= Get From Dictionary ${output['interface']['${expected_interface}']} protocol
${status_check}= Run Keyword and Return Status Should Be Equal As Strings ${EXPECTED_STATUS} ${int_status}
${protocol_check}= Run Keyword and Return Status Should Be Equal As Strings ${EXPECTED_STATUS} ${int_protocol}
IF ${status_check} and ${protocol_check}
Set Test Message ++SUCCESSFUL++ ${DEVICE} interface ${expected_interface} state is ${int_status}\n append=True
ELSE
Fail ++UNSUCCESSFUL++ ${DEVICE} interface ${expected_interface} state is ${int_status}
END
END
END
END
NOTE: You may need to scroll down to see the Parameter File section.
DEVICES_DATA:
C8Kv-01:
INTERFACES:
- GigabitEthernet1
- GigabitEthernet3
- Loopback0
CSR1Kv-01:
INTERFACES:
- GigabitEthernet1
- GigabitEthernet2
- Loopback0
EXPECTED_STATUS: up
From your test case Job File page:
*** Settings ***
# CXTA
Library CXTA
Resource cxta.robot
# Import keywords from opensource libraries in robot framework here:
# http://robotframework.org/robotframework/#standard-libraries
Library Collections
Suite Setup Run Keywords
... load testbed
Suite Teardown Run Keywords
... Disconnect From All Devices
*** Test Cases ***
Connect to device via NETCONF
[Documentation] Connect to device(s) under test via NETCONF connection.
set netconf timeout to "180" seconds
${status}= Run Keyword And Ignore Error connect to device "${DEVICE}" via netconf using alias "nc1"
IF '${status[0]}' == 'FAIL'
Fail ++UNSUCCESSFUL++ ${DEVICE} not connected
ELSE
Set Test Message ++SUCCESSFUL++ ${DEVICE} connected \n append=True
END
Verify Device Interface Status via NETCONF Get Operation
[Documentation] Verify given interfaces are in expected state via NETCONF.
${output} ${dict}= netconf get filter_type=subtree filter=${RPC_FILTER} reply_dict=${true} device=${DEVICE} alias=nc1
${interfaces_dict}= Set Variable ${dict['rpc-reply']['data']['interfaces']}
${interfaces_list}= dq query data=${interfaces_dict} filters=get_values('name')
FOR ${expected_interface} IN @{EXPECTED_INTERFACES}
IF "${expected_interface}" in @{interfaces_list}
${interface_list_idx}= Get Index From List ${interfaces_list} ${expected_interface}
${interface_oper_status}= Set Variable ${interfaces_dict['interface'][${interface_list_idx}]['state']['oper-status']}
${status}= Run Keyword and Return Status Should Be Equal As Strings ${EXPECTED_STATE} ${interface_oper_status}
IF ${status}
Set Test Message ++SUCCESSFUL++ ${DEVICE} has interface ${expected_interface} in the expected ${EXPECTED_STATE} state\n append=True
ELSE
Fail ++UNSUCCESSFUL++ Expected interface state was ${EXPECTED_STATE}, but ${DEVICE} has interface ${expected_interface} in the ${interface_oper_status} state
END
END
END
NOTE: You may need to scroll down to see the Parameter File section.
DEVICE: XR9Kv-01
RPC_FILTER: |
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<state>
<enabled/>
<admin-status/>
<oper-status/>
</state>
</interface>
</interfaces>
EXPECTED_INTERFACES:
- Loopback0
- GigabitEthernet0/0/0/1
- GigabitEthernet0/0/0/2
- GigabitEthernet0/0/0/3
EXPECTED_STATE: UP
From your test case Job File page:
*** Settings ***
Library CXTA
Resource cxta.robot
Library genie.libs.robot.GenieRobot
Library genie.libs.robot.GenieRobotApis
Library Collections
Suite Setup Run Keywords
... load testbed #load testbed file
Suite Teardown Run Keywords
... disconnect from all devices #disconnect from all devices
*** Test Cases ***
1. CONNECT TO DEVICE UNDER TEST (REST)
[Documentation] Connect to device(s) under test via NX-API REST connection.
${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
2. VERIFY THE GIVEN INTERFACE STATE IS UP FOR THE DUT
[Documentation] Verify given interfaces are in expected state via NX-API.
${resp}= nxapi method nxapi cli device=${DEVICE} action=send commands=show interface brief message_format=json_rpc command_type=cli alias=rest
VAR ${interfaces_dict} ${resp.json()['result']['body']['TABLE_interface']}
${interfaces_list}= dq query data=${interfaces_dict} filters=get_values('interface')
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_interface']['ROW_interface'][${interface_list_idx}]['state']}
${status}= Run Keyword and Return Status Should Be Equal As Strings ${EXPECTED_STATE} ${state}
IF ${status}
Set Test Message ++SUCCESSFUL++ ${DEVICE} has interface ${expected_interface} in the expected ${EXPECTED_STATE} state\n append=True
ELSE
Fail ++UNSUCCESSFUL++ Expected interface state was ${EXPECTED_STATE}, but ${DEVICE} has interface ${expected_interface} in the ${state} state
END
END
END
NOTE: You may need to scroll down to see the Parameter File section.
DEVICE: N9Kv-01
EXPECTED_INTERFACES:
- Ethernet1/1
- loopback 0
EXPECTED_STATE: up
Continue to the next section to create additional test cases to verify the OSPF state on your devices.