Add new CSIT test cases for VTN Manager Flowfilter
[integration/test.git] / csit / libraries / ClusterKeywords.robot
index dcf9bb11b86054ddbb187613b0c5c87047c51eed..f332c5c3b30a3eb427e3696cdbaa26c1cd731872 100644 (file)
@@ -49,6 +49,69 @@ Get Cluster Shard Status
     Length Should Be    ${follower_list}    ${lenght-1}    Not enough or too many Followers in shard ${shard_type} ${shard}
     [Return]    ${leader}    ${follower_list}
 
+Get Cluster Entity Owner
+    [Arguments]    ${controller_index_list}    ${device_type}    ${device}
+    [Documentation]    Checks Entity Owner status for a ${device} and returns owner index and list of candidates from a ${controller_index_list}.
+    ...    ${device_type} can be openflow, ovsdb, etc.
+    ${owner}    ${candidates_list}=    Get Device Entity Owner And Candidates Indexes    controller@{controller_index_list}[0]    ${device_type}    ${device}
+    List Should Contain Value    ${controller_index_list}    ${owner}    Owner ${owner} not exisiting in ${controller_index_list}
+    List Should Contain Sublist    ${candidates_list}    ${controller_index_list}    Candidates are missing in ${candidates_list}
+    Remove Values From List    ${candidates_list}    ${owner}
+    [Return]    ${owner}    ${candidates_list}
+
+Get Device Entity Owner And Followers Indexes
+    [Arguments]    ${session}    ${device_type}    ${device}
+    [Documentation]    Returns the owner and followers indexes for a ${device}. Follower list = candidate list - owner
+    ${owner}    ${candidates_list}=    Get Device Entity Owner And Candidates Indexes    ${session}    ${device_type}    ${device}
+    Remove Values From List    ${candidates_list}    ${owner}
+    [Return]    ${owner}    ${candidates_list}
+
+Get Device Entity Owner And Candidates Indexes
+    [Arguments]    ${session}    ${device_type}    ${device}
+    [Documentation]    Returns the owner and candidates indexes for a ${device}. Returns raw information, does not check missing
+    ...    cluster nodes or so.
+    ${candidates_list}=    Create List
+    ${data}=    Utils.Get Data From URI    ${session}    /restconf/operational/entity-owners:entity-owners
+    Log    ${data}
+    ${device_style}=    BuiltIn.Set_Variable_If    '${device_type}' == 'netconf'    openflow    ${device_type}
+    ${entity_type}=    BuiltIn.Set_Variable_If    '${device_type}' == 'netconf'    netconf-node/${device}    ${device_type}
+    ${clear_data}=    Run Keyword If    '${device_style}' == 'openflow'    Extract OpenFlow Device Data    ${data}
+    ...    ELSE IF    '${device_style}' == 'ovsdb'    Extract Ovsdb Device Data    ${data}
+    ...    ELSE    Fail    Not recognized device type: ${device_type}
+    ${json}=    RequestsLibrary.To Json    ${clear_data}
+    ${entity_type_list}=    Get From Dictionary    &{json}[entity-owners]    entity-type
+    ${entity_type_index}=    Get Index From List Of Dictionaries    ${entity_type_list}    type    ${entity_type}
+    Should Not Be Equal    ${entity_type_index}    -1    No Entity Owner found for ${device_type}
+    ${entity_list}=    Get From Dictionary    @{entity_type_list}[${entity_type_index}]    entity
+    ${entity_index}=    Utils.Get Index From List Of Dictionaries    ${entity_list}    id    ${device}
+    Should Not Be Equal    ${entity_index}    -1    Device ${device} not found in Entity Owner ${device_type}
+    ${entity_owner}=    Get From Dictionary    @{entity_list}[${entity_index}]    owner
+    Should Not Be Empty    ${entity_owner}    No owner found for ${device}
+    ${owner}=    Replace String    ${entity_owner}    member-    ${EMPTY}
+    ${owner}=    Convert To Integer    ${owner}
+    ${entity_candidates_list}=    Get From Dictionary    @{entity_list}[${entity_index}]    candidate
+    : FOR    ${entity_candidate}    IN    @{entity_candidates_list}
+    \    ${candidate}=    Replace String    &{entity_candidate}[name]    member-    ${EMPTY}
+    \    ${candidate}=    Convert To Integer    ${candidate}
+    \    Append To List    ${candidates_list}    ${candidate}
+    [Return]    ${owner}    ${candidates_list}
+
+Extract OpenFlow Device Data
+    [Arguments]    ${data}
+    [Documentation]    Remove superfluous OpenFlow device data from Entity Owner printout.
+    ${clear_data}=    Replace String    ${data}    /general-entity:entity[general-entity:name='    ${EMPTY}
+    ${clear_data}=    Replace String    ${clear_data}    ']    ${EMPTY}
+    Log    ${clear_data}
+    [Return]    ${clear_data}
+
+Extract Ovsdb Device Data
+    [Arguments]    ${data}
+    [Documentation]    Remove superfluous OVSDB device data from Entity Owner printout.
+    ${clear_data}=    Replace String    ${data}    /network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='    ${EMPTY}
+    ${clear_data}=    Replace String    ${clear_data}    ']    ${EMPTY}
+    Log    ${clear_data}
+    [Return]    ${clear_data}
+
 Check Item Occurrence At URI In Cluster
     [Arguments]    ${controller_index_list}    ${dictionary_item_occurrence}    ${uri}
     [Documentation]    Send a GET with the supplied ${uri} to all cluster instances in ${controller_index_list}
@@ -60,11 +123,22 @@ Check Item Occurrence At URI In Cluster
 
 Put And Check At URI In Cluster
     [Arguments]    ${controller_index_list}    ${controller_index}    ${uri}    ${body}
-    [Documentation]    Send a PUT with the supplied ${uri} and ${body} (json string) to a ${controller_index}
-    ...    and check the data is replicated in all instances in ${controller_index_list}.
+    [Documentation]    Wrapper keyword for "Create Data And Check At URI In Cluster" using PUT
+    Create Data And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${uri}    ${body}    PUT
+
+Post And Check At URI In Cluster
+    [Arguments]    ${controller_index_list}    ${controller_index}    ${uri}    ${body}
+    [Documentation]    Wrapper keyword for "Create Data And Check At URI In Cluster" using POST
+    Create Data And Check At URI In Cluster    ${controller_index_list}    ${controller_index}    ${uri}    ${body}    POST
+
+Create Data And Check At URI In Cluster
+    [Arguments]    ${controller_index_list}    ${controller_index}    ${uri}    ${body}    ${create_method}=PUT
+    [Documentation]    Send a ${create_method} REST call with the supplied ${uri} and ${body} (json string) to a
+    ...    ${controller_index} and check the data is replicated in all instances in ${controller_index_list}.
     ${expected_body}=    Hsf Json    ${body}
     Log    ${body}
-    ${resp}    RequestsLibrary.Put Request    controller${controller_index}    ${uri}    data=${body}    headers=${HEADERS_YANG_JSON}
+    ${resp}    Run Keyword If    "${create_method}" == "POST"    RequestsLibrary.Post Request    controller${controller_index}    ${uri}    data=${body}    headers=${HEADERS}
+    ...    ELSE    RequestsLibrary.Put Request    controller${controller_index}    ${uri}    data=${body}    headers=${HEADERS_YANG_JSON}
     Log    ${resp.content}
     Log    ${resp.status_code}
     ${status_code}=    Convert To String    ${resp.status_code}
@@ -97,6 +171,7 @@ Start Multiple Controllers
     [Documentation]    Give this keyword a scalar or list of controllers to be started.
     : FOR    ${i}    IN    @{controller_index_list}
     \    ${output}=    Utils.Run Command On Controller    ${ODL_SYSTEM_${i}_IP}    ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
+    : FOR    ${i}    IN    @{controller_index_list}
     \    ClusterKeywords.Wait For Controller Sync    ${timeout}    ${ODL_SYSTEM_${i}_IP}
 
 Get Controller List
@@ -143,6 +218,13 @@ Stop One Or More Controllers
     : FOR    ${ip}    IN    @{controllers}
     \    Run Command On Remote System    ${ip}    ${cmd}
 
+Stop Controller Node And Verify
+    [Arguments]    ${node}
+    [Documentation]    Stops the given node
+    @{leader_list}=    BuiltIn.Create List    ${node}
+    Kill One Or More Controllers    @{leader_list}
+    Controller Down Check    ${node}
+
 Kill One Or More Controllers
     [Arguments]    @{controllers}
     [Documentation]    Give this keyword a scalar or list of controllers to be stopped.
@@ -178,6 +260,13 @@ Start One Or More Controllers
     : FOR    ${ip}    IN    @{controllers}
     \    Run Command On Remote System    ${ip}    ${cmd}
 
+Start Controller Node And Verify
+    [Arguments]    ${node}    ${start_timeout}
+    [Documentation]    Starts the given node
+    @{controllers}=    BuiltIn.CreateList    ${node}
+    Start One Or More Controllers    @{controllers}
+    Wait For Controller Sync    ${start_timeout}    @{controllers}
+
 Wait For Cluster Sync
     [Arguments]    ${timeout}    @{controllers}
     [Documentation]    Waits for one or more clustered controllers to report Sync Status as true.
@@ -205,7 +294,7 @@ Controller Sync Status Should Be False
 Get Controller Sync Status
     [Arguments]    ${controller_ip}
     [Documentation]    Return Sync Status.
-    Create_Session    session    http://${controller_ip}:${RESTCONFPORT}    headers=${HEADERS}    auth=${AUTH}
+    Create_Session    session    http://${controller_ip}:${RESTCONFPORT}    headers=${HEADERS}    auth=${AUTH}    max_retries=0
     ${data}=    Get Data From URI    session    ${jolokia_conf}
     Log    ${data}
     ${json}=    To Json    ${data}
@@ -288,12 +377,12 @@ Rejoin One Controller To Another
 Modify IPTables
     [Arguments]    ${isolated controller}    ${controller}    ${rule type}
     [Documentation]    Adds a rule, usually inserting or deleting an entry between two controllers.
-    ${base string}    Set Variable    sudo iptables ${rule type} OUTPUT -p all --source
+    ${base string}    Set Variable    sudo /sbin/iptables ${rule type} OUTPUT -p all --source
     ${cmd string}    Catenate    ${base string}    ${isolated controller} --destination ${controller} -j DROP
     Run Command On Remote System    ${isolated controller}    ${cmd string}
     ${cmd string}    Catenate    ${base string}    ${controller} --destination ${isolated controller} -j DROP
     Run Command On Remote System    ${isolated controller}    ${cmd string}
-    ${cmd string}    Set Variable    sudo iptables -L -n
+    ${cmd string}    Set Variable    sudo /sbin/iptables -L -n
     ${return string}=    Run Command On Remote System    ${isolated controller}    ${cmd string}
     #If inserting rules:
     Run Keyword If    "${rule type}" == '-I'    Should Match Regexp    ${return string}    [\s\S]*DROP *all *-- *${isolated controller} *${controller}[\s\S]*
@@ -312,7 +401,7 @@ Flush IPTables
     [Arguments]    ${isolated controller}
     [Documentation]    This keyword is generally not called from a test case but supports a complete wipe of all rules on
     ...    all contollers.
-    ${cmd string}    Set Variable    sudo iptables -v -F
+    ${cmd string}    Set Variable    sudo /sbin/iptables -v -F
     ${return string}=    Run Command On Remote System    ${isolated controller}    ${cmd string}
     Log    return: ${return string}
     Should Contain    ${return string}    Flushing chain `INPUT'