MCPcopy Create free account
hub / github.com/FDio/vpp / api

Method api

test/vpp_papi_provider.py:385–447  ·  view source on GitHub ↗

Call API function and check it's return value. Call the appropriate hooks before and after the API call :param api_fn: API function to call :param api_args: tuple of API function arguments :param expected_retval: Expected return value(s) (Default value = 0) :

(self, api_fn, api_args, expected_retval: int | list[int] = 0)

Source from the content-addressed store, hash-verified

383 self.vpp.disconnect()
384
385 def api(self, api_fn, api_args, expected_retval: int | list[int] = 0):
386 """Call API function and check it's return value.
387 Call the appropriate hooks before and after the API call
388
389 :param api_fn: API function to call
390 :param api_args: tuple of API function arguments
391 :param expected_retval: Expected return value(s) (Default value = 0)
392 :returns: reply from the API
393
394 """
395 self.hook.before_api(api_fn.__name__, api_args)
396 reply = api_fn(**api_args)
397
398 retval = None
399 if hasattr(reply, "retval"):
400 retval = reply.retval
401 elif type(reply) is tuple and hasattr(reply[0], "retval"):
402 retval = reply[0].retval
403
404 if self._expect_api_retval is self._negative:
405 if retval is not None and retval >= 0:
406 msg = (
407 "%s(%s) passed unexpectedly: expected negative "
408 "return value instead of %d in %s"
409 % (
410 api_fn.__name__,
411 as_fn_signature(api_args),
412 retval,
413 reprlib.repr(reply),
414 )
415 )
416 self.test_class.logger.info(msg)
417 raise UnexpectedApiReturnValueError(retval, msg, reply)
418 elif self._expect_api_retval is None:
419 if retval is not None and (
420 (isinstance(expected_retval, int) and retval != expected_retval)
421 or (isinstance(expected_retval, list) and retval not in expected_retval)
422 ):
423 msg = (
424 "%s(%s) failed, expected %d return value instead "
425 "of %d in %s"
426 % (
427 api_fn.__name__,
428 as_fn_signature(api_args),
429 expected_retval,
430 retval,
431 reprlib.repr(reply),
432 )
433 )
434 self.test_class.logger.info(msg)
435 raise UnexpectedApiReturnValueError(retval, msg, reply)
436 elif isinstance(self._expect_api_retval, list):
437 if retval is not None and retval not in self._expect_api_retval:
438 msg = f"{api_fn.__name__}{as_fn_signature(api_args)} failed, expected return value in {expected_retval}, got {retval} in {reprlib.repr(reply)}"
439 self.test_class.logger.info(msg)
440 raise UnexpectedApiReturnValueError(retval, msg, reply)
441 else:
442 raise Exception(

Callers 15

fMethod · 0.95
want_interface_eventsMethod · 0.95
p2p_ethernet_addMethod · 0.95
p2p_ethernet_delMethod · 0.95
create_vlan_subifMethod · 0.95
create_loopbackMethod · 0.95
ip_route_dumpMethod · 0.95
ip_route_v2_dumpMethod · 0.95
ip_neighbor_add_delMethod · 0.95
udp_encap_addMethod · 0.95

Calls 4

as_fn_signatureFunction · 0.85
after_apiMethod · 0.80
before_apiMethod · 0.45

Tested by 5

route_lookupMethod · 0.36
route_lookupMethod · 0.36
route_lookupMethod · 0.36
route_lookupMethod · 0.36
_route_existsMethod · 0.36