Merge ~aluria/charm-hw-health/+git/hw-health-charm:bug/1852945 into ~nagios-charmers/charm-hw-health:master

Proposed by Alvaro Uria
Status: Merged
Approved by: Jeremy Lounder
Approved revision: cf636e32ed93ca56965555b45d5ff690d3076014
Merged at revision: a2ad5e0dde73cecb647e98b24af3e9a050538d5b
Proposed branch: ~aluria/charm-hw-health/+git/hw-health-charm:bug/1852945
Merge into: ~nagios-charmers/charm-hw-health:master
Diff against target: 331 lines (+292/-1)
4 files modified
src/files/megacli/check_megacli.py (+1/-1)
src/tests/hw-health-samples/megacli.output.nrpe.critical.1 (+135/-0)
src/tests/hw-health-samples/megacli.output.nrpe.critical.2 (+135/-0)
src/tests/unit/test_check_megacli.py (+21/-0)
Reviewer Review Type Date Requested Status
Jeremy Lounder (community) Approve
Nagios Charm developers Pending
Review via email: mp+375671@code.launchpad.net

Commit message

Fix KeyError bug on degraded MegaCLI drives

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Jeremy Lounder (jldev) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision a2ad5e0dde73cecb647e98b24af3e9a050538d5b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/files/megacli/check_megacli.py b/src/files/megacli/check_megacli.py
2index 364a654..ab3d99f 100755
3--- a/src/files/megacli/check_megacli.py
4+++ b/src/files/megacli/check_megacli.py
5@@ -87,7 +87,7 @@ def parse_output(policy=False):
6 if len(errors) > 0:
7 msg = ', '.join([
8 '{}({})'.format(cnt, vars()[cnt])
9- for cnt in ('failed_ld', 'wrg_policy_ld') if vars()['cnt'] > 0
10+ for cnt in ('failed_ld', 'wrg_policy_ld') if vars().get(cnt, 0) > 0
11 ])
12 msg += '; '.join(errors)
13 else:
14diff --git a/src/tests/hw-health-samples/megacli.output.nrpe.critical.1 b/src/tests/hw-health-samples/megacli.output.nrpe.critical.1
15new file mode 100644
16index 0000000..ee557b9
17--- /dev/null
18+++ b/src/tests/hw-health-samples/megacli.output.nrpe.critical.1
19@@ -0,0 +1,135 @@
20+
21+
22+Adapter 0 -- Virtual Drive Information:
23+Virtual Drive: 0 (Target Id: 0)
24+Name :
25+RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
26+Size : 3.637 TB
27+Sector Size : 512
28+Is VD emulated : Yes
29+Mirror Data : 3.637 TB
30+State : Degraded
31+Strip Size : 64 KB
32+Number Of Drives : 2
33+Span Depth : 1
34+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
35+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
36+Default Access Policy: Read/Write
37+Current Access Policy: Read/Write
38+Disk Cache Policy : Disk's Default
39+Encryption Type : None
40+Default Power Savings Policy: Controller Defined
41+Current Power Savings Policy: None
42+Can spin up in 1 minute: Yes
43+LD has drives that support T10 power conditions: No
44+LD's IO profile supports MAX power savings with cached writes: No
45+Bad Blocks Exist: No
46+Is VD Cached: No
47+
48+
49+Virtual Drive: 1 (Target Id: 1)
50+Name :
51+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
52+Size : 3.637 TB
53+Sector Size : 512
54+Is VD emulated : No
55+Parity Size : 0
56+State : Optimal
57+Strip Size : 64 KB
58+Number Of Drives : 1
59+Span Depth : 1
60+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
61+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
62+Default Access Policy: Read/Write
63+Current Access Policy: Read/Write
64+Disk Cache Policy : Disk's Default
65+Encryption Type : None
66+Default Power Savings Policy: Controller Defined
67+Current Power Savings Policy: None
68+Can spin up in 1 minute: Yes
69+LD has drives that support T10 power conditions: No
70+LD's IO profile supports MAX power savings with cached writes: No
71+Bad Blocks Exist: No
72+Is VD Cached: No
73+
74+
75+Virtual Drive: 2 (Target Id: 2)
76+Name :
77+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
78+Size : 3.637 TB
79+Sector Size : 512
80+Is VD emulated : No
81+Parity Size : 0
82+State : Optimal
83+Strip Size : 64 KB
84+Number Of Drives : 1
85+Span Depth : 1
86+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
87+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
88+Default Access Policy: Read/Write
89+Current Access Policy: Read/Write
90+Disk Cache Policy : Disk's Default
91+Encryption Type : None
92+Default Power Savings Policy: Controller Defined
93+Current Power Savings Policy: None
94+Can spin up in 1 minute: Yes
95+LD has drives that support T10 power conditions: No
96+LD's IO profile supports MAX power savings with cached writes: No
97+Bad Blocks Exist: No
98+Is VD Cached: No
99+
100+
101+Virtual Drive: 3 (Target Id: 3)
102+Name :
103+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
104+Size : 3.637 TB
105+Sector Size : 512
106+Is VD emulated : No
107+Parity Size : 0
108+State : Optimal
109+Strip Size : 64 KB
110+Number Of Drives : 1
111+Span Depth : 1
112+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
113+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
114+Default Access Policy: Read/Write
115+Current Access Policy: Read/Write
116+Disk Cache Policy : Disk's Default
117+Encryption Type : None
118+Default Power Savings Policy: Controller Defined
119+Current Power Savings Policy: None
120+Can spin up in 1 minute: Yes
121+LD has drives that support T10 power conditions: No
122+LD's IO profile supports MAX power savings with cached writes: No
123+Bad Blocks Exist: No
124+Is VD Cached: No
125+
126+
127+Virtual Drive: 4 (Target Id: 4)
128+Name :
129+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
130+Size : 3.637 TB
131+Sector Size : 512
132+Is VD emulated : No
133+Parity Size : 0
134+State : Optimal
135+Strip Size : 64 KB
136+Number Of Drives : 1
137+Span Depth : 1
138+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
139+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
140+Default Access Policy: Read/Write
141+Current Access Policy: Read/Write
142+Disk Cache Policy : Disk's Default
143+Encryption Type : None
144+Default Power Savings Policy: Controller Defined
145+Current Power Savings Policy: None
146+Can spin up in 1 minute: Yes
147+LD has drives that support T10 power conditions: No
148+LD's IO profile supports MAX power savings with cached writes: No
149+Bad Blocks Exist: No
150+Is VD Cached: No
151+
152+
153+
154+Exit Code: 0x00
155diff --git a/src/tests/hw-health-samples/megacli.output.nrpe.critical.2 b/src/tests/hw-health-samples/megacli.output.nrpe.critical.2
156new file mode 100644
157index 0000000..d0ee574
158--- /dev/null
159+++ b/src/tests/hw-health-samples/megacli.output.nrpe.critical.2
160@@ -0,0 +1,135 @@
161+
162+
163+Adapter 0 -- Virtual Drive Information:
164+Virtual Drive: 0 (Target Id: 0)
165+Name :
166+RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
167+Size : 3.637 TB
168+Sector Size : 512
169+Is VD emulated : Yes
170+Mirror Data : 3.637 TB
171+State : Degraded
172+Strip Size : 64 KB
173+Number Of Drives : 2
174+Span Depth : 1
175+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
176+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
177+Default Access Policy: Read/Write
178+Current Access Policy: Read/Write
179+Disk Cache Policy : Disk's Default
180+Encryption Type : None
181+Default Power Savings Policy: Controller Defined
182+Current Power Savings Policy: None
183+Can spin up in 1 minute: Yes
184+LD has drives that support T10 power conditions: No
185+LD's IO profile supports MAX power savings with cached writes: No
186+Bad Blocks Exist: No
187+Is VD Cached: No
188+
189+
190+Virtual Drive: 1 (Target Id: 1)
191+Name :
192+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
193+Size : 3.637 TB
194+Sector Size : 512
195+Is VD emulated : No
196+Parity Size : 0
197+State : Optimal
198+Strip Size : 64 KB
199+Number Of Drives : 1
200+Span Depth : 1
201+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
202+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
203+Default Access Policy: Read/Write
204+Current Access Policy: Read/Write
205+Disk Cache Policy : Disk's Default
206+Encryption Type : None
207+Default Power Savings Policy: Controller Defined
208+Current Power Savings Policy: None
209+Can spin up in 1 minute: Yes
210+LD has drives that support T10 power conditions: No
211+LD's IO profile supports MAX power savings with cached writes: No
212+Bad Blocks Exist: No
213+Is VD Cached: No
214+
215+
216+Virtual Drive: 2 (Target Id: 2)
217+Name :
218+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
219+Size : 3.637 TB
220+Sector Size : 512
221+Is VD emulated : No
222+Parity Size : 0
223+State : Optimal
224+Strip Size : 64 KB
225+Number Of Drives : 1
226+Span Depth : 1
227+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
228+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
229+Default Access Policy: Read/Write
230+Current Access Policy: Read/Write
231+Disk Cache Policy : Disk's Default
232+Encryption Type : None
233+Default Power Savings Policy: Controller Defined
234+Current Power Savings Policy: None
235+Can spin up in 1 minute: Yes
236+LD has drives that support T10 power conditions: No
237+LD's IO profile supports MAX power savings with cached writes: No
238+Bad Blocks Exist: No
239+Is VD Cached: No
240+
241+
242+Virtual Drive: 3 (Target Id: 3)
243+Name :
244+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
245+Size : 3.637 TB
246+Sector Size : 512
247+Is VD emulated : No
248+Parity Size : 0
249+State : Optimal
250+Strip Size : 64 KB
251+Number Of Drives : 1
252+Span Depth : 1
253+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
254+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
255+Default Access Policy: Read/Write
256+Current Access Policy: Read/Write
257+Disk Cache Policy : Disk's Default
258+Encryption Type : None
259+Default Power Savings Policy: Controller Defined
260+Current Power Savings Policy: None
261+Can spin up in 1 minute: Yes
262+LD has drives that support T10 power conditions: No
263+LD's IO profile supports MAX power savings with cached writes: No
264+Bad Blocks Exist: No
265+Is VD Cached: No
266+
267+
268+Virtual Drive: 4 (Target Id: 4)
269+Name :
270+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
271+Size : 3.637 TB
272+Sector Size : 512
273+Is VD emulated : No
274+Parity Size : 0
275+State : Degraded
276+Strip Size : 64 KB
277+Number Of Drives : 1
278+Span Depth : 1
279+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
280+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
281+Default Access Policy: Read/Write
282+Current Access Policy: Read/Write
283+Disk Cache Policy : Disk's Default
284+Encryption Type : None
285+Default Power Savings Policy: Controller Defined
286+Current Power Savings Policy: None
287+Can spin up in 1 minute: Yes
288+LD has drives that support T10 power conditions: No
289+LD's IO profile supports MAX power savings with cached writes: No
290+Bad Blocks Exist: No
291+Is VD Cached: No
292+
293+
294+
295+Exit Code: 0x00
296diff --git a/src/tests/unit/test_check_megacli.py b/src/tests/unit/test_check_megacli.py
297index d2e21c4..988075a 100644
298--- a/src/tests/unit/test_check_megacli.py
299+++ b/src/tests/unit/test_check_megacli.py
300@@ -4,6 +4,8 @@ import sys
301 import unittest
302 import unittest.mock as mock
303
304+import nagios_plugin3
305+
306 sys.path.append('files/megacli')
307 import check_megacli # noqa: E402
308
309@@ -17,3 +19,22 @@ class TestCheckMegaCLI(unittest.TestCase):
310 actual = mock_print.getvalue()
311 expected = 'OK: Optimal, ldrives[1], pdrives[4]\n'
312 self.assertEqual(actual, expected)
313+
314+ @mock.patch('sys.stdout', new_callable=io.StringIO)
315+ def test_parse_output_critical_singledrive(self, mock_print):
316+ check_megacli.INPUT_FILE = os.path.join(
317+ os.getcwd(), 'tests', 'hw-health-samples', 'megacli.output.nrpe.critical.1')
318+ expected = 'CRITICAL: adapter(0):ld(0):state(Degraded)'
319+ with self.assertRaises(nagios_plugin3.CriticalError) as context:
320+ check_megacli.parse_output()
321+ self.assertEqual(expected, str(context.exception))
322+
323+ @mock.patch('sys.stdout', new_callable=io.StringIO)
324+ def test_parse_output_critical_multiple(self, mock_print):
325+ check_megacli.INPUT_FILE = os.path.join(
326+ os.getcwd(), 'tests', 'hw-health-samples', 'megacli.output.nrpe.critical.2')
327+ expected = ('CRITICAL: adapter(0):ld(0):state(Degraded);'
328+ ' adapter(0):ld(4):state(Degraded)')
329+ with self.assertRaises(nagios_plugin3.CriticalError) as context:
330+ check_megacli.parse_output()
331+ self.assertEqual(expected, str(context.exception))

Subscribers

People subscribed via source and target branches