Skip to content

Commit

Permalink
[CLI][PFCWD] Fix issue with specifying ports in pfcwd start on masic …
Browse files Browse the repository at this point in the history
…platforms (sonic-net#1203)

When ports are specified as option to 'pfcwd start', port validation fails on multi ASIC platform as the validation logic is executed on each ASIC namespace. Validation for valid ports fails as the port exits in only one namespace and not in others.

Changed logic to perform port validation after collecting ports from all namespaces. If port validation fails there is no config change on other valid ports
  • Loading branch information
smaheshm authored Nov 12, 2020
1 parent 40377d3 commit b226159
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self, namespace=None, display=constants.DISPLAY_ALL):
self.config_db = None
self.multi_asic = multi_asic_util.MultiAsic(display, namespace)
self.table = []
self.all_ports = []

@multi_asic_util.run_on_multi_asic
def collect_stats(self, empty, queues):
Expand Down Expand Up @@ -147,9 +148,27 @@ def show_stats(self, empty, queues):
tablefmt='simple'
))

@multi_asic_util.run_on_multi_asic
def get_all_namespace_ports(self):
ports = get_all_ports(
self.db, self.multi_asic.current_namespace,
self.multi_asic.display_option
)
self.all_ports.extend(ports)

def get_invalid_ports(self, ports=[]):
if len(ports) == 0:
return []
self.get_all_namespace_ports()
port_set = set(ports)
# "all" is a valid option, remove before performing set diff
port_set.discard("all")
return port_set - set(self.all_ports)

@multi_asic_util.run_on_multi_asic
def collect_config(self, ports):
table = []

if len(ports) == 0:
ports = get_all_ports(
self.db, self.multi_asic.current_namespace,
Expand Down Expand Up @@ -208,23 +227,24 @@ def config(self, ports):
tablefmt='simple'
))

@multi_asic_util.run_on_multi_asic
def start(self, action, restoration_time, ports, detection_time):
invalid_ports = self.get_invalid_ports(ports)
if len(invalid_ports):
click.echo("Failed to run command, invalid options:")
for opt in invalid_ports:
click.echo(opt)
exit()
self.start_cmd(action, restoration_time, ports, detection_time)

@multi_asic_util.run_on_multi_asic
def start_cmd(self, action, restoration_time, ports, detection_time):
if os.geteuid() != 0:
exit("Root privileges are required for this operation")
allowed_strs = ['ports', 'all', 'detection-time']

all_ports = get_all_ports(
self.db, self.multi_asic.current_namespace,
self.multi_asic.display_option
)
allowed_strs = allowed_strs + all_ports
for p in ports:
if p not in allowed_strs:
raise click.BadOptionUsage(
"Bad command line format. Try 'pfcwd start --help' for "
"usage"
)

if len(ports) == 0:
ports = all_ports
Expand Down Expand Up @@ -379,7 +399,6 @@ def big_red_switch(self, big_red_switch):
pfcwd_info
)


# Show stats
class Show(object):
# Show commands
Expand Down

0 comments on commit b226159

Please sign in to comment.