Skip to content

Commit

Permalink
[Bug Fix] Fix disk check test and drops group test (sonic-net#3424)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BYGX-wcr committed Jul 16, 2024
1 parent c03c9c8 commit b9a6049
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tests/disk_check_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import syslog
from unittest.mock import patch
import pytest
import subprocess

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

assert max_log_lvl == syslog.LOG_ERR

@classmethod
def teardown_class(cls):
subprocess.run("rm -rf /tmp/tmp*", shell=True) # cleanup the temporary dirs
print("TEARDOWN")
10 changes: 7 additions & 3 deletions tests/drops_group_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import shutil
from click.testing import CliRunner
from utilities_common.cli import UserCache

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -97,14 +98,17 @@
sonic_drops_test 0 0
"""

dropstat_path = "/tmp/dropstat-27"

def remove_tmp_dropstat_file():
# remove the tmp portstat
cache = UserCache("dropstat")
cache.remove_all()

class TestDropCounters(object):
@classmethod
def setup_class(cls):
print("SETUP")
if os.path.exists(dropstat_path):
shutil.rmtree(dropstat_path)
remove_tmp_dropstat_file()
os.environ["PATH"] += os.pathsep + scripts_path
os.environ["UTILITIES_UNIT_TESTING"] = "1"

Expand Down

0 comments on commit b9a6049

Please sign in to comment.