On iSCSI connections, when we are making sure that there no links remain
like /dev/disk/by-id/scsi-* we make several calls to os.path.realpath
which normal behavior is:
- If file path doesn't exist, returns the same file path
- If file path exists, return the real path
But there is a third option, and that is when the file did exist but it
dissapear right when the call to os.readlink in posixpath:_joinrealpath
path, ok = _joinrealpath(path, os.readlink(newpath), seen)
Which ends up raising an exception such as:
OSError: [Errno 2] No such file or directory:
'/dev/disk/by-id/scsi-20024f40058540081'
And because of this exception the detach will fail when it shouldn't.
This patch adds includes the call to os.path.realpath within a
try...except clause to prevent this race condition from unexpectely
making the detach operation fail.
Change-Id: Ieb58826b28c62094c941fce10863c0a75fb4e8aa
Closes-Bug: #1719719