Fix bgpcep-1node-bgp-ingest tests
[integration/test.git] / csit / libraries / WorkflowsL2switch.robot
1 *** Settings ***
2 Documentation     Resource for L2switch workflows. TODO: Refactor KWs once this test works in public.
3 Library           RequestsLibrary
4 Resource          Utils.robot
5 Resource          FlowLib.robot
6 Resource          MininetKeywords.robot
7 Resource          ../variables/Variables.robot
8
9 *** Variables ***
10 ${log_level}      ERROR
11
12 *** Keywords ***
13 Workflow Single Switch Multiple Hosts
14     [Arguments]    ${hosts}    ${sustain_time}=0
15     [Documentation]    Workflow to bring a Linear topology of ${switches} switches, push flows, hold for ${sustain_time} seconds, delete flows and stop topology.
16     ...    This KW returns workflow state (PASS/FAIL), error message and topology discover time.
17     # Define required variables
18     ${error_message}=    BuiltIn.Set Variable    Test has completed
19     ${host_discover_time}=    BuiltIn.Set Variable    ${0}
20     # Workflow starts
21     BuiltIn.Log to console    ${\n}
22     BuiltIn.Log To Console    Starting mininet with one switch and ${hosts} hosts
23     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    MininetKeywords.Start Mininet Multiple Hosts    ${hosts}    mininet_timeout=${hosts}
24     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail starting mininet    ${host_discover_time}
25     BuiltIn.Log To Console    Check 1 switch
26     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${hosts}    2s    FlowLib.Check Switches In Inventory
27     ...    ${1}
28     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking switch    ${host_discover_time}
29     BuiltIn.Log To Console    Ping all hosts
30     @{host_list}=    MininetKeywords.Get Mininet Hosts
31     ${start_time}=    DateTime.Get Current Date    result_format=timestamp
32     ${status}=    MininetKeywords.Ping All Hosts    @{host_list}
33     BuiltIn.Return From Keyword If    ${status} != ${0}    ${status}    Ping test fails    ${host_discover_time}
34     BuiltIn.Log To Console    Verify controller is OK
35     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Utils.Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
36     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller is dead    ${host_discover_time}
37     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Utils.Verify Controller Has No Null Pointer Exceptions    ${ODL_SYSTEM_IP}
38     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller has NPE    ${host_discover_time}
39     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Utils.Verify Controller Has No Runtime Exceptions    ${ODL_SYSTEM_IP}
40     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller has RuntimeException    ${topology_discover_time}
41     Log To Console    Check number of hosts in topology is ${hosts}
42     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${hosts}    2s    FlowLib.Check Number Of Hosts
43     ...    ${hosts}
44     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking hosts    ${host_discover_time}
45     ${end_time}=    DateTime.Get Current Date    result_format=timestamp
46     ${host_discover_time}=    DateTime.Subtract Date From Date    ${end_time}    ${start_time}
47     BuiltIn.Log To Console    Host Discovery Time = ${host_discover_time} seconds
48     BuiltIn.Log To Console    Sleep for ${sustain_time} seconds
49     BuiltIn.Sleep    ${sustain_time}
50     BuiltIn.Log To Console    Stopping Mininet
51     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    MininetKeywords.Stop Mininet And Exit
52     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail stopping mininet    ${host_discover_time}
53     BuiltIn.Log To Console    Checking No Switches
54     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Wait Until Keyword Succeeds    5s    1s    FlowLib.Check No Switches In Inventory
55     ...    ${1}
56     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no switch    ${host_discover_time}
57     BuiltIn.Log To Console    Checking no hosts are present in operational database
58     ${status}    ${result}    BuiltIn.Run Keyword And Ignore Error    Wait Until Keyword Succeeds    5s    1s    FlowLib.Check No Hosts
59     BuiltIn.Return From Keyword If    '${status}' == 'FAIL'    ${status}    Hosts are present    ${host_discover_time}
60     ${max-hosts}    BuiltIn.Convert To String    ${hosts}
61     [Return]    PASS    ${error_message}    ${host_discover_time}
62
63 Workflow Setup
64     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
65     BuiltIn.Wait Until Keyword Succeeds    3x    1s    KarafKeywords.Issue Command On Karaf Console    log:set ${log_level}
66
67 Workflow Teardown
68     [Documentation]    Cleanup when workflow is interrupt
69     Utils.Clean Mininet System
70     RequestsLibrary.Delete All Sessions