Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in integration about smartctl and return error code 4 #43

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

gthvn1
Copy link
Contributor

@gthvn1 gthvn1 commented Dec 19, 2023

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.

@gthvn1 gthvn1 self-assigned this Dec 19, 2023
@gthvn1 gthvn1 requested a review from stormi December 19, 2023 14:45
@gthvn1
Copy link
Contributor Author

gthvn1 commented Dec 19, 2023

I can also be a little bit more restrictive and check that return code from run_command is either 0 or 4 and failed if it is not the case.

@benjamreis
Copy link
Contributor

I can also be a little bit more restrictive and check that return code from run_command is either 0 or 4 and failed if it is not the case.

I'd be more confortable with that yeah.

@gthvn1 gthvn1 force-pushed the gtn-dont-check-return-status-for-smartctl branch 2 times, most recently from 645faf1 to f741e78 Compare December 19, 2023 15:26
@gthvn1 gthvn1 force-pushed the gtn-dont-check-return-status-for-smartctl branch 3 times, most recently from 297d79b to b699c04 Compare December 19, 2023 15:44
@gthvn1 gthvn1 changed the title Don't check return status from smartctl -a Ensure that return code of smartctl is 0 or 4 Dec 19, 2023
@gthvn1 gthvn1 force-pushed the gtn-dont-check-return-status-for-smartctl branch 2 times, most recently from 06ff29e to e5928ed Compare December 19, 2023 16:00
@gthvn1 gthvn1 changed the title Ensure that return code of smartctl is 0 or 4 Fix issue in integration about smartctl and return error code 4 Dec 19, 2023
@@ -24,7 +24,7 @@ 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)
results[disk] = json.loads(cmd['stdout'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does smartctl always output JSON, even when there's an error? And what about stderr in case the command failed?

Copy link
Member

@stormi stormi Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would have checked the return code, and whenever the return code differs from 0 and 4, replace result[disk] with something which contains the return code, raw stdout and stderr (but just for the affected disks). That's why I'd also check with XO so that we know how they would handle this case. Do they display the JSON, uninterpreted? Do they look for specific pieces of information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we are already returning stdout that contains the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they just display the raw json (and we see the error code in it)

Copy link
Member

@stormi stormi Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this, the man page and a test I made gives me all I wanted to know: it wraps the call to "regular" smartctl and apparently always puts the result inside JSON, even when there are non-recoverable errors (unless there's an error generating the JSON itself, I guess).

See this example where I gave it a non recognised argument:

smartctl -j -a --wrongarg /dev/sdb
{
  "json_format_version": [
    1,
    0
  ],
  "smartctl": {
    "version": [
      7,
      0
    ],
    "svn_revision": "4883",
    "platform_info": "x86_64-linux-4.19.0+1",
    "build_info": "(local build)",
    "argv": [
      "smartctl",
      "-j",
      "-a",
      "--wrongarg",
      "/dev/sdb"
    ],
    "messages": [
      {
        "string": "=======> UNRECOGNIZED OPTION: wrongarg",
        "severity": "error"
      }
    ],
    "exit_status": 1
  }
}

So LGTM.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Dec 20, 2023

Screenshot from 2023-12-20 09-17-04

Copy link
Member

@stormi stormi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: "Some device doesn't support SMART capability" => "Some devices don't support SMART capability(ies?)", in the commit message.

@gthvn1
Copy link
Contributor Author

gthvn1 commented Dec 20, 2023

I followed the error message reported by smartctl:
SMART support is: Unavailable - device lacks SMART capability.
I can modify it no pbs

@gthvn1
Copy link
Contributor Author

gthvn1 commented Dec 20, 2023

But I think that SMART is the capability of monitoring and reporting disks status

Some devices don't support SMART capability and getting information
from such devices returns an error code 4. As it happens in CI we remove
the check of the return code knowing that this error code is a field
of the JSON output.

Signed-off-by: Guillaume <[email protected]>
@gthvn1 gthvn1 force-pushed the gtn-dont-check-return-status-for-smartctl branch from e5928ed to d4b8cd6 Compare December 20, 2023 14:05
@stormi stormi merged commit 5193737 into master Dec 20, 2023
4 checks passed
@gthvn1 gthvn1 deleted the gtn-dont-check-return-status-for-smartctl branch December 20, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants