Skip to content
Closed
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
2 changes: 2 additions & 0 deletions docs/api_wiki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def test_fun(duthosts, rand_one_dut_hostname, ptfhost):

- [get_interfaces_status](sonichost_methods/get_interfaces_status.md) - Get interfaces status on the DUT and parse the result into a dict.

- [show_interfaces_portchannel](sonichost_methods/show_interfaces_portchannel.md) - Retrieve information about PortChannel interfaces and parse the result into a dict.

- [show_ipv6_interfaces](sonichost_methods/show_ipv6_interfaces.md) - Retrieve information about IPv6 interfaces and parse the result into a dict.

- [get_intf_link_local_ipv6_addr](sonichost_methods/get_intf_link_local_ipv6_addr.md) - Get the link local ipv6 address of the interface
Expand Down
47 changes: 47 additions & 0 deletions docs/api_wiki/sonic_asic_methods/show_interfaces_portchannel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# show_interfaces_portchannel

- [Overview](#overview)
- [Examples](#examples)
- [Arguments](#arguments)
- [Expected Output](#expected-output)

## Overview
Retrieve information about PortChannel interfaces and parse the result into a dict.

## Examples
```python
def test_fun(duthosts, rand_one_dut_hostname):
duthost = duthosts[rand_one_dut_hostname]

portchannel_ifs = duthost.show_interfaces_portchannel()
```

## Arguments
This function takes no arguments.

## Expected Output
Returns a dictionary containing information about the DUT's PortChannel interfaces.
Note: The returned dictionary does not include protocol and port flags.

Example output:

```json
{
"PortChannel101": {
"protocol": "LACP",
"ports": ["Ethernet0"]
},
"PortChannel102": {
"protocol": "LACP",
"ports": ["Ethernet20", "Ethernet40"]
},
"PortChannel103": {
"protocol": "LACP",
"ports": ["Ethernet68", "Ethernet72", "Ethernet76"]
},
"PortChannel104": {
"protocol": "LACP",
"ports": ["Ethernet80"]
}
}
```
51 changes: 51 additions & 0 deletions tests/common/devices/sonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,57 @@ def show_ipv6_interfaces(self):
result[iface]["oper"] = admin_oper[1]
return result

def show_interfaces_portchannel(self) -> dict:
'''
Retrieves information about PortChannel interfaces by running "show interfaces portchannel" on the DUT
and then parses the result into a dict.

Example output:
{
"PortChannel101": {
"protocol": "LACP",
"ports": ["Ethernet0"]
},
"PortChannel102": {
"protocol": "LACP",
"ports": ["Ethernet20", "Ethernet40"]
},
"PortChannel103": {
"protocol": "LACP",
"ports": ["Ethernet68", "Ethernet72", "Ethernet76"]
},
"PortChannel104": {
"protocol": "LACP",
"ports": ["Ethernet80"]
}
}
'''
def remove_flags(string: str) -> str:
'''
Example:
Input: LACP(A)(Up)
Output: LACP
'''
p = string.find('(')
if p != -1:
string = string[0:p]
return string

result = {pc_info["team dev"]: pc_info for pc_info in self.show_and_parse("show interfaces portchannel")}
for portchannel in result.keys():
del result[portchannel]["no."]
del result[portchannel]["team dev"] # redundant, because it is equal to the key (i.e., portchannel)
# Removing protocol flags
protocol = remove_flags(result[portchannel]["protocol"])
result[portchannel]["protocol"] = protocol
# Removing flags on each member port
member_ports = result[portchannel]["ports"].split()
for i in range(0, len(member_ports)):
port = remove_flags(member_ports[i])
member_ports[i] = port
result[portchannel]["ports"] = member_ports
return result

def get_crm_facts(self):
"""Run various 'crm show' commands and parse their output to gather CRM facts

Expand Down
Loading
Loading