diff options
author | Vratko Polak <vrpolak@cisco.com> | 2019-07-09 12:17:09 +0200 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2019-07-12 13:00:49 +0000 |
commit | 33fb34665214bbbd0a4b3154169b21c2da01f69b (patch) | |
tree | 9ebb70889824451cf8411875159a6fafd70b60ac /resources/libraries/python/L2Util.py | |
parent | ccfe499e2a27f2caf234ecbb2ec948120810eab6 (diff) |
PapiExecutor always verifies
Do not support returning unverified replies anymore.
Basically, ".get_replies().verify_replies()" is now just ".get_replies()".
This allows fairly large simplifications both at call sites
and in PapiExecutor.py
+ Rename get_dumps to get_details.
+ Introduce get_reply and get_sw_if_index.
+ Rename variables holding get_*() value,
+ e.g. get_stats() value is stored to variable named "stats".
+ Rename "item" of subsequent loop to hint the type instead.
+ Rename "details" function argument to "verbose".
+ Process reply details in place, instead of building new list.
- Except hybrid blocks which can return both list or single item.
- Except human readable text building blocks.
+ Rename most similar names to sw_if_index.
- Except "vpp_sw_index" and some function names.
+ Use single run_cli_cmd from PapiExecutor.
+ Do not chain methods over multiple lines.
+ Small space gain is not worth readability loss.
+ Include minor code and docstrings improvement.
+ Add some TODOs.
Change-Id: Ib2110a3d2101a74d5837baab3a58dc46aafc6ce3
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources/libraries/python/L2Util.py')
-rw-r--r-- | resources/libraries/python/L2Util.py | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/resources/libraries/python/L2Util.py b/resources/libraries/python/L2Util.py index f1476044a6..7c575a290e 100644 --- a/resources/libraries/python/L2Util.py +++ b/resources/libraries/python/L2Util.py @@ -130,8 +130,7 @@ class L2Util(object): filter_mac=int(filter_mac), bvi_mac=int(bvi_mac)) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args).get_replies(err_msg).\ - verify_reply(err_msg=err_msg) + papi_exec.add(cmd, **args).get_reply(err_msg) @staticmethod def create_l2_bd(node, bd_id, flood=1, uu_flood=1, forward=1, learn=1, @@ -170,8 +169,7 @@ class L2Util(object): arp_term=int(arp_term), is_add=1) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args).get_replies(err_msg).\ - verify_reply(err_msg=err_msg) + papi_exec.add(cmd, **args).get_reply(err_msg) @staticmethod def add_interface_to_l2_bd(node, interface, bd_id, shg=0, port_type=0): @@ -203,8 +201,7 @@ class L2Util(object): port_type=int(port_type), enable=1) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args).get_replies(err_msg).\ - verify_reply(err_msg=err_msg) + papi_exec.add(cmd, **args).get_reply(err_msg) @staticmethod def vpp_add_l2_bridge_domain(node, bd_id, port_1, port_2, learn=True): @@ -252,8 +249,8 @@ class L2Util(object): ' {host}'.format(host=node['host']) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd1, **args1).add(cmd2, **args2).add(cmd2, **args3).\ - get_replies(err_msg).verify_replies(err_msg=err_msg) + papi_exec.add(cmd1, **args1).add(cmd2, **args2).add(cmd2, **args3) + papi_exec.get_replies(err_msg) @staticmethod def vpp_setup_bidirectional_cross_connect(node, interface1, interface2): @@ -289,8 +286,7 @@ class L2Util(object): ' host {host}'.format(host=node['host']) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args1).add(cmd, **args2).get_replies(err_msg).\ - verify_replies(err_msg=err_msg) + papi_exec.add(cmd, **args1).add(cmd, **args2).get_replies(err_msg) @staticmethod def vpp_setup_bidirectional_l2_patch(node, interface1, interface2): @@ -326,8 +322,7 @@ class L2Util(object): ' host {host}'.format(host=node['host']) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args1).add(cmd, **args2).get_replies(err_msg).\ - verify_replies(err_msg=err_msg) + papi_exec.add(cmd, **args1).add(cmd, **args2).get_replies(err_msg) @staticmethod def linux_add_bridge(node, br_name, if_1, if_2, set_up=True): @@ -393,22 +388,19 @@ class L2Util(object): """ cmd = 'bridge_domain_dump' - cmd_reply = 'bridge_domain_details' args = dict(bd_id=int(bd_id)) err_msg = 'Failed to get L2FIB dump on host {host}'.format( host=node['host']) with PapiExecutor(node) as papi_exec: - papi_resp = papi_exec.add(cmd, **args).get_dump(err_msg) - - data = papi_resp.reply[0]['api_reply'] + details = papi_exec.add(cmd, **args).get_details(err_msg) bd_data = list() if bd_id == Constants.BITWISE_NON_ZERO else dict() - for bridge_domain in data: + for bridge_domain in details: if bd_id == Constants.BITWISE_NON_ZERO: - bd_data.append(bridge_domain[cmd_reply]) + bd_data.append(bridge_domain) else: - if bridge_domain[cmd_reply]['bd_id'] == bd_id: - return bridge_domain[cmd_reply] + if bridge_domain['bd_id'] == bd_id: + return bridge_domain return bd_data @@ -453,8 +445,7 @@ class L2Util(object): err_msg = 'Failed to set VLAN TAG rewrite on host {host}'.format( host=node['host']) with PapiExecutor(node) as papi_exec: - papi_exec.add(cmd, **args).get_replies(err_msg).\ - verify_reply(err_msg=err_msg) + papi_exec.add(cmd, **args).get_reply(err_msg) @staticmethod def get_l2_fib_table(node, bd_id): @@ -469,22 +460,16 @@ class L2Util(object): """ cmd = 'l2_fib_table_dump' - cmd_reply = 'l2_fib_table_details' args = dict(bd_id=int(bd_id)) err_msg = 'Failed to get L2FIB dump on host {host}'.format( host=node['host']) with PapiExecutor(node) as papi_exec: - papi_resp = papi_exec.add(cmd, **args).get_dump(err_msg) - - data = papi_resp.reply[0]['api_reply'] + details = papi_exec.add(cmd, **args).get_details(err_msg) - fib_data = list() - for fib in data: - fib_item = fib[cmd_reply] + for fib_item in details: fib_item['mac'] = L2Util.bin_to_mac(fib_item['mac']) - fib_data.append(fib_item) - return fib_data + return details @staticmethod def get_l2_fib_entry_by_mac(node, bd_index, mac): |