+ return "PapiResponse({str})".format(str=str(self))
+
+ def verify_reply(self, cmd_reply=None, idx=0,
+ err_msg="Failed to verify PAPI reply."):
+ """Verify and return data from the PAPI response.
+
+ Note: Use only with a simple request / reply command. In this case the
+ PAPI reply includes 'retval' which is checked in this method.
+
+ Do not use with 'dump' and 'vpp-stats' methods.
+
+ Use if PAPI response includes only one command reply.
+
+ Use it this way (preferred):
+
+ with PapiExecutor(node) as papi_exec:
+ data = papi_exec.add('show_version').get_replies().verify_reply()
+
+ or if you must provide the expected reply (not recommended):
+
+ with PapiExecutor(node) as papi_exec:
+ data = papi_exec.add('show_version').get_replies().\
+ verify_reply('show_version_reply')
+
+ :param cmd_reply: PAPI reply. If None, list of 'requests' should have
+ been provided to the __init__ method as pre-generated list of
+ replies is used in this method in this case.
+ The PapiExecutor._execute() method provides the requests
+ automatically.
+ :param idx: Index to PapiResponse.reply list.
+ :param err_msg: The message used if the verification fails.
+ :type cmd_reply: str
+ :type idx: int
+ :type err_msg: str or None
+ :returns: Verified data from PAPI response.
+ :rtype: dict
+ :raises AssertionError: If the PAPI return value is not 0, so the reply
+ is not valid.
+ :raises KeyError, IndexError: If the reply does not have expected
+ structure.
+ """
+ cmd_rpl = self.expected_replies[idx] if cmd_reply is None else cmd_reply
+
+ data = self.reply[idx]['api_reply'][cmd_rpl]
+ if data['retval'] != 0:
+ raise AssertionError("{msg}\nidx={idx}, cmd_reply={reply}".
+ format(msg=err_msg, idx=idx, reply=cmd_rpl))
+
+ return data
+
+ def verify_replies(self, cmd_replies=None,
+ err_msg="Failed to verify PAPI reply."):
+ """Verify and return data from the PAPI response.
+
+ Note: Use only with request / reply commands. In this case each
+ PAPI reply includes 'retval' which is checked.
+
+ Do not use with 'dump' and 'vpp-stats' methods.
+
+ Use if PAPI response includes more than one command reply.
+
+ Use it this way:
+
+ with PapiExecutor(node) as papi_exec:
+ papi_exec.add(cmd1, **args1).add(cmd2, **args2).add(cmd2, **args3).\
+ get_replies(err_msg).verify_replies()
+
+ or if you need the data from the PAPI response:
+
+ with PapiExecutor(node) as papi_exec:
+ data = papi_exec.add(cmd1, **args1).add(cmd2, **args2).\
+ add(cmd2, **args3).get_replies(err_msg).verify_replies()
+
+ or if you must provide the list of expected replies (not recommended):
+
+ with PapiExecutor(node) as papi_exec:
+ data = papi_exec.add(cmd1, **args1).add(cmd2, **args2).\
+ add(cmd2, **args3).get_replies(err_msg).\
+ verify_replies(cmd_replies=cmd_replies)
+
+ :param cmd_replies: List of PAPI command replies. If None, list of
+ 'requests' should have been provided to the __init__ method as
+ pre-generated list of replies is used in this method in this case.
+ The PapiExecutor._execute() method provides the requests
+ automatically.
+ :param err_msg: The message used if the verification fails.
+ :type cmd_replies: list of str or None
+ :type err_msg: str
+ :returns: List of verified data from PAPI response.
+ :rtype list
+ :raises AssertionError: If the PAPI response does not include at least
+ one of specified command replies.
+ """
+ data = list()
+
+ cmd_rpls = self.expected_replies if cmd_replies is None else cmd_replies
+
+ if len(self.reply) != len(cmd_rpls):
+ raise AssertionError(err_msg)
+ for idx, cmd_reply in enumerate(cmd_rpls):
+ data.append(self.verify_reply(cmd_reply, idx, err_msg))
+
+ return data