945ac7f7ecf5c439ee15bc1a05d5dd3bf3050d41
[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}    Get Cluster Shard Status    ${controller_index_list}    config    topology
15     ${topo_oper_leader}    ${topo_oper_followers_list}    Get Cluster Shard Status    ${controller_index_list}    operational    topology
16     ${owner_oper_leader}    ${owner_oper_followers_list}    Get Cluster Shard Status    ${controller_index_list}    operational    entity-ownership
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     Log    operational entity-ownership Leader is ${owner_oper_leader} and followers are ${owner_oper_followers_list}
20
21 Check Ovsdb Shards Status After Cluster Event
22     [Arguments]    ${controller_index_list}
23     [Documentation]    Check Shard Status after some cluster event.
24     Wait Until Keyword Succeeds    90s    1s    Check Ovsdb Shards Status    ${controller_index_list}
25
26 Get Ovsdb Entity Owner Status For One Device
27     [Arguments]    ${controller_index_list}
28     [Documentation]    Check Entity Owner Status and identify owner and candidate.
29     ${owner}    ${candidates_list}    Wait Until Keyword Succeeds    10s    1s    Get Cluster Entity Owner For Ovsdb    ${controller_index_list}
30     ...    ovsdb    ovsdb:1
31     [Return]    ${owner}    ${candidates_list}
32
33 Get Cluster Entity Owner For Ovsdb
34     [Arguments]    ${controller_index_list}    ${device_type}    ${device}
35     [Documentation]    Checks Entity Owner status for a ${device} and returns owner index and list of candidates from a ${controller_index_list}.
36     ...    ${device_type} is openflow, ovsdb, etc...
37     ${length}=    Get Length    ${controller_index_list}
38     ${candidates_list}=    Create List
39     ${data}=    Get Data From URI    controller@{controller_index_list}[0]    /restconf/operational/entity-owners:entity-owners
40     Log    ${data}
41     ${data}=    Replace String    ${data}    /network-topology:network-topology/network-topology:topology[network-topology:topology-id='    ${EMPTY}
42     # the UUID will not always be the same so need to use regexp to remove this string
43     ${data}=    Replace String Using Regexp    ${data}    \/network-topology:node\\[network-topology:node-id='ovsdb://uuid/........-....-....-....-............    ${EMPTY}
44     Log    ${data}
45     ${clear_data}=    Replace String    ${data}    ']    ${EMPTY}
46     Log    ${clear_data}
47     ${json}=    To Json    ${clear_data}
48     ${entity_type_list}=    Get From Dictionary    &{json}[entity-owners]    entity-type
49     ${entity_type_index}=    Get Index From List Of Dictionaries    ${entity_type_list}    type    ${device_type}
50     Should Not Be Equal    ${entity_type_index}    -1    No Entity Owner found for ${device_type}
51     ${entity_list}=    Get From Dictionary    @{entity_type_list}[${entity_type_index}]    entity
52     ${entity_index}=    Get Index From List Of Dictionaries    ${entity_list}    id    ${device}
53     Should Not Be Equal    ${entity_index}    -1    Device ${device} not found in Entity Owner ${device_type}
54     ${entity_owner}=    Get From Dictionary    @{entity_list}[${entity_index}]    owner
55     Should Not Be Empty    ${entity_owner}    No owner found for ${device}
56     ${owner}=    Replace String    ${entity_owner}    member-    ${EMPTY}
57     ${owner}=    Convert To Integer    ${owner}
58     List Should Contain Value    ${controller_index_list}    ${owner}    Owner ${owner} not exisiting in ${controller_index_list}
59     ${entity_candidates_list}=    Get From Dictionary    @{entity_list}[${entity_index}]    candidate
60     ${list_length}=    Get Length    ${entity_candidates_list}
61     : FOR    ${entity_candidate}    IN    @{entity_candidates_list}
62     \    ${candidate}=    Replace String    &{entity_candidate}[name]    member-    ${EMPTY}
63     \    ${candidate}=    Convert To Integer    ${candidate}
64     \    Run Keyword If    '${candidate}' != '${owner}'    Append To List    ${candidates_list}    ${candidate}
65     [Return]    ${owner}    ${candidates_list}
66
67 Create Bridge And Verify
68     [Arguments]    ${controller_index_list}    ${controller_index}
69     [Documentation]    Create bridge in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
70      # need to get UUID which should be the same on all controllers in cluster, so asking controller1
71     ${ovsdb_uuid}=    Get OVSDB UUID    controller_http_session=controller${controller_index}
72     ${body}=    OperatingSystem.Get File    ${CURDIR}/../variables/ovsdb/create_bridge_3node.json
73     ${body}    Replace String    ${body}    ovsdb://127.0.0.1:61644    ovsdb://uuid/${ovsdb_uuid}
74     ${body}    Replace String    ${body}    tcp:controller1:6633    tcp:${ODL_SYSTEM_1_IP}:6640
75     ${body}    Replace String    ${body}    tcp:controller2:6633    tcp:${ODL_SYSTEM_2_IP}:6640
76     ${body}    Replace String    ${body}    tcp:controller3:6633    tcp:${ODL_SYSTEM_3_IP}:6640
77     ${body}    Replace String    ${body}    127.0.0.1    ${MININET}
78     ${body}    Replace String    ${body}    br01    ${BRIDGE}
79     ${body}    Replace String    ${body}    61644    ${OVSDB_PORT}
80     Log    ${body}
81     ${TOOLS_SYSTEM_IP1}    Replace String    ${TOOLS_SYSTEM_IP}    ${TOOLS_SYSTEM_IP}    "${TOOLS_SYSTEM_IP}"
82     ${dictionary}=    Create Dictionary    ${TOOLS_SYSTEM_IP1}=1    ${OVSDBPORT}=4    ${BRIDGE}=1
83     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}
84     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}
85
86 Create Bridge Manually And Verify
87     [Arguments]    ${controller_index_list}    ${controller_index}
88     [Documentation]    Create bridge in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
89     Run Command On Remote System    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl add-br br-s1
90     ${dictionary_operational}=    Create Dictionary    br-s1=5
91     ${dictionary_config}=    Create Dictionary    br-s1=0
92     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary_config}    ${CONFIG_TOPO_API}
93     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary_operational}    ${OPERATIONAL_TOPO_API}
94
95 Delete Bridge Manually And Verify
96     [Arguments]    ${controller_index_list}    ${controller_index}
97     [Documentation]    Delete bridge in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
98     Run Command On Remote System    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl del-br br-s1
99     ${dictionary}=    Create Dictionary    br-s1=0
100     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary}    ${OPERATIONAL_TOPO_API}
101
102 Delete Bridge Via Rest Call And Verify
103     [Arguments]    ${controller_index_list}    ${controller_index}
104     [Documentation]    Delete bridge in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
105     # need to get UUID which should be the same on all controllers in cluster, so asking controller1
106     ${ovsdb_uuid}=    Get OVSDB UUID    controller_http_session=controller1
107     ${dictionary}=    Create Dictionary    ${BRIDGE}=0
108     Delete 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}
109     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}
110
111 Add Port To The Manual Bridge And Verify
112     [Arguments]    ${controller_index_list}    ${controller_index}
113     [Documentation]    Add Port in ${controller_index} and verify it gets applied in all instances in ${controller_index_list}.
114     Run Command On Remote System    ${TOOLS_SYSTEM_IP}    sudo ovs-vsctl add-port br-s1 vx1 -- set Interface vx1 type=vxlan
115     ${dictionary_operational}=    Create Dictionary    vx1=2
116     ${dictionary_config}=    Create Dictionary    vx1=0
117     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary_config}    ${CONFIG_TOPO_API}
118     Wait Until Keyword Succeeds    5s    1s    Check Item Occurrence At URI In Cluster    ${controller_index_list}    ${dictionary_operational}    ${OPERATIONAL_TOPO_API}