Adds test suits for Cluster HA Leader follower failover
[integration/test.git] / csit / libraries / ClusterOpenFlow.robot
1 *** Settings ***
2 Documentation     Cluster OpenFlow library. So far this library is only to be used by OpenFlow cluster test as it is very specific for this test.
3 Library           RequestsLibrary
4 Resource          ClusterKeywords.robot
5 Resource          MininetKeywords.robot
6 Resource          Utils.robot
7 Variables         ../variables/Variables.py
8
9 *** Variables ***
10 ${config_table_0}    ${CONFIG_NODES_API}/node/openflow:1/table/0
11 ${operational_table_0}    ${OPERATIONAL_NODES_API}/node/openflow:1/table/0
12 ${operational_port_1}    ${OPERATIONAL_NODES_API}/node/openflow:1/node-connector/openflow:1:1
13
14 *** Keywords ***
15 Get InventoryConfig Shard Status
16     [Arguments]    ${controller_index_list}
17     [Documentation]    Check Status for Inventory Config shard in OpenFlow application.
18     ${inv_conf_leader}    ${inv_conf_followers_list}    Wait Until Keyword Succeeds    10s    1s    ClusterKeywords.Get Cluster Shard Status    ${controller_index_list}
19     ...    config    inventory
20     Log    config inventory Leader is ${inv_conf_leader} and followers are ${inv_conf_followers_list}
21     [Return]    ${inv_conf_leader}    ${inv_conf_followers_list}
22
23 Check OpenFlow Shards Status
24     [Arguments]    ${controller_index_list}
25     [Documentation]    Check Status for all shards in OpenFlow application.
26     ${inv_conf_leader}    ${inv_conf_followers_list}    ClusterKeywords.Get Cluster Shard Status    ${controller_index_list}    config    inventory
27     ${inv_oper_leader}    ${inv_oper_followers_list}    ClusterKeywords.Get Cluster Shard Status    ${controller_index_list}    operational    inventory
28     ${topo_oper_leader}    ${topo_oper_followers_list}    ClusterKeywords.Get Cluster Shard Status    ${controller_index_list}    operational    topology
29     ${owner_oper_leader}    ${owner_oper_followers_list}    ClusterKeywords.Get Cluster Shard Status    ${controller_index_list}    operational    entity-ownership
30     Log    config inventory Leader is ${inv_conf_leader} and followers are ${inv_conf_followers_list}
31     Log    operational inventory Leader is ${inv_oper_leader} and followers are ${inv_oper_followers_list}
32     Log    operational topology Leader is ${topo_oper_leader} and followers are ${topo_oper_followers_list}
33     Log    operational entity-ownership Leader is ${owner_oper_leader} and followers are ${owner_oper_followers_list}
34
35 Check OpenFlow Shards Status After Cluster Event
36     [Arguments]    ${controller_index_list}
37     [Documentation]    Check Shards Status after some cluster event.
38     Wait Until Keyword Succeeds    90s    1s    ClusterOpenFlow.Check OpenFlow Shards Status    ${controller_index_list}
39
40 Get OpenFlow Entity Owner Status For One Device
41     [Arguments]    ${controller_index_list}    ${device}
42     [Documentation]    Check Entity Owner Status and identify owner and candidate.
43     ${owner}    ${candidates_list}    Wait Until Keyword Succeeds    10s    1s    ClusterKeywords.Get Cluster Entity Owner    ${controller_index_list}
44     ...    openflow    ${device}
45     [Return]    ${owner}    ${candidates_list}
46
47 Check OpenFlow Network Operational Information For Sample Topology
48     [Arguments]    ${controller_index_list}
49     [Documentation]    Check devices in tree,2 are in operational inventory and topology in all instances in ${controller_index_list}.
50     ...    Inventory should show 1x node_id per device 1x node_id per connector. Topology should show 2x node_id per device + 3x node_id per connector
51     ...    + 5x node_id per link termination. TODO: A Keyword that can calculate this based on mininet topology.
52     ${dictionary}    Create Dictionary    openflow:1=4    openflow:2=5    openflow:3=5
53     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
54     ${dictionary}    Create Dictionary    openflow:1=21    openflow:2=19    openflow:3=19
55     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
56
57 Check No OpenFlow Network Operational Information
58     [Arguments]    ${controller_index_list}
59     [Documentation]    Check device is not in operational inventory or topology in all cluster instances in ${controller_index_list}.
60     ${dictionary}    Create Dictionary    openflow=0
61     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
62     ${dictionary}    Create Dictionary    openflow=0
63     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
64
65 Add Sample Flow And Verify
66     [Arguments]    ${controller_index_list}    ${controller_index}
67     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
68     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_1.json
69     # There are slight differences on the way He and Li plugin display table information. He plugin has an additional Hashmap field
70     # replicating some of the matches in the flows section. Same comment applies for further keywords.
71     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"1"=1
72     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"1"=1
73     ClusterKeywords.Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
74     Wait Until Keyword Succeeds    15s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
75
76 Modify Sample Flow And Verify
77     [Arguments]    ${controller_index_list}    ${controller_index}
78     [Documentation]    Modify sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
79     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_2.json
80     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"2"=1
81     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"2"=1
82     ClusterKeywords.Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
83     Wait Until Keyword Succeeds    15s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
84
85 Delete Sample Flow And Verify
86     [Arguments]    ${controller_index_list}    ${controller_index}
87     [Documentation]    Delete sample flow in Owner and verify it gets removed from all instances.
88     ${dictionary}=    Create Dictionary    10.0.2.0/24=0
89     ClusterKeywords.Delete And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1
90     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
91
92 Send RPC Add Sample Flow And Verify
93     [Arguments]    ${controller_index_list}    ${controller_index}
94     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied from all instances in ${controller_index_list}.
95     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/add_flow_rpc.json
96     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2
97     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1
98     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:add-flow    data=${body}    headers=${HEADERS_YANG_JSON}
99     Log    ${resp.content}
100     Should Be Equal As Strings    ${resp.status_code}    200
101     Wait Until Keyword Succeeds    15s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
102
103 Send RPC Delete Sample Flow And Verify
104     [Arguments]    ${controller_index_list}    ${controller_index}
105     [Documentation]    Delete sample flow in ${controller_index} and verify it gets removed from all instances in ${controller_index_list}.
106     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/delete_flow_rpc.json
107     ${dictionary}=    Create Dictionary    10.0.1.0/24=0
108     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:remove-flow    data=${body}    headers=${HEADERS_YANG_JSON}
109     Log    ${resp.content}
110     Should Be Equal As Strings    ${resp.status_code}    200
111     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
112
113 Take OpenFlow Device Link Down and Verify
114     [Arguments]    ${controller_index_list}
115     [Documentation]    Take a link down and verify port status in all instances in ${controller_index_list}.
116     ${dictionary}=    Create Dictionary    "link-down":true=1
117     ${ouput}=    MininetKeywords.Send Mininet Command    ${mininet_conn_id}    link s1 s2 down
118     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}
119     ${dictionary}    Create Dictionary    openflow:1=16    openflow:2=14    openflow:3=19
120     Wait Until Keyword Succeeds    20s    2s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
121
122 Take OpenFlow Device Link Up and Verify
123     [Arguments]    ${controller_index_list}
124     [Documentation]    Take the link up and verify port status in all instances in ${controller_index_list}.
125     ${dictionary}=    Create Dictionary    "link-down":true=0
126     ${ouput}=    MininetKeywords.Send Mininet Command    ${mininet_conn_id}    link s1 s2 up
127     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}
128     ${dictionary}    Create Dictionary    openflow:1=21    openflow:2=19    openflow:3=19
129     Wait Until Keyword Succeeds    5s    1s    ClusterKeywords.Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}