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