Create Test Cases in Git
CXTM Git Integration
  • Introduction
  • NaC Introduction
  • Manual Validation
  • CXTM Introduction
  • CXTM Projects
  • CXTM Test Cases
  • CXTM Test Automation
  • CXTM Git Integration
  • CXTM Batches
  • CXTM Notifications
  • Final Deployment
  • CXTM Reporting
  • CXTM References
  • Bonus Content

Create Test Cases in Git

In this section, you will create test cases in the Git repository.

Step 1 - Create the Verify Features on NX-OS via REST test case

  1. Copy and paste the below command in the VS Code Server terminal window to create the verify_features_on_NXOS_via_rest.robot file in the cxtm directory.

    code-server -r cxtm/verify_features_on_NXOS_via_rest.robot
            
  2. Copy and paste the code below into your open 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
    
            
  3. Press Ctrl + s to save the verify_features_on_NXOS_via_rest.robot file.

Warning

Be sure to save your file! Not saving will result in your code not executing.


Step 2 - Create the Verify Interface State on NX-OS via REST test case

  1. Copy and paste the below command in the VS Code Server terminal window to create the verify_interface_state_on_NXOS_via_REST.robot file in the cxtm directory.

    code-server -r cxtm/verify_interface_state_on_NXOS_via_REST.robot
            
  2. Copy and paste the code below into your open 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
    
            
  3. Press Ctrl + s to save the verify_interface_state_on_NXOS_via_REST.robot file.

Warning

Be sure to save your file! Not saving will result in your code not executing.


Step 3 - Create the Verify BGP Neighbor State on NX-OS via REST test case

  1. Copy and paste the below command in the VS Code Server terminal window to create the verify_BGP_neighbor_state_on_NXOS_via_REST.robot file in the cxtm directory.

    code-server -r cxtm/verify_BGP_neighbor_state_on_NXOS_via_REST.robot
            
  2. Copy and paste the code below into your open 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
    
            
  3. Press Ctrl + s to save the verify_interface_state_on_NXOS_via_REST.robot file.

Warning

Be sure to save your file! Not saving will result in your code not executing.


Step 4 - Create the Verify Route Table State on NX-OS via REST test case

  1. Copy and paste the below command in the VS Code Server terminal window to create the verify_route_table_state_on_NXOS_via_REST.robot file in the cxtm directory.

    code-server -r cxtm/verify_route_table_state_on_NXOS_via_REST.robot
            
  2. Copy and paste the code below into your open 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
    
            
  3. Press Ctrl + s to save the verify_route_table_state_on_NXOS_via_REST.robot file.

Warning

Be sure to save your file! Not saving will result in your code not executing.


Step 5 - Commit and push the test cases to your Git repo

  1. Copy and paste the below command in the VS Code Server terminal window to add the CXTM test cases.

    git add cxtm/
            
  2. Copy and paste the below command in the VS Code Server terminal window to commit the CXTM test cases.

    git commit -m "committing CXTM test cases"
            
  3. Copy and paste the below command in the VS Code Server terminal window to push the CXTM test cases to main.

    git push
            

Continue to the next section.