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