From dd8f2cc400082ac6b70a8644de0243d1f83dc21d Mon Sep 17 00:00:00 2001 From: lbuckuli Date: Thu, 29 Sep 2016 16:29:09 +0000 Subject: [PATCH] Edited suites to use norm_json.py instead of HsfJson Change-Id: I3cf78a44420f6e7e18b90ae4c87cc352a327f334 Signed-off-by: lbuckuli Signed-off-by: Shrutika Ingole --- csit/libraries/ConfigViaRestconf.robot | 6 +-- csit/libraries/HsfJson/hsf_json.py | 52 ------------------- csit/libraries/HsfJson/hsfl.py | 36 ------------- csit/libraries/HsfJson/hsfod.py | 41 --------------- csit/libraries/PcepOperations.robot | 6 +-- .../bgpcep/bgpuser/bgp_app_peer_basic.robot | 6 +-- csit/suites/bgpcep/bgpuser/cases.robot | 6 +-- .../bgpcep/bgpuser/ebgp_peers_basic.robot | 1 - .../bgpcep/bgpuser/ibgp_peers_basic.robot | 1 - csit/suites/bgpcep/pcepuser/pcepuser.robot | 6 +-- .../suites/bgpcep/tcpmd5user/tcpmd5user.robot | 6 +-- .../notifications/notifications_basic.robot | 1 - 12 files changed, 18 insertions(+), 150 deletions(-) delete mode 100644 csit/libraries/HsfJson/hsf_json.py delete mode 100644 csit/libraries/HsfJson/hsfl.py delete mode 100644 csit/libraries/HsfJson/hsfod.py diff --git a/csit/libraries/ConfigViaRestconf.robot b/csit/libraries/ConfigViaRestconf.robot index 28a7521ab0..384356357f 100644 --- a/csit/libraries/ConfigViaRestconf.robot +++ b/csit/libraries/ConfigViaRestconf.robot @@ -31,7 +31,7 @@ Documentation Robot keyword library (Resource) for runtime changes to config Library OperatingSystem Library RequestsLibrary Library String -Library ${CURDIR}/HsfJson/hsf_json.py +Library ${CURDIR}/norm_json.py Variables ${CURDIR}/../variables/Variables.py *** Variables *** @@ -98,8 +98,8 @@ Normalize_Jsons_Save_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} + ${actual_normalized}= norm_json.normalize_json_text ${actual_raw} + ${expected_normalized}= norm_json.normalize_json_text ${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}' diff --git a/csit/libraries/HsfJson/hsf_json.py b/csit/libraries/HsfJson/hsf_json.py deleted file mode 100644 index f581e66c3d..0000000000 --- a/csit/libraries/HsfJson/hsf_json.py +++ /dev/null @@ -1,52 +0,0 @@ -"""This module contains single a function for normalizing JSON strings.""" -# Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. -# -# 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 -# -# FIXME: Use ${CURDIR}/../norm_json.py everywhere, then delete ${CURDIR}. -# https://trello.com/c/N3s0xhc6/260-rename-hfsjson-hsf-json-py-to-something-friendlier - -try: - import simplejson as _json -except ImportError: # Python2.7 calls it json. - import json as _json -from hsfl import Hsfl as _Hsfl -from hsfod import Hsfod as _Hsfod - - -__author__ = "Vratko Polak" -__copyright__ = "Copyright(c) 2015, Cisco Systems, Inc." -__license__ = "Eclipse Public License v1.0" -__email__ = "vrpolak@cisco.com" - - -def _hsfl_array(s_and_end, scan_once, **kwargs): - """Scan JSON array as usual, but return hsfl instead of list.""" - values, end = _json.decoder.JSONArray(s_and_end, scan_once, **kwargs) - return _Hsfl(values), end - - -class _Decoder(_json.JSONDecoder): - """Private class to act as customized JSON decoder. - - Based on: http://stackoverflow.com/questions/10885238/ - python-change-list-type-for-json-decoding""" - def __init__(self, **kwargs): - """Initialize decoder with special array implementation.""" - _json.JSONDecoder.__init__(self, **kwargs) - # Use the custom JSONArray - self.parse_array = _hsfl_array - # Use the python implemenation of the scanner - self.scan_once = _json.scanner.py_make_scanner(self) - - -def hsf_json(text): # pylint likes lowercase, Robot shall understand Hsf_Json - """Return sorted indented JSON string, or an error message string.""" - try: - object_decoded = _json.loads(text, cls=_Decoder, object_hook=_Hsfod) - except ValueError as err: - return str(err) + '\n' + text - pretty_json = _json.dumps(object_decoded, separators=(',', ': '), indent=1) - return pretty_json + '\n' # to avoid diff "no newline" warning line diff --git a/csit/libraries/HsfJson/hsfl.py b/csit/libraries/HsfJson/hsfl.py deleted file mode 100644 index 99e70a41b1..0000000000 --- a/csit/libraries/HsfJson/hsfl.py +++ /dev/null @@ -1,36 +0,0 @@ -"""This module contains single class, to store a sorted list.""" -# Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. -# -# 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 - -__author__ = "Vratko Polak" -__copyright__ = "Copyright(c) 2015, Cisco Systems, Inc." -__license__ = "Eclipse Public License v1.0" -__email__ = "vrpolak@cisco.com" - - -class Hsfl(list): - """ - Hashable sorted frozen list implementation stub. - - Supports only __init__, __repr__ and __hash__ methods. - Other list methods are available, but they may break contract. - """ - - def __init__(self, *args, **kwargs): - """Contruct super, sort and compute repr and hash cache values.""" - sup = super(Hsfl, self) - sup.__init__(*args, **kwargs) - sup.sort(key=repr) - self.__repr = repr(tuple(self)) - self.__hash = hash(self.__repr) - - def __repr__(self): - """Return cached repr string.""" - return self.__repr - - def __hash__(self): - """Return cached hash.""" - return self.__hash diff --git a/csit/libraries/HsfJson/hsfod.py b/csit/libraries/HsfJson/hsfod.py deleted file mode 100644 index 39fd312b35..0000000000 --- a/csit/libraries/HsfJson/hsfod.py +++ /dev/null @@ -1,41 +0,0 @@ -"""This module contains single class, to store a sorted dict.""" -# Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. -# -# 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 - -import collections as _collections - - -__author__ = "Vratko Polak" -__copyright__ = "Copyright(c) 2015, Cisco Systems, Inc." -__license__ = "Eclipse Public License v1.0" -__email__ = "vrpolak@cisco.com" - - -class Hsfod(_collections.OrderedDict): - """ - Hashable sorted (by key) frozen OrderedDict implementation stub. - - Supports only __init__, __repr__ and __hash__ methods. - Other OrderedDict methods are available, but they may break contract. - """ - - def __init__(self, *args, **kwargs): - """Put arguments to OrderedDict, sort, pass to super, cache values.""" - self_unsorted = _collections.OrderedDict(*args, **kwargs) - items_sorted = sorted(self_unsorted.items(), key=repr) - sup = super(Hsfod, self) # possibly something else than OrderedDict - sup.__init__(items_sorted) - # Repr string is used for sorting, keys are more important than values. - self.__repr = '{' + repr(self.keys()) + ':' + repr(self.values()) + '}' - self.__hash = hash(self.__repr) - - def __repr__(self): - """Return cached repr string.""" - return self.__repr - - def __hash__(self): - """Return cached hash.""" - return self.__hash diff --git a/csit/libraries/PcepOperations.robot b/csit/libraries/PcepOperations.robot index 78130a83f1..1d6478ef96 100644 --- a/csit/libraries/PcepOperations.robot +++ b/csit/libraries/PcepOperations.robot @@ -7,7 +7,7 @@ Documentation Robot keyword library (Resource) for performing PCEP operation ... terms of the Eclipse Public License v1.0 which accompanies this distribution, ... and is available at http://www.eclipse.org/legal/epl-v10.html Library RequestsLibrary -Library ${CURDIR}/HsfJson/hsf_json.py +Library ${CURDIR}/norm_json.py Variables ${CURDIR}/../variables/Variables.py *** Keywords *** @@ -59,7 +59,7 @@ Pcep_Json_Is_Refused [Documentation] Given text should be equal to json response when device refuses tunnel removal. ${expected_raw}= BuiltIn.Set_Variable {"output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}} # TODO: Is that JSON worth referencing pcepuser variables from this library? - ${expected_normalized}= hsf_json.hsf_json ${expected_raw} - ${actual_normalized}= hsf_json.hsf_json ${actual_raw} + ${expected_normalized}= norm_json.normalize_json_text ${expected_raw} + ${actual_normalized}= norm_json.normalize_json_text ${actual_raw} BuiltIn.Should_Be_Equal ${actual_normalized} ${expected_normalized} # TODO: Would the diff approach be more useful? diff --git a/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot b/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot index 291462b63b..fbef0807e5 100644 --- a/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot +++ b/csit/suites/bgpcep/bgpuser/bgp_app_peer_basic.robot @@ -54,7 +54,7 @@ Test Teardown FailFast.Start_Failing_Fast_If_This_Failed Library OperatingSystem Library SSHLibrary timeout=10s Library RequestsLibrary -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py +Library ${CURDIR}/../../../libraries/norm_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${TOOLS_SYSTEM_IP} ${ODL_STREAM} Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot @@ -377,8 +377,8 @@ Compare_Topology Normalize_And_Save_Expected_Json [Arguments] ${json_text} ${filename} ${directory} - [Documentation] Normalize given json using hsf_json library. Log and save the result to given filename under given directory. - ${json_normalized}= hsf_json.Hsf_Json ${json_text} + [Documentation] Normalize given json using norm_json library. Log and save the result to given filename under given directory. + ${json_normalized}= norm_json.normalize_json_text ${json_text} BuiltIn.Log ${json_normalized} OperatingSystem.Create_File ${directory}${/}${filename} ${json_normalized} # TODO: Should we prepend .json to the filename? When we detect it is not already prepended? diff --git a/csit/suites/bgpcep/bgpuser/cases.robot b/csit/suites/bgpcep/bgpuser/cases.robot index 2debef4d0e..0258d96e17 100644 --- a/csit/suites/bgpcep/bgpuser/cases.robot +++ b/csit/suites/bgpcep/bgpuser/cases.robot @@ -32,7 +32,7 @@ Test Teardown FailFast.Start_Failing_Fast_If_This_Failed Library OperatingSystem Library SSHLibrary timeout=10s Library RequestsLibrary -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py +Library ${CURDIR}/../../../libraries/norm_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${TOOLS_SYSTEM_IP} ${ODL_STREAM} Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot @@ -267,8 +267,8 @@ Compare_Topology Normalize_And_Save_Expected_Json [Arguments] ${json_text} ${filename} ${directory} - [Documentation] Normalize given json using hsf_json library. Log and save the result to given filename under given directory. - ${json_normalized}= hsf_json.Hsf_Json ${json_text} + [Documentation] Normalize given json using norm_json library. Log and save the result to given filename under given directory. + ${json_normalized}= norm_json.normalize_json_text ${json_text} BuiltIn.Log ${json_normalized} OperatingSystem.Create_File ${directory}${/}${filename} ${json_normalized} # TODO: Should we prepend .json to the filename? When we detect it is not already prepended? diff --git a/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot b/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot index 3191254aa4..c122623248 100644 --- a/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot +++ b/csit/suites/bgpcep/bgpuser/ebgp_peers_basic.robot @@ -22,7 +22,6 @@ Test Setup SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing Test Teardown FailFast.Start_Failing_Fast_If_This_Failed Library OperatingSystem Library RequestsLibrary -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${TOOLS_SYSTEM_IP} ${ODL_STREAM} Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot diff --git a/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot b/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot index bcfcdddab9..a9adfef91f 100644 --- a/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot +++ b/csit/suites/bgpcep/bgpuser/ibgp_peers_basic.robot @@ -31,7 +31,6 @@ Test Teardown FailFast.Start_Failing_Fast_If_This_Failed Library OperatingSystem Library RequestsLibrary Library DateTime -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Variables ${CURDIR}/../../../variables/bgpuser/variables.py ${TOOLS_SYSTEM_IP} ${ODL_STREAM} Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot diff --git a/csit/suites/bgpcep/pcepuser/pcepuser.robot b/csit/suites/bgpcep/pcepuser/pcepuser.robot index ee5fd21fa0..f95b29e7cf 100644 --- a/csit/suites/bgpcep/pcepuser/pcepuser.robot +++ b/csit/suites/bgpcep/pcepuser/pcepuser.robot @@ -11,7 +11,7 @@ Suite Teardown Tear_It_Down Library OperatingSystem Library SSHLibrary Library RequestsLibrary -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py +Library ${CURDIR}/../../../libraries/norm_json.py Resource ${CURDIR}/../../../libraries/NexusKeywords.robot Resource ${CURDIR}/../../../libraries/PcepOperations.robot Resource ${CURDIR}/../../../libraries/Utils.robot @@ -133,13 +133,13 @@ Compare_Topology [Documentation] Get current pcep-topology as json, normalize both expected and actual json. ... Save normalized jsons to files for later processing. ... Error codes and normalized jsons should match exactly. - ${normexp}= Hsf_Json ${expected} + ${normexp}= norm_json.normalize_json_text ${expected} Log ${normexp} Create_File ${ExpDir}${/}${name} ${normexp} ${resp}= RequestsLibrary.Get Request ses topology/pcep-topology Log ${resp} Log ${resp.text} - ${normresp}= Hsf_Json ${resp.text} + ${normresp}= norm_json.normalize_json_text ${resp.text} Log ${normresp} Create_File ${ActDir}${/}${name} ${normresp} Should_Be_Equal_As_Strings ${resp.status_code} 200 diff --git a/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot b/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot index 31ee4be88b..b7943296bc 100644 --- a/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot +++ b/csit/suites/bgpcep/tcpmd5user/tcpmd5user.robot @@ -18,7 +18,7 @@ Library OperatingSystem Library RequestsLibrary Library SSHLibrary prompt=]> Library String -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py +Library ${CURDIR}/../../../libraries/norm_json.py Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot Resource ${CURDIR}/../../../libraries/NexusKeywords.robot @@ -173,13 +173,13 @@ Compare_Topology ... Save normalized jsons to files for later processing. ... Error codes and normalized jsons should match exactly. # FIXME: See bgpuser to move handling of expected outside WUKS loop, as in bgpuser suite. - ${normexp}= hsf_json.Hsf_Json ${expected} + ${normexp}= norm_json.normalize_json_text ${expected} BuiltIn.Log ${normexp} OperatingSystem.Create_File ${directory_for_expected_responses}${/}${name} ${normexp} ${resp}= RequestsLibrary.Get_Request ses topology/pcep-topology BuiltIn.Log ${resp} BuiltIn.Log ${resp.text} - ${normresp}= hsf_json.Hsf_Json ${resp.text} + ${normresp}= norm_json.normalize_json_text ${resp.text} BuiltIn.Log ${normresp} OperatingSystem.Create_File ${directory_for_actual_responses}${/}${name} ${normresp} BuiltIn.Should_Be_Equal_As_Strings ${resp.status_code} 200 diff --git a/csit/suites/netconf/notifications/notifications_basic.robot b/csit/suites/netconf/notifications/notifications_basic.robot index 09f08cb053..2d72f6e5e6 100644 --- a/csit/suites/netconf/notifications/notifications_basic.robot +++ b/csit/suites/netconf/notifications/notifications_basic.robot @@ -32,7 +32,6 @@ Library OperatingSystem Library SSHLibrary timeout=10s Library RequestsLibrary Library Collections -Library ${CURDIR}/../../../libraries/HsfJson/hsf_json.py Variables ${CURDIR}/../../../variables/Variables.py Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot Resource ${CURDIR}/../../../libraries/FailFast.robot -- 2.36.6