On 25Oct2015 11:35, Ganesh Pal <[email protected]> wrote:
In the below code, we found that the command i.e cmd = "mount
/filesystem1" succeeded. But the test failed due to the weaker stderr
[...]
out, err = proc.communicate()
if err != "":
Checking stderr is never the correct way to do this.
[...]
- To handle this case, Iam planning to use return code and modify the
above code as below ( Any other suggestions please let me know)
def mount_me():
cmd = ("mount /filesystem1")
out, err, ret = run(cmd, timeout=60) # run is the wrapper,
returns (stdout, stderr, returncode)
if ret != 0: # zero means succeeded
This is the correct approach.
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
return False
- Do I need to add more check to ensure the mount actually succeeds,
may be a function?
No. Mount should have a zero status if it succeeds and anon-zero exit status if
it fails. There is no grey area here.
if ret != 0 and check_df_output():
logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret))
Rather than looking at the stdout or stderr of df, consider calling
os.statvfs() directly from Python:
https://docs.python.org/3/library/os.html#os.statvfs
Iam using python 2.7 on Linux
It is the same in Python 2.
Cheers,
Cameron Simpson <[email protected]>
--
https://mail.python.org/mailman/listinfo/python-list