Skip to content

Commit b226159

Browse files
authored
[CLI][PFCWD] Fix issue with specifying ports in pfcwd start on masic 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
1 parent 40377d3 commit b226159

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

pfcwd/main.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, namespace=None, display=constants.DISPLAY_ALL):
105105
self.config_db = None
106106
self.multi_asic = multi_asic_util.MultiAsic(display, namespace)
107107
self.table = []
108+
self.all_ports = []
108109

109110
@multi_asic_util.run_on_multi_asic
110111
def collect_stats(self, empty, queues):
@@ -147,9 +148,27 @@ def show_stats(self, empty, queues):
147148
tablefmt='simple'
148149
))
149150

151+
@multi_asic_util.run_on_multi_asic
152+
def get_all_namespace_ports(self):
153+
ports = get_all_ports(
154+
self.db, self.multi_asic.current_namespace,
155+
self.multi_asic.display_option
156+
)
157+
self.all_ports.extend(ports)
158+
159+
def get_invalid_ports(self, ports=[]):
160+
if len(ports) == 0:
161+
return []
162+
self.get_all_namespace_ports()
163+
port_set = set(ports)
164+
# "all" is a valid option, remove before performing set diff
165+
port_set.discard("all")
166+
return port_set - set(self.all_ports)
167+
150168
@multi_asic_util.run_on_multi_asic
151169
def collect_config(self, ports):
152170
table = []
171+
153172
if len(ports) == 0:
154173
ports = get_all_ports(
155174
self.db, self.multi_asic.current_namespace,
@@ -208,23 +227,24 @@ def config(self, ports):
208227
tablefmt='simple'
209228
))
210229

211-
@multi_asic_util.run_on_multi_asic
212230
def start(self, action, restoration_time, ports, detection_time):
231+
invalid_ports = self.get_invalid_ports(ports)
232+
if len(invalid_ports):
233+
click.echo("Failed to run command, invalid options:")
234+
for opt in invalid_ports:
235+
click.echo(opt)
236+
exit()
237+
self.start_cmd(action, restoration_time, ports, detection_time)
238+
239+
@multi_asic_util.run_on_multi_asic
240+
def start_cmd(self, action, restoration_time, ports, detection_time):
213241
if os.geteuid() != 0:
214242
exit("Root privileges are required for this operation")
215-
allowed_strs = ['ports', 'all', 'detection-time']
216243

217244
all_ports = get_all_ports(
218245
self.db, self.multi_asic.current_namespace,
219246
self.multi_asic.display_option
220247
)
221-
allowed_strs = allowed_strs + all_ports
222-
for p in ports:
223-
if p not in allowed_strs:
224-
raise click.BadOptionUsage(
225-
"Bad command line format. Try 'pfcwd start --help' for "
226-
"usage"
227-
)
228248

229249
if len(ports) == 0:
230250
ports = all_ports
@@ -379,7 +399,6 @@ def big_red_switch(self, big_red_switch):
379399
pfcwd_info
380400
)
381401

382-
383402
# Show stats
384403
class Show(object):
385404
# Show commands

0 commit comments

Comments
 (0)