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