Int Test Job Files
CXTM Test Automation
  • Introduction
  • CXTM Basics
  • CXTM Projects
  • CXTM Test Cases
  • CXTM Test Automation
  • Revisit Imported Test Cases
  • CXTM Batches
  • CXTM Notifications
  • NetDevOps
  • CXTM Reporting
  • CXTM References
  • Bonus: Project Users
  • Bonus: CXTM REST API
  • Bonus: Secret Env Variables

Create Interface Test Job Files

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.

Step 1 - Create Job File for Verify Interface State on IOS-XE via CLI Test Case


From your project home page:

  1. Click on VIEW TEST CASES



  2. Locate the test case Verify Interface State on IOS-XE via CLI that has identifier 1.02
  3. For this test case's row, click on the + (plus) icon under the Job File? column



  4. For Runtime Image Version select cxta:24.5 from the dropdown



  5. Use the code below to insert into the Script Text section:
  6.     
    *** 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
            


  7. Use the parameters below and insert them into the Parameter File section of your Job File.
  8. Warning

    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
    



  9. Scroll back up to the top of the Job File page and click Save




Step 2 - Create Job File for Verify Interface State on IOS-XR via NETCONF Test Case


From your test case Job File page:

  1. Navigate back to your project home by clicking on the Project LTROPS-2711 tab in the navigation breadcrumbs.



  2. Click on VIEW TEST CASES



  3. Locate the test case Verify Interface State on IOS-XR via NETCONF that has identifier 1.03
  4. For this test case's row, click on the + (plus) icon under the Job File? column



  5. For Runtime Image Version select cxta:24.5 from the dropdown



  6. Examine the Robot test automation below and insert it into the Script Text section of the Job File
  7.     
    *** 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
    


  8. Use the parameters below and insert them into the Parameter File section of your Job File.
  9. Warning

    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
    


  10. Scroll back up to the top of the Job File page and click Save


Step 3 - Create Job File for Verify Interface State on NX-OS via REST Test Case


From your test case Job File page:

  1. Navigate back to your project home by clicking on the Project LTROPS-2711 tab in the navigation breadcrumbs.



  2. Click on VIEW TEST CASES



  3. Locate the test case Verify Interface State on NX-OS via REST that has identifier 1.04
  4. For this test case's row, click on the + (plus) icon under the Job File? column



  5. For Runtime Image Version select cxta:24.5 from the dropdown



  6. Examine the Robot test automation below and insert it into the Script Text section of the Job File
  7.     
    *** 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
    


  8. Use the parameters below and insert them into the Parameter File section of your Job File.
  9. Warning

    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
    


  10. Scroll back up to the top of the Job File page and click Save


Continue to the next section to create additional test cases to verify the OSPF state on your devices.