Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add missing libraries for VPP python API handling of interfaces #1490

Merged
merged 1 commit into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
28 changes: 28 additions & 0 deletions tests/robot/libraries/interface/afpacket.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[Documentation] Keywords for working with VAT terminal

*** Settings ***
Resource ../vpp_api.robot
Resource ./interface_generic.robot

*** Variables ***
${terminal_timeout}= 30s
${bd_timeout}= 15s

*** Keywords ***

vpp_api: Check Afpacket Interface State
[Arguments] ${node} ${name} @{desired_state}
${internal_name}= Get Interface Internal Name ${node} ${name}
${int_state}= vpp_api: Get Interface State By Name ${node} ${internal_name}
${ipv4_list}= vpp_term: Get Interface IPs ${node} ${internal_name}
${config}= Get VPP Interface Config As Json ${node} ${name}
${host_int}= Set Variable ${config["afpacket"]["host_if_name"]}
${enabled}= Set Variable ${int_state["admin_up_down"]}
${mtu}= Set Variable ${int_state["mtu"][0]}
${str_mac}= Set Variable ${int_state["l2_address"]}
${mac}= Convert str To MAC Address ${str_mac}
${actual_state}= Create List enabled=${enabled} mtu=${mtu} mac=${mac}
:FOR ${ip} IN @{ipv4_list}
\ Append To List ${actual_state} ipv4=${ip}
List Should Contain Sub List ${actual_state} ${desired_state}
[Return] ${actual_state}
59 changes: 59 additions & 0 deletions tests/robot/libraries/interface/interface_generic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

def get_interface_index_from_api(data, name):
"""Process data from sw_interface_dump API and return index
of the interface specified by name.

:param data: Output of interface dump API call.
:param name: Name of the interface to find.
:type data: list
:type name: str
:returns: Index of the specified interface.
:rtype: int
:raises RuntimeError: If the interface is not found.
"""

for iface in data:
if iface["sw_interface_details"]["interface_name"] == name:
return iface["sw_interface_details"]["sw_if_index"]
else:
raise RuntimeError(
"Interface with name {name} not found in dump. "
"Dumped data: {data}".format(name=name, data=data))


def get_interface_state_from_api(data, index=-1, name="_"):
"""Process data from sw_interface_dump API and return state
of the interface specified by name or index.

:param data: Output of interface dump API call.
:param index: Index of the interface to find.
:param name: Name of the interface to find.
:type data: list
:type index: int
:type name: str
:returns: State of the specified interface.
:rtype: str
:raises RuntimeError: If the interface is not found.
"""

if index == -1 and name == "_":
raise ValueError("Provide either an interface index or a name.")

for iface in data:
if iface["sw_interface_details"]["sw_if_index"] == int(index)\
or iface["sw_interface_details"]["interface_name"] == name:
return iface["sw_interface_details"]
else:
raise RuntimeError(
"Interface with index {index} or name {name} not found in dump.\n "
"Dumped data:\n {data}".format(index=index, name=name, data=data))


def convert_str_to_mac_address(hex_mac):
"""Just add colons in the right places."""

hex_pairs = [hex_mac[(x*2):((x+1)*2)] for x in range(6)]

mac = "{0}:{1}:{2}:{3}:{4}:{5}".format(*hex_pairs)

return mac
36 changes: 36 additions & 0 deletions tests/robot/libraries/interface/interface_generic.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[Documentation] Keywords for working with VAT terminal

*** Settings ***
Library interface_generic.py

Resource ../vpp_api.robot

*** Variables ***
${terminal_timeout}= 30s
${bd_timeout}= 15s

*** Keywords ***

vpp_api: Interfaces Dump
[Arguments] ${node}
${out}= Execute API Command ${node} sw_interface_dump
[Return] ${out}

vpp_api: Get Interface Index
[Arguments] ${node} ${name}
[Documentation] Return interface index with specified name
${out}= vpp_api: Interfaces Dump ${node}
${index}= Get Interface Index From API ${out[0]["api_reply"]} ${name}
[Return] ${index}

vpp_api: Get Interface State By Name
[Arguments] ${node} ${name}
${out}= vpp_api: Interfaces Dump ${node}
${state}= Get Interface State From API ${out[0]["api_reply"]} name=${name}
[Return] ${state}

vpp_api: Get Interface State By Index
[Arguments] ${node} ${index}
${out}= vpp_api: Interfaces Dump ${node}
${state}= Get Interface State From API ${out[0]["api_reply"]} index=${index}
[Return] ${state}