Add check for missing candidates in entity owner Keyword
[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}    Get Cluster Shard Status    ${controller_index_list}    config    inventory
19     ${inv_oper_leader}    ${inv_oper_followers_list}    Get Cluster Shard Status    ${controller_index_list}    operational    inventory
20     ${topo_oper_leader}    ${topo_oper_followers_list}    Get Cluster Shard Status    ${controller_index_list}    operational    topology
21     ${owner_oper_leader}    ${owner_oper_followers_list}    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    Check OpenFlow Shards Status    ${controller_index_list}
31
32 Get Cluster Entity Owner For Openflow
33     [Arguments]    ${controller_index_list}    ${device_type}    ${device}
34     [Documentation]    Checks OpenFlow Entity Owner status for a ${device} and returns owner index and list of candidates from a ${controller_index_list}.
35     ...    ${device_type} is normally openflow.
36     ${length}=    Get Length    ${controller_index_list}
37     ${candidates_list}=    Create List
38     ${data}=    Get Data From URI    controller@{controller_index_list}[0]    /restconf/operational/entity-owners:entity-owners
39     Log    ${data}
40     ${data}=    Replace String    ${data}    /general-entity:entity[general-entity:name='    ${EMPTY}
41     ${clear_data}=    Replace String    ${data}    ']    ${EMPTY}
42     Log    ${clear_data}
43     ${json}=    To Json    ${clear_data}
44     ${entity_type_list}=    Get From Dictionary    &{json}[entity-owners]    entity-type
45     ${entity_type_index}=    Get Index From List Of Dictionaries    ${entity_type_list}    type    ${device_type}
46     Should Not Be Equal    ${entity_type_index}    -1    No Entity Owner found for ${device_type}
47     ${entity_list}=    Get From Dictionary    @{entity_type_list}[${entity_type_index}]    entity
48     ${entity_index}=    Get Index From List Of Dictionaries    ${entity_list}    id    ${device}
49     Should Not Be Equal    ${entity_index}    -1    Device ${device} not found in Entity Owner ${device_type}
50     ${entity_owner}=    Get From Dictionary    @{entity_list}[${entity_index}]    owner
51     Should Not Be Empty    ${entity_owner}    No owner found for ${device}
52     ${owner}=    Replace String    ${entity_owner}    member-    ${EMPTY}
53     ${owner}=    Convert To Integer    ${owner}
54     List Should Contain Value    ${controller_index_list}    ${owner}    Owner ${owner} not exisiting in ${controller_index_list}
55     ${entity_candidates_list}=    Get From Dictionary    @{entity_list}[${entity_index}]    candidate
56     ${list_length}=    Get Length    ${entity_candidates_list}
57     : FOR    ${entity_candidate}    IN    @{entity_candidates_list}
58     \    ${candidate}=    Replace String    &{entity_candidate}[name]    member-    ${EMPTY}
59     \    ${candidate}=    Convert To Integer    ${candidate}
60     \    Append To List    ${candidates_list}    ${candidate}
61     List Should Contain Sublist    ${candidates_list}    ${controller_index_list}    Candidates are missing in ${candidates_list}
62     Remove Values From List    ${candidates_list}    ${owner}
63     [Return]    ${owner}    ${candidates_list}
64
65 Get OpenFlow Entity Owner Status For One Device
66     [Arguments]    ${controller_index_list}
67     [Documentation]    Check Entity Owner Status and identify owner and candidate.
68     ${owner}    ${candidates_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Entity Owner For Openflow    ${controller_index_list}
69     ...    openflow    openflow:1
70     [Return]    ${owner}    ${candidates_list}
71
72 Check OpenFlow Network Operational Information For One Device
73     [Arguments]    ${controller_index_list}
74     [Documentation]    Check device openflow:1 is in operational inventory and topology in all instances in ${controller_index_list}.
75     ...    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.
76     ${dictionary}    Create Dictionary    openflow:1=4
77     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
78     ${dictionary}    Create Dictionary    openflow:1=11
79     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
80
81 Check No OpenFlow Network Operational Information
82     [Arguments]    ${controller_index_list}
83     [Documentation]    Check device is not in operational inventory or topology in all cluster instances in ${controller_index_list}.
84     ${dictionary}    Create Dictionary    openflow=0
85     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_NODES_API}
86     ${dictionary}    Create Dictionary    openflow=0
87     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
88
89 Add Sample Flow And Verify
90     [Arguments]    ${controller_index_list}    ${controller_index}
91     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
92     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_1.json
93     # There are slight differences on the way He and Li plugin display table information. He plugin has an additional Hashmap field
94     # replicating some of the matches in the flows section. Same comment applies for further keywords.
95     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"1"=1
96     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"1"=1
97     Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
98     Wait Until Keyword Succeeds    15s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
99
100 Modify Sample Flow And Verify
101     [Arguments]    ${controller_index_list}    ${controller_index}
102     [Documentation]    Modify sample flow in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
103     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/sample_flow_2.json
104     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2    "output-node-connector":"2"=1
105     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1    "output-node-connector":"2"=1
106     Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1    ${body}
107     Wait Until Keyword Succeeds    15s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
108
109 Delete Sample Flow And Verify
110     [Arguments]    ${controller_index_list}    ${controller_index}
111     [Documentation]    Delete sample flow in Owner and verify it gets removed from all instances.
112     ${dictionary}=    Create Dictionary    10.0.2.0/24=0
113     Delete And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${config_table_0}/flow/1
114     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
115
116 Send RPC Add Sample Flow And Verify
117     [Arguments]    ${controller_index_list}    ${controller_index}
118     [Documentation]    Add sample flow in ${controller_index} and verify it gets applied from all instances in ${controller_index_list}.
119     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/add_flow_rpc.json
120     Run Keyword If    '${ODL_OF_PLUGIN}' == 'helium'    Set Test Variable    &{dictionary}    10.0.1.0/24=2
121     Run Keyword If    '${ODL_OF_PLUGIN}' == 'lithium'    Set Test Variable    &{dictionary}    10.0.1.0/24=1
122     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:add-flow    data=${body}    headers=${HEADERS_YANG_JSON}
123     Log    ${resp.content}
124     Should Be Equal As Strings    ${resp.status_code}    200
125     Wait Until Keyword Succeeds    15s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
126
127 Send RPC Delete Sample Flow And Verify
128     [Arguments]    ${controller_index_list}    ${controller_index}
129     [Documentation]    Delete sample flow in ${controller_index} and verify it gets removed from all instances in ${controller_index_list}.
130     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/openflowplugin/delete_flow_rpc.json
131     ${dictionary}=    Create Dictionary    10.0.1.0/24=0
132     ${resp}    RequestsLibrary.Post Request    controller${controller_index}    /restconf/operations/sal-flow:remove-flow    data=${body}    headers=${HEADERS_YANG_JSON}
133     Log    ${resp.content}
134     Should Be Equal As Strings    ${resp.status_code}    200
135     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_table_0}
136
137 Take OpenFlow Device Link Down and Verify
138     [Arguments]    ${controller_index_list}
139     [Documentation]    Take a link down and verify port status in all instances in ${controller_index_list}.
140     ${dictionary}=    Create Dictionary    "link-down":true=1
141     ${ouput}=    Send Mininet Command    ${mininet_conn_id}    link s1 h1 down
142     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}
143
144 Take OpenFlow Device Link Up and Verify
145     [Arguments]    ${controller_index_list}
146     [Documentation]    Take the link up and verify port status in all instances in ${controller_index_list}.
147     ${dictionary}=    Create Dictionary    "link-down":true=0
148     ${ouput}=    Send Mininet Command    ${mininet_conn_id}    link s1 h1 up
149     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${operational_port_1}