Skip to content

Commit 9d095aa

Browse files
disk_check.py: Move to python2 (sonic-net#1903)
Move to python2
1 parent f3f8667 commit 9d095aa

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

scripts/disk_check.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

44
"""
@@ -69,17 +69,20 @@ def test_writable(dirs):
6969

7070

7171
def run_cmd(cmd):
72-
proc = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE)
73-
ret = proc.returncode
72+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
73+
(output, err) = p.communicate()
74+
## Wait for end of command. Get return returncode ##
75+
ret = p.wait()
7476
if ret:
7577
log_err("failed: ret={} cmd={}".format(ret, cmd))
7678
else:
7779
log_info("ret={} cmd: {}".format(ret, cmd))
7880

79-
if proc.stdout:
80-
log_info("stdout: {}".format(proc.stdout.decode("utf-8")))
81-
if proc.stderr:
82-
log_info("stderr: {}".format(proc.stderr.decode("utf-8")))
81+
if output:
82+
log_info("stdout: {}".format(output.decode("utf-8")))
83+
if err:
84+
log_info("stderr: {}".format(err.decode("utf-8")))
85+
8386
return ret
8487

8588

@@ -113,6 +116,12 @@ def do_mnt(dirs):
113116
break
114117

115118
if ret:
119+
for i in (UPPER_DIR, WORK_DIR):
120+
if os.path.exists(i):
121+
ret = run_cmd("rm -rf {}".format(i))
122+
if ret:
123+
log_err("Failed to remove {}".format(i))
124+
116125
log_err("Failed to mount {} as Read-Write".format(dirs))
117126
else:
118127
log_info("{} are mounted as Read-Write".format(dirs))

0 commit comments

Comments
 (0)