Skip to content

Commit

Permalink
Don't check return status from smartctl -a
Browse files Browse the repository at this point in the history
Some device doesn't support SMART capability and getting information
from such device returns an error code 4. As it happens in CI we remove
the check of the return code when running the command and the check is
done within the plugin. It allows to check specific errors.

Signed-off-by: Guillaume <[email protected]>
  • Loading branch information
gthvn1 committed Dec 19, 2023
1 parent e9415e0 commit 297d79b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions SOURCES/etc/xapi.d/plugins/smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import XenAPIPlugin

sys.path.append('.')
from xcpngutils import configure_logging, run_command, error_wrapped
from xcpngutils import configure_logging, run_command, error_wrapped, raise_plugin_error
from xcpngutils.operationlocker import OperationLocker

@error_wrapped
Expand All @@ -24,7 +24,11 @@ def get_information(session, args):
with OperationLocker():
disks = _list_disks()
for disk in disks:
cmd = run_command(["smartctl", "-j", "-a", disk])
cmd = run_command(["smartctl", "-j", "-a", disk], check=False)
# Error 4 is a lack of SMART capability but the JSON is valid so
# we can return it to client without considering it as an error.
if cmd['returncode'] != 0 and cmd['returncode'] != 4:
raise_plugin_error(cmd['returncode'], "Got unknown errors")
results[disk] = json.loads(cmd['stdout'])
return json.dumps(results)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_smartctl_error(self, _list_disks, run_command, fs):

def test_smartctl_information(self, _list_disks, run_command, fs):
_list_disks.return_value = ["/dev/sda"]
run_command.return_value = {"stdout": SMARTCTL_INFO}
run_command.return_value = {"stdout": SMARTCTL_INFO, "returncode": 0}

res = get_information(None, None)
assert json.loads(res) == json.loads(SMARTCTL_INFO_EXPECTED)
Expand Down

0 comments on commit 297d79b

Please sign in to comment.