ff7ecae896881d797bee000090e3e73469bea3fb
[integration/test.git] / csit / libraries / ClusterOvsdb.robot
1 *** Settings ***
2 Documentation     Cluster Ovsdb library. So far this library is only to be used by Ovsdb 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 *** Keywords ***
10 Check Ovsdb Shards Status
11     [Arguments]    ${controller_index_list}
12     [Documentation]    Check Status for all shards in Ovsdb application.
13     ${topo_conf_leader}    ${topo_conf_followers_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Shard Status    ${controller_index_list}
14     ...    config    topology
15     ${topo_oper_leader}    ${topo_oper_followers_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Shard Status    ${controller_index_list}
16     ...    operational    topology
17     Log    config topology Leader is ${topo_conf_leader} and followers are ${topo_conf_followers_list}
18     Log    operational topology Leader is ${topo_oper_leader} and followers are ${topo_oper_followers_list}
19
20 Get Ovsdb Entity Owner Status For One Device
21     [Arguments]    ${controller_index_list}
22     [Documentation]    Check Entity Owner Status and identify owner and candidate.
23     ${owner}    ${candidates_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Entity Owner For Ovsdb    ${controller_index_list}
24     ...    ovsdb    ovsdb:1
25     [Return]    ${owner}    ${candidates_list}
26
27 Get Cluster Entity Owner For Ovsdb
28     [Arguments]    ${controller_index_list}    ${device_type}    ${device}
29     [Documentation]    Checks Entity Owner status for a ${device} and returns owner index and list of candidates from a ${controller_index_list}.
30     ...    ${device_type} is openflow, ovsdb, etc...
31     ${length}=    Get Length    ${controller_index_list}
32     ${candidates_list}=    Create List
33     ${data}=    Get Data From URI    controller@{controller_index_list}[0]    /restconf/operational/entity-owners:entity-owners
34     Log    ${data}
35     ${data}=    Replace String    ${data}    /network-topology:network-topology/network-topology:topology[network-topology:topology-id='    ${EMPTY}
36     # the UUID will not always be the same so need to use regexp to remove this string
37     ${data}=    Replace String Using Regexp    ${data}    \/network-topology:node\\[network-topology:node-id='ovsdb://uuid/........-....-....-....-............    ${EMPTY}
38     Log    ${data}
39     ${clear_data}=    Replace String    ${data}    ']    ${EMPTY}
40     Log    ${clear_data}
41     ${json}=    To Json    ${clear_data}
42     ${entity_type_list}=    Get From Dictionary    &{json}[entity-owners]    entity-type
43     ${entity_type_index}=    Get Index From List Of Dictionaries    ${entity_type_list}    type    ${device_type}
44     Should Not Be Equal    ${entity_type_index}    -1    No Entity Owner found for ${device_type}
45     ${entity_list}=    Get From Dictionary    @{entity_type_list}[${entity_type_index}]    entity
46     ${entity_index}=    Get Index From List Of Dictionaries    ${entity_list}    id    ${device}
47     Should Not Be Equal    ${entity_index}    -1    Device ${device} not found in Entity Owner ${device_type}
48     ${entity_owner}=    Get From Dictionary    @{entity_list}[${entity_index}]    owner
49     Should Not Be Empty    ${entity_owner}    No owner found for ${device}
50     ${owner}=    Replace String    ${entity_owner}    member-    ${EMPTY}
51     ${owner}=    Convert To Integer    ${owner}
52     List Should Contain Value    ${controller_index_list}    ${owner}    Owner ${owner} not exisiting in ${controller_index_list}
53     ${entity_candidates_list}=    Get From Dictionary    @{entity_list}[${entity_index}]    candidate
54     ${list_length}=    Get Length    ${entity_candidates_list}
55     : FOR    ${entity_candidate}    IN    @{entity_candidates_list}
56     \    ${candidate}=    Replace String    &{entity_candidate}[name]    member-    ${EMPTY}
57     \    ${candidate}=    Convert To Integer    ${candidate}
58     \    List Should Contain Value    ${controller_index_list}    ${candidate}    Candidate ${candidate} not exisiting in ${controller_index_list}
59     \    Run Keyword If    '${candidate}' != '${owner}'    Append To List    ${candidates_list}    ${candidate}
60     [Return]    ${owner}    ${candidates_list}
61
62 Create Bridge And Verify
63     [Arguments]    ${controller_index_list}    ${controller_index}
64     [Documentation]    Create bridge in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
65     ${sample}=    OperatingSystem.Get File    ${CURDIR}/../variables/ovsdb/create_bridge_3node.json
66     Log    ${sample}
67     ${sample1}    Replace String    ${sample}    tcp:controller1:6633    tcp:${ODL_SYSTEM_1_IP}:6640
68     Log    ${sample1}
69     ${sample2}    Replace String    ${sample1}    tcp:controller2:6633    tcp:${ODL_SYSTEM_2_IP}:6640
70     Log    ${sample2}
71     ${sample3}    Replace String    ${sample2}    tcp:controller3:6633    tcp:${ODL_SYSTEM_3_IP}:6640
72     Log    ${sample3}
73     ${sample4}    Replace String    ${sample3}    127.0.0.1    ${MININET}
74     Log    ${sample4}
75     ${sample5}    Replace String    ${sample4}    br01    ${BRIDGE}
76     Log    ${sample5}
77     ${body}    Replace String    ${sample5}    61644    ${OVSDB_PORT}
78     Log    ${body}
79     ${dictionary}=    Create Dictionary    ${MININET}=1    ${OVSDBPORT}=4    ${BRIDGE}=1
80     Put And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${SOUTHBOUND_CONFIG_API}%2Fbridge%2F${BRIDGE}    ${body}    ${HEADERS}
81     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}