Skip to content

Commit 150642e

Browse files
authored
[dropcounters] Fix clear for non-root users (#1253)
Signed-off-by: Danny Allen <[email protected]>
1 parent becf5b5 commit 150642e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

scripts/dropstat

+12-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ try:
3030
sys.path.insert(0, modules_path)
3131
sys.path.insert(0, test_path)
3232
import mock_tables.dbconnector
33-
socket.gethostname = lambda : 'sonic_drops_test'
33+
socket.gethostname = lambda: 'sonic_drops_test'
34+
os.getuid = lambda: 27
3435
except KeyError:
3536
pass
3637

@@ -75,8 +76,10 @@ std_port_headers_map = {
7576
# Standard Switch-Level Headers
7677
std_switch_description_header = ['DEVICE']
7778

78-
# Bookkeeping Files
79-
dropstat_dir = '/tmp/dropstat/'
79+
80+
def get_dropstat_dir():
81+
dropstat_dir_prefix = '/tmp/dropstat'
82+
return "{}-{}/".format(dropstat_dir_prefix, os.getuid())
8083

8184

8285
class DropStat(object):
@@ -89,8 +92,9 @@ class DropStat(object):
8992
self.db.connect(self.db.ASIC_DB)
9093
self.db.connect(self.db.APPL_DB)
9194

92-
self.port_drop_stats_file = os.path.join(dropstat_dir, 'port-stats-{}'.format(os.getuid()))
93-
self.switch_drop_stats_file = os.path.join(dropstat_dir + 'switch-stats-{}'.format(os.getuid()))
95+
dropstat_dir = get_dropstat_dir()
96+
self.port_drop_stats_file = os.path.join(dropstat_dir, 'port-stats')
97+
self.switch_drop_stats_file = os.path.join(dropstat_dir + 'switch-stats')
9498

9599
self.stat_lookup = {}
96100
self.reverse_stat_lookup = {}
@@ -405,6 +409,8 @@ Examples:
405409
group = args.group
406410
counter_type = args.type
407411

412+
dropstat_dir = get_dropstat_dir()
413+
408414
# Create the directory to hold clear results
409415
if not os.path.exists(dropstat_dir):
410416
try:
@@ -422,5 +428,6 @@ Examples:
422428
else:
423429
print("Command not recognized")
424430

431+
425432
if __name__ == '__main__':
426433
main()

tests/drops_group_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
sonic_drops_test 0 0
8383
"""
8484

85-
dropstat_path = "/tmp/dropstat"
85+
dropstat_path = "/tmp/dropstat-27"
8686

8787
class TestDropCounters(object):
8888
@classmethod

0 commit comments

Comments
 (0)