Browse Source

Allow SMART self test to recover themselves

Johann Schmitz 2 years ago
parent
commit
ae7c1a7b74
4 changed files with 136 additions and 2 deletions
  1. 4
    1
      smartcheck/__main__.py
  2. 4
    1
      smartcheck/check.py
  3. 12
    0
      tests/check.py
  4. 116
    0
      tests/samples/wdc-wd2000fyyz-recovered.txt

+ 4
- 1
smartcheck/__main__.py View File

@@ -47,6 +47,9 @@ def main():
47 47
     parser.add_argument('-x', '--exclude-notices', help='Do not report NOTICE warnings (default: %(default)s)', action='store_true', default=False)
48 48
     parser.add_argument('-n', '--notices-are-warnings', help='Exit with status code 1 on NOTICEs too (default: %(default)s)', action='store_true', default=False)
49 49
 
50
+    parser.add_argument('--accept-recovered-self-test', action='store_true', default=False,
51
+                        help='Only check the latest self test (accept a newer self tests without error)')
52
+
50 53
     parser.add_argument('--ignore-attributes', help='Ignore this S.M.A.R.T. attributes (id or name)', nargs='*')
51 54
     parser.add_argument('-v', '--verbose', help='Verbose messages', action='store_true', default=False)
52 55
     parser.add_argument('--debug', help="Print debug messages", action="store_true", default=False)
@@ -102,7 +105,7 @@ def main():
102 105
                 if any((ae.level == AttributeWarning.Critical for ae in attribute_errors.values())):
103 106
                     exit_code = 2
104 107
 
105
-            if not check.check_tests():
108
+            if not check.check_tests(latest_only=args.accept_recovered_self_test):
106 109
                 msg = (msg.strip() + '; S.M.A.R.T. self test reported an error').lstrip(';').strip()
107 110
                 exit_code = 2
108 111
 

+ 4
- 1
smartcheck/check.py View File

@@ -248,12 +248,15 @@ class SMARTCheck(object):
248 248
     def check(self, ignore_attributes=None):
249 249
         return len(self.check_attributes(ignore_attributes or [])) == 0 and self.check_tests() and self.ata_error_count == 0
250 250
 
251
-    def check_tests(self):
251
+    def check_tests(self, latest_only=False):
252 252
         ok_test_results = [
253 253
             'Completed without error',
254 254
             'Interrupted (host reset)', # reboot during self test
255 255
             'Aborted by host'
256 256
         ]
257
+        if latest_only and self.self_tests['test_results']:
258
+            return not self.self_tests['test_results'][2] in ok_test_results
259
+
257 260
         return not any([x[2] not in ok_test_results for x in self.self_tests['test_results']])
258 261
 
259 262
     def check_attributes(self, ignore_attributes=None):

+ 12
- 0
tests/check.py View File

@@ -6,6 +6,7 @@ from smartcheck.check import SMARTCheck, AttributeWarning, parse_range_specifier
6 6
 samples_path = os.path.join(os.path.dirname(__file__), 'samples')
7 7
 db_path = os.path.join(samples_path, '../../smartcheck/disks.yaml')
8 8
 
9
+
9 10
 class CheckTest(unittest.TestCase):
10 11
 
11 12
     def test_check_broken1(self):
@@ -181,6 +182,17 @@ ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_
181 182
                 (5, 'Reallocated_Sector_Ct'): AttributeWarning(AttributeWarning.Notice, 'Reallocated_Sector_Ct', 84)
182 183
             })
183 184
 
185
+    def test_check_recovered_self_tests(self):
186
+        with open(os.path.join(samples_path, 'seagate-barracuda-broken2.txt')) as f:
187
+            check = SMARTCheck(f)
188
+            self.assertFalse(check.check_tests())
189
+            self.assertFalse(check.check())
190
+
191
+        with open(os.path.join(samples_path, 'seagate-barracuda-broken2.txt')) as f:
192
+            check = SMARTCheck(f)
193
+            self.assertTrue(check.check_tests(latest_only=True))
194
+            self.assertFalse(check.check())
195
+
184 196
     def test_parse_range_specifier(self):
185 197
         # greater than
186 198
         f = parse_range_specifier(1)

+ 116
- 0
tests/samples/wdc-wd2000fyyz-recovered.txt View File

@@ -0,0 +1,116 @@
1
+smartctl 6.3 2014-07-26 r3976 [x86_64-linux-4.4.26-gentoo-cit-1] (local build)
2
+Copyright (C) 2002-14, Bruce Allen, Christian Franke, www.smartmontools.org
3
+
4
+=== START OF INFORMATION SECTION ===
5
+Model Family:     Western Digital RE4 (SATA 6Gb/s)
6
+Device Model:     WDC WD2000FYYZ-01UL1B2
7
+Serial Number:    WD-WMC1P0DCMTW3
8
+LU WWN Device Id: 5 0014ee 0ae9a25c2
9
+Firmware Version: 01.01K03
10
+User Capacity:    2.000.398.934.016 bytes [2,00 TB]
11
+Sector Size:      512 bytes logical/physical
12
+Rotation Rate:    7200 rpm
13
+Device is:        In smartctl database [for details use: -P show]
14
+ATA Version is:   ATA8-ACS (minor revision not indicated)
15
+SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
16
+Local Time is:    Wed Dec 14 16:00:46 2016 CET
17
+SMART support is: Available - device has SMART capability.
18
+SMART support is: Enabled
19
+
20
+=== START OF READ SMART DATA SECTION ===
21
+SMART overall-health self-assessment test result: PASSED
22
+
23
+General SMART Values:
24
+Offline data collection status:  (0x84)	Offline data collection activity
25
+					was suspended by an interrupting command from host.
26
+					Auto Offline Data Collection: Enabled.
27
+Self-test execution status:      (   0)	The previous self-test routine completed
28
+					without error or no self-test has ever
29
+					been run.
30
+Total time to complete Offline
31
+data collection: 		(26100) seconds.
32
+Offline data collection
33
+capabilities: 			 (0x7b) SMART execute Offline immediate.
34
+					Auto Offline data collection on/off support.
35
+					Suspend Offline collection upon new
36
+					command.
37
+					Offline surface scan supported.
38
+					Self-test supported.
39
+					Conveyance Self-test supported.
40
+					Selective Self-test supported.
41
+SMART capabilities:            (0x0003)	Saves SMART data before entering
42
+					power-saving mode.
43
+					Supports SMART auto save timer.
44
+Error logging capability:        (0x01)	Error logging supported.
45
+					General Purpose Logging supported.
46
+Short self-test routine
47
+recommended polling time: 	 (   2) minutes.
48
+Extended self-test routine
49
+recommended polling time: 	 ( 285) minutes.
50
+Conveyance self-test routine
51
+recommended polling time: 	 (   5) minutes.
52
+SCT capabilities: 	       (0x70bd)	SCT Status supported.
53
+					SCT Error Recovery Control supported.
54
+					SCT Feature Control supported.
55
+					SCT Data Table supported.
56
+
57
+SMART Attributes Data Structure revision number: 16
58
+Vendor Specific SMART Attributes with Thresholds:
59
+ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
60
+  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
61
+  3 Spin_Up_Time            0x0027   100   253   021    Pre-fail  Always       -       0
62
+  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       4
63
+  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
64
+  7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
65
+  9 Power_On_Hours          0x0032   082   082   000    Old_age   Always       -       13384
66
+ 10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
67
+ 11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
68
+ 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       4
69
+183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
70
+192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       1
71
+193 Load_Cycle_Count        0x0032   200   200   000    Old_age   Always       -       2
72
+194 Temperature_Celsius     0x0022   122   117   000    Old_age   Always       -       28
73
+196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
74
+197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
75
+198 Offline_Uncorrectable   0x0030   200   200   000    Old_age   Offline      -       0
76
+199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
77
+200 Multi_Zone_Error_Rate   0x0008   200   200   000    Old_age   Offline      -       6
78
+
79
+SMART Error Log Version: 1
80
+No Errors Logged
81
+
82
+SMART Self-test log structure revision number 1
83
+Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
84
+# 1  Extended offline    Completed without error       00%     13360         -
85
+# 2  Extended offline    Completed without error       00%     13286         -
86
+# 3  Extended offline    Completed without error       00%     13238         -
87
+# 4  Extended offline    Completed without error       00%     13189         -
88
+# 5  Extended offline    Completed without error       00%     13165         -
89
+# 6  Short offline       Completed without error       00%     13161         -
90
+# 7  Extended offline    Completed: read failure       10%     13119         3907004231
91
+# 8  Extended offline    Completed without error       00%     12951         -
92
+# 9  Extended offline    Completed without error       00%     12783         -
93
+#10  Extended offline    Completed without error       00%     12615         -
94
+#11  Extended offline    Completed without error       00%     12452         -
95
+#12  Extended offline    Completed without error       00%     12278         -
96
+#13  Extended offline    Completed without error       00%     12111         -
97
+#14  Extended offline    Completed without error       00%     11943         -
98
+#15  Extended offline    Completed without error       00%     11775         -
99
+#16  Extended offline    Completed without error       00%     11612         -
100
+#17  Extended offline    Completed without error       00%     11439         -
101
+#18  Extended offline    Completed without error       00%     11272         -
102
+#19  Extended offline    Completed without error       00%     11104         -
103
+#20  Extended offline    Completed without error       00%     10936         -
104
+#21  Extended offline    Completed without error       00%     10768         -
105
+1 of 1 failed self-tests are outdated by newer successful extended offline self-test # 1
106
+
107
+SMART Selective self-test log data structure revision number 1
108
+ SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
109
+    1        0        0  Not_testing
110
+    2        0        0  Not_testing
111
+    3        0        0  Not_testing
112
+    4        0        0  Not_testing
113
+    5        0        0  Not_testing
114
+Selective self-test flags (0x0):
115
+  After scanning selected spans, do NOT read-scan remainder of disk.
116
+If Selective self-test is pending on power-up, resume after 0 minute delay.