Skip to content

Commit

Permalink
[dropcounters] Fix clear for non-root users (sonic-net#1253)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Allen <daall@microsoft.com>
  • Loading branch information
daall committed Dec 22, 2020
1 parent becf5b5 commit 150642e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions scripts/dropstat
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ try:
sys.path.insert(0, modules_path)
sys.path.insert(0, test_path)
import mock_tables.dbconnector
socket.gethostname = lambda : 'sonic_drops_test'
socket.gethostname = lambda: 'sonic_drops_test'
os.getuid = lambda: 27
except KeyError:
pass

Expand Down Expand Up @@ -75,8 +76,10 @@ std_port_headers_map = {
# Standard Switch-Level Headers
std_switch_description_header = ['DEVICE']

# Bookkeeping Files
dropstat_dir = '/tmp/dropstat/'

def get_dropstat_dir():
dropstat_dir_prefix = '/tmp/dropstat'
return "{}-{}/".format(dropstat_dir_prefix, os.getuid())


class DropStat(object):
Expand All @@ -89,8 +92,9 @@ class DropStat(object):
self.db.connect(self.db.ASIC_DB)
self.db.connect(self.db.APPL_DB)

self.port_drop_stats_file = os.path.join(dropstat_dir, 'port-stats-{}'.format(os.getuid()))
self.switch_drop_stats_file = os.path.join(dropstat_dir + 'switch-stats-{}'.format(os.getuid()))
dropstat_dir = get_dropstat_dir()
self.port_drop_stats_file = os.path.join(dropstat_dir, 'port-stats')
self.switch_drop_stats_file = os.path.join(dropstat_dir + 'switch-stats')

self.stat_lookup = {}
self.reverse_stat_lookup = {}
Expand Down Expand Up @@ -405,6 +409,8 @@ Examples:
group = args.group
counter_type = args.type

dropstat_dir = get_dropstat_dir()

# Create the directory to hold clear results
if not os.path.exists(dropstat_dir):
try:
Expand All @@ -422,5 +428,6 @@ Examples:
else:
print("Command not recognized")


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion tests/drops_group_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
sonic_drops_test 0 0
"""

dropstat_path = "/tmp/dropstat"
dropstat_path = "/tmp/dropstat-27"

class TestDropCounters(object):
@classmethod
Expand Down

0 comments on commit 150642e

Please sign in to comment.