Skip to content

Commit b9a6049

Browse files
authored
[Bug Fix] Fix disk check test and drops group test (sonic-net#3424)
* tests/disk_check_test.py: remove temp files during teardown - modify teardown_class() to remove /tmp/tmp* * tests/drops_group_test.py: add code to remove temporary files when setting up test class - add a remove_tmp_dropstat_file() function as a helper to clean the cache - add an invocation of remove_tmp_dropstat_file() in setup_class() of TestDropCounters class * tests/disk_check_test.py: fix the subprocess command in the teardown_class() function * tests/disk_check_test.py: fix formatting for pre-commit check * tests/drops_group_test.py: fix formatting for pre-commit check
1 parent c03c9c8 commit b9a6049

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

tests/disk_check_test.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
import syslog
33
from unittest.mock import patch
4-
import pytest
54
import subprocess
65

76
sys.path.append("scripts")
@@ -178,3 +177,7 @@ def test_readonly(self, mock_proc, mock_log):
178177

179178
assert max_log_lvl == syslog.LOG_ERR
180179

180+
@classmethod
181+
def teardown_class(cls):
182+
subprocess.run("rm -rf /tmp/tmp*", shell=True) # cleanup the temporary dirs
183+
print("TEARDOWN")

tests/drops_group_test.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import shutil
55
from click.testing import CliRunner
6+
from utilities_common.cli import UserCache
67

78
test_path = os.path.dirname(os.path.abspath(__file__))
89
modules_path = os.path.dirname(test_path)
@@ -97,14 +98,17 @@
9798
sonic_drops_test 0 0
9899
"""
99100

100-
dropstat_path = "/tmp/dropstat-27"
101+
102+
def remove_tmp_dropstat_file():
103+
# remove the tmp portstat
104+
cache = UserCache("dropstat")
105+
cache.remove_all()
101106

102107
class TestDropCounters(object):
103108
@classmethod
104109
def setup_class(cls):
105110
print("SETUP")
106-
if os.path.exists(dropstat_path):
107-
shutil.rmtree(dropstat_path)
111+
remove_tmp_dropstat_file()
108112
os.environ["PATH"] += os.pathsep + scripts_path
109113
os.environ["UTILITIES_UNIT_TESTING"] = "1"
110114

0 commit comments

Comments
 (0)