fixing play.py and data change counter
[integration/test.git] / csit / libraries / ConfigViaRestconf.robot
index d421beb2781de9893b9fc33a1451a73d13b41eab..8c78556e125d71d6a92ffcaa98bafc5f40989ffc 100644 (file)
@@ -26,8 +26,8 @@ Documentation     Robot keyword library (Resource) for runtime changes to config
 ...
 ...               Prerequisities:
 ...               * netconf-connector feature installed on ODL.
-...               * Setup_Config_Via_Restconf called from suite Setup once
-...               (or before any other keyword from this library, but just once).
+...               * Setup_Config_Via_Restconf called from suite Setup
+...               (or before any other call to a keyword from this library) at least once.
 Library           OperatingSystem
 Library           RequestsLibrary
 Library           String
@@ -43,9 +43,12 @@ ${cvr_workspace}    /tmp
 Setup_Config_Via_Restconf
     [Documentation]    Creates Requests session to be used by subsequent keywords.
     ...    Also remembers worspace to use when needed and two temp files for JSON data.
+    # Check for multiple Setup calls.
+    ${variable_was_set}=    BuiltIn.Get_Variable_Value    ${cvr_actfile}    NEVER
+    BuiltIn.Return_From_Keyword_If    '''${variable_was_set}''' != '''NEVER'''
     # Do not append slash at the end uf URL, Requests would add another, resulting in error.
-    RequestsLibrary.Create_Session    cvr_session    http://${CONTROLLER}:${RESTCONFPORT}${CONTROLLER_CONFIG_MOUNT}    headers=${HEADERS_XML}    auth=${AUTH}
-    ${workspace_defined}    BuiltIn.Run_Keyword_And_return_Status    BuiltIn.Variable_Should_Exist    ${WORKSPACE}
+    RequestsLibrary.Create_Session    cvr_session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${CONTROLLER_CONFIG_MOUNT}    headers=${HEADERS_XML}    auth=${AUTH}
+    ${workspace_defined}=    BuiltIn.Run_Keyword_And_return_Status    BuiltIn.Variable_Should_Exist    ${WORKSPACE}
     BuiltIn.Run_Keyword_If    ${workspace_defined}    BuiltIn.Set_Suite_Variable    ${cvr_workspace}    ${WORKSPACE}
     BuiltIn.Set_Suite_Variable    ${cvr_actfile}    ${cvr_workspace}${/}actual.json
     BuiltIn.Set_Suite_Variable    ${cvr_expfile}    ${cvr_workspace}${/}expected.json
@@ -112,7 +115,8 @@ Delete_Xml_Template_Folder_Config_Via_Restconf
 Resolve_URI_From_Template_Folder
     [Arguments]    ${folder}    ${mapping_as_string}
     [Documentation]    Read URI template from folder, strip endline, make changes according to mapping, return the result.
-    ${uri_template}=    OperatingSystem.Get_File    ${folder}${/}config.uri
+    ${status}    ${uri_template}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get_File    ${folder}${/}config.uri.${ODL_STREAM}
+    ${uri_template}=     BuiltIn.Run Keyword If     '${status}' != 'PASS'    OperatingSystem.Get_File    ${folder}${/}config.uri    ELSE   BuiltIn.Set Variable    ${uri_template}
     BuiltIn.Log    ${uri_template}
     ${uri_part}=    Strip_Endline_And_Apply_Substitutions_From_Mapping    ${uri_template}    ${mapping_as_string}
     [Return]    ${uri_part}
@@ -120,7 +124,8 @@ Resolve_URI_From_Template_Folder
 Resolve_Xml_Data_From_Template_Folder
     [Arguments]    ${folder}    ${mapping_as_string}
     [Documentation]    Read XML data template from folder, strip endline, make changes according to mapping, return the result.
-    ${data_template}=    OperatingSystem.Get_File    ${folder}${/}data.xml
+    ${status}    ${data_template}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get_File    ${folder}${/}data.xml.${ODL_STREAM}
+    ${data_template}=     BuiltIn.Run Keyword If     '${status}' != 'PASS'    OperatingSystem.Get_File    ${folder}${/}data.xml    ELSE   BuiltIn.Set Variable    ${data_template}
     BuiltIn.Log    ${data_template}
     ${xml_data}=    Strip_Endline_And_Apply_Substitutions_From_Mapping    ${data_template}    ${mapping_as_string}
     [Return]    ${xml_data}
@@ -128,7 +133,8 @@ Resolve_Xml_Data_From_Template_Folder
 Resolve_Json_Data_From_Template_Folder
     [Arguments]    ${folder}    ${mapping_as_string}
     [Documentation]    Read JSON data template from folder, strip endline, make changes according to mapping, return the result.
-    ${data_template}=    OperatingSystem.Get_File    ${folder}${/}data.json
+    ${status}    ${data_template}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get_File    ${folder}${/}data.json.${ODL_STREAM}
+    ${data_template}=     BuiltIn.Run Keyword If     '${status}' != 'PASS'    OperatingSystem.Get_File    ${folder}${/}data.json    ELSE   BuiltIn.Set Variable    ${data_template}
     BuiltIn.Log    ${data_template}
     ${json_data}=    Strip_Endline_And_Apply_Substitutions_From_Mapping    ${data_template}    ${mapping_as_string}
     [Return]    ${json_data}
@@ -159,7 +165,7 @@ Put_Xml_Config_Via_Restconf
     [Documentation]    Put XML data to given controller-config URI, check reponse text is empty and status_code is one of allowed ones.
     BuiltIn.Log    ${uri_part}
     BuiltIn.Log    ${xml_data}
-    ${response}=    RequestsLibrary.Put    cvr_session    ${uri_part}    data=${xml_data}
+    ${response}=    RequestsLibrary.Put Request    cvr_session    ${uri_part}    data=${xml_data}
     BuiltIn.Log    ${response.text}
     BuiltIn.Log    ${response.status_code}
     BuiltIn.Should_Be_Empty    ${response.text}
@@ -169,7 +175,7 @@ Get_Xml_Config_Via_Restconf
     [Arguments]    ${uri_part}
     [Documentation]    Get XML data from given controller-config URI, check status_code is one of allowed ones, return response text.
     BuiltIn.Log    ${uri_part}
-    ${response}=    RequestsLibrary.Get    cvr_session    ${uri_part}    headers=${ACCEPT_XML}
+    ${response}=    RequestsLibrary.Get Request    cvr_session    ${uri_part}    headers=${ACCEPT_XML}
     BuiltIn.Log    ${response.text}
     BuiltIn.Log    ${response.status_code}
     BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
@@ -179,7 +185,7 @@ Get_Json_Config_Via_Restconf
     [Arguments]    ${uri_part}
     [Documentation]    Get XML data from given controller-config URI, check status_code is one of allowed ones, return response text.
     BuiltIn.Log    ${uri_part}
-    ${response}=    RequestsLibrary.Get    cvr_session    ${uri_part}    headers=${ACCEPT_JSON}
+    ${response}=    RequestsLibrary.Get Request    cvr_session    ${uri_part}    headers=${ACCEPT_JSON}
     BuiltIn.Log    ${response.text}
     BuiltIn.Log    ${response.status_code}
     BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
@@ -189,7 +195,7 @@ Delete_Config_Via_Restconf
     [Arguments]    ${uri_part}
     [Documentation]    Delete resource at controller-config URI, check reponse text is empty and status_code is 204.
     BuiltIn.Log    ${uri_part}
-    ${response}=    RequestsLibrary.Delete    cvr_session    ${uri_part}
+    ${response}=    RequestsLibrary.Delete Request    cvr_session    ${uri_part}
     BuiltIn.Log    ${response.text}
     BuiltIn.Should_Be_Empty    ${response.text}
     BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
@@ -214,4 +220,5 @@ Post_Xml_Config_Via_Restconf
     ${response}=    RequestsLibrary.Post_Request    cvr_session    ${uri_part}    data=${xml_data}
     BuiltIn.Log    ${response.text}
     BuiltIn.Should_Be_Empty    ${response.text}
+    # TODO: status_code is integrer, so compare to ${204}. Also, there is a Improvement for 201 to be a better code.
     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    204