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

storage: SMART support #19103

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/storaged/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ import { VDODetails } from "./vdo-details.jsx";
import { NFSDetails } from "./nfs-details.jsx";
import { StratisPoolDetails, StratisStoppedPoolDetails } from "./stratis-details.jsx";
import { JobsPanel } from "./jobs-panel.jsx";
import { SmartDetails } from "./smart-details.jsx";

const _ = cockpit.gettext;

export class StdDetailsLayout extends React.Component {
render() {
const client = this.props.client;
const drive = this.props.drive;
const drive_ata = client.drives_ata[drive.path];

if (this.props.sidebar) {
return (
<>
Expand Down Expand Up @@ -73,6 +78,11 @@ export class StdDetailsLayout extends React.Component {
</div>
<JobsPanel client={this.props.client} />
</StackItem>
{ drive_ata &&
<StackItem>
<SmartDetails smartInfo={drive_ata} />
</StackItem>
Comment on lines +82 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

These 3 added lines are not executed by any test. Details

}
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storaged/drive-details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ export class DriveDetails extends React.Component {

const content = <Block client={this.props.client} block={drive_block} />;

return <StdDetailsLayout client={this.props.client} header={header} content={content} />;
return <StdDetailsLayout client={this.props.client} drive={drive} header={header} content={content} />;
}
}
120 changes: 120 additions & 0 deletions pkg/storaged/smart-details.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* This file is part of Cockpit.
*
* Copyright (C) 2017 Red Hat, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

It's a new file, should be 2023.

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, we live in ${current_year}

*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

import cockpit from "cockpit";
import React, { useState } from "react";
import * as timeformat from "timeformat.js";

import { Card, CardBody, CardHeader, CardTitle, DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm } from "@patternfly/react-core";
import { Dropdown, DropdownItem, KebabToggle } from '@patternfly/react-core/dist/esm/deprecated/components/Dropdown/index.js';

const _ = cockpit.gettext;

const selftestStatusDescription = {
success: _("Successful"),
aborted: _("Aborted"),
interrupted: _("Interrupted"),
fatal: _("Did not complete"),
error_unknown: _("Failed (Unknown)"),
error_electrical: _("Failed (Electrical)"),
error_servo: _("Failed (Servo)"),
error_read: _("Failed (Read)"),
error_handling: _("Failed (Damaged)"),
inprogress: _("In progress"),
};

const SmartActions = ({ smartInfo }) => {
const [isKebabOpen, setKebabOpen] = useState(false);
const smartSelftestStatus = smartInfo.SmartSelftestStatus;
Comment on lines +42 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

These 3 added lines are not executed by any test. Details


const runSmartTest = async (type) => {
await smartInfo.SmartSelftestStart(type, {});
Comment on lines +46 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test. Details

};

const abortSmartTest = async () => {
await smartInfo.SmartSelftestAbort({});
Comment on lines +50 to +51
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test. Details

};

const actions = [
<DropdownItem key="run-short-test"
isDisabled={smartSelftestStatus === "inprogress"}
onClick={() => { setKebabOpen(false); runSmartTest('short') }}>
{_("Run short test")}
</DropdownItem>,
<DropdownItem key="run-extended-test"
isDisabled={smartSelftestStatus === "inprogress"}
onClick={() => { setKebabOpen(false); runSmartTest('extended') }}>
{_("Run extended test")}
</DropdownItem>,
<DropdownItem key="run-conveyance-test"
isDisabled={smartSelftestStatus === "inprogress"}
onClick={() => { setKebabOpen(false); runSmartTest('conveyance') }}>
{_("Run conveyance test")}
</DropdownItem>,
Comment on lines +54 to +69
Copy link
Contributor

Choose a reason for hiding this comment

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

These 16 added lines are not executed by any test. Details

];

if (smartInfo.SmartSelftestStatus === "inprogress") {
actions.push(
<DropdownItem key="abort-smart-test"
onClick={() => { setKebabOpen(false); abortSmartTest('conveyance') }}>
{_("Abort test")}
</DropdownItem>,
Comment on lines +72 to +77
Copy link
Contributor

Choose a reason for hiding this comment

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

These 6 added lines are not executed by any test. Details

);
}

return (
<Dropdown toggle={<KebabToggle onToggle={(_, isOpen) => setKebabOpen(isOpen)} />}
isPlain
isOpen={isKebabOpen}
position="right"
id="smart-actions"
dropdownItems={actions} />
Comment on lines +81 to +87
Copy link
Contributor

Choose a reason for hiding this comment

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

These 7 added lines are not executed by any test. Details

);
};

export const SmartDetails = ({ smartInfo }) => {
const SmartDetailRow = ({ title, value }) => {
if (value === undefined)
return null;
Comment on lines +91 to +94
Copy link
Contributor

Choose a reason for hiding this comment

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

These 4 added lines are not executed by any test. Details


return (
<DescriptionListGroup>
<DescriptionListTerm>{title}</DescriptionListTerm>
<DescriptionListDescription>{value}</DescriptionListDescription>
</DescriptionListGroup>
Comment on lines +96 to +100
Copy link
Contributor

Choose a reason for hiding this comment

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

These 5 added lines are not executed by any test. Details

);
};

return (
<Card>
<CardHeader actions={{ actions: <SmartActions smartInfo={smartInfo} /> }}>
<CardTitle component="h2">{_("S.M.A.R.T")}</CardTitle>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's really something one can translate?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm force of habit

Copy link
Member

Choose a reason for hiding this comment

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

Maybe in non-latin languages? Like chinese or russian or so?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if in doubt, keep it translatable. I can't say I like the many dots, this looks a bit like a 90's superhero comic 😁 So please either "SMART", or at least make it consistent and add a period to the T as well.

</CardHeader>
<CardBody>
<DescriptionList isHorizontal horizontalTermWidthModifier={{ default: '20ch' }}>
<SmartDetailRow title={_("Power on hours")} value={cockpit.format(_("$0 hours"), Math.round(smartInfo.SmartPowerOnSeconds / 3600))} />
<SmartDetailRow title={_("Last updated")} value={timeformat.dateTime(new Date(smartInfo.SmartUpdated * 1000))} />
<SmartDetailRow title={_("Smart selftest status")} value={selftestStatusDescription[smartInfo.SmartSelftestStatus]} />
<SmartDetailRow title={_("Number of bad sectors")} value={smartInfo.SmartNumBadSectors} />
<SmartDetailRow title={_("Atributes failing")} value={smartInfo.SmartNumAttributesFailing} />
</DescriptionList>
</CardBody>
</Card>
Comment on lines +104 to +118
Copy link
Contributor

Choose a reason for hiding this comment

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

These 15 added lines are not executed by any test. Details

);
};