From 6e134f16e83179b98536128362af636e8a97daa8 Mon Sep 17 00:00:00 2001 From: Neetha John Date: Thu, 28 Jan 2021 21:22:31 -0800 Subject: [PATCH 1/2] Allow ecn unit test to run without sudo Signed-off-by: Neetha John --- scripts/ecnconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/ecnconfig b/scripts/ecnconfig index cdebf21e79..b63f771cc5 100755 --- a/scripts/ecnconfig +++ b/scripts/ecnconfig @@ -166,7 +166,7 @@ class EcnConfig(object): return result def set_wred_threshold(self, profile, threshold, value): - if os.geteuid() != 0: + if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": sys.exit("Root privileges required for this operation") field = WRED_CONFIG_FIELDS[threshold] @@ -179,7 +179,7 @@ class EcnConfig(object): json.dump(prof_table, fd) def set_wred_prob(self, profile, drop_color, value): - if os.geteuid() != 0: + if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": sys.exit("Root privileges required for this operation") field = WRED_CONFIG_FIELDS[drop_color] @@ -227,7 +227,7 @@ class EcnQ(object): ) def set(self, enable): - if os.geteuid() != 0: + if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": sys.exit("Root privileges required for this operation") for queue in self.queues: if self.verbose: From 6f6c1dcef8fcea18536bc7b8cccd55236dfecda3 Mon Sep 17 00:00:00 2001 From: Neetha John Date: Fri, 29 Jan 2021 09:45:36 -0800 Subject: [PATCH 2/2] Address review comments Signed-off-by: Neetha John --- scripts/ecnconfig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/ecnconfig b/scripts/ecnconfig index b63f771cc5..62a14b9106 100755 --- a/scripts/ecnconfig +++ b/scripts/ecnconfig @@ -89,6 +89,10 @@ OFF = "[]" lossless_queues = ['3', '4'] +def chk_exec_privilege(): + if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": + sys.exit("Root privileges required for this operation") + class EcnConfig(object): """ Process ecnconfig @@ -166,8 +170,7 @@ class EcnConfig(object): return result def set_wred_threshold(self, profile, threshold, value): - if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": - sys.exit("Root privileges required for this operation") + chk_exec_privilege() field = WRED_CONFIG_FIELDS[threshold] if self.verbose: @@ -179,8 +182,7 @@ class EcnConfig(object): json.dump(prof_table, fd) def set_wred_prob(self, profile, drop_color, value): - if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": - sys.exit("Root privileges required for this operation") + chk_exec_privilege() field = WRED_CONFIG_FIELDS[drop_color] if self.verbose: @@ -227,8 +229,8 @@ class EcnQ(object): ) def set(self, enable): - if os.geteuid() != 0 and os.environ.get("UTILITIES_UNIT_TESTING", "0") != "2": - sys.exit("Root privileges required for this operation") + chk_exec_privilege() + for queue in self.queues: if self.verbose: print("%s ECN on %s queue %s" % ("Enable" if enable else "Disable", ','.join(self.ports_key), queue))