Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / openflowplugin / EntityOwnership / 010_Switch_Disconnect.robot
1 *** Settings ***
2 Documentation     Test suite for entity ownership service and openflowplugin. Makes changes on switch side.
3 Suite Setup       Start Suite
4 Suite Teardown    End Suite
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Test Template     Reconnecting Switch Scenario
7 Library           SSHLibrary
8 Library           RequestsLibrary
9 Library           XML
10 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
11 Resource          ${CURDIR}/../../../libraries/Utils.robot
12 Resource          ${CURDIR}/../../../libraries/FlowLib.robot
13 Resource          ${CURDIR}/../../../libraries/OvsManager.robot
14 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
15 Resource          ${CURDIR}/../../../libraries/ClusterOpenFlow.robot
16 Library           Collections
17
18 *** Variables ***
19 ${SWITCHES}       1
20 ${START_CMD}      sudo mn --topo linear,${SWITCHES}
21 @{cntls_idx_list}    ${1}    ${2}    ${3}
22
23 *** Test Cases ***
24 Switches To Be Connected To All Nodes
25     [Documentation]    Initial check for correct connected topology.
26     [Template]    NONE
27     BuiltIn.Wait Until Keyword Succeeds    5x    3s    Check All Switches Connected To All Cluster Nodes
28
29 Reconnecting Switch s1
30     s1
31
32 Switches Still Be Connected To All Nodes
33     [Template]    NONE
34     BuiltIn.Wait Until Keyword Succeeds    5x    3s    Check All Switches Connected To All Cluster Nodes
35
36 *** Keywords ***
37 Start Suite
38     SetupUtils.Setup_Utils_For_Setup_And_Teardown
39     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${TOOLS_SYSTEM_PROMPT}
40     BuiltIn.Set Suite Variable    ${mininet_conn_id}
41     SSHLibrary.Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/id_rsa    any
42     SSHLibrary.Put File    ${CURDIR}/../../../libraries/DynamicMininet.py    .
43     SSHLibrary.Execute Command    sudo ovs-vsctl set-manager ptcp:6644
44     SSHLibrary.Execute Command    sudo mn -c
45     SSHLibrary.Write    ${START_CMD}
46     SSHLibrary.Read Until    mininet>
47     ${cntls_list}    BuiltIn.Create List    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
48     ${switch_list}    BuiltIn.Create List
49     FOR    ${i}    IN RANGE    0    ${SWITCHES}
50         ${sid}=    BuiltIn.Evaluate    ${i}+1
51         Collections.Append To List    ${switch_list}    s${sid}
52     END
53     BuiltIn.Set Suite Variable    ${active_member}    1
54     OvsManager.Setup Clustered Controller For Switches    ${switch_list}    ${cntls_list}
55     BuiltIn.Wait Until Keyword Succeeds    10s    1s    ClusterOpenFlow.Verify Switch Connections Running On Member    ${SWITCHES}    1
56
57 End Suite
58     RequestsLibrary.Delete All Sessions
59     Utils.Stop Mininet
60
61 Check All Switches Connected To All Cluster Nodes
62     [Documentation]    Verifies all switches are connected to all cluster nodes
63     OvsManager.Get Ovsdb Data
64     FOR    ${i}    IN RANGE    0    ${SWITCHES}
65         ${sid}=    BuiltIn.Evaluate    ${i}+1
66         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_1_IP}    update_data=${False}
67         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_2_IP}    update_data=${False}
68         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_3_IP}    update_data=${False}
69     END
70
71 Reconnecting Switch Scenario
72     [Arguments]    ${switch_name}
73     [Documentation]    Disconnect and connect master and slave and check switch data to be consistent
74     BuiltIn.Set Test Variable    ${disc_cntl}    ${Empty}
75     ${idx}=    BuiltIn.Evaluate    str("${switch_name}"[1:])
76     BuiltIn.Set Test Variable    ${idx}
77     Disconnect Switchs Old Master    ${switch_name}
78     Reconnect Switchs Old Master    ${switch_name}
79     Disconnect Switchs Slave    ${switch_name}
80     Reconnect Switchs Slave    ${switch_name}
81     [Teardown]    Run Keyword If    "${disc_cntl}"!="${Empty}"    OvsManager.Reconnect Switch To Controller And Verify Connected    ${switch_name}    ${disc_cntl}
82
83 Disconnect Switchs Old Master
84     [Arguments]    ${switch_name}
85     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
86     ${old_master}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_owner}_IP}
87     OvsManager.Disconnect Switch From Controller And Verify Disconnected    ${switch_name}    ${old_master}
88     BuiltIn.Set Test Variable    ${disc_cntl}    ${old_master}
89     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${old_successors}    after_stop=True
90     ${new_master}=    BuiltIn.Wait Until Keyword Succeeds    5x    3s    Verify New Master Controller Node    ${switch_name}    ${old_master}
91     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
92     BuiltIn.Set Test Variable    ${old_owner}
93     BuiltIn.Set Test Variable    ${old_successors}
94     BuiltIn.Set Test Variable    ${old_master}
95     BuiltIn.Set Test Variable    ${owner}
96     BuiltIn.Set Test Variable    ${new_master}
97
98 Reconnect Switchs Old Master
99     [Arguments]    ${switch_name}
100     OvsManager.Reconnect Switch To Controller And Verify Connected    ${switch_name}    ${old_master}
101     BuiltIn.Set Test Variable    ${disc_cntl}    ${Empty}
102     ${new_owner}    ${new_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
103     BuiltIn.Should Be Equal    ${owner}    ${new_owner}
104
105 Disconnect Switchs Slave
106     [Arguments]    ${switch_name}
107     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
108     ${old_successor}=    Collections.Get From List    ${old_successors}    0
109     ${old_slave}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_successor}_IP}
110     OvsManager.Disconnect Switch From Controller And Verify Disconnected    ${switch_name}    ${old_slave}
111     BuiltIn.Set Test Variable    ${disc_cntl}    ${old_slave}
112     ${tmp_candidates}=    BuiltIn.Create List    @{ClusterManagement__member_index_list}
113     Collections.Remove Values From List    ${tmp_candidates}    ${old_successor}
114     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${tmp_candidates}    after_stop=True
115     BuiltIn.Should Be Equal    ${owner}    ${old_owner}
116     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
117     BuiltIn.Set Test Variable    ${old_owner}
118     BuiltIn.Set Test Variable    ${old_successors}
119     BuiltIn.Set Test Variable    ${old_successor}
120     BuiltIn.Set Test Variable    ${old_slave}
121     BuiltIn.Set Test Variable    ${owner}
122
123 Reconnect Switchs Slave
124     [Arguments]    ${switch_name}
125     OvsManager.Reconnect Switch To Controller And Verify Connected    ${switch_name}    ${old_slave}
126     BuiltIn.Set Test Variable    ${disc_cntl}    ${Empty}
127     ${new_owner}    ${new_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
128     BuiltIn.Should Be Equal    ${old_owner}    ${new_owner}
129
130 Verify New Master Controller Node
131     [Arguments]    ${switch_name}    ${old_master}
132     [Documentation]    Checks if given node is different from actual master
133     ${idx}=    BuiltIn.Evaluate    "${switch_name}"[1:]
134     ${owner}    ${successors}=    ClusterManagement.Get Owner And Candidates For Device    openflow:${idx}    openflow    ${active_member}
135     ${new_master}    BuiltIn.Set Variable    ${ODL_SYSTEM_${owner}_IP}
136     BuiltIn.Should Not Be Equal    ${old_master}    ${new_master}
137     Return From Keyword    ${new_master}