Bug 4267: Fix Tcpmd5user suite 43/26643/16
authorVratko Polak <vrpolak@cisco.com>
Thu, 10 Sep 2015 10:53:18 +0000 (12:53 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 15 Sep 2015 23:27:28 +0000 (23:27 +0000)
Bug 3753 was causing failures that can be avoided by
making changes described at Bug 4267.
The tcpmd5user suite was changes to both detect Bug 3753 symptom
and apply the workaround so that testing can proceed.

This required changes to ConfigViaRestconf library:
+ Added GET methods, useful for checking the configuration change was applied.
+ Added support for JSON data.
+ Including normalization provided by HsfJson library.
+ Deviations are now Logged as diff.
+ Configurable workspace to store files being diffed.
+ All this in Verify_* keywords.
+ Added "Readme" text to library documentation.

Change-Id: I52edd0503620f2459ff829dc786bfe208d9242b7
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
csit/libraries/ConfigViaRestconf.robot
csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot
csit/variables/Variables.py
csit/variables/tcpmd5user/pcep_dispatcher_module/config.uri [new file with mode: 0644]
csit/variables/tcpmd5user/pcep_dispatcher_module/data.json [new file with mode: 0644]
csit/variables/tcpmd5user/pcep_dispatcher_module/data.xml [new file with mode: 0644]

index 189d23e75b817ef06ff0f87f180084d2978dfa7c..dd83c246bd43dfcece5564f25eeb61478dc3b260 100644 (file)
@@ -6,20 +6,49 @@ Documentation     Robot keyword library (Resource) for runtime changes to config
 ...               This program and the accompanying materials are made available under the
 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
+...
+...
+...               The purpose of this library is to make runtime changes to ODL configuration
+...               easier from Robot suite contributor point of view.
+...
+...               Different ODL parts have varying ways of configuration,
+...               this library affects only the Config Subsystem way.
+...               Config Subsystem has (apart Java APIs mostly available only from inside of ODL)
+...               NETCONF server as its publicly available entry point.
+...               Netconf-connector feature makes this netconf server available for RESTCONF calls.
+...               Unfortunately, URIs and data payloads tend to be quite convoluted,
+...               so using RequestsLibrary directly from test cases is unwieldy.
+...
+...               The main strength of this library are *_Template_Folder_Config_Via_Restconf keywords
+...               User gives a path to directory where files with templates for URI fragment
+...               and XML (or JSON) data are present, and a mapping with substitution to make;
+...               the keywords will take it from there.
+...
+...               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).
 Library           OperatingSystem
 Library           RequestsLibrary
 Library           String
+Library           ${CURDIR}/HsfJson/hsf_json.py
 Variables         ${CURDIR}/../variables/Variables.py
 
 *** Variables ***
 # TODO: Make the following list more narrow when Bug 2594 is fixed.
 @{allowed_status_codes}    ${200}    ${201}    ${204}    # List of integers, not strings. Used by both PUT and DELETE.
+cvr_workspace     /tmp
 
 *** Keywords ***
 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.
     # 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}
+    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
 
 Teardown_Config_Via_Restconf
     [Documentation]    Teardown to pair with Setup (otherwise no-op).
@@ -33,6 +62,47 @@ Put_Xml_Template_Folder_Config_Via_Restconf
     ${xml_data}=    Resolve_Xml_Data_From_Template_Folder    ${folder}    ${mapping_as_string}
     Put_Xml_Config_Via_Restconf    ${uri_part}    ${xml_data}
 
+Get_Xml_Template_Folder_Config_Via_Restconf
+    [Arguments]    ${folder}    ${mapping_as_string}={}
+    [Documentation]    Resolve URI from folder, GET from controller config in XML form.
+    ${uri_part}=    Resolve_URI_From_Template_Folder    ${folder}    ${mapping_as_string}
+    ${xml_data}=    Get_Xml_Config_Via_Restconf    ${uri_part}
+    [Return]    ${xml_data}
+
+Get_Json_Template_Folder_Config_Via_Restconf
+    [Arguments]    ${folder}    ${mapping_as_string}={}
+    [Documentation]    Resolve URI from folder, GET from controller config in JSON form.
+    ${uri_part}=    Resolve_URI_From_Template_Folder    ${folder}    ${mapping_as_string}
+    ${json_string}=    Get_Json_Config_Via_Restconf    ${uri_part}
+    [Return]    ${json_string}
+
+Verify_Xml_Template_Folder_Config_Via_Restconf
+    [Arguments]    ${folder}    ${mapping_as_string}={}
+    [Documentation]    Resolve URI from folder, GET from controller config, compare to expected data.
+    # FIXME: This is subject to pseudorandom field ordering issue, use with care.
+    ${expected_data}=    Resolve_Xml_Data_From_Template_Folder    ${folder}    ${mapping_as_string}
+    ${actual_data}=    Get_Xml_Template_Folder_Config_Via_Restconf    ${folder}    ${mapping_as_string}
+    BuiltIn.Should_Be_Equal    ${actual_data}    ${expected_data}
+
+Verify_Json_Template_Folder_Config_Via_Restconf
+    [Arguments]    ${folder}    ${mapping_as_string}={}
+    [Documentation]    Resolve URI from folder, GET from controller config, compare to expected data as normalized JSONs.
+    ${expected}=    Resolve_Json_Data_From_Template_Folder    ${folder}    ${mapping_as_string}
+    ${actual}=    Get_Json_Template_Folder_Config_Via_Restconf    ${folder}    ${mapping_as_string}
+    Normalize_Jsons_And_Compare    ${actual}    ${expected}
+
+Normalize_Jsons_And_Compare
+    [Arguments]    ${actual_raw}    ${expected_raw}
+    [Documentation]    Use HsfJson to normalize both arguments, compute and Log diff, fail if diff is non-empty.
+    ...    This keywords assumes ${WORKSPACE} is defined as a suite variable.
+    ${actual_normalized}=    hsf_json.Hsf_Json    ${actual_raw}
+    ${expected_normalized}=    hsf_json.Hsf_Json    ${expected_raw}
+    OperatingSystem.Create_File    ${cvr_expfile}    ${expected_normalized}
+    OperatingSystem.Create_File    ${cvr_actfile}    ${actual_normalized}
+    ${diff}=    OperatingSystem.Run    diff -du '${cvr_expfile}' '${cvr_actfile}'
+    BuiltIn.Log    ${diff}
+    BuiltIn.Should_Be_Empty    ${diff}
+
 Delete_Xml_Template_Folder_Config_Via_Restconf
     [Arguments]    ${folder}    ${mapping_as_string}={}
     [Documentation]    Resolve URI from folder, DELETE from controller config.
@@ -49,12 +119,20 @@ Resolve_URI_From_Template_Folder
 
 Resolve_Xml_Data_From_Template_Folder
     [Arguments]    ${folder}    ${mapping_as_string}
-    [Documentation]    Read data template from folder, strip endline, make changes according to mapping, return the result.
+    [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
     BuiltIn.Log    ${data_template}
     ${xml_data}=    Strip_Endline_And_Apply_Substitutions_From_Mapping    ${data_template}    ${mapping_as_string}
     [Return]    ${xml_data}
 
+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
+    BuiltIn.Log    ${data_template}
+    ${json_data}=    Strip_Endline_And_Apply_Substitutions_From_Mapping    ${data_template}    ${mapping_as_string}
+    [Return]    ${json_data}
+
 Strip_Endline_And_Apply_Substitutions_From_Mapping
     [Arguments]    ${template_as_string}    ${mapping_as_string}
     [Documentation]    Strip endline, apply substitutions, Log and return the result.
@@ -87,6 +165,26 @@ Put_Xml_Config_Via_Restconf
     BuiltIn.Should_Be_Empty    ${response.text}
     BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
 
+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}
+    BuiltIn.Log    ${response.text}
+    BuiltIn.Log    ${response.status_code}
+    BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
+    [Return]    ${response.text}
+
+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}
+    BuiltIn.Log    ${response.text}
+    BuiltIn.Log    ${response.status_code}
+    BuiltIn.Should_Contain    ${allowed_status_codes}    ${response.status_code}
+    [Return]    ${response.text}
+
 Delete_Config_Via_Restconf
     [Arguments]    ${uri_part}
     [Documentation]    Delete resource at controller-config URI, check reponse text is empty and status_code is 204.
index 606aa98a5b10356824e5da061ba09b07f816d196..c89209d118fe7986ed619d63a93cf6c8e49a94ee 100644 (file)
@@ -64,6 +64,13 @@ Enable_Tcpmd5_No_Password_Yet
     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_server_channel_module
     # TODO: Is it worth changing ConfigViaRestconf to read ${directory_with_template_folders} variable by default?
 
+Check_For_Bug_3753_Via_Bug_4267
+    [Documentation]    Check state of disptcher configuration module, apply workaround if needed.
+    ...    This test case should not be failing, failure indicates Bug 3753 was not fixed enough yet.
+    ...    For more details, see https://bugs.opendaylight.org/show_bug.cgi?id=4267#c2
+    ConfigViaRestconf.Verify_Json_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_dispatcher_module
+    [Teardown]    BuiltIn.Run_Keyword_If_Test_Failed    ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_dispatcher_module
+
 Topology_Unauthorized_2
     [Documentation]    The same logic as Topology_Unauthorized_1 as no password was provided to ODL.
     [Tags]    critical
index 17e6f3adf3bcfcdf5eb4681db6dde4b81d1be868..89c0295f6257a589b41dd513ca13e42fb47cc71e 100644 (file)
@@ -20,6 +20,7 @@ SCOPE = 'sdn'
 HEADERS = {'Content-Type': 'application/json'}
 HEADERS_XML = {'Content-Type': 'application/xml'}
 ACCEPT_XML = {'Accept': 'application/xml'}
+ACCEPT_JSON = {'Accept': 'application/json'}
 ODL_CONTROLLER_SESSION = None
 TOPO_TREE_LEVEL = 2
 TOPO_TREE_DEPTH = 3
diff --git a/csit/variables/tcpmd5user/pcep_dispatcher_module/config.uri b/csit/variables/tcpmd5user/pcep_dispatcher_module/config.uri
new file mode 100644 (file)
index 0000000..89fc159
--- /dev/null
@@ -0,0 +1 @@
+config:modules/module/odl-pcep-impl-cfg:pcep-dispatcher-impl/global-pcep-dispatcher?prettyPrint=true
diff --git a/csit/variables/tcpmd5user/pcep_dispatcher_module/data.json b/csit/variables/tcpmd5user/pcep_dispatcher_module/data.json
new file mode 100644 (file)
index 0000000..5b91e3d
--- /dev/null
@@ -0,0 +1,33 @@
+{
+ "module": [
+  {
+   "type": "odl-pcep-impl-cfg:pcep-dispatcher-impl",
+   "name": "global-pcep-dispatcher",
+   "odl-pcep-impl-cfg:boss-group": {
+    "type": "netty:netty-threadgroup",
+    "name": "global-boss-group"
+   },
+   "odl-pcep-impl-cfg:max-unknown-messages": 5,
+   "odl-pcep-impl-cfg:md5-server-channel-factory": {
+    "type": "odl-tcpmd5-netty-cfg:md5-server-channel-factory",
+    "name": "md5-server-channel-factory"
+   },
+   "odl-pcep-impl-cfg:md5-channel-factory": {
+    "type": "odl-tcpmd5-netty-cfg:md5-channel-factory",
+    "name": "md5-client-channel-factory"
+   },
+   "odl-pcep-impl-cfg:pcep-extensions": {
+    "type": "odl-pcep-spi-cfg:extensions",
+    "name": "global-pcep-extensions"
+   },
+   "odl-pcep-impl-cfg:pcep-session-proposal-factory": {
+    "type": "odl-pcep-api-cfg:pcep-session-proposal-factory",
+    "name": "pcep-session-proposal-factory-sr"
+   },
+   "odl-pcep-impl-cfg:worker-group": {
+    "type": "netty:netty-threadgroup",
+    "name": "global-worker-group"
+   }
+  }
+ ]
+}
\ No newline at end of file
diff --git a/csit/variables/tcpmd5user/pcep_dispatcher_module/data.xml b/csit/variables/tcpmd5user/pcep_dispatcher_module/data.xml
new file mode 100644 (file)
index 0000000..49c098f
--- /dev/null
@@ -0,0 +1,29 @@
+<module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+ <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">x:pcep-dispatcher-impl</type>
+ <name>global-pcep-dispatcher</name>
+ <pcep-extensions xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep:spi">x:extensions</type>
+  <name>global-pcep-extensions</name>
+ </pcep-extensions>
+ <pcep-session-proposal-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:pcep">x:pcep-session-proposal-factory</type>
+  <name>pcep-session-proposal-factory-sr</name>
+ </pcep-session-proposal-factory>
+ <boss-group xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:netty">x:netty-threadgroup</type>
+  <name>global-boss-group</name>
+ </boss-group>
+ <worker-group xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:netty">x:netty-threadgroup</type>
+  <name>global-worker-group</name>
+ </worker-group>
+ <max-unknown-messages xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">5</max-unknown-messages>
+ <md5-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-channel-factory</type>
+  <name>md5-client-channel-factory</name>
+ </md5-channel-factory>
+ <md5-server-channel-factory xmlns="urn:opendaylight:params:xml:ns:yang:controller:pcep:impl">
+  <type xmlns:x="urn:opendaylight:params:xml:ns:yang:controller:tcpmd5:netty:cfg">x:md5-server-channel-factory</type>
+  <name>md5-server-channel-factory</name>
+ </md5-server-channel-factory>
+</module>