Skip to content

Commit 5cc9417

Browse files
renukamanavalanqiluo-msft
authored andcommitted
disk_check: Script updated to run good in 201811 & 201911 (sonic-net#1747)
What I did Have independent subdirs for each mounted dir to avoid any collisions of files/dirs by same name. Adopt for older version of python3 How I did it Changes: Individual subdirs for each dir to be mounted subprocess args made compatible with older version of python3 (tested in version 3.5.3) How to verify it Simulate read-only state Run this script Test ssh via new tacacs user (who had not logged in earlier)
1 parent 8768089 commit 5cc9417

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

scripts/disk_check.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
Monit may be used to invoke it periodically, to help scan & fix and
2222
report via syslog.
2323
24+
Tidbit:
25+
If you would like to test this script, you could simulate a RO disk
26+
with the following command. Reboot will revert the effect.
27+
sudo bash -c "echo u > /proc/sysrq-trigger"
28+
2429
"""
2530

2631
import argparse
@@ -64,17 +69,17 @@ def test_writable(dirs):
6469

6570

6671
def run_cmd(cmd):
67-
proc = subprocess.run(cmd, shell=True, text=True, capture_output=True)
72+
proc = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
6873
ret = proc.returncode
6974
if ret:
7075
log_err("failed: ret={} cmd={}".format(ret, cmd))
7176
else:
7277
log_info("ret={} cmd: {}".format(ret, cmd))
7378

7479
if proc.stdout:
75-
log_info("stdout: {}".format(str(proc.stdout)))
80+
log_info("stdout: {}".format(proc.stdout.decode("utf-8")))
7681
if proc.stderr:
77-
log_info("stderr: {}".format(str(proc.stderr)))
82+
log_info("stderr: {}".format(proc.stderr.decode("utf-8")))
7883
return ret
7984

8085

@@ -95,9 +100,15 @@ def do_mnt(dirs):
95100
return 1
96101

97102
for d in dirs:
103+
d_name = get_dname(d)
104+
d_upper = os.path.join(UPPER_DIR, d_name)
105+
d_work = os.path.join(WORK_DIR, d_name)
106+
os.mkdir(d_upper)
107+
os.mkdir(d_work)
108+
98109
ret = run_cmd("mount -t overlay overlay_{} -o lowerdir={},"
99110
"upperdir={},workdir={} {}".format(
100-
get_dname(d), d, UPPER_DIR, WORK_DIR, d))
111+
d_name, d, d_upper, d_work, d))
101112
if ret:
102113
break
103114

tests/disk_check_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import syslog
33
from unittest.mock import patch
44
import pytest
5+
import subprocess
56

67
sys.path.append("scripts")
78
import disk_check
@@ -26,7 +27,7 @@
2627
"workdir": "/tmp/tmpy",
2728
"mounts": "overlay_tmpx blahblah",
2829
"err": "/tmpx is not read-write|READ-ONLY: Mounted ['/tmpx'] to make Read-Write",
29-
"cmds": ['mount -t overlay overlay_tmpx -o lowerdir=/tmpx,upperdir=/tmp/tmpx,workdir=/tmp/tmpy /tmpx']
30+
"cmds": ['mount -t overlay overlay_tmpx -o lowerdir=/tmpx,upperdir=/tmp/tmpx/tmpx,workdir=/tmp/tmpy/tmpx /tmpx']
3031
},
3132
"3": {
3233
"desc": "Not good as /tmpx is not read-write; mount fail as create of upper fails",
@@ -90,9 +91,12 @@ def __init__(self, proc_upd = None):
9091
self.stderr = proc_upd.get("stderr", None)
9192

9293

93-
def mock_subproc_run(cmd, shell, text, capture_output):
94+
def mock_subproc_run(cmd, shell, stdout):
9495
global cmds
9596

97+
assert shell == True
98+
assert stdout == subprocess.PIPE
99+
96100
upd = (current_tc["proc"][len(cmds)]
97101
if len(current_tc.get("proc", [])) > len(cmds) else None)
98102
cmds.append(cmd)

0 commit comments

Comments
 (0)