aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/VhostUser.py
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python/VhostUser.py')
-rw-r--r--resources/libraries/python/VhostUser.py49
1 files changed, 34 insertions, 15 deletions
diff --git a/resources/libraries/python/VhostUser.py b/resources/libraries/python/VhostUser.py
index a24bc97633..48cce002bd 100644
--- a/resources/libraries/python/VhostUser.py
+++ b/resources/libraries/python/VhostUser.py
@@ -20,7 +20,7 @@ from resources.libraries.python.topology import NodeType, Topology
from resources.libraries.python.InterfaceUtil import InterfaceUtil
-class VhostUser(object):
+class VhostUser:
"""Vhost-user interfaces L1 library."""
@staticmethod
@@ -33,15 +33,16 @@ class VhostUser(object):
response.
:rtype: list
"""
- cmd = "sw_interface_vhost_user_dump"
+ cmd = u"sw_interface_vhost_user_dump"
+
with PapiSocketExecutor(node) as papi_exec:
details = papi_exec.add(cmd).get_details()
for vhost in details:
- vhost["interface_name"] = vhost["interface_name"].rstrip('\x00')
- vhost["sock_filename"] = vhost["sock_filename"].rstrip('\x00')
+ vhost[u"interface_name"] = vhost[u"interface_name"]
+ vhost[u"sock_filename"] = vhost[u"sock_filename"]
- logger.debug("VhostUser details:\n{details}".format(details=details))
+ logger.debug(f"VhostUser details:\n{details}")
return details
@@ -56,17 +57,18 @@ class VhostUser(object):
:returns: SW interface index.
:rtype: int
"""
- cmd = 'create_vhost_user_if'
- err_msg = 'Failed to create Vhost-user interface on host {host}'.format(
- host=node['host'])
+ cmd = u"create_vhost_user_if"
+ err_msg = f"Failed to create Vhost-user interface " \
+ f"on host {node[u'host']}"
args = dict(
- sock_filename=str(socket)
+ sock_filename=str(socket).encode(encoding=u"utf-8")
)
+
with PapiSocketExecutor(node) as papi_exec:
sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
# Update the Topology:
- if_key = Topology.add_new_port(node, 'vhost')
+ if_key = Topology.add_new_port(node, u"vhost")
Topology.update_interface_sw_if_index(node, if_key, sw_if_index)
ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index)
@@ -90,9 +92,9 @@ class VhostUser(object):
:returns: Interface name or None if not found.
:rtype: str
"""
- for interface in node['interfaces'].values():
- if interface.get('socket') == socket:
- return interface.get('name')
+ for interface in node[u"interfaces"].values():
+ if interface.get(u"socket") == socket:
+ return interface.get(u"name")
return None
@staticmethod
@@ -107,7 +109,6 @@ class VhostUser(object):
:returns: l2_address of the given interface.
:rtype: str
"""
-
return InterfaceUtil.vpp_get_interface_mac(node, sw_if_index)
@staticmethod
@@ -127,5 +128,23 @@ class VhostUser(object):
:type nodes: dict
"""
for node in nodes.values():
- if node['type'] == NodeType.DUT:
+ if node[u"type"] == NodeType.DUT:
VhostUser.vpp_show_vhost(node)
+
+ @staticmethod
+ def vhost_user_dump(node):
+ """Get vhost-user data for the given node.
+
+ :param node: VPP node to get interface data from.
+ :type node: dict
+ :returns: List of dictionaries with all vhost-user interfaces.
+ :rtype: list
+ """
+ cmd = u"sw_interface_vhost_user_dump"
+ err_msg = f"Failed to get vhost-user dump on host {node['host']}"
+
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd).get_details(err_msg)
+
+ logger.debug(f"Vhost-user details:\n{details}")
+ return details