Fix REST headers in Cluster test
[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}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Shard Status    ${controller_index_list}
19     ...    config    inventory
20     ${inv_oper_leader}    ${inv_oper_followers_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Shard Status    ${controller_index_list}
21     ...    operational    inventory
22     ${topo_oper_leader}    ${topo_oper_followers_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Shard Status    ${controller_index_list}
23     ...    operational    topology
24     Log    config inventory Leader is ${inv_conf_leader} and followers are ${inv_conf_followers_list}
25     Log    operational inventory Leader is ${inv_oper_leader} and followers are ${inv_oper_followers_list}
26     Log    operational topology Leader is ${topo_oper_leader} and followers are ${topo_oper_followers_list}
27
28 Get OpenFlow Entity Owner Status For One Device
29     [Arguments]    ${controller_index_list}
30     [Documentation]    Check Entity Owner Status and identify owner and candidate.
31     ${owner}    ${candidates_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Entity Owner Status    ${controller_index_list}
32     ...    openflow    openflow:1
33     [Return]    ${owner}    ${candidates_list}
34
35 Check OpenFlow Network Operational Information For One Device
36     [Arguments]    ${controller_index_list}
37     [Documentation]    Check device openflow:1 is in operational inventory and topology in all instances in ${controller_index_list}.
38     ...    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.
39     ${dictionary}    Create Dictionary    openflow:1=4
40     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
41     ${dictionary}    Create Dictionary    openflow:1=11
42     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
43
44 Check No OpenFlow Network Operational Information
45     [Arguments]    ${controller_index_list}
46     [Documentation]    Check device is not in operational inventory or topology in all cluster instances in ${controller_index_list}.
47     ${dictionary}    Create Dictionary    openflow=0
48     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
49     ${dictionary}    Create Dictionary    openflow=0
50     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
51
52 Add Sample Flow And Verify
53     [Arguments]    ${controller_index_list}    ${controller_index}
54     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
55     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_1.json
56     ${dictionary}=    Create Dictionary    10.0.1.0/24=1
57     Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
58     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
59
60 Modify Sample Flow And Verify
61     [Arguments]    ${controller_index_list}    ${controller_index}
62     [Documentation]    Modify sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
63     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_2.json
64     ${dictionary}=    Create Dictionary    10.0.2.0/24=1
65     Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
66     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
67
68 Delete Sample Flow And Verify
69     [Arguments]    ${controller_index_list}    ${controller_index}
70     [Documentation]    Delete sample flow in Owner and verify it gets removed from all instances.
71     ${dictionary}=    Create Dictionary    10.0.2.0/24=0
72     Delete And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1
73     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
74
75 Send RPC Add Sample Flow And Verify
76     [Arguments]    ${controller_index_list}    ${controller_index}
77     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied from all instances in ${controller_index_list}.
78     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/add_flow_rpc.json
79     ${dictionary}=    Create Dictionary    10.0.1.0/24=1
80     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:add-flow    ${body}    ${HEADERS_YANG_JSON}
81     Log    ${resp.content}
82     Should Be Equal As Strings    ${resp.status_code}    200
83     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
84
85 Send RPC Delete Sample Flow And Verify
86     [Arguments]    ${controller_index_list}    ${controller_index}
87     [Documentation]    Delete sample flow in ${controller_index} and verify it gets removed from all instances in ${controller_index_list}.
88     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/delete_flow_rpc.json
89     ${dictionary}=    Create Dictionary    10.0.1.0/24=0
90     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:remove-flow    ${body}    ${HEADERS_YANG_JSON}
91     Log    ${resp.content}
92     Should Be Equal As Strings    ${resp.status_code}    200
93     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
94
95 Take OpenFlow Device Link Down and Verify
96     [Arguments]    ${controller_index_list}
97     [Documentation]    Take a link down and verify port status in all instances in ${controller_index_list}.
98     ${dictionary}=    Create Dictionary    "link-down":true=1
99     ${ouput}=    Send Mininet Command    ${mininet_conn_id}    link s1 h1 down
100     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}
101
102 Take OpenFlow Device Link Up and Verify
103     [Arguments]    ${controller_index_list}
104     [Documentation]    Take the link up and verify port status in all instances in ${controller_index_list}.
105     ${dictionary}=    Create Dictionary    "link-down":true=0
106     ${ouput}=    Send Mininet Command    ${mininet_conn_id}    link s1 h1 up
107     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}