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

[ecnconfig] Allow ecn unit test to run without sudo #1390

Merged
merged 2 commits into from
Jan 29, 2021
Merged
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
14 changes: 8 additions & 6 deletions scripts/ecnconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,8 +170,7 @@ class EcnConfig(object):
return result

def set_wred_threshold(self, profile, threshold, value):
if os.geteuid() != 0:
sys.exit("Root privileges required for this operation")
chk_exec_privilege()

field = WRED_CONFIG_FIELDS[threshold]
if self.verbose:
Expand All @@ -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:
sys.exit("Root privileges required for this operation")
chk_exec_privilege()

field = WRED_CONFIG_FIELDS[drop_color]
if self.verbose:
Expand Down Expand Up @@ -227,8 +229,8 @@ class EcnQ(object):
)

def set(self, enable):
if os.geteuid() != 0:
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))
Expand Down