From 1e18c645e6356167aaeb54204c8cc10b40c618a2 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Tue, 12 Mar 2019 13:38:22 +0100 Subject: [PATCH] Do not fail when called on an invalid device When calling smartctl on bcache devices, we will get a non-zero return code. In this case, we fail safe and do not enable a potentially unavailable feature. Additionally, other possible failures with device identification will be caught and safely handled this way. Change-Id: Ie10fb24cbfedf98c8bb53b710b95962579d3284e Closes-Bug: #1819652 --- hooks/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hooks/utils.py b/hooks/utils.py index 3064f7a5..786c1bbe 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -211,9 +211,13 @@ def should_enable_discard(devices): if (device.startswith("/dev/nvme") or device.startswith("/dev/vd")): continue + try: + sata_3_or_less = is_sata30orless(device) + except subprocess.CalledProcessError: + sata_3_or_less = True if (device.startswith("/dev/") and os.path.exists(device) and - is_sata30orless(device)): + sata_3_or_less): discard_enable = False log("SSD Discard autodetection: {} is forcing discard off" "(sata <= 3.0)".format(device), level=WARNING)