X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FPapiExecutor.py;h=ecee70c9c5e14ee284c9e65652145bb31a73273b;hp=6b2168052680d6aad636370735ade7d26a13ea03;hb=b6606e7625e308a66bdfb9d5a9c065b58e429a99;hpb=a33b52ae0f255021d89307ebc694f6e907906151 diff --git a/resources/libraries/python/PapiExecutor.py b/resources/libraries/python/PapiExecutor.py index 6b21680526..ecee70c9c5 100644 --- a/resources/libraries/python/PapiExecutor.py +++ b/resources/libraries/python/PapiExecutor.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Cisco and/or its affiliates. +# Copyright (c) 2021 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -23,6 +23,8 @@ import subprocess import sys import tempfile import time +from collections import UserDict + from pprint import pformat from robot.api import logger @@ -67,11 +69,11 @@ def dictize(obj): """ if not hasattr(obj, u"_asdict"): return obj - ret = obj._asdict() - old_get = ret.__getitem__ + overriden = UserDict(obj._asdict()) + old_get = overriden.__getitem__ new_get = lambda self, key: dictize(old_get(self, key)) - ret.__getitem__ = new_get - return ret + overriden.__getitem__ = new_get + return overriden class PapiSocketExecutor: @@ -792,16 +794,17 @@ class PapiSocketExecutor: if not isinstance(reply, list): reply = [reply] for item in reply: - self.crc_checker.check_api_name(item.__class__.__name__) + message_name = item.__class__.__name__ + self.crc_checker.check_api_name(message_name) dict_item = dictize(item) if u"retval" in dict_item.keys(): # *_details messages do not contain retval. retval = dict_item[u"retval"] if retval != exp_rv: - # TODO: What exactly to log and raise here? raise AssertionError( f"Retval {retval!r} does not match expected " - f"retval {exp_rv!r}" + f"retval {exp_rv!r} in message {message_name} " + f"for command {command}." ) replies.append(dict_item) return replies @@ -870,6 +873,8 @@ class PapiExecutor: is "stats". - the second parameter must be 'path' as it is used by PapiExecutor method 'add'. + - even if the parameter contains multiple paths, there is only one + reply item (for each .add). """ def __init__(self, node):