Merge lp:~bladernr/opencompute/merge-github-junk into lp:opencompute/opencompute-testing
- merge-github-junk
- Merge into opencompute-testing
Proposed by
Jeff Lane
Status: | Merged |
---|---|
Approved by: | Jeff Lane |
Approved revision: | 47 |
Merged at revision: | 30 |
Proposed branch: | lp:~bladernr/opencompute/merge-github-junk |
Merge into: | lp:opencompute/opencompute-testing |
Diff against target: |
9031 lines (+7262/-531) 109 files modified
README.tips (+121/-0) bin/bad_block_test (+72/-0) bin/bios_info (+2/-0) bin/block_device_resource (+80/-0) bin/check_sata_port (+2/-0) bin/check_sata_port_leopard (+38/-0) bin/check_usb_port (+2/-0) bin/check_usb_port_leopard (+43/-0) bin/cpu_info (+2/-0) bin/cpu_info_leopard (+83/-0) bin/create_raid (+140/-0) bin/dcmi_inventory (+136/-0) bin/dcmi_power_off_on (+190/-0) bin/dcmi_power_reset (+139/-0) bin/dcmi_priv_admin (+174/-0) bin/dcmi_priv_oper (+174/-0) bin/dcmi_priv_user (+174/-0) bin/dcmi_sampling (+271/-0) bin/dcmi_thermal_ib (+212/-0) bin/dcmi_thermal_oob (+243/-0) bin/disk_health (+138/-0) bin/disk_info (+2/-0) bin/disk_info_leopard (+67/-0) bin/ipmi_fru (+163/-0) bin/ipmi_inventory (+214/-0) bin/ipmi_power_draw (+126/-0) bin/ipmi_power_off_on (+193/-0) bin/ipmi_power_policy (+165/-0) bin/ipmi_power_reset (+142/-0) bin/ipmi_priv_admin (+176/-0) bin/ipmi_priv_oper (+174/-0) bin/ipmi_priv_user (+176/-0) bin/ipmi_sampling (+273/-0) bin/ipmi_sel_entries (+9/-11) bin/ipmi_sensors_ib (+215/-0) bin/ipmi_sensors_oob (+240/-0) bin/ipmi_warm_reboot (+173/-0) bin/ocp_memory_info (+80/-0) bin/ping_test (+76/-0) bin/processor_topology (+6/-0) bin/raid_availability_test (+62/-0) bin/raid_hdd_info (+61/-0) bin/raid_info (+2/-0) bin/read_write_file (+181/-0) bin/rebulid_raid (+280/-0) bin/system_stress (+71/-0) debian/changelog (+13/-1) debian/control (+2/-2) examples/bmc.cfg (+144/-0) examples/me.cfg (+81/-8) jobs/TC-001-0001-CPU_Memory.txt.in (+0/-32) jobs/TC-001-0002-Platform_Controller_Hub.txt.in (+0/-14) jobs/TC-001-0006-Hardware_Monitoring.txt (+22/-0) jobs/TC-001-0007-In_band_Platform_Controller_Hub_Management_Engine.txt (+15/-0) jobs/TC-001-0008-Out_of_band_Platform_Controller_Hub_Management_Engine.txt (+16/-0) jobs/TC-002-0002-Management_Node_Identifier.txt (+6/-0) jobs/TC-002-0003-Rights_and_Credentials.txt (+14/-0) jobs/TC-002-0006-Remotely_Power_Control.txt (+13/-0) jobs/TC-002-0007-Power_Draw.txt (+9/-0) jobs/TC-002-0008-Temperature.txt (+8/-0) jobs/TC-002-0009-User_Levels.txt (+26/-0) jobs/TC-002-0010-Inventory.txt (+19/-0) jobs/TC-002-0011-System_Log.txt.in (+0/-10) jobs/TC-003-0001-Hardware_Information.txt.in (+0/-58) jobs/TC-003-0003-Network_Performance.txt.in (+0/-23) jobs/TC-003-0004-Disk_Healthiness.txt (+40/-0) jobs/TC-003-0005-System_Stress.txt (+7/-0) jobs/TC-004-0001-JBOD_Testing.txt (+74/-0) jobs/TC-005-0001-CPU_Memory.txt (+35/-0) jobs/TC-005-0002-Platform_Controller_Hub.txt (+15/-0) jobs/TC-005-0006-Sensors_Monitoring.txt (+55/-0) jobs/TC-005-0009-Power_Policy.txt (+30/-0) jobs/TC-006-0002-Management_Node_Identifier.txt (+6/-0) jobs/TC-006-0003-Rights_and_Credentials.txt (+21/-0) jobs/TC-006-0006-Remotely_Power_Control.txt (+27/-0) jobs/TC-006-0007-Temperature.txt (+8/-0) jobs/TC-006-0008-User_Levels.txt (+26/-0) jobs/TC-006-0009-Inventory.txt (+20/-0) jobs/TC-006-0010-System_Log.txt (+27/-0) jobs/TC-007-0001-System_Information.txt (+43/-0) jobs/TC-007-0002-Network_Interface_Controller.txt (+24/-0) jobs/TC-007-0003-Hard_Disk_Drive.txt (+44/-0) jobs/TC-007-0004-System_Idle_and_Stress_Test.txt (+8/-0) jobs/TC-007-0005-JBOD_Testing.txt (+74/-0) jobs/dcmi_in_band.txt.in (+0/-56) jobs/ipmi.txt.in (+0/-151) jobs/ocp-disk.txt.in (+0/-17) jobs/ocp-local.txt.in (+0/-62) jobs/ocp-memory.txt.in (+0/-20) jobs/ocp-miscellanea.txt.in (+0/-19) jobs/ocp-power-management.txt.in (+0/-42) whitelists/opencompute-certify-basic.whitelist (+42/-0) whitelists/opencompute-certify-basic_leopard.whitelist (+37/-0) whitelists/opencompute-certify-iperf.whitelist (+1/-1) whitelists/opencompute-certify-local.whitelist (+18/-2) whitelists/opencompute-certify-local_leopard.whitelist (+48/-0) whitelists/opencompute-certify-raid0.whitelist (+29/-0) whitelists/opencompute-certify-raid0_leopard.whitelist (+29/-0) whitelists/opencompute-certify-raid6.whitelist (+31/-0) whitelists/opencompute-certify-raid6_leopard.whitelist (+30/-0) whitelists/opencompute-certify-remoteBMC_leopard.whitelist (+42/-0) whitelists/opencompute-certify-remoteME.whitelist (+8/-1) whitelists/opencompute-certify-remotePC.whitelist (+32/-0) whitelists/opencompute-certify-remotePC_leopard.whitelist (+34/-0) whitelists/opencompute-certify-stress.whitelist (+32/-0) whitelists/opencompute-certify-stressBMC_leopard.whitelist (+27/-0) whitelists/opencompute-certify-stressME.whitelist (+28/-0) whitelists/opencompute-certify-stress_leopard.whitelist (+32/-0) whitelists/sample-normal.whitelist (+27/-1) |
To merge this branch: | bzr merge lp:~bladernr/opencompute/merge-github-junk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jeff Lane | Approve | ||
Review via email: mp+268148@code.launchpad.net |
Commit message
Description of the change
Merges in all the stuff ITRI put into github.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'README.tips' | |||
2 | --- README.tips 1970-01-01 00:00:00 +0000 | |||
3 | +++ README.tips 2015-08-14 22:03:31 +0000 | |||
4 | @@ -0,0 +1,121 @@ | |||
5 | 1 | ############User manual and installation guide################ | ||
6 | 2 | Note: Please use Ubuntu 12.04 or lately. | ||
7 | 3 | |||
8 | 4 | ######[Run Checkbox]###### | ||
9 | 5 | $ opencompute-certification | ||
10 | 6 | Note, sudo is not necessary, you should be prompted for a root password. | ||
11 | 7 | |||
12 | 8 | ######[Important directory]###### | ||
13 | 9 | Runtime Logs: $HOME/.cache/plainbox/ | ||
14 | 10 | Results: $HOME/.local/plainbox/ | ||
15 | 11 | |||
16 | 12 | ############################################################################################## | ||
17 | 13 | Before running ME/BMC test, please fill in related information in configuration file. | ||
18 | 14 | Each section exists in configuration file has its own purpose. | ||
19 | 15 | The following will explain how to fill in settings in each section. | ||
20 | 16 | |||
21 | 17 | Note: | ||
22 | 18 | 1. Path of configuration file: /etc/xdg/bmc.cfg or /etc/xdg/me.cfg | ||
23 | 19 | 2. Without these settings pre-setting in configuration file, you won't start tests smoothly. | ||
24 | 20 | |||
25 | 21 | ############################################################################################## | ||
26 | 22 | |||
27 | 23 | |||
28 | 24 | ############User manual of each section################ | ||
29 | 25 | |||
30 | 26 | ######[Targets]###### | ||
31 | 27 | For remotely access via IPMI/DCMI, you need to fill in ME/BMC IP address of SUT. | ||
32 | 28 | For example, ME/BMC IP: 10.2.107.5 | ||
33 | 29 | [Targets] | ||
34 | 30 | Target1: 10.2.107.5 | ||
35 | 31 | |||
36 | 32 | ######[Account]###### | ||
37 | 33 | For remotely access via IPMI/DCMI, you need to fill in ME/BMC account here. | ||
38 | 34 | For example, USER/PASSWORD: OCP/OCP. Then, the settings in this section must be | ||
39 | 35 | [Account] | ||
40 | 36 | USER: OCP | ||
41 | 37 | PASSWORD: OCP | ||
42 | 38 | |||
43 | 39 | ######[Sensors] and [SensorsForCPUTemp]###### | ||
44 | 40 | For thermal tests of ME/BMC sensors, you need to check and set Sensor ID before starting tests. | ||
45 | 41 | Refers to TC-001-0006-Hardware_Monitoring.txt.in, | ||
46 | 42 | there are five kinds of sensors to monitor, so please write corresponding sensor ID to this field. | ||
47 | 43 | For example, the sensor ID related to these five kinds of sensors on Winterfell | ||
48 | 44 | are "outlet Temp", "inlet Temp", "PCH Temp", "P0 DIMM Temp", "P1 DIMM Temp", "P0 Therm Margin", | ||
49 | 45 | "P1 Therm Margin", "CPU0 Tjmax", "CPU1 Tjmax" | ||
50 | 46 | [Sensors] | ||
51 | 47 | Outlet: Outlet Temp | ||
52 | 48 | Inlet: Inlet Temp | ||
53 | 49 | PCH: PCH Temp | ||
54 | 50 | Px DIMM: P0 DIMM Temp | ||
55 | 51 | Py DIMM: P1 DIMM Temp | ||
56 | 52 | CPUx: CPU0 Temp | ||
57 | 53 | CPUy: CPU1 Temp | ||
58 | 54 | |||
59 | 55 | Note: | ||
60 | 56 | Case1. There are CPU sensors to monitor CPU temperature directly. | ||
61 | 57 | You just fill in sensor IDs behind key "CPUx" and "CPUy" and | ||
62 | 58 | don't care the section [SensorsForCPUTemp] at all. | ||
63 | 59 | Case2. There are no CPU sensors to monitor CPU temperature directly. | ||
64 | 60 | CPUx temperature is derived from Px Therm Margin and CPUx Tjmax. | ||
65 | 61 | ie,"CPU0 Temp" = "P0 Therm Margin" + "CPU0 Tjmax" | ||
66 | 62 | (It still requires "PU0 Temp" marked behind key "CPUx") | ||
67 | 63 | Besides, please also fill in "P0 Therm Margin", "PU0 Tjmax" | ||
68 | 64 | to corresponding section presented as below. | ||
69 | 65 | [SensorsForCPUTemp] | ||
70 | 66 | Px Therm Margin: P0 Therm Margin | ||
71 | 67 | Py Therm Margin: P1 Therm Margin | ||
72 | 68 | CPUx Tjmax: CPU0 Tjmax | ||
73 | 69 | CPUy Tjmax: CPU1 Tjmax | ||
74 | 70 | |||
75 | 71 | |||
76 | 72 | ######[SensorsForSampling]###### | ||
77 | 73 | Refers to test case TC-002-0008-001-Temp_Sampling_Increment, the description is to retrieve CPU and intake temperature 30 times. | ||
78 | 74 | For example, the related sensor IDs on Winterfell are "Inlet Temp", "P0 Therm Margin", "P1 Therm Margin", "CPU0 Tjmax", "CPU1 Tjmax". | ||
79 | 75 | [SensorsForSampling] | ||
80 | 76 | Inlet: Inlet Temp | ||
81 | 77 | CPUx: CPU0 Temp | ||
82 | 78 | CPUy: CPU1 Temp | ||
83 | 79 | Note: if the CPU0 temperature derives from "P0 therm Margin" and "CPU0 Tjmax", | ||
84 | 80 | you have to give a string "CPU0 temp" behind key "CPUx". And also remember to fill in the sensor ID in section [SensorsForCPUTemp]. | ||
85 | 81 | Please refer to section [Sensors]. | ||
86 | 82 | |||
87 | 83 | |||
88 | 84 | ############################################################################################## | ||
89 | 85 | The following four sections [Admin Level], [Operator Level], [User Level] and [Add User Test] are for User level test. | ||
90 | 86 | Please refer to TC-002-0009-User_Levels.txt.in. In these four sections, you don't need to modify settings here. | ||
91 | 87 | |||
92 | 88 | ######[Admin Level]###### | ||
93 | 89 | [Admin Level] | ||
94 | 90 | ADMIN_NAME: ccma_admin | ||
95 | 91 | ADMIN_PASSWD: ccma_admin | ||
96 | 92 | priv_level: 4 | ||
97 | 93 | user_id: 3 | ||
98 | 94 | channel_num: 1 | ||
99 | 95 | Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test. | ||
100 | 96 | |||
101 | 97 | ######[Operator Level]###### | ||
102 | 98 | [Operator Level] | ||
103 | 99 | OPER_NAME: ccma_oper | ||
104 | 100 | OPER_PASSWD: ccma_oper | ||
105 | 101 | priv_level: 3 | ||
106 | 102 | user_id: 4 | ||
107 | 103 | channel_num: 1 | ||
108 | 104 | Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test. | ||
109 | 105 | |||
110 | 106 | ######[User Level]###### | ||
111 | 107 | [User Level] | ||
112 | 108 | USER_NAME: ccma_user | ||
113 | 109 | USER_PASSWD: ccma_user | ||
114 | 110 | priv_level: 2 | ||
115 | 111 | user_id: 5 | ||
116 | 112 | channel_num: 1 | ||
117 | 113 | Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test. | ||
118 | 114 | |||
119 | 115 | |||
120 | 116 | ######[Add User Test]###### | ||
121 | 117 | [Add User Test] | ||
122 | 118 | NEW_USER_NAME: ccma_test | ||
123 | 119 | NEW_USER_ID: 6 | ||
124 | 120 | Note: Do not need to create this account manually | ||
125 | 121 | |||
126 | 0 | 122 | ||
127 | === added file 'bin/bad_block_test' | |||
128 | --- bin/bad_block_test 1970-01-01 00:00:00 +0000 | |||
129 | +++ bin/bad_block_test 2015-08-14 22:03:31 +0000 | |||
130 | @@ -0,0 +1,72 @@ | |||
131 | 1 | #!/usr/bin/env python3 | ||
132 | 2 | |||
133 | 3 | """ | ||
134 | 4 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
135 | 5 | Industrial Technology Research Institute | ||
136 | 6 | |||
137 | 7 | It is NOT YET officially approved by OCP. | ||
138 | 8 | |||
139 | 9 | bad_block_test | ||
140 | 10 | 1. Use badblocks command to perform a full disk bad block scan | ||
141 | 11 | with given pattern. | ||
142 | 12 | 2. The duration of the test is under 24 hours. | ||
143 | 13 | 3. Criteria: pass if no hard disk error. | ||
144 | 14 | |||
145 | 15 | Authors | ||
146 | 16 | Nelson Chu <Nelson.Chu@itri.org.tw> | ||
147 | 17 | |||
148 | 18 | This program is free software: you can redistribute it and/or modify | ||
149 | 19 | it under the terms of the GNU General Public License version 3, | ||
150 | 20 | as published by the Free Software Foundation. | ||
151 | 21 | |||
152 | 22 | This program is distributed in the hope that it will be useful, | ||
153 | 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
154 | 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
155 | 25 | GNU General Public License for more details. | ||
156 | 26 | |||
157 | 27 | You should have received a copy of the GNU General Public License | ||
158 | 28 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
159 | 29 | |||
160 | 30 | """ | ||
161 | 31 | |||
162 | 32 | import os | ||
163 | 33 | import re | ||
164 | 34 | import sys | ||
165 | 35 | from subprocess import check_output, STDOUT | ||
166 | 36 | from argparse import ArgumentParser, RawTextHelpFormatter | ||
167 | 37 | |||
168 | 38 | def run(pattern, device): | ||
169 | 39 | return_code = 0 | ||
170 | 40 | command = "badblocks -wsvf -t {0} {1}".format(pattern, device) | ||
171 | 41 | |||
172 | 42 | try: | ||
173 | 43 | with open(os.devnull, "w") as NULL: | ||
174 | 44 | output = check_output(command, stderr=STDOUT, shell=True) | ||
175 | 45 | output = output.decode('utf-8') | ||
176 | 46 | except Exception as e: | ||
177 | 47 | print(e.output.decode('utf-8')) | ||
178 | 48 | return_code = 10 | ||
179 | 49 | return return_code | ||
180 | 50 | |||
181 | 51 | bad_blocks_match = re.search(r'\n(Pass completed\,\s(\d+)\s.*)\n$', output) | ||
182 | 52 | if bad_blocks_match: | ||
183 | 53 | print(bad_blocks_match.group(1)) | ||
184 | 54 | if int(bad_blocks_match.group(2)) != 0: | ||
185 | 55 | return_code = 20 | ||
186 | 56 | else: | ||
187 | 57 | print("Cannot parse badblocks output.") | ||
188 | 58 | return_code = 30 | ||
189 | 59 | return return_code | ||
190 | 60 | |||
191 | 61 | def main(): | ||
192 | 62 | parser = ArgumentParser(formatter_class=RawTextHelpFormatter) | ||
193 | 63 | parser.add_argument('-t', '--pattern', type=str, required=True, | ||
194 | 64 | help=("Specify a test pattern to be read \n" | ||
195 | 65 | + "(and written) to disk blocks.")) | ||
196 | 66 | parser.add_argument('-d', '--device', type=str, required=True, | ||
197 | 67 | help=("The device which tests in badblocks.")) | ||
198 | 68 | args = parser.parse_args() | ||
199 | 69 | return run(args.pattern, args.device) | ||
200 | 70 | |||
201 | 71 | if __name__ == '__main__': | ||
202 | 72 | sys.exit(main()) | ||
203 | 0 | 73 | ||
204 | === modified file 'bin/bios_info' | |||
205 | --- bin/bios_info 2015-03-03 15:59:42 +0000 | |||
206 | +++ bin/bios_info 2015-08-14 22:03:31 +0000 | |||
207 | @@ -3,6 +3,8 @@ | |||
208 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications |
209 | 4 | Industrial Technology Research Institute | 4 | Industrial Technology Research Institute |
210 | 5 | 5 | ||
211 | 6 | It is NOT YET officially approved by OCP. | ||
212 | 7 | |||
213 | 6 | bios_info | 8 | bios_info |
214 | 7 | 1. Use lshw command to gather BIOS information. | 9 | 1. Use lshw command to gather BIOS information. |
215 | 8 | 2. The program will output BIOS vendor, version and release date. | 10 | 2. The program will output BIOS vendor, version and release date. |
216 | 9 | 11 | ||
217 | === added file 'bin/block_device_resource' | |||
218 | --- bin/block_device_resource 1970-01-01 00:00:00 +0000 | |||
219 | +++ bin/block_device_resource 2015-08-14 22:03:31 +0000 | |||
220 | @@ -0,0 +1,80 @@ | |||
221 | 1 | #!/usr/bin/env python3 | ||
222 | 2 | |||
223 | 3 | import os | ||
224 | 4 | import re | ||
225 | 5 | from glob import glob | ||
226 | 6 | |||
227 | 7 | rootdir_pattern = re.compile('^.*?/devices') | ||
228 | 8 | |||
229 | 9 | def device_state(name): | ||
230 | 10 | """ | ||
231 | 11 | Follow pmount policy to determine whether a device is removable or internal. | ||
232 | 12 | """ | ||
233 | 13 | with open('/sys/block/%s/device/block/%s/removable' % (name, name)) as f: | ||
234 | 14 | if f.read(1) == '1': | ||
235 | 15 | return 'removable' | ||
236 | 16 | |||
237 | 17 | path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name)) | ||
238 | 18 | hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire") | ||
239 | 19 | for bus in hotplug_buses: | ||
240 | 20 | if os.path.exists('/sys/bus/%s' % bus): | ||
241 | 21 | for device_bus in os.listdir('/sys/bus/%s/devices' % bus): | ||
242 | 22 | device_link = rootdir_pattern.sub('', os.readlink( | ||
243 | 23 | '/sys/bus/%s/devices/%s' % (bus, device_bus))) | ||
244 | 24 | if re.search(device_link, path): | ||
245 | 25 | return 'removable' | ||
246 | 26 | |||
247 | 27 | return 'internal' | ||
248 | 28 | |||
249 | 29 | |||
250 | 30 | def usb_support(name, version): | ||
251 | 31 | """ | ||
252 | 32 | Check the USB specification number for both hub port and device | ||
253 | 33 | """ | ||
254 | 34 | path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name)) | ||
255 | 35 | |||
256 | 36 | # Remove the usb config.interface part of the path | ||
257 | 37 | m = re.match('((.*usb\d+).*\/)\d-[\d\.:\-]+\/.*', path) | ||
258 | 38 | if m: | ||
259 | 39 | device_path = m.group(1) | ||
260 | 40 | hub_port_path = m.group(2) | ||
261 | 41 | |||
262 | 42 | # Check the highest version of USB the device supports | ||
263 | 43 | with open('/sys/devices/%s/version' %device_path) as f: | ||
264 | 44 | if float(f.readline()) < version: | ||
265 | 45 | return 'unsupported' | ||
266 | 46 | |||
267 | 47 | # Check the highest version of USB the hub supports | ||
268 | 48 | with open('/sys/devices/%s/version' %hub_port_path) as f: | ||
269 | 49 | if float(f.readline()) < version: | ||
270 | 50 | return 'unsupported' | ||
271 | 51 | |||
272 | 52 | return 'supported' | ||
273 | 53 | |||
274 | 54 | return 'unsupported' | ||
275 | 55 | |||
276 | 56 | def device_rotation(name): | ||
277 | 57 | with open('/sys/block/%s/device/block/%s/queue/rotational' % (name, name)) as f: | ||
278 | 58 | if f.read(1) == '1': | ||
279 | 59 | return 'yes' | ||
280 | 60 | |||
281 | 61 | return 'no' | ||
282 | 62 | |||
283 | 63 | for path in glob('/sys/block/*/device'): | ||
284 | 64 | name = re.sub('.*/(.*?)/device', '\g<1>', path) | ||
285 | 65 | state = device_state(name) | ||
286 | 66 | usb2 = usb_support(name, 2.00) | ||
287 | 67 | usb3 = usb_support(name, 3.00) | ||
288 | 68 | rotation = device_rotation(name) | ||
289 | 69 | # FIXME: Remove leading block device name when the requirements | ||
290 | 70 | # checking code in Checkbox allows it | ||
291 | 71 | print("""\ | ||
292 | 72 | %(name)s_state: %(state)s | ||
293 | 73 | %(name)s_usb2: %(usb2)s | ||
294 | 74 | %(name)s_usb3: %(usb3)s | ||
295 | 75 | %(name)s_rotation: %(rotation)s | ||
296 | 76 | """ % {"name": name, | ||
297 | 77 | "state": state, | ||
298 | 78 | "usb2": usb2, | ||
299 | 79 | "usb3": usb3, | ||
300 | 80 | "rotation": rotation}) | ||
301 | 0 | 81 | ||
302 | === modified file 'bin/check_sata_port' | |||
303 | --- bin/check_sata_port 2015-03-03 15:59:42 +0000 | |||
304 | +++ bin/check_sata_port 2015-08-14 22:03:31 +0000 | |||
305 | @@ -3,6 +3,8 @@ | |||
306 | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications |
307 | 4 | # Industrial Technology Research Institute | 4 | # Industrial Technology Research Institute |
308 | 5 | # | 5 | # |
309 | 6 | # It is NOT YET officially approved by OCP. | ||
310 | 7 | # | ||
311 | 6 | # check_sata_port | 8 | # check_sata_port |
312 | 7 | # 1. Use dmesg command to gather SATA information. | 9 | # 1. Use dmesg command to gather SATA information. |
313 | 8 | # 2. Criteria: SATA port speed up to 6.0Gps. | 10 | # 2. Criteria: SATA port speed up to 6.0Gps. |
314 | 9 | 11 | ||
315 | === added file 'bin/check_sata_port_leopard' | |||
316 | --- bin/check_sata_port_leopard 1970-01-01 00:00:00 +0000 | |||
317 | +++ bin/check_sata_port_leopard 2015-08-14 22:03:31 +0000 | |||
318 | @@ -0,0 +1,38 @@ | |||
319 | 1 | #!/bin/bash | ||
320 | 2 | # | ||
321 | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
322 | 4 | # Industrial Technology Research Institute | ||
323 | 5 | # | ||
324 | 6 | # It is NOT YET officially approved by OCP. | ||
325 | 7 | # | ||
326 | 8 | # check_sata_port | ||
327 | 9 | # 1. Retrieve dmesg log to gather SATA information. | ||
328 | 10 | # 2. Criteria: SATA port speed up to 6.0Gps. | ||
329 | 11 | # | ||
330 | 12 | # Authors | ||
331 | 13 | # Nelson Chu <Nelson.Chu@itri.org.tw> | ||
332 | 14 | # | ||
333 | 15 | # This program is free software: you can redistribute it and/or modify | ||
334 | 16 | # it under the terms of the GNU General Public License version 3, | ||
335 | 17 | # as published by the Free Software Foundation. | ||
336 | 18 | # | ||
337 | 19 | # This program is distributed in the hope that it will be useful, | ||
338 | 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
339 | 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
340 | 22 | # GNU General Public License for more details. | ||
341 | 23 | # | ||
342 | 24 | # You should have received a copy of the GNU General Public License | ||
343 | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
344 | 26 | # | ||
345 | 27 | |||
346 | 28 | output=(`cat /var/log/dmesg |grep -i "SATA link up"| awk '{print $7}'`) | ||
347 | 29 | |||
348 | 30 | for ((i=0; i<${#output[@]}; i++)); do | ||
349 | 31 | if [ "$output" != "6.0" ]; then | ||
350 | 32 | echo "Do not support SATA 6Gps ports" | ||
351 | 33 | exit 1 | ||
352 | 34 | fi | ||
353 | 35 | done | ||
354 | 36 | |||
355 | 37 | echo "Support SATA 6Gps ports" | ||
356 | 38 | exit 0 | ||
357 | 0 | 39 | ||
358 | === modified file 'bin/check_usb_port' | |||
359 | --- bin/check_usb_port 2015-03-03 15:59:42 +0000 | |||
360 | +++ bin/check_usb_port 2015-08-14 22:03:31 +0000 | |||
361 | @@ -3,6 +3,8 @@ | |||
362 | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications |
363 | 4 | # Industrial Technology Research Institute | 4 | # Industrial Technology Research Institute |
364 | 5 | # | 5 | # |
365 | 6 | # It is NOT YET officially approved by OCP. | ||
366 | 7 | # | ||
367 | 6 | # check_usb_port | 8 | # check_usb_port |
368 | 7 | # 1. Use dmesg command to gather USB information. | 9 | # 1. Use dmesg command to gather USB information. |
369 | 8 | # 2. Criteria: USB version must be 2.0. | 10 | # 2. Criteria: USB version must be 2.0. |
370 | 9 | 11 | ||
371 | === added file 'bin/check_usb_port_leopard' | |||
372 | --- bin/check_usb_port_leopard 1970-01-01 00:00:00 +0000 | |||
373 | +++ bin/check_usb_port_leopard 2015-08-14 22:03:31 +0000 | |||
374 | @@ -0,0 +1,43 @@ | |||
375 | 1 | #!/bin/bash | ||
376 | 2 | # | ||
377 | 3 | # Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
378 | 4 | # Industrial Technology Research Institute | ||
379 | 5 | # | ||
380 | 6 | # It is NOT YET officially approved by OCP. | ||
381 | 7 | # | ||
382 | 8 | # check_usb_port | ||
383 | 9 | # 1. Retrieve dmesg log to gather USB information. | ||
384 | 10 | # 2. Criteria: USB version must be 2.0 or higher. | ||
385 | 11 | # | ||
386 | 12 | # Authors | ||
387 | 13 | # Nelson Chu <Nelson.Chu@itri.org.tw> | ||
388 | 14 | # | ||
389 | 15 | # This program is free software: you can redistribute it and/or modify | ||
390 | 16 | # it under the terms of the GNU General Public License version 3, | ||
391 | 17 | # as published by the Free Software Foundation. | ||
392 | 18 | # | ||
393 | 19 | # This program is distributed in the hope that it will be useful, | ||
394 | 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
395 | 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
396 | 22 | # GNU General Public License for more details. | ||
397 | 23 | # | ||
398 | 24 | # You should have received a copy of the GNU General Public License | ||
399 | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
400 | 26 | # | ||
401 | 27 | |||
402 | 28 | support_usb_3=`cat /var/log/dmesg |grep -i "xhci_hcd" -c` | ||
403 | 29 | |||
404 | 30 | if [ "$support_usb_3" -gt "0" ]; then | ||
405 | 31 | echo "Support USB 3.0 ports." | ||
406 | 32 | exit 0 | ||
407 | 33 | fi | ||
408 | 34 | |||
409 | 35 | output=`cat /var/log/dmesg |grep -i ehci_hcd:| awk '{print $5}'` | ||
410 | 36 | |||
411 | 37 | if [ "$output" = "2.0" ]; then | ||
412 | 38 | echo "Support USB 2.0 ports." | ||
413 | 39 | exit 0 | ||
414 | 40 | fi | ||
415 | 41 | |||
416 | 42 | echo "Do not support USB 2.0 ports or higher." | ||
417 | 43 | exit 1 | ||
418 | 0 | 44 | ||
419 | === modified file 'bin/cpu_info' | |||
420 | --- bin/cpu_info 2015-03-03 15:59:42 +0000 | |||
421 | +++ bin/cpu_info 2015-08-14 22:03:31 +0000 | |||
422 | @@ -3,6 +3,8 @@ | |||
423 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications |
424 | 4 | Industrial Technology Research Institute | 4 | Industrial Technology Research Institute |
425 | 5 | 5 | ||
426 | 6 | It is NOT YET officially approved by OCP. | ||
427 | 7 | |||
428 | 6 | cpu_info | 8 | cpu_info |
429 | 7 | Use lshw command to gather CPU information. | 9 | Use lshw command to gather CPU information. |
430 | 8 | The program will output CPU model and L1, L2, L3 cache size. | 10 | The program will output CPU model and L1, L2, L3 cache size. |
431 | 9 | 11 | ||
432 | === added file 'bin/cpu_info_leopard' | |||
433 | --- bin/cpu_info_leopard 1970-01-01 00:00:00 +0000 | |||
434 | +++ bin/cpu_info_leopard 2015-08-14 22:03:31 +0000 | |||
435 | @@ -0,0 +1,83 @@ | |||
436 | 1 | #!/usr/bin/env python3 | ||
437 | 2 | """ | ||
438 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
439 | 4 | Industrial Technology Research Institute | ||
440 | 5 | |||
441 | 6 | It is NOT YET officially approved by OCP. | ||
442 | 7 | |||
443 | 8 | cpu_info | ||
444 | 9 | Use dmidecode command to gather CPU information. | ||
445 | 10 | The program will output CPU model and L1, L2, L3 cache size. | ||
446 | 11 | Criteria: CPU model and product family must match user's input. | ||
447 | 12 | |||
448 | 13 | Authors | ||
449 | 14 | Nelson Chu <Nelson.Chu@itri.org.tw> | ||
450 | 15 | |||
451 | 16 | This program is free software: you can redistribute it and/or modify | ||
452 | 17 | it under the terms of the GNU General Public License version 3, | ||
453 | 18 | as published by the Free Software Foundation. | ||
454 | 19 | |||
455 | 20 | This program is distributed in the hope that it will be useful, | ||
456 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
457 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
458 | 23 | GNU General Public License for more details. | ||
459 | 24 | |||
460 | 25 | You should have received a copy of the GNU General Public License | ||
461 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
462 | 27 | |||
463 | 28 | """ | ||
464 | 29 | |||
465 | 30 | import os | ||
466 | 31 | import re | ||
467 | 32 | import sys | ||
468 | 33 | import xml.etree.ElementTree as ET | ||
469 | 34 | from subprocess import check_output | ||
470 | 35 | from argparse import ArgumentParser, RawTextHelpFormatter | ||
471 | 36 | |||
472 | 37 | def run(product, family): | ||
473 | 38 | command = "dmidecode -t processor |grep -E 'Version|Cache'" | ||
474 | 39 | with open(os.devnull, 'w') as NULL: | ||
475 | 40 | output = check_output(command, stderr=NULL, shell=True) | ||
476 | 41 | output = output.decode('utf-8').strip() | ||
477 | 42 | |||
478 | 43 | cpu_attr = [] | ||
479 | 44 | for item in output.split('\n'): | ||
480 | 45 | cpu_attr.append(item.strip()) | ||
481 | 46 | |||
482 | 47 | for attr in cpu_attr: | ||
483 | 48 | if attr.startswith("Version"): | ||
484 | 49 | processor = attr.split(':')[1].strip() | ||
485 | 50 | print(processor) | ||
486 | 51 | match = re.search(product + '.*' + family, processor) | ||
487 | 52 | if not match: | ||
488 | 53 | print("Fail: Cannot match CPU %s %s family." %(product, family) | ||
489 | 54 | ,file=sys.stderr) | ||
490 | 55 | return 1 | ||
491 | 56 | else: | ||
492 | 57 | cache_handle = attr.split(':')[1].strip() | ||
493 | 58 | command = "dmidecode -t cache|grep -a6 {0}".format(cache_handle) +\ | ||
494 | 59 | "|grep -E 'Socket Designation|Installed Size'" | ||
495 | 60 | with open(os.devnull, 'w') as NULL: | ||
496 | 61 | output = check_output(command, stderr=NULL, shell=True) | ||
497 | 62 | output = output.decode('utf-8').strip() | ||
498 | 63 | print(output.split('\n')[0].split(':')[1].strip(),":", end="") | ||
499 | 64 | print(output.split('\n')[1].split(':')[1].strip()) | ||
500 | 65 | |||
501 | 66 | return 0 | ||
502 | 67 | |||
503 | 68 | def main(): | ||
504 | 69 | parser = ArgumentParser(formatter_class=RawTextHelpFormatter) | ||
505 | 70 | |||
506 | 71 | parser.add_argument('-p', '--product', type=str, required=True, | ||
507 | 72 | help=("The CPU product name. [Example: Xeon]")) | ||
508 | 73 | parser.add_argument('-f', '--family', type=str, required=True, | ||
509 | 74 | help=("Processor family. [Example: E5]")) | ||
510 | 75 | |||
511 | 76 | args = parser.parse_args() | ||
512 | 77 | |||
513 | 78 | product = args.product.title() | ||
514 | 79 | family = args.family.title() | ||
515 | 80 | return run(product, family) | ||
516 | 81 | |||
517 | 82 | if __name__ == '__main__': | ||
518 | 83 | sys.exit(main()) | ||
519 | 0 | 84 | ||
520 | === added file 'bin/create_raid' | |||
521 | --- bin/create_raid 1970-01-01 00:00:00 +0000 | |||
522 | +++ bin/create_raid 2015-08-14 22:03:31 +0000 | |||
523 | @@ -0,0 +1,140 @@ | |||
524 | 1 | #!/usr/bin/env python3 | ||
525 | 2 | """ | ||
526 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
527 | 4 | Industrial Technology Research Institute | ||
528 | 5 | |||
529 | 6 | It is NOT YET officially approved by OCP. | ||
530 | 7 | |||
531 | 8 | create_raid | ||
532 | 9 | Use megacli command to build user desired RAID on JBOD. | ||
533 | 10 | |||
534 | 11 | Warning: Make sure there is no RAID configuration in LSI RAID card | ||
535 | 12 | before this program is performed. | ||
536 | 13 | |||
537 | 14 | Authors | ||
538 | 15 | Nelson Chu <Nelson.Chu@itri.org.tw> | ||
539 | 16 | |||
540 | 17 | This program is free software: you can redistribute it and/or modify | ||
541 | 18 | it under the terms of the GNU General Public License version 3, | ||
542 | 19 | as published by the Free Software Foundation. | ||
543 | 20 | |||
544 | 21 | This program is distributed in the hope that it will be useful, | ||
545 | 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
546 | 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
547 | 24 | GNU General Public License for more details. | ||
548 | 25 | |||
549 | 26 | You should have received a copy of the GNU General Public License | ||
550 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
551 | 28 | |||
552 | 29 | """ | ||
553 | 30 | |||
554 | 31 | import os | ||
555 | 32 | import re | ||
556 | 33 | import sys | ||
557 | 34 | from time import sleep | ||
558 | 35 | from subprocess import check_output, STDOUT, CalledProcessError | ||
559 | 36 | from argparse import ArgumentParser, RawTextHelpFormatter | ||
560 | 37 | |||
561 | 38 | def get_adapter(): | ||
562 | 39 | """ | ||
563 | 40 | Gather all adapter number if there are multiple RAID cards. | ||
564 | 41 | """ | ||
565 | 42 | |||
566 | 43 | command = 'megacli -CfgDsply -Aall|grep Adapter' | ||
567 | 44 | adapter_list = [] | ||
568 | 45 | |||
569 | 46 | adapter_info = check_output(command, shell=True) | ||
570 | 47 | adapter_info = adapter_info.decode('utf-8') | ||
571 | 48 | |||
572 | 49 | for adapter in adapter_info.strip().split('\n'): | ||
573 | 50 | adapter_list.append(adapter.strip().split(' ')[-1]) | ||
574 | 51 | return adapter_list | ||
575 | 52 | |||
576 | 53 | |||
577 | 54 | def get_all_disk(adapter): | ||
578 | 55 | """ | ||
579 | 56 | Gather all disks Enclosure and Slot number, and make a | ||
580 | 57 | Enclosure:Slot pair list. | ||
581 | 58 | """ | ||
582 | 59 | |||
583 | 60 | command = 'megacli -PDList -A{0}'.format(adapter) \ | ||
584 | 61 | + '|grep -E "Enclosure Device ID|Slot Number"' | ||
585 | 62 | |||
586 | 63 | disk_list = [] | ||
587 | 64 | disk_info = check_output(command, shell=True) | ||
588 | 65 | disk_info = disk_info.decode('utf-8') | ||
589 | 66 | |||
590 | 67 | for line in disk_info.strip().split('\n'): | ||
591 | 68 | if line.startswith('Enclosure'): | ||
592 | 69 | match = re.search(r'\d+', line) | ||
593 | 70 | disk_list.append(match.group(0)) | ||
594 | 71 | if line.startswith('Slot'): | ||
595 | 72 | match = re.search(r'\d+', line) | ||
596 | 73 | enclosure = disk_list.pop() | ||
597 | 74 | E_S = '%s:%s' %(enclosure, match.group(0)) | ||
598 | 75 | disk_list.append(E_S) | ||
599 | 76 | return disk_list | ||
600 | 77 | |||
601 | 78 | |||
602 | 79 | def build_raid(raid_type, adapter, disk_list): | ||
603 | 80 | """ | ||
604 | 81 | Use all disks creatd RAID. | ||
605 | 82 | If RAID type is 6 then set last disk as hot spare. | ||
606 | 83 | """ | ||
607 | 84 | |||
608 | 85 | if raid_type == 0: | ||
609 | 86 | disk = ','.join(disk_list) | ||
610 | 87 | command = 'megacli -CfgLDadd -r{0} [{1}] WB Direct -a{2}'.format( | ||
611 | 88 | raid_type, disk, adapter) | ||
612 | 89 | |||
613 | 90 | if raid_type == 6: | ||
614 | 91 | # use the last disk as hot spare | ||
615 | 92 | spare = disk_list.pop() | ||
616 | 93 | |||
617 | 94 | disk = ','.join(disk_list) | ||
618 | 95 | command = 'megacli -CfgLDadd -r{0} [{1}] WB Direct -Hsp[{2}] -a{3}'.format( | ||
619 | 96 | raid_type, disk, spare, adapter) | ||
620 | 97 | |||
621 | 98 | output = check_output(command, stderr=STDOUT, shell=True) | ||
622 | 99 | output = output.decode('utf-8') | ||
623 | 100 | # wait for raid created | ||
624 | 101 | sleep(5) | ||
625 | 102 | print(output) | ||
626 | 103 | |||
627 | 104 | |||
628 | 105 | def main(): | ||
629 | 106 | parser = ArgumentParser(formatter_class=RawTextHelpFormatter) | ||
630 | 107 | parser.add_argument('-t', '--type', type=int, required=True, | ||
631 | 108 | help=("The RAID type which want to create. " | ||
632 | 109 | "[Example: 0 or 6]")) | ||
633 | 110 | args = parser.parse_args() | ||
634 | 111 | knox_dict = {} | ||
635 | 112 | |||
636 | 113 | # get RAID card adapter number | ||
637 | 114 | try: | ||
638 | 115 | adapter_list = get_adapter() | ||
639 | 116 | except CalledProcessError as e: | ||
640 | 117 | print(e.output.decode('utf-8')) | ||
641 | 118 | return 10 | ||
642 | 119 | |||
643 | 120 | # get all disks in JBOD | ||
644 | 121 | try: | ||
645 | 122 | for adapter in adapter_list: | ||
646 | 123 | knox_dict[adapter] = get_all_disk(adapter) | ||
647 | 124 | except CalledProcessError as e: | ||
648 | 125 | print(e.output.decode('utf-8')) | ||
649 | 126 | return 20 | ||
650 | 127 | |||
651 | 128 | # use all HDDs to build RAID | ||
652 | 129 | try: | ||
653 | 130 | for adapter, disk_list in knox_dict.items(): | ||
654 | 131 | build_raid(args.type, adapter, disk_list) | ||
655 | 132 | except CalledProcessError as e: | ||
656 | 133 | print(e.output.decode('utf-8')) | ||
657 | 134 | return 30 | ||
658 | 135 | |||
659 | 136 | return 0 | ||
660 | 137 | |||
661 | 138 | |||
662 | 139 | if __name__ == '__main__': | ||
663 | 140 | sys.exit(main()) | ||
664 | 0 | 141 | ||
665 | === added file 'bin/dcmi_inventory' | |||
666 | --- bin/dcmi_inventory 1970-01-01 00:00:00 +0000 | |||
667 | +++ bin/dcmi_inventory 2015-08-14 22:03:31 +0000 | |||
668 | @@ -0,0 +1,136 @@ | |||
669 | 1 | #!/usr/bin/env python3 | ||
670 | 2 | """ | ||
671 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
672 | 4 | Industrial Technology Research Institute | ||
673 | 5 | |||
674 | 6 | File Name | ||
675 | 7 | dcmi_inventory | ||
676 | 8 | 1. Use dcmitool to collect inventory information including Asset Tag, Device ID, System GUI, Firmware/Software Information, Management Controller ID | ||
677 | 9 | 2. Criteria: All information mentioned above must not should not be null | ||
678 | 10 | Authors | ||
679 | 11 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
680 | 12 | |||
681 | 13 | This program is free software: you can redistribute it and/or modify | ||
682 | 14 | it under the terms of the GNU General Public License version 3, | ||
683 | 15 | as published by the Free Software Foundation. | ||
684 | 16 | |||
685 | 17 | This program is distributed in the hope that it will be useful, | ||
686 | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
687 | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
688 | 20 | GNU General Public License for more details. | ||
689 | 21 | |||
690 | 22 | You should have received a copy of the GNU General Public License | ||
691 | 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
692 | 24 | |||
693 | 25 | """ | ||
694 | 26 | |||
695 | 27 | import sys | ||
696 | 28 | import time | ||
697 | 29 | import shlex | ||
698 | 30 | import subprocess | ||
699 | 31 | import re | ||
700 | 32 | import subprocess | ||
701 | 33 | from subprocess import ( | ||
702 | 34 | CalledProcessError, | ||
703 | 35 | check_call, | ||
704 | 36 | check_output | ||
705 | 37 | ) | ||
706 | 38 | |||
707 | 39 | def get_asset_tag(): | ||
708 | 40 | |||
709 | 41 | try: | ||
710 | 42 | cmd = 'dcmitool dcmi asset_tag' | ||
711 | 43 | dcmi_asset_tag_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
712 | 44 | time.sleep(5) | ||
713 | 45 | except CalledProcessError as command_exception: | ||
714 | 46 | print("Failed executing dcmi command for getting asset tag. Reason:%s" % command_exception) | ||
715 | 47 | |||
716 | 48 | try: | ||
717 | 49 | asset_tag = re.search(r'Asset tag\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_asset_tag_return) | ||
718 | 50 | if asset_tag == None: | ||
719 | 51 | return 'Error' | ||
720 | 52 | return asset_tag.group(1).strip() | ||
721 | 53 | except: | ||
722 | 54 | return 'Error' | ||
723 | 55 | |||
724 | 56 | def get_guid(): | ||
725 | 57 | |||
726 | 58 | try: | ||
727 | 59 | cmd = 'dcmitool mc guid' | ||
728 | 60 | dcmi_guid_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
729 | 61 | time.sleep(5) | ||
730 | 62 | except CalledProcessError as command_exception: | ||
731 | 63 | print("Failed executing dcmi command for getting guid. Reason:%s" % command_exception) | ||
732 | 64 | |||
733 | 65 | try: | ||
734 | 66 | mcguid = re.search(r'System GUID\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_guid_return) | ||
735 | 67 | if mcguid == None: | ||
736 | 68 | return 'Error' | ||
737 | 69 | return mcguid.group(1).strip() | ||
738 | 70 | except: | ||
739 | 71 | return 'Error' | ||
740 | 72 | |||
741 | 73 | def get_mcid(): | ||
742 | 74 | |||
743 | 75 | try: | ||
744 | 76 | cmd = 'dcmitool dcmi get_mc_id_string' | ||
745 | 77 | dcmi_mcid_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
746 | 78 | time.sleep(5) | ||
747 | 79 | except CalledProcessError as command_exception: | ||
748 | 80 | print("Failed executing dcmi command for getting mc id. Reason:%s" % command_exception) | ||
749 | 81 | |||
750 | 82 | try: | ||
751 | 83 | mcid = re.search(r'Get Management Controller Identifier String\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcid_return) | ||
752 | 84 | if mcid == None: | ||
753 | 85 | return 'Error' | ||
754 | 86 | return mcid.group(1).strip() | ||
755 | 87 | except: | ||
756 | 88 | return 'Error' | ||
757 | 89 | |||
758 | 90 | def get_mcinfo(): | ||
759 | 91 | |||
760 | 92 | try: | ||
761 | 93 | cmd = 'dcmitool mc info' | ||
762 | 94 | dcmi_mcinfo_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
763 | 95 | time.sleep(5) | ||
764 | 96 | except CalledProcessError as command_exception: | ||
765 | 97 | print("Failed executing dcmi command for getting mc info. Reason:%s" % command_exception) | ||
766 | 98 | |||
767 | 99 | try: | ||
768 | 100 | deviceid = re.search(r'Device ID\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcinfo_return) | ||
769 | 101 | Manufac = re.search(r'Manufacturer Name\s*:\s*([a-zA-Z-._ ]+)', dcmi_mcinfo_return) | ||
770 | 102 | Firm = re.search(r'Firmware Revision\s+\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcinfo_return) | ||
771 | 103 | |||
772 | 104 | if deviceid == None or Manufac == None or Firm == None: | ||
773 | 105 | return 'Error', 'Error', 'Error' | ||
774 | 106 | return (deviceid.group(1).strip(), Manufac.group(1).strip(), Firm.group(1).strip()) | ||
775 | 107 | except: | ||
776 | 108 | return 'Error', 'Error', 'Error' | ||
777 | 109 | |||
778 | 110 | def main(): | ||
779 | 111 | |||
780 | 112 | flag = 0 | ||
781 | 113 | inventory_dict = {} | ||
782 | 114 | inventory_list = ['Asset Tag', 'System GUID', 'Get Management Controller Identifier String', 'Device ID', 'Manufacturer Name', 'Firmware Revision'] | ||
783 | 115 | Device_ID, Manufacturer, Firmware = get_mcinfo() | ||
784 | 116 | inventory_dict.update({'Asset Tag':get_asset_tag()}) | ||
785 | 117 | inventory_dict.update({'System GUID':get_guid()}) | ||
786 | 118 | inventory_dict.update({'Get Management Controller Identifier String':get_mcid()}) | ||
787 | 119 | inventory_dict.update({'Device ID':Device_ID}) | ||
788 | 120 | inventory_dict.update({'Manufacturer Name':Manufacturer}) | ||
789 | 121 | inventory_dict.update({'Firmware Revision':Firmware}) | ||
790 | 122 | |||
791 | 123 | for item in inventory_list: | ||
792 | 124 | if inventory_dict.get(item) == 'Error': | ||
793 | 125 | flag = 1 | ||
794 | 126 | else: | ||
795 | 127 | print("{}: {}".format(item, inventory_dict.get(item))) | ||
796 | 128 | |||
797 | 129 | if flag == 1: | ||
798 | 130 | return 1 | ||
799 | 131 | return 0 | ||
800 | 132 | |||
801 | 133 | if __name__ == '__main__': | ||
802 | 134 | sys.exit(main()) | ||
803 | 135 | |||
804 | 136 | |||
805 | 0 | 137 | ||
806 | === added file 'bin/dcmi_power_off_on' | |||
807 | --- bin/dcmi_power_off_on 1970-01-01 00:00:00 +0000 | |||
808 | +++ bin/dcmi_power_off_on 2015-08-14 22:03:31 +0000 | |||
809 | @@ -0,0 +1,190 @@ | |||
810 | 1 | #! /usr/bin/env python3 | ||
811 | 2 | """ | ||
812 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
813 | 4 | Industrial Technology Research Institute | ||
814 | 5 | |||
815 | 6 | File Name | ||
816 | 7 | dcmi_power_off_on | ||
817 | 8 | Use dcmitool out-of-band access to turn on/off the SUT | ||
818 | 9 | |||
819 | 10 | Authors | ||
820 | 11 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
821 | 12 | |||
822 | 13 | This program is free software: you can redistribute it and/or modify | ||
823 | 14 | it under the terms of the GNU General Public License version 3, | ||
824 | 15 | as published by the Free Software Foundation. | ||
825 | 16 | |||
826 | 17 | This program is distributed in the hope that it will be useful, | ||
827 | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
828 | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
829 | 20 | GNU General Public License for more details. | ||
830 | 21 | |||
831 | 22 | You should have received a copy of the GNU General Public License | ||
832 | 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
833 | 24 | |||
834 | 25 | """ | ||
835 | 26 | from argparse import ( | ||
836 | 27 | ArgumentParser, | ||
837 | 28 | RawTextHelpFormatter | ||
838 | 29 | ) | ||
839 | 30 | |||
840 | 31 | import sys | ||
841 | 32 | import configparser | ||
842 | 33 | import shlex | ||
843 | 34 | import subprocess | ||
844 | 35 | import ast | ||
845 | 36 | import time | ||
846 | 37 | from subprocess import ( | ||
847 | 38 | check_output, | ||
848 | 39 | CalledProcessError | ||
849 | 40 | ) | ||
850 | 41 | |||
851 | 42 | def check_power_status(host_ip, user, password): | ||
852 | 43 | |||
853 | 44 | cmd_status_on = 'dcmitool -H {} -U {} -P {} power status| grep -q "on"'\ | ||
854 | 45 | .format(host_ip, user, password) | ||
855 | 46 | check_on_value = subprocess.call(cmd_status_on, shell=True) | ||
856 | 47 | time.sleep(5) | ||
857 | 48 | |||
858 | 49 | cmd_status_off = 'dcmitool -H {} -U {} -P {} power status| grep -q "off"'\ | ||
859 | 50 | .format(host_ip, user, password) | ||
860 | 51 | check_off_value = subprocess.call(cmd_status_off, shell=True) | ||
861 | 52 | time.sleep(5) | ||
862 | 53 | |||
863 | 54 | if check_on_value == 0 and check_off_value == 1: | ||
864 | 55 | check_status = 'on' | ||
865 | 56 | |||
866 | 57 | elif check_on_value == 1 and check_off_value == 0: | ||
867 | 58 | check_status = 'off' | ||
868 | 59 | |||
869 | 60 | else: | ||
870 | 61 | check_status = 'error' | ||
871 | 62 | |||
872 | 63 | return check_status | ||
873 | 64 | |||
874 | 65 | def run_power_off(host_ip, user, password): | ||
875 | 66 | cmd_power_off = 'dcmitool -H {} -U {} -P {} power off'\ | ||
876 | 67 | .format(host_ip, user, password) | ||
877 | 68 | power_off_return_code = subprocess.call(cmd_power_off, shell=True) | ||
878 | 69 | return power_off_return_code | ||
879 | 70 | |||
880 | 71 | def run_power_on(host_ip, user, password): | ||
881 | 72 | cmd_power_on = 'dcmitool -H {} -U {} -P {} power on'\ | ||
882 | 73 | .format(host_ip, user, password) | ||
883 | 74 | power_on_return_code = subprocess.call(cmd_power_on, shell=True) | ||
884 | 75 | return power_on_return_code | ||
885 | 76 | |||
886 | 77 | def dcmi_reset_oob(args): | ||
887 | 78 | |||
888 | 79 | #DCMI config file | ||
889 | 80 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
890 | 81 | if not "config" in vars(args): | ||
891 | 82 | config_file = DEFAULT_CFG | ||
892 | 83 | else: | ||
893 | 84 | config_file = args.config | ||
894 | 85 | |||
895 | 86 | config = configparser.RawConfigParser() | ||
896 | 87 | |||
897 | 88 | try: | ||
898 | 89 | config.readfp(open(config_file)) | ||
899 | 90 | except IOError: | ||
900 | 91 | print("No config file found") | ||
901 | 92 | return 10 | ||
902 | 93 | |||
903 | 94 | try: | ||
904 | 95 | targets_options = config.options('Targets') | ||
905 | 96 | targets_list = [] | ||
906 | 97 | for target_key in targets_options: | ||
907 | 98 | targets_list.append(config.get('Targets', target_key)) | ||
908 | 99 | |||
909 | 100 | if not targets_list: | ||
910 | 101 | print("Invalid or Empty targets") | ||
911 | 102 | return 20 | ||
912 | 103 | |||
913 | 104 | except configparser.Error: | ||
914 | 105 | print("Invalid or Empty targets") | ||
915 | 106 | return 30 | ||
916 | 107 | |||
917 | 108 | try: | ||
918 | 109 | user_value = config.get('Account', 'USER') | ||
919 | 110 | passwd_value = config.get('Account', 'PASSWORD') | ||
920 | 111 | if not user_value or not passwd_value: | ||
921 | 112 | print("Invalid or Empty credential info") | ||
922 | 113 | return 40 | ||
923 | 114 | |||
924 | 115 | except configparser.Error: | ||
925 | 116 | print("Invalid or Empty credential info") | ||
926 | 117 | return 50 | ||
927 | 118 | |||
928 | 119 | ping_flag = 0 | ||
929 | 120 | for tg in targets_list: | ||
930 | 121 | |||
931 | 122 | if not tg or not user_value or not passwd_value: | ||
932 | 123 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
933 | 124 | return 21 | ||
934 | 125 | else: | ||
935 | 126 | |||
936 | 127 | print("SUT =", tg) | ||
937 | 128 | print("USER =", user_value) | ||
938 | 129 | print("PASSWORD =", passwd_value) | ||
939 | 130 | |||
940 | 131 | for n in range(2): | ||
941 | 132 | |||
942 | 133 | count = 0 | ||
943 | 134 | while count < 10: | ||
944 | 135 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
945 | 136 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
946 | 137 | if ping_rtn == 0: | ||
947 | 138 | print("Destination Host Reachable") | ||
948 | 139 | |||
949 | 140 | #run test | ||
950 | 141 | status = check_power_status(tg, user_value, passwd_value) | ||
951 | 142 | |||
952 | 143 | if status == 'on': | ||
953 | 144 | #run power off | ||
954 | 145 | power_off_result = run_power_off(tg, user_value, passwd_value) | ||
955 | 146 | print(" ") | ||
956 | 147 | if power_off_result == 1: | ||
957 | 148 | print("Failed to power off SUT.") | ||
958 | 149 | return 88 | ||
959 | 150 | elif status == 'off': | ||
960 | 151 | #run power on | ||
961 | 152 | power_on_result = run_power_on(tg, user_value, passwd_value) | ||
962 | 153 | print(" ") | ||
963 | 154 | if power_on_result == 1: | ||
964 | 155 | print("Failed to power on SUT.") | ||
965 | 156 | return 99 | ||
966 | 157 | else: | ||
967 | 158 | #do nothing | ||
968 | 159 | print("Failed to check power status") | ||
969 | 160 | return 77 | ||
970 | 161 | |||
971 | 162 | time.sleep(30) | ||
972 | 163 | break | ||
973 | 164 | |||
974 | 165 | else: | ||
975 | 166 | time.sleep(10) | ||
976 | 167 | count = count+1 | ||
977 | 168 | print("Destination Host Unreachable") | ||
978 | 169 | |||
979 | 170 | if count == 10: | ||
980 | 171 | print("Host Has No Response, End of Test") | ||
981 | 172 | ping_flag = 100 | ||
982 | 173 | |||
983 | 174 | if ping_flag == 100: | ||
984 | 175 | return 100 | ||
985 | 176 | return 0 | ||
986 | 177 | |||
987 | 178 | def main(): | ||
988 | 179 | |||
989 | 180 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
990 | 181 | parser = ArgumentParser(description=intro_message, | ||
991 | 182 | formatter_class=RawTextHelpFormatter) | ||
992 | 183 | parser.add_argument('--config', type=str, | ||
993 | 184 | default="/etc/checkbox.d/me.cfg", | ||
994 | 185 | help="Supply config file for getting authentication info") | ||
995 | 186 | args = parser.parse_args() | ||
996 | 187 | return dcmi_reset_oob(args) | ||
997 | 188 | |||
998 | 189 | if __name__ == "__main__": | ||
999 | 190 | sys.exit(main()) | ||
1000 | 0 | 191 | ||
1001 | === added file 'bin/dcmi_power_reset' | |||
1002 | --- bin/dcmi_power_reset 1970-01-01 00:00:00 +0000 | |||
1003 | +++ bin/dcmi_power_reset 2015-08-14 22:03:31 +0000 | |||
1004 | @@ -0,0 +1,139 @@ | |||
1005 | 1 | #!/usr/bin/env python3 | ||
1006 | 2 | """ | ||
1007 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1008 | 4 | Industrial Technology Research Institute | ||
1009 | 5 | |||
1010 | 6 | File Name | ||
1011 | 7 | dcmi_power_reset | ||
1012 | 8 | Complete 20 power reset on SUT successfully using dcmitool out-of-band access | ||
1013 | 9 | |||
1014 | 10 | Authors | ||
1015 | 11 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1016 | 12 | |||
1017 | 13 | This program is free software: you can redistribute it and/or modify | ||
1018 | 14 | it under the terms of the GNU General Public License version 3, | ||
1019 | 15 | as published by the Free Software Foundation. | ||
1020 | 16 | |||
1021 | 17 | This program is distributed in the hope that it will be useful, | ||
1022 | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1023 | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1024 | 20 | GNU General Public License for more details. | ||
1025 | 21 | |||
1026 | 22 | You should have received a copy of the GNU General Public License | ||
1027 | 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1028 | 24 | |||
1029 | 25 | """ | ||
1030 | 26 | |||
1031 | 27 | from argparse import ( | ||
1032 | 28 | ArgumentParser, | ||
1033 | 29 | RawTextHelpFormatter | ||
1034 | 30 | ) | ||
1035 | 31 | |||
1036 | 32 | import sys | ||
1037 | 33 | import configparser | ||
1038 | 34 | import shlex | ||
1039 | 35 | import subprocess | ||
1040 | 36 | import ast | ||
1041 | 37 | import time | ||
1042 | 38 | from subprocess import ( | ||
1043 | 39 | check_output, | ||
1044 | 40 | CalledProcessError | ||
1045 | 41 | ) | ||
1046 | 42 | |||
1047 | 43 | def run(host_ip, user, password): | ||
1048 | 44 | cmd = 'dcmitool -H {} -U {} -P {} power reset'.format(host_ip, user, password) | ||
1049 | 45 | power_reset_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
1050 | 46 | return power_reset_return | ||
1051 | 47 | |||
1052 | 48 | def dcmi_reset_oob(args): | ||
1053 | 49 | |||
1054 | 50 | #DCMI config file | ||
1055 | 51 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
1056 | 52 | if not "config" in vars(args): | ||
1057 | 53 | config_file = DEFAULT_CFG | ||
1058 | 54 | else: | ||
1059 | 55 | config_file = args.config | ||
1060 | 56 | |||
1061 | 57 | config = configparser.RawConfigParser() | ||
1062 | 58 | try: | ||
1063 | 59 | config.readfp(open(config_file)) | ||
1064 | 60 | except IOError: | ||
1065 | 61 | print("No config file found") | ||
1066 | 62 | return 1 | ||
1067 | 63 | |||
1068 | 64 | try: | ||
1069 | 65 | targets_options = config.options('Targets') | ||
1070 | 66 | targets_list = [] | ||
1071 | 67 | for target_key in targets_options: | ||
1072 | 68 | targets_list.append(config.get('Targets', target_key)) | ||
1073 | 69 | if not targets_list: | ||
1074 | 70 | print("Invalid or Empty targets") | ||
1075 | 71 | return 2 | ||
1076 | 72 | except configparser.Error: | ||
1077 | 73 | print("Invalid or Empty targets") | ||
1078 | 74 | return 2 | ||
1079 | 75 | |||
1080 | 76 | try: | ||
1081 | 77 | user_value = config.get("Account", "USER") | ||
1082 | 78 | password_value = config.get("Account", "PASSWORD") | ||
1083 | 79 | except configparser.NoOptionError: | ||
1084 | 80 | print("Invalid or Empty credential info") | ||
1085 | 81 | return 3 | ||
1086 | 82 | |||
1087 | 83 | ping_flag = 0 | ||
1088 | 84 | for tg in targets_list: | ||
1089 | 85 | |||
1090 | 86 | if not tg or not user_value or not password_value: | ||
1091 | 87 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
1092 | 88 | return 4 | ||
1093 | 89 | else: | ||
1094 | 90 | print("SUT =", tg) | ||
1095 | 91 | print("USER =", user_value) | ||
1096 | 92 | print("PASSWORD =", password_value) | ||
1097 | 93 | |||
1098 | 94 | for n in range(20): | ||
1099 | 95 | print("---------------- %s ----------------" % n) | ||
1100 | 96 | count = 0 | ||
1101 | 97 | while count < 10: | ||
1102 | 98 | print("+++++++++++ %s ++++++++++++" % count) | ||
1103 | 99 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
1104 | 100 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
1105 | 101 | |||
1106 | 102 | if ping_rtn == 0: | ||
1107 | 103 | print("Destination Host Reachable") | ||
1108 | 104 | |||
1109 | 105 | try: | ||
1110 | 106 | power_control = run(tg, user_value, password_value) | ||
1111 | 107 | print(power_control) | ||
1112 | 108 | except CalledProcessError as dcmi_exception: | ||
1113 | 109 | print("Failed executing dcmi, Reason: %s" % dcmi_exception) | ||
1114 | 110 | return 6 | ||
1115 | 111 | |||
1116 | 112 | time.sleep(30) | ||
1117 | 113 | break | ||
1118 | 114 | else: | ||
1119 | 115 | time.sleep(10) | ||
1120 | 116 | count = count+1 | ||
1121 | 117 | print("Destination Host Unreachable") | ||
1122 | 118 | |||
1123 | 119 | if count == 10: | ||
1124 | 120 | print("Host Has No Response, End of Test") | ||
1125 | 121 | ping_flag = 100 | ||
1126 | 122 | |||
1127 | 123 | if ping_flag == 100: | ||
1128 | 124 | return 100 | ||
1129 | 125 | return 0 | ||
1130 | 126 | |||
1131 | 127 | def main(): | ||
1132 | 128 | |||
1133 | 129 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
1134 | 130 | parser = ArgumentParser(description=intro_message, | ||
1135 | 131 | formatter_class=RawTextHelpFormatter) | ||
1136 | 132 | parser.add_argument('--config', | ||
1137 | 133 | default="/etc/checkbox.d/me.cfg", | ||
1138 | 134 | help="Supply config file for getting authentication info") | ||
1139 | 135 | args = parser.parse_args() | ||
1140 | 136 | return dcmi_reset_oob(args) | ||
1141 | 137 | |||
1142 | 138 | if __name__ == "__main__": | ||
1143 | 139 | sys.exit(main()) | ||
1144 | 0 | 140 | ||
1145 | === added file 'bin/dcmi_priv_admin' | |||
1146 | --- bin/dcmi_priv_admin 1970-01-01 00:00:00 +0000 | |||
1147 | +++ bin/dcmi_priv_admin 2015-08-14 22:03:31 +0000 | |||
1148 | @@ -0,0 +1,174 @@ | |||
1149 | 1 | #! /usr/bin/env python3 | ||
1150 | 2 | """ | ||
1151 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1152 | 4 | Industrial Technology Research Institute | ||
1153 | 5 | |||
1154 | 6 | File Name | ||
1155 | 7 | dcmi_priv_admin | ||
1156 | 8 | 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account | ||
1157 | 9 | 2. Criteria: Reading power status, performing power reset and adding a user account must all be successful | ||
1158 | 10 | |||
1159 | 11 | Authors | ||
1160 | 12 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1161 | 13 | |||
1162 | 14 | This program is free software: you can redistribute it and/or modify | ||
1163 | 15 | it under the terms of the GNU General Public License version 3, | ||
1164 | 16 | as published by the Free Software Foundation. | ||
1165 | 17 | |||
1166 | 18 | This program is distributed in the hope that it will be useful, | ||
1167 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1168 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1169 | 21 | GNU General Public License for more details. | ||
1170 | 22 | |||
1171 | 23 | You should have received a copy of the GNU General Public License | ||
1172 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1173 | 25 | |||
1174 | 26 | """ | ||
1175 | 27 | from argparse import ( | ||
1176 | 28 | ArgumentParser, | ||
1177 | 29 | RawTextHelpFormatter | ||
1178 | 30 | ) | ||
1179 | 31 | |||
1180 | 32 | import sys | ||
1181 | 33 | import configparser | ||
1182 | 34 | import shlex | ||
1183 | 35 | import subprocess | ||
1184 | 36 | import ast | ||
1185 | 37 | import time | ||
1186 | 38 | from subprocess import ( | ||
1187 | 39 | check_output, | ||
1188 | 40 | CalledProcessError | ||
1189 | 41 | ) | ||
1190 | 42 | |||
1191 | 43 | def get_power_status(host_ip, user, password): | ||
1192 | 44 | cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\ | ||
1193 | 45 | .format(host_ip, user, password) | ||
1194 | 46 | status_code = subprocess.call(cmd_status, shell=True) | ||
1195 | 47 | return status_code | ||
1196 | 48 | |||
1197 | 49 | def power_reset(host_ip, user, password): | ||
1198 | 50 | cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\ | ||
1199 | 51 | .format(host_ip, user, password) | ||
1200 | 52 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
1201 | 53 | return reset_code | ||
1202 | 54 | |||
1203 | 55 | def add_user(host_ip, user, password, new_id, new_user): | ||
1204 | 56 | cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\ | ||
1205 | 57 | .format(host_ip, user, password, new_id, new_user) | ||
1206 | 58 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
1207 | 59 | return add_user_code | ||
1208 | 60 | |||
1209 | 61 | def dcmi_user_level_test(args): | ||
1210 | 62 | |||
1211 | 63 | #DCMI config file | ||
1212 | 64 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
1213 | 65 | if not "config" in vars(args): | ||
1214 | 66 | config_file = DEFAULT_CFG | ||
1215 | 67 | else: | ||
1216 | 68 | config_file = args.config | ||
1217 | 69 | config = configparser.RawConfigParser() | ||
1218 | 70 | try: | ||
1219 | 71 | config.readfp(open(config_file)) | ||
1220 | 72 | except IOError: | ||
1221 | 73 | print("No config file found") | ||
1222 | 74 | return 10 | ||
1223 | 75 | |||
1224 | 76 | try: | ||
1225 | 77 | targets_options = config.options('Targets') | ||
1226 | 78 | targets_list = [] | ||
1227 | 79 | for target_key in targets_options: | ||
1228 | 80 | targets_list.append(config.get('Targets', target_key)) | ||
1229 | 81 | if not targets_list: | ||
1230 | 82 | print("Invalid or Empty targets") | ||
1231 | 83 | return 20 | ||
1232 | 84 | except configparser.Error: | ||
1233 | 85 | print("Invalid or Empty targets") | ||
1234 | 86 | return 20 | ||
1235 | 87 | |||
1236 | 88 | try: | ||
1237 | 89 | user_value = config.get("Admin Level", "ADMIN_NAME") | ||
1238 | 90 | password_value = config.get("Admin Level", "ADMIN_PASSWD") | ||
1239 | 91 | except configparser.NoOptionError: | ||
1240 | 92 | print("Invalid or Empty credential info") | ||
1241 | 93 | print("Require Operator Level info pre-configured in /etc/checkbox.d/me.cfg") | ||
1242 | 94 | return 30 | ||
1243 | 95 | |||
1244 | 96 | try: | ||
1245 | 97 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
1246 | 98 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
1247 | 99 | except configparser.NoOptionError: | ||
1248 | 100 | print("Invalid or Empty new user info") | ||
1249 | 101 | print("Require new User info pre-configured in /etc/checkbox.d/me.cfg") | ||
1250 | 102 | return 40 | ||
1251 | 103 | |||
1252 | 104 | flag = 0 | ||
1253 | 105 | for tg in targets_list: | ||
1254 | 106 | |||
1255 | 107 | if not tg or not user_value or not password_value: | ||
1256 | 108 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
1257 | 109 | return 50 | ||
1258 | 110 | else: | ||
1259 | 111 | print("SUT", tg) | ||
1260 | 112 | |||
1261 | 113 | ping_result = ping_test(tg) | ||
1262 | 114 | if ping_result != 0: | ||
1263 | 115 | return 88 | ||
1264 | 116 | |||
1265 | 117 | status_result = get_power_status(tg, user_value, password_value) | ||
1266 | 118 | time.sleep(5) | ||
1267 | 119 | |||
1268 | 120 | reset_result = power_reset(tg, user_value, password_value) | ||
1269 | 121 | time.sleep(5) | ||
1270 | 122 | if not new_user_value or not new_user_id_value: | ||
1271 | 123 | print("Require new user info pre-configured in /etc/checkbox.d/me.cfg") | ||
1272 | 124 | return 60 | ||
1273 | 125 | else: | ||
1274 | 126 | |||
1275 | 127 | ping_result = ping_test(tg) | ||
1276 | 128 | if ping_result != 0: | ||
1277 | 129 | return 88 | ||
1278 | 130 | |||
1279 | 131 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
1280 | 132 | time.sleep(5) | ||
1281 | 133 | |||
1282 | 134 | if status_result == 0 and reset_result == 0 and add_user_result == 0: | ||
1283 | 135 | print("User can read power status.") | ||
1284 | 136 | print("User can reset power.") | ||
1285 | 137 | print("User can add a new user.") | ||
1286 | 138 | else: | ||
1287 | 139 | print("Authentication: Not Administrator Level") | ||
1288 | 140 | flag = 1 | ||
1289 | 141 | |||
1290 | 142 | if flag == 1: | ||
1291 | 143 | return 100 | ||
1292 | 144 | return 0 | ||
1293 | 145 | |||
1294 | 146 | def ping_test(host_ip): | ||
1295 | 147 | count = 0 | ||
1296 | 148 | while count < 10: | ||
1297 | 149 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
1298 | 150 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
1299 | 151 | if ping_rtn == 0: | ||
1300 | 152 | return 0 | ||
1301 | 153 | else: | ||
1302 | 154 | print("Destination Host Unreachable") | ||
1303 | 155 | time.sleep(10) | ||
1304 | 156 | count = count+1 | ||
1305 | 157 | |||
1306 | 158 | if count == 10: | ||
1307 | 159 | print("Host Has No Response, End of Test") | ||
1308 | 160 | return 1 | ||
1309 | 161 | |||
1310 | 162 | |||
1311 | 163 | def main(): | ||
1312 | 164 | |||
1313 | 165 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
1314 | 166 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
1315 | 167 | parser.add_argument('--config', type=str, | ||
1316 | 168 | default="/etc/checkbox.d/me.cfg", | ||
1317 | 169 | help="Supply config file for getting authentication info") | ||
1318 | 170 | args = parser.parse_args() | ||
1319 | 171 | return dcmi_user_level_test(args) | ||
1320 | 172 | |||
1321 | 173 | if __name__ == "__main__": | ||
1322 | 174 | sys.exit(main()) | ||
1323 | 0 | 175 | ||
1324 | === added file 'bin/dcmi_priv_oper' | |||
1325 | --- bin/dcmi_priv_oper 1970-01-01 00:00:00 +0000 | |||
1326 | +++ bin/dcmi_priv_oper 2015-08-14 22:03:31 +0000 | |||
1327 | @@ -0,0 +1,174 @@ | |||
1328 | 1 | #! /usr/bin/env python3 | ||
1329 | 2 | """ | ||
1330 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1331 | 4 | Industrial Technology Research Institute | ||
1332 | 5 | |||
1333 | 6 | File Name | ||
1334 | 7 | dcmi_priv_oper | ||
1335 | 8 | 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account | ||
1336 | 9 | 2. Criteria: power status reading and power reset must be successful and must fail at adding a new user account | ||
1337 | 10 | |||
1338 | 11 | Authors | ||
1339 | 12 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1340 | 13 | |||
1341 | 14 | This program is free software: you can redistribute it and/or modify | ||
1342 | 15 | it under the terms of the GNU General Public License version 3, | ||
1343 | 16 | as published by the Free Software Foundation. | ||
1344 | 17 | |||
1345 | 18 | This program is distributed in the hope that it will be useful, | ||
1346 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1347 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1348 | 21 | GNU General Public License for more details. | ||
1349 | 22 | |||
1350 | 23 | You should have received a copy of the GNU General Public License | ||
1351 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1352 | 25 | |||
1353 | 26 | """ | ||
1354 | 27 | from argparse import ( | ||
1355 | 28 | ArgumentParser, | ||
1356 | 29 | RawTextHelpFormatter | ||
1357 | 30 | ) | ||
1358 | 31 | |||
1359 | 32 | import sys | ||
1360 | 33 | import configparser | ||
1361 | 34 | import shlex | ||
1362 | 35 | import subprocess | ||
1363 | 36 | import ast | ||
1364 | 37 | import time | ||
1365 | 38 | from subprocess import ( | ||
1366 | 39 | check_output, | ||
1367 | 40 | CalledProcessError | ||
1368 | 41 | ) | ||
1369 | 42 | |||
1370 | 43 | def get_power_status(host_ip, user, password): | ||
1371 | 44 | cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\ | ||
1372 | 45 | .format(host_ip, user, password) | ||
1373 | 46 | status_code = subprocess.call(cmd_status, shell=True) | ||
1374 | 47 | return status_code | ||
1375 | 48 | |||
1376 | 49 | def power_reset(host_ip, user, password): | ||
1377 | 50 | cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\ | ||
1378 | 51 | .format(host_ip, user, password) | ||
1379 | 52 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
1380 | 53 | return reset_code | ||
1381 | 54 | |||
1382 | 55 | def add_user(host_ip, user, password, new_id, new_user): | ||
1383 | 56 | cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\ | ||
1384 | 57 | .format(host_ip, user, password, new_id, new_user) | ||
1385 | 58 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
1386 | 59 | return add_user_code | ||
1387 | 60 | |||
1388 | 61 | def dcmi_user_level_test(args): | ||
1389 | 62 | |||
1390 | 63 | #DCMI config file | ||
1391 | 64 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
1392 | 65 | if not "config" in vars(args): | ||
1393 | 66 | config_file = DEFAULT_CFG | ||
1394 | 67 | else: | ||
1395 | 68 | config_file = args.config | ||
1396 | 69 | config = configparser.RawConfigParser() | ||
1397 | 70 | try: | ||
1398 | 71 | config.readfp(open(config_file)) | ||
1399 | 72 | except IOError: | ||
1400 | 73 | print("No config file found") | ||
1401 | 74 | return 10 | ||
1402 | 75 | |||
1403 | 76 | try: | ||
1404 | 77 | targets_options = config.options('Targets') | ||
1405 | 78 | targets_list = [] | ||
1406 | 79 | for target_key in targets_options: | ||
1407 | 80 | targets_list.append(config.get('Targets', target_key)) | ||
1408 | 81 | if not targets_list: | ||
1409 | 82 | print("Invalid or Empty targets") | ||
1410 | 83 | return 20 | ||
1411 | 84 | except configparser.Error: | ||
1412 | 85 | print("Invalid or Empty targets") | ||
1413 | 86 | return 20 | ||
1414 | 87 | |||
1415 | 88 | try: | ||
1416 | 89 | user_value = config.get("Operator Level", "OPER_NAME") | ||
1417 | 90 | password_value = config.get("Operator Level", "OPER_PASSWD") | ||
1418 | 91 | except configparser.NoOptionError: | ||
1419 | 92 | print("Invalid or Empty credential info") | ||
1420 | 93 | print("Require Operator Level info pre-configured in /etc/checkbox.d/me.cfg") | ||
1421 | 94 | return 30 | ||
1422 | 95 | |||
1423 | 96 | try: | ||
1424 | 97 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
1425 | 98 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
1426 | 99 | except configparser.NoOptionError: | ||
1427 | 100 | print("Invalid or Empty new user info") | ||
1428 | 101 | print("Require new User info pre-configured in /etc/checkbox.d/me.cfg") | ||
1429 | 102 | return 40 | ||
1430 | 103 | |||
1431 | 104 | flag = 0 | ||
1432 | 105 | for tg in targets_list: | ||
1433 | 106 | |||
1434 | 107 | if not tg or not user_value or not password_value: | ||
1435 | 108 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
1436 | 109 | return 50 | ||
1437 | 110 | else: | ||
1438 | 111 | print("SUT", tg) | ||
1439 | 112 | |||
1440 | 113 | ping_result = ping_test(tg) | ||
1441 | 114 | if ping_result != 0: | ||
1442 | 115 | return 88 | ||
1443 | 116 | |||
1444 | 117 | status_result = get_power_status(tg, user_value, password_value) | ||
1445 | 118 | time.sleep(5) | ||
1446 | 119 | |||
1447 | 120 | reset_result = power_reset(tg, user_value, password_value) | ||
1448 | 121 | time.sleep(5) | ||
1449 | 122 | if not new_user_value or not new_user_id_value: | ||
1450 | 123 | print("Require new user info pre-configured in /etc/checkbox.d/me.cfg") | ||
1451 | 124 | return 60 | ||
1452 | 125 | else: | ||
1453 | 126 | |||
1454 | 127 | ping_result = ping_test(tg) | ||
1455 | 128 | if ping_result != 0: | ||
1456 | 129 | return 88 | ||
1457 | 130 | |||
1458 | 131 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
1459 | 132 | time.sleep(5) | ||
1460 | 133 | |||
1461 | 134 | if status_result == 0 and reset_result == 0 and add_user_result == 1: | ||
1462 | 135 | print("User can read power status.") | ||
1463 | 136 | print("User can reset power.") | ||
1464 | 137 | print("User can't add a new user.") | ||
1465 | 138 | else: | ||
1466 | 139 | print("Authentication: Not Operator Level") | ||
1467 | 140 | flag = 1 | ||
1468 | 141 | |||
1469 | 142 | if flag == 1: | ||
1470 | 143 | return 100 | ||
1471 | 144 | return 0 | ||
1472 | 145 | |||
1473 | 146 | def ping_test(host_ip): | ||
1474 | 147 | count = 0 | ||
1475 | 148 | while count < 10: | ||
1476 | 149 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
1477 | 150 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
1478 | 151 | if ping_rtn == 0: | ||
1479 | 152 | return 0 | ||
1480 | 153 | else: | ||
1481 | 154 | print("Destination Host Unreachable") | ||
1482 | 155 | time.sleep(10) | ||
1483 | 156 | count = count+1 | ||
1484 | 157 | |||
1485 | 158 | if count == 10: | ||
1486 | 159 | print("Host Has No Response, End of Test") | ||
1487 | 160 | return 1 | ||
1488 | 161 | |||
1489 | 162 | |||
1490 | 163 | def main(): | ||
1491 | 164 | |||
1492 | 165 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
1493 | 166 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
1494 | 167 | parser.add_argument('--config', type=str, | ||
1495 | 168 | default="/etc/checkbox.d/me.cfg", | ||
1496 | 169 | help="Supply config file for getting authentication info") | ||
1497 | 170 | args = parser.parse_args() | ||
1498 | 171 | return dcmi_user_level_test(args) | ||
1499 | 172 | |||
1500 | 173 | if __name__ == "__main__": | ||
1501 | 174 | sys.exit(main()) | ||
1502 | 0 | 175 | ||
1503 | === added file 'bin/dcmi_priv_user' | |||
1504 | --- bin/dcmi_priv_user 1970-01-01 00:00:00 +0000 | |||
1505 | +++ bin/dcmi_priv_user 2015-08-14 22:03:31 +0000 | |||
1506 | @@ -0,0 +1,174 @@ | |||
1507 | 1 | #! /usr/bin/env python3 | ||
1508 | 2 | """ | ||
1509 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1510 | 4 | Industrial Technology Research Institute | ||
1511 | 5 | |||
1512 | 6 | File Name | ||
1513 | 7 | dcmi_priv_uesr | ||
1514 | 8 | 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account | ||
1515 | 9 | 2. Criteria: power status reading must be successful and must fail at power reset and adding a new user account | ||
1516 | 10 | |||
1517 | 11 | Authors | ||
1518 | 12 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1519 | 13 | |||
1520 | 14 | This program is free software: you can redistribute it and/or modify | ||
1521 | 15 | it under the terms of the GNU General Public License version 3, | ||
1522 | 16 | as published by the Free Software Foundation. | ||
1523 | 17 | |||
1524 | 18 | This program is distributed in the hope that it will be useful, | ||
1525 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1526 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1527 | 21 | GNU General Public License for more details. | ||
1528 | 22 | |||
1529 | 23 | You should have received a copy of the GNU General Public License | ||
1530 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1531 | 25 | |||
1532 | 26 | """ | ||
1533 | 27 | from argparse import ( | ||
1534 | 28 | ArgumentParser, | ||
1535 | 29 | RawTextHelpFormatter | ||
1536 | 30 | ) | ||
1537 | 31 | |||
1538 | 32 | import sys | ||
1539 | 33 | import configparser | ||
1540 | 34 | import shlex | ||
1541 | 35 | import subprocess | ||
1542 | 36 | import ast | ||
1543 | 37 | import time | ||
1544 | 38 | from subprocess import ( | ||
1545 | 39 | check_output, | ||
1546 | 40 | CalledProcessError | ||
1547 | 41 | ) | ||
1548 | 42 | |||
1549 | 43 | def get_power_status(host_ip, user, password): | ||
1550 | 44 | cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\ | ||
1551 | 45 | .format(host_ip, user, password) | ||
1552 | 46 | status_code = subprocess.call(cmd_status, shell=True) | ||
1553 | 47 | return status_code | ||
1554 | 48 | |||
1555 | 49 | def power_reset(host_ip, user, password): | ||
1556 | 50 | cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\ | ||
1557 | 51 | .format(host_ip, user, password) | ||
1558 | 52 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
1559 | 53 | return reset_code | ||
1560 | 54 | |||
1561 | 55 | def add_user(host_ip, user, password, new_id, new_user): | ||
1562 | 56 | cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\ | ||
1563 | 57 | .format(host_ip, user, password, new_id, new_user) | ||
1564 | 58 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
1565 | 59 | return add_user_code | ||
1566 | 60 | |||
1567 | 61 | def dcmi_user_level_test(args): | ||
1568 | 62 | |||
1569 | 63 | #DCMI config file | ||
1570 | 64 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
1571 | 65 | if not "config" in vars(args): | ||
1572 | 66 | config_file = DEFAULT_CFG | ||
1573 | 67 | else: | ||
1574 | 68 | config_file = args.config | ||
1575 | 69 | config = configparser.RawConfigParser() | ||
1576 | 70 | try: | ||
1577 | 71 | config.readfp(open(config_file)) | ||
1578 | 72 | except IOError: | ||
1579 | 73 | print("No config file found") | ||
1580 | 74 | return 10 | ||
1581 | 75 | |||
1582 | 76 | try: | ||
1583 | 77 | targets_options = config.options('Targets') | ||
1584 | 78 | targets_list = [] | ||
1585 | 79 | for target_key in targets_options: | ||
1586 | 80 | targets_list.append(config.get('Targets', target_key)) | ||
1587 | 81 | if not targets_list: | ||
1588 | 82 | print("Invalid or Empty targets") | ||
1589 | 83 | return 20 | ||
1590 | 84 | except configparser.Error: | ||
1591 | 85 | print("Invalid or Empty targets") | ||
1592 | 86 | return 20 | ||
1593 | 87 | |||
1594 | 88 | try: | ||
1595 | 89 | user_value = config.get("User Level", "USER_NAME") | ||
1596 | 90 | password_value = config.get("User Level", "USER_PASSWD") | ||
1597 | 91 | except configparser.NoOptionError: | ||
1598 | 92 | print("Invalid or Empty credential info") | ||
1599 | 93 | print("Require User Level info pre-configured in /etc/checkbox.d/me.cfg") | ||
1600 | 94 | return 30 | ||
1601 | 95 | |||
1602 | 96 | try: | ||
1603 | 97 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
1604 | 98 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
1605 | 99 | except configparser.NoOptionError: | ||
1606 | 100 | print("Invalid or Empty new user info") | ||
1607 | 101 | print("Require new User info pre-configured in /etc/checkbox.d/me.cfg") | ||
1608 | 102 | return 40 | ||
1609 | 103 | |||
1610 | 104 | flag = 0 | ||
1611 | 105 | for tg in targets_list: | ||
1612 | 106 | |||
1613 | 107 | if not tg or not user_value or not password_value: | ||
1614 | 108 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
1615 | 109 | return 50 | ||
1616 | 110 | else: | ||
1617 | 111 | print("SUT", tg) | ||
1618 | 112 | |||
1619 | 113 | ping_result = ping_test(tg) | ||
1620 | 114 | if ping_result != 0: | ||
1621 | 115 | return 88 | ||
1622 | 116 | |||
1623 | 117 | status_result = get_power_status(tg, user_value, password_value) | ||
1624 | 118 | time.sleep(5) | ||
1625 | 119 | |||
1626 | 120 | reset_result = power_reset(tg, user_value, password_value) | ||
1627 | 121 | time.sleep(5) | ||
1628 | 122 | if not new_user_value or not new_user_id_value: | ||
1629 | 123 | print("Require new user info pre-configured in /etc/checkbox.d/me.cfg") | ||
1630 | 124 | return 60 | ||
1631 | 125 | else: | ||
1632 | 126 | |||
1633 | 127 | ping_result = ping_test(tg) | ||
1634 | 128 | if ping_result != 0: | ||
1635 | 129 | return 88 | ||
1636 | 130 | |||
1637 | 131 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
1638 | 132 | time.sleep(5) | ||
1639 | 133 | |||
1640 | 134 | if status_result == 0 and reset_result == 1 and add_user_result == 1: | ||
1641 | 135 | print("User can read power status.") | ||
1642 | 136 | print("User can't reset power.") | ||
1643 | 137 | print("User can't add a new user.") | ||
1644 | 138 | else: | ||
1645 | 139 | print("Authentication: Not User Level") | ||
1646 | 140 | flag = 1 | ||
1647 | 141 | |||
1648 | 142 | if flag == 1: | ||
1649 | 143 | return 100 | ||
1650 | 144 | return 0 | ||
1651 | 145 | |||
1652 | 146 | def ping_test(host_ip): | ||
1653 | 147 | count = 0 | ||
1654 | 148 | while count < 10: | ||
1655 | 149 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
1656 | 150 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
1657 | 151 | if ping_rtn == 0: | ||
1658 | 152 | return 0 | ||
1659 | 153 | else: | ||
1660 | 154 | print("Destination Host Unreachable") | ||
1661 | 155 | time.sleep(10) | ||
1662 | 156 | count = count+1 | ||
1663 | 157 | |||
1664 | 158 | if count == 10: | ||
1665 | 159 | print("Host Has No Response, End of Test") | ||
1666 | 160 | return 1 | ||
1667 | 161 | |||
1668 | 162 | |||
1669 | 163 | def main(): | ||
1670 | 164 | |||
1671 | 165 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
1672 | 166 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
1673 | 167 | parser.add_argument('--config', type=str, | ||
1674 | 168 | default="/etc/checkbox.d/me.cfg", | ||
1675 | 169 | help="Supply config file for getting authentication info") | ||
1676 | 170 | args = parser.parse_args() | ||
1677 | 171 | return dcmi_user_level_test(args) | ||
1678 | 172 | |||
1679 | 173 | if __name__ == "__main__": | ||
1680 | 174 | sys.exit(main()) | ||
1681 | 0 | 175 | ||
1682 | === added file 'bin/dcmi_sampling' | |||
1683 | --- bin/dcmi_sampling 1970-01-01 00:00:00 +0000 | |||
1684 | +++ bin/dcmi_sampling 2015-08-14 22:03:31 +0000 | |||
1685 | @@ -0,0 +1,271 @@ | |||
1686 | 1 | #!/usr/bin/env python3 | ||
1687 | 2 | """ | ||
1688 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1689 | 4 | Industrial Technology Research Institute | ||
1690 | 5 | |||
1691 | 6 | File Name | ||
1692 | 7 | dcmi_sampling | ||
1693 | 8 | 1. Retrieve CPU and intake temperature 30 times at 3 second intervals using dcmitool | ||
1694 | 9 | 2. If failed to retrieve temperature at any time within 30 times, the test is considered failed | ||
1695 | 10 | |||
1696 | 11 | Authors | ||
1697 | 12 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1698 | 13 | |||
1699 | 14 | This program is free software: you can redistribute it and/or modify | ||
1700 | 15 | it under the terms of the GNU General Public License version 3, | ||
1701 | 16 | as published by the Free Software Foundation. | ||
1702 | 17 | |||
1703 | 18 | This program is distributed in the hope that it will be useful, | ||
1704 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1705 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1706 | 21 | GNU General Public License for more details. | ||
1707 | 22 | |||
1708 | 23 | You should have received a copy of the GNU General Public License | ||
1709 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1710 | 25 | |||
1711 | 26 | """ | ||
1712 | 27 | import sys | ||
1713 | 28 | import time | ||
1714 | 29 | import re | ||
1715 | 30 | import configparser | ||
1716 | 31 | import shlex | ||
1717 | 32 | import subprocess | ||
1718 | 33 | from argparse import ( | ||
1719 | 34 | ArgumentParser, | ||
1720 | 35 | RawTextHelpFormatter | ||
1721 | 36 | ) | ||
1722 | 37 | from subprocess import ( | ||
1723 | 38 | check_output, | ||
1724 | 39 | CalledProcessError | ||
1725 | 40 | ) | ||
1726 | 41 | |||
1727 | 42 | def get_sdr_remote(host_ip, user, password): | ||
1728 | 43 | cmd = "dcmitool -H {} -U {} -P {} sdr".format(host_ip, user, password) | ||
1729 | 44 | sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT, | ||
1730 | 45 | universal_newlines=True) | ||
1731 | 46 | return sdr_return | ||
1732 | 47 | |||
1733 | 48 | def parse_sdr(output): | ||
1734 | 49 | output = output.strip() | ||
1735 | 50 | output_1Line = output.split("\n") | ||
1736 | 51 | data = {} | ||
1737 | 52 | |||
1738 | 53 | for line in output_1Line: | ||
1739 | 54 | sub_value = {} | ||
1740 | 55 | string_list = line.split("|") | ||
1741 | 56 | name = string_list[0].strip() | ||
1742 | 57 | sensor_output = string_list[1].strip() | ||
1743 | 58 | sub_value.update({'output':sensor_output}) | ||
1744 | 59 | status = string_list[2].strip() | ||
1745 | 60 | sub_value.update({'status':status}) | ||
1746 | 61 | data.update({name:sub_value}) | ||
1747 | 62 | return data | ||
1748 | 63 | |||
1749 | 64 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
1750 | 65 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
1751 | 66 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
1752 | 67 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
1753 | 68 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
1754 | 69 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
1755 | 70 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
1756 | 71 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
1757 | 72 | return str(CPU_temp)+' degrees C' | ||
1758 | 73 | else: | ||
1759 | 74 | return 'Error' | ||
1760 | 75 | else: | ||
1761 | 76 | return 'None' | ||
1762 | 77 | |||
1763 | 78 | def dcmi_sdr(args): | ||
1764 | 79 | |||
1765 | 80 | cmd_flag = 0 | ||
1766 | 81 | #DCMI config file | ||
1767 | 82 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
1768 | 83 | if not "config" in vars(args): | ||
1769 | 84 | config_file = DEFAULT_CFG | ||
1770 | 85 | else: | ||
1771 | 86 | config_file = args.config | ||
1772 | 87 | |||
1773 | 88 | config = configparser.RawConfigParser() | ||
1774 | 89 | |||
1775 | 90 | try: | ||
1776 | 91 | config.readfp(open(config_file)) | ||
1777 | 92 | except IOError: | ||
1778 | 93 | print("No config file found") | ||
1779 | 94 | return 10 | ||
1780 | 95 | |||
1781 | 96 | try: | ||
1782 | 97 | sensor_nick = config.options("SensorsForSampling") | ||
1783 | 98 | except configparser.NoSectionError: | ||
1784 | 99 | print("No Section: SensorsForSampling") | ||
1785 | 100 | return 20 | ||
1786 | 101 | |||
1787 | 102 | if sensor_nick: | ||
1788 | 103 | sensor_list = [] | ||
1789 | 104 | for id in sensor_nick: | ||
1790 | 105 | sensor_key = config.get("SensorsForSampling", id) | ||
1791 | 106 | if sensor_key: | ||
1792 | 107 | sensor_list.append(sensor_key) | ||
1793 | 108 | else: | ||
1794 | 109 | print("No Sensor ID specified in Config file") | ||
1795 | 110 | return 30 | ||
1796 | 111 | else: | ||
1797 | 112 | print("No key of Sensor ID specified in config file") | ||
1798 | 113 | return 40 | ||
1799 | 114 | |||
1800 | 115 | try: | ||
1801 | 116 | targets_options = config.options('Targets') | ||
1802 | 117 | targets_list = [] | ||
1803 | 118 | for target_key in targets_options: | ||
1804 | 119 | targets_list.append(config.get('Targets', target_key)) | ||
1805 | 120 | if not targets_list: | ||
1806 | 121 | print("Invalid or Empty targets") | ||
1807 | 122 | return 60 | ||
1808 | 123 | except configparser.Error: | ||
1809 | 124 | print("Invalid or Empty targets") | ||
1810 | 125 | return 60 | ||
1811 | 126 | |||
1812 | 127 | try: | ||
1813 | 128 | user_value = config.get("Account", "USER") | ||
1814 | 129 | password_value = config.get("Account", "PASSWORD") | ||
1815 | 130 | except configparser.NoOptionError: | ||
1816 | 131 | print("Invalid or Empty credential info") | ||
1817 | 132 | return 70 | ||
1818 | 133 | |||
1819 | 134 | for tg in targets_list: | ||
1820 | 135 | |||
1821 | 136 | if not tg or not user_value or not password_value: | ||
1822 | 137 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
1823 | 138 | return 80 | ||
1824 | 139 | else: | ||
1825 | 140 | |||
1826 | 141 | c = 0 | ||
1827 | 142 | while c < 10: | ||
1828 | 143 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
1829 | 144 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
1830 | 145 | if ping_rtn == 0: | ||
1831 | 146 | print("Destination Host Reachable") | ||
1832 | 147 | break | ||
1833 | 148 | else: | ||
1834 | 149 | time.sleep(10) | ||
1835 | 150 | c = c+1 | ||
1836 | 151 | print("Destination Host Unreachable") | ||
1837 | 152 | |||
1838 | 153 | if c == 10: | ||
1839 | 154 | print("Host Has No Response, End of Test") | ||
1840 | 155 | return 99 | ||
1841 | 156 | |||
1842 | 157 | |||
1843 | 158 | sampling_data = [] | ||
1844 | 159 | times = 30 | ||
1845 | 160 | for n in range(times): | ||
1846 | 161 | |||
1847 | 162 | try: | ||
1848 | 163 | sensor_data = get_sdr_remote(tg, user_value, password_value) | ||
1849 | 164 | time.sleep(3) | ||
1850 | 165 | except CalledProcessError as dcmi_exception: | ||
1851 | 166 | print("Failed executing dcmi, Reason: %s" % dcmi_exception) | ||
1852 | 167 | sensor_data = '' | ||
1853 | 168 | |||
1854 | 169 | sampling_data.append(sensor_data) | ||
1855 | 170 | |||
1856 | 171 | count = 0 | ||
1857 | 172 | prs_flag = 0 | ||
1858 | 173 | dis_flag = 0 | ||
1859 | 174 | for output in sampling_data: | ||
1860 | 175 | try: | ||
1861 | 176 | data = parse_sdr(output) | ||
1862 | 177 | except: | ||
1863 | 178 | print("Parsing output of sdr table error") | ||
1864 | 179 | print("=======================================================") | ||
1865 | 180 | prs_flag = 1 | ||
1866 | 181 | count = count+1 | ||
1867 | 182 | continue | ||
1868 | 183 | |||
1869 | 184 | disable = 0 | ||
1870 | 185 | need_data = {} | ||
1871 | 186 | |||
1872 | 187 | for need_id in sensor_list: | ||
1873 | 188 | |||
1874 | 189 | if data.get(need_id): | ||
1875 | 190 | need_value = data.get(need_id).get('output') | ||
1876 | 191 | need_data.update({need_id:need_value}) | ||
1877 | 192 | if data.get(need_id).get('status') != 'ok': | ||
1878 | 193 | disable = 1 | ||
1879 | 194 | else: | ||
1880 | 195 | |||
1881 | 196 | try: | ||
1882 | 197 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
1883 | 198 | except configparser.NoOptionError: | ||
1884 | 199 | CPUx_Temp = '' | ||
1885 | 200 | |||
1886 | 201 | try: | ||
1887 | 202 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
1888 | 203 | except configparser.NoOptionError: | ||
1889 | 204 | CPUy_Temp = '' | ||
1890 | 205 | |||
1891 | 206 | if need_id == CPUx_Temp: | ||
1892 | 207 | |||
1893 | 208 | try: | ||
1894 | 209 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
1895 | 210 | except configparser.NoOptionError: | ||
1896 | 211 | PxTM = '' | ||
1897 | 212 | |||
1898 | 213 | try: | ||
1899 | 214 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
1900 | 215 | except configparser.NoOptionError: | ||
1901 | 216 | CPUx_Tjmax = '' | ||
1902 | 217 | |||
1903 | 218 | if PxTM and CPUx_Tjmax: | ||
1904 | 219 | Px_temp = calculate_CPU_temp(data, PxTM, CPUx_Tjmax) | ||
1905 | 220 | need_data.update({CPUx_Temp:Px_temp}) | ||
1906 | 221 | if Px_temp == 'None' or Px_temp == 'Error': | ||
1907 | 222 | disable = 1 | ||
1908 | 223 | else: | ||
1909 | 224 | disable = 1 | ||
1910 | 225 | |||
1911 | 226 | elif need_id == CPUy_Temp: | ||
1912 | 227 | |||
1913 | 228 | try: | ||
1914 | 229 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
1915 | 230 | except configparser.NoOptionError: | ||
1916 | 231 | PyTM = '' | ||
1917 | 232 | |||
1918 | 233 | try: | ||
1919 | 234 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
1920 | 235 | except configparser.NoOptionError: | ||
1921 | 236 | CPUy_Tjmax = '' | ||
1922 | 237 | |||
1923 | 238 | if PyTM and CPUy_Tjmax: | ||
1924 | 239 | Py_temp = calculate_CPU_temp(data, PyTM, CPUy_Tjmax) | ||
1925 | 240 | need_data.update({CPUy_Temp:Py_temp}) | ||
1926 | 241 | if Py_temp == 'None' or Py_temp == 'Error': | ||
1927 | 242 | disable = 1 | ||
1928 | 243 | else: | ||
1929 | 244 | disable = 1 | ||
1930 | 245 | |||
1931 | 246 | else: | ||
1932 | 247 | need_data.update({need_id:'None'}) | ||
1933 | 248 | disable = 1 | ||
1934 | 249 | |||
1935 | 250 | if disable == 1: | ||
1936 | 251 | dis_flag = 1 | ||
1937 | 252 | print(need_data) | ||
1938 | 253 | print("=======================================================") | ||
1939 | 254 | count = count+1 | ||
1940 | 255 | print("Pass: %d" %(times-count)) | ||
1941 | 256 | print("Fail: %d" %(count)) | ||
1942 | 257 | |||
1943 | 258 | if cmd_flag == 1 or prs_flag == 1 or dis_flag == 1: | ||
1944 | 259 | return 100 | ||
1945 | 260 | return 0 | ||
1946 | 261 | |||
1947 | 262 | def main(): | ||
1948 | 263 | |||
1949 | 264 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
1950 | 265 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
1951 | 266 | parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters") | ||
1952 | 267 | args = parser.parse_args() | ||
1953 | 268 | return dcmi_sdr(args) | ||
1954 | 269 | |||
1955 | 270 | if __name__ == "__main__": | ||
1956 | 271 | sys.exit(main()) | ||
1957 | 0 | 272 | ||
1958 | === added file 'bin/dcmi_thermal_ib' | |||
1959 | --- bin/dcmi_thermal_ib 1970-01-01 00:00:00 +0000 | |||
1960 | +++ bin/dcmi_thermal_ib 2015-08-14 22:03:31 +0000 | |||
1961 | @@ -0,0 +1,212 @@ | |||
1962 | 1 | #!/usr/bin/env python3 | ||
1963 | 2 | """ | ||
1964 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
1965 | 4 | Industrial Technology Research Institute | ||
1966 | 5 | |||
1967 | 6 | File Name | ||
1968 | 7 | dcmi_thermal_ib | ||
1969 | 8 | 1. Retrieve CPU, DIMM, chipset, inlet and outlet temperatures via DCMI in-band access using dcmitool. | ||
1970 | 9 | 2. The motherboard has five thermal sensors: | ||
1971 | 10 | Two for CPU0 and CPU1 temperatures, | ||
1972 | 11 | Two for CPU0 DIMM group and CPU1 DIMM group temperatures, | ||
1973 | 12 | One for PCH temperature, | ||
1974 | 13 | One for Inlet temperature, | ||
1975 | 14 | One for outlet temperature. | ||
1976 | 15 | 3. Criteria: Must retrieve temperatures from all abovementioned thermal sensors via DCMI in-band access. | ||
1977 | 16 | |||
1978 | 17 | Authors | ||
1979 | 18 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
1980 | 19 | |||
1981 | 20 | This program is free software: you can redistribute it and/or modify | ||
1982 | 21 | it under the terms of the GNU General Public License version 3, | ||
1983 | 22 | as published by the Free Software Foundation. | ||
1984 | 23 | |||
1985 | 24 | This program is distributed in the hope that it will be useful, | ||
1986 | 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1987 | 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1988 | 27 | GNU General Public License for more details. | ||
1989 | 28 | |||
1990 | 29 | You should have received a copy of the GNU General Public License | ||
1991 | 30 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1992 | 31 | |||
1993 | 32 | """ | ||
1994 | 33 | import sys | ||
1995 | 34 | import time | ||
1996 | 35 | import re | ||
1997 | 36 | import configparser | ||
1998 | 37 | import shlex | ||
1999 | 38 | import subprocess | ||
2000 | 39 | import ast | ||
2001 | 40 | from argparse import ( | ||
2002 | 41 | ArgumentParser, | ||
2003 | 42 | RawTextHelpFormatter | ||
2004 | 43 | ) | ||
2005 | 44 | from subprocess import ( | ||
2006 | 45 | check_output, | ||
2007 | 46 | CalledProcessError | ||
2008 | 47 | ) | ||
2009 | 48 | |||
2010 | 49 | |||
2011 | 50 | def get_sdr(): | ||
2012 | 51 | cmd = "dcmitool sdr" | ||
2013 | 52 | sdr_return = subprocess.check_output(shlex.split(cmd), universal_newlines=True) | ||
2014 | 53 | return sdr_return | ||
2015 | 54 | |||
2016 | 55 | def parse_sdr(output): | ||
2017 | 56 | output = output.strip() | ||
2018 | 57 | output_1Line = output.split("\n") | ||
2019 | 58 | data = {} | ||
2020 | 59 | |||
2021 | 60 | for line in output_1Line: | ||
2022 | 61 | sub_value = {} | ||
2023 | 62 | string_list = line.split("|") | ||
2024 | 63 | name = string_list[0].strip() | ||
2025 | 64 | sensor_output = string_list[1].strip() | ||
2026 | 65 | sub_value.update({'output':sensor_output}) | ||
2027 | 66 | status = string_list[2].strip() | ||
2028 | 67 | sub_value.update({'status':status}) | ||
2029 | 68 | data.update({name:sub_value}) | ||
2030 | 69 | return data | ||
2031 | 70 | |||
2032 | 71 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
2033 | 72 | |||
2034 | 73 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
2035 | 74 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
2036 | 75 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
2037 | 76 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
2038 | 77 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
2039 | 78 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
2040 | 79 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
2041 | 80 | return str(CPU_temp)+' degrees C' | ||
2042 | 81 | else: | ||
2043 | 82 | return 'Error' | ||
2044 | 83 | else: | ||
2045 | 84 | return 'None' | ||
2046 | 85 | |||
2047 | 86 | def dcmi_sdr(args): | ||
2048 | 87 | |||
2049 | 88 | flag = 0 | ||
2050 | 89 | #DCMI config file | ||
2051 | 90 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
2052 | 91 | if not "config" in vars(args): | ||
2053 | 92 | config_file = DEFAULT_CFG | ||
2054 | 93 | else: | ||
2055 | 94 | config_file = args.config | ||
2056 | 95 | config = configparser.RawConfigParser() | ||
2057 | 96 | |||
2058 | 97 | try: | ||
2059 | 98 | config.readfp(open(config_file)) | ||
2060 | 99 | except IOError: | ||
2061 | 100 | print("No config file found") | ||
2062 | 101 | return 10 | ||
2063 | 102 | |||
2064 | 103 | try: | ||
2065 | 104 | sensor_nick = config.options("Sensors") | ||
2066 | 105 | except configparser.NoSectionError: | ||
2067 | 106 | print("No Section: Sensors") | ||
2068 | 107 | return 20 | ||
2069 | 108 | |||
2070 | 109 | if sensor_nick: | ||
2071 | 110 | sensor_list = [] | ||
2072 | 111 | for id in sensor_nick: | ||
2073 | 112 | sensor_key = config.get("Sensors", id) | ||
2074 | 113 | if sensor_key: | ||
2075 | 114 | sensor_list.append(sensor_key) | ||
2076 | 115 | else: | ||
2077 | 116 | print("No Sensor ID specified in Config file") | ||
2078 | 117 | return 30 | ||
2079 | 118 | else: | ||
2080 | 119 | print("No key of Sensor ID specified in config file") | ||
2081 | 120 | return 40 | ||
2082 | 121 | |||
2083 | 122 | try: | ||
2084 | 123 | sensor_data = get_sdr() | ||
2085 | 124 | time.sleep(5) | ||
2086 | 125 | except CalledProcessError as dcmi_exception: | ||
2087 | 126 | print("Failed executing dcmi, Reason: %s" % dcmi_exception) | ||
2088 | 127 | return 50 | ||
2089 | 128 | |||
2090 | 129 | try: | ||
2091 | 130 | data = parse_sdr(sensor_data) | ||
2092 | 131 | except: | ||
2093 | 132 | print("Parsing output of sdr table error") | ||
2094 | 133 | return 60 | ||
2095 | 134 | |||
2096 | 135 | need_data = {} | ||
2097 | 136 | for need_id in sensor_list: | ||
2098 | 137 | if data.get(need_id): | ||
2099 | 138 | need_value = data.get(need_id).get('output') | ||
2100 | 139 | need_data.update({need_id:need_value}) | ||
2101 | 140 | |||
2102 | 141 | if data.get(need_id).get('status') != 'ok': | ||
2103 | 142 | flag = 1 | ||
2104 | 143 | else: | ||
2105 | 144 | |||
2106 | 145 | try: | ||
2107 | 146 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
2108 | 147 | except configparser.NoOptionError: | ||
2109 | 148 | CPUx_Temp = '' | ||
2110 | 149 | |||
2111 | 150 | try: | ||
2112 | 151 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
2113 | 152 | except configparser.NoOptionError: | ||
2114 | 153 | CPUy_Temp = '' | ||
2115 | 154 | |||
2116 | 155 | if need_id == CPUx_Temp: | ||
2117 | 156 | |||
2118 | 157 | try: | ||
2119 | 158 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
2120 | 159 | except configparser.NoOptionError: | ||
2121 | 160 | PxTM = '' | ||
2122 | 161 | |||
2123 | 162 | try: | ||
2124 | 163 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
2125 | 164 | except configparser.NoOptionError: | ||
2126 | 165 | CPUx_Tjmax = '' | ||
2127 | 166 | |||
2128 | 167 | if PxTM and CPUx_Tjmax: | ||
2129 | 168 | need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)}) | ||
2130 | 169 | if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error': | ||
2131 | 170 | flag = 1 | ||
2132 | 171 | else: | ||
2133 | 172 | flag = 1 | ||
2134 | 173 | |||
2135 | 174 | elif need_id == CPUy_Temp: | ||
2136 | 175 | |||
2137 | 176 | try: | ||
2138 | 177 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
2139 | 178 | except configparser.NoOptionError: | ||
2140 | 179 | PyTM = '' | ||
2141 | 180 | |||
2142 | 181 | try: | ||
2143 | 182 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
2144 | 183 | except configparser.NoOptionError: | ||
2145 | 184 | CPUy_Tjmax = '' | ||
2146 | 185 | |||
2147 | 186 | |||
2148 | 187 | if PyTM and CPUy_Tjmax: | ||
2149 | 188 | need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)}) | ||
2150 | 189 | if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error': | ||
2151 | 190 | flag = 1 | ||
2152 | 191 | else: | ||
2153 | 192 | flag = 1 | ||
2154 | 193 | else: | ||
2155 | 194 | flag = 1 | ||
2156 | 195 | |||
2157 | 196 | print("%s: %s" %(need_id, need_data.get(need_id))) | ||
2158 | 197 | |||
2159 | 198 | if flag == 1: | ||
2160 | 199 | return 100 | ||
2161 | 200 | return 0 | ||
2162 | 201 | |||
2163 | 202 | def main(): | ||
2164 | 203 | |||
2165 | 204 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
2166 | 205 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
2167 | 206 | parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters") | ||
2168 | 207 | args = parser.parse_args() | ||
2169 | 208 | return dcmi_sdr(args) | ||
2170 | 209 | |||
2171 | 210 | if __name__ == "__main__": | ||
2172 | 211 | sys.exit(main()) | ||
2173 | 212 | |||
2174 | 0 | 213 | ||
2175 | === added file 'bin/dcmi_thermal_oob' | |||
2176 | --- bin/dcmi_thermal_oob 1970-01-01 00:00:00 +0000 | |||
2177 | +++ bin/dcmi_thermal_oob 2015-08-14 22:03:31 +0000 | |||
2178 | @@ -0,0 +1,243 @@ | |||
2179 | 1 | #!/usr/bin/env python3 | ||
2180 | 2 | """ | ||
2181 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
2182 | 4 | Industrial Technology Research Institute | ||
2183 | 5 | |||
2184 | 6 | File Name | ||
2185 | 7 | dcmi_thermal_oob | ||
2186 | 8 | 1. Retrieving CPU, DIMM, chipset, inlet, outlet temperature via DCMI out-of-band access using dcmitool. | ||
2187 | 9 | 2. The motherboard has five thermal sensors: Two for CPU0 and CPU1 temperatures, | ||
2188 | 10 | Two for CPU0 DIMM group and CPU1 DIMM group temperatures, | ||
2189 | 11 | One for PCH temperature, | ||
2190 | 12 | One for Inlet temperature, | ||
2191 | 13 | One for outlet temperature. | ||
2192 | 14 | 3. Criteria: Must retrieve temperatures from all abovementioned thermal sensors via DCMI out-of-band access. | ||
2193 | 15 | |||
2194 | 16 | Authors | ||
2195 | 17 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
2196 | 18 | |||
2197 | 19 | This program is free software: you can redistribute it and/or modify | ||
2198 | 20 | it under the terms of the GNU General Public License version 3, | ||
2199 | 21 | as published by the Free Software Foundation. | ||
2200 | 22 | |||
2201 | 23 | This program is distributed in the hope that it will be useful, | ||
2202 | 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2203 | 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2204 | 26 | GNU General Public License for more details. | ||
2205 | 27 | |||
2206 | 28 | You should have received a copy of the GNU General Public License | ||
2207 | 29 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2208 | 30 | |||
2209 | 31 | """ | ||
2210 | 32 | import sys | ||
2211 | 33 | import time | ||
2212 | 34 | import re | ||
2213 | 35 | import configparser | ||
2214 | 36 | import shlex | ||
2215 | 37 | import subprocess | ||
2216 | 38 | import ast | ||
2217 | 39 | from argparse import ( | ||
2218 | 40 | ArgumentParser, | ||
2219 | 41 | RawTextHelpFormatter | ||
2220 | 42 | ) | ||
2221 | 43 | from subprocess import ( | ||
2222 | 44 | check_output, | ||
2223 | 45 | CalledProcessError | ||
2224 | 46 | ) | ||
2225 | 47 | |||
2226 | 48 | def get_sdr_remote(host_ip, user, password): | ||
2227 | 49 | cmd = "dcmitool -H {} -U {} -P {} sdr".format(host_ip, user, password) | ||
2228 | 50 | sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT, | ||
2229 | 51 | universal_newlines=True) | ||
2230 | 52 | return sdr_return | ||
2231 | 53 | |||
2232 | 54 | def parse_sdr(output): | ||
2233 | 55 | output = output.strip() | ||
2234 | 56 | output_1Line = output.split("\n") | ||
2235 | 57 | data = {} | ||
2236 | 58 | |||
2237 | 59 | for line in output_1Line: | ||
2238 | 60 | sub_value = {} | ||
2239 | 61 | string_list = line.split("|") | ||
2240 | 62 | name = string_list[0].strip() | ||
2241 | 63 | sensor_output = string_list[1].strip() | ||
2242 | 64 | sub_value.update({'output':sensor_output}) | ||
2243 | 65 | status = string_list[2].strip() | ||
2244 | 66 | sub_value.update({'status':status}) | ||
2245 | 67 | data.update({name:sub_value}) | ||
2246 | 68 | return data | ||
2247 | 69 | |||
2248 | 70 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
2249 | 71 | |||
2250 | 72 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
2251 | 73 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
2252 | 74 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
2253 | 75 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
2254 | 76 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
2255 | 77 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
2256 | 78 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
2257 | 79 | return str(CPU_temp)+' degrees C' | ||
2258 | 80 | else: | ||
2259 | 81 | return 'Error' | ||
2260 | 82 | else: | ||
2261 | 83 | return 'None' | ||
2262 | 84 | |||
2263 | 85 | def dcmi_sdr(args): | ||
2264 | 86 | |||
2265 | 87 | flag = 0 | ||
2266 | 88 | #DCMI config file | ||
2267 | 89 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
2268 | 90 | if not "config" in vars(args): | ||
2269 | 91 | config_file = DEFAULT_CFG | ||
2270 | 92 | else: | ||
2271 | 93 | config_file = args.config | ||
2272 | 94 | |||
2273 | 95 | config = configparser.RawConfigParser() | ||
2274 | 96 | |||
2275 | 97 | try: | ||
2276 | 98 | config.readfp(open(config_file)) | ||
2277 | 99 | except IOError: | ||
2278 | 100 | print("No config file found") | ||
2279 | 101 | return 10 | ||
2280 | 102 | |||
2281 | 103 | try: | ||
2282 | 104 | sensor_nick = config.options("Sensors") | ||
2283 | 105 | except configparser.NoSectionError: | ||
2284 | 106 | print("No Section: Sensors") | ||
2285 | 107 | return 20 | ||
2286 | 108 | |||
2287 | 109 | if sensor_nick: | ||
2288 | 110 | sensor_list = [] | ||
2289 | 111 | for id in sensor_nick: | ||
2290 | 112 | sensor_key = config.get("Sensors", id) | ||
2291 | 113 | if sensor_key: | ||
2292 | 114 | sensor_list.append(sensor_key) | ||
2293 | 115 | else: | ||
2294 | 116 | print("No Sensor ID specified in Config file") | ||
2295 | 117 | return 30 | ||
2296 | 118 | else: | ||
2297 | 119 | print("No key of Sensor ID specified in config file") | ||
2298 | 120 | return 40 | ||
2299 | 121 | |||
2300 | 122 | try: | ||
2301 | 123 | targets_options = config.options('Targets') | ||
2302 | 124 | targets_list = [] | ||
2303 | 125 | for target_key in targets_options: | ||
2304 | 126 | targets_list.append(config.get('Targets', target_key)) | ||
2305 | 127 | if not targets_list: | ||
2306 | 128 | print("Invalid or Empty targets") | ||
2307 | 129 | return 60 | ||
2308 | 130 | except configparser.Error: | ||
2309 | 131 | print("Invalid or Empty targets") | ||
2310 | 132 | return 60 | ||
2311 | 133 | |||
2312 | 134 | try: | ||
2313 | 135 | user_value = config.get("Account", "USER") | ||
2314 | 136 | password_value = config.get("Account", "PASSWORD") | ||
2315 | 137 | except configparser.NoOptionError: | ||
2316 | 138 | print("Invalid or Empty credential info") | ||
2317 | 139 | return 70 | ||
2318 | 140 | |||
2319 | 141 | for tg in targets_list: | ||
2320 | 142 | |||
2321 | 143 | if not tg or not user_value or not password_value: | ||
2322 | 144 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
2323 | 145 | return 80 | ||
2324 | 146 | else: | ||
2325 | 147 | |||
2326 | 148 | print("SUT =", tg) | ||
2327 | 149 | print("USER =", user_value) | ||
2328 | 150 | print("PASSWORD =", password_value) | ||
2329 | 151 | |||
2330 | 152 | try: | ||
2331 | 153 | sensor_data = get_sdr_remote(tg, user_value, password_value) | ||
2332 | 154 | time.sleep(5) | ||
2333 | 155 | except CalledProcessError as dcmi_exception: | ||
2334 | 156 | print("Failed executing dcmi, Reason: %s" % dcmi_exception) | ||
2335 | 157 | return 50 | ||
2336 | 158 | |||
2337 | 159 | try: | ||
2338 | 160 | data = parse_sdr(sensor_data) | ||
2339 | 161 | except: | ||
2340 | 162 | print("Parsing output of sdr table error") | ||
2341 | 163 | flag = 1 | ||
2342 | 164 | continue | ||
2343 | 165 | |||
2344 | 166 | need_data = {} | ||
2345 | 167 | for need_id in sensor_list: | ||
2346 | 168 | |||
2347 | 169 | if data.get(need_id): | ||
2348 | 170 | need_value = data.get(need_id).get('output') | ||
2349 | 171 | need_data.update({need_id:need_value}) | ||
2350 | 172 | |||
2351 | 173 | if data.get(need_id).get('status') != 'ok': | ||
2352 | 174 | flag = 1 | ||
2353 | 175 | else: | ||
2354 | 176 | |||
2355 | 177 | try: | ||
2356 | 178 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
2357 | 179 | except configparser.NoOptionError: | ||
2358 | 180 | CPUx_Temp = '' | ||
2359 | 181 | |||
2360 | 182 | try: | ||
2361 | 183 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
2362 | 184 | except configparser.NoOptionError: | ||
2363 | 185 | CPUy_Temp = '' | ||
2364 | 186 | |||
2365 | 187 | if need_id == CPUx_Temp: | ||
2366 | 188 | |||
2367 | 189 | try: | ||
2368 | 190 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
2369 | 191 | except configparser.NoOptionError: | ||
2370 | 192 | PxTM = '' | ||
2371 | 193 | |||
2372 | 194 | try: | ||
2373 | 195 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
2374 | 196 | except configparser.NoOptionError: | ||
2375 | 197 | CPUx_Tjmax = '' | ||
2376 | 198 | |||
2377 | 199 | if PxTM and CPUx_Tjmax: | ||
2378 | 200 | need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)}) | ||
2379 | 201 | if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error': | ||
2380 | 202 | flag = 1 | ||
2381 | 203 | else: | ||
2382 | 204 | flag = 1 | ||
2383 | 205 | |||
2384 | 206 | elif need_id == CPUy_Temp: | ||
2385 | 207 | |||
2386 | 208 | try: | ||
2387 | 209 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
2388 | 210 | except configparser.NoOptionError: | ||
2389 | 211 | PyTM = '' | ||
2390 | 212 | |||
2391 | 213 | try: | ||
2392 | 214 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
2393 | 215 | except configparser.NoOptionError: | ||
2394 | 216 | CPUy_Tjmax = '' | ||
2395 | 217 | |||
2396 | 218 | if PyTM and CPUy_Tjmax: | ||
2397 | 219 | need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)}) | ||
2398 | 220 | if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error': | ||
2399 | 221 | flag = 1 | ||
2400 | 222 | else: | ||
2401 | 223 | flag = 1 | ||
2402 | 224 | else: | ||
2403 | 225 | #need_data.update({need_id:'None'}) | ||
2404 | 226 | flag = 1 | ||
2405 | 227 | |||
2406 | 228 | print("%s: %s" %(need_id, need_data.get(need_id))) | ||
2407 | 229 | |||
2408 | 230 | if flag == 1: | ||
2409 | 231 | return 100 | ||
2410 | 232 | return 0 | ||
2411 | 233 | |||
2412 | 234 | def main(): | ||
2413 | 235 | |||
2414 | 236 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
2415 | 237 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
2416 | 238 | parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters") | ||
2417 | 239 | args = parser.parse_args() | ||
2418 | 240 | return dcmi_sdr(args) | ||
2419 | 241 | |||
2420 | 242 | if __name__ == "__main__": | ||
2421 | 243 | sys.exit(main()) | ||
2422 | 0 | 244 | ||
2423 | === added file 'bin/disk_health' | |||
2424 | --- bin/disk_health 1970-01-01 00:00:00 +0000 | |||
2425 | +++ bin/disk_health 2015-08-14 22:03:31 +0000 | |||
2426 | @@ -0,0 +1,138 @@ | |||
2427 | 1 | #!/usr/bin/env python3 | ||
2428 | 2 | |||
2429 | 3 | """ | ||
2430 | 4 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
2431 | 5 | Industrial Technology Research Institute | ||
2432 | 6 | |||
2433 | 7 | It is NOT YET officially approved by OCP. | ||
2434 | 8 | |||
2435 | 9 | disk_health | ||
2436 | 10 | 1. Use smartmontools to monitor disk health. | ||
2437 | 11 | 2. SMART threshold, grown defect list (glist or reallocated sectors) | ||
2438 | 12 | <= 100 for 4TB, glist <=50 for 2TB for all vendors. | ||
2439 | 13 | 3. SMART HDD temp <= 60 degrees centigrade. | ||
2440 | 14 | 4. Criteria: all threshold must not exceed the criteria listed in item 2 | ||
2441 | 15 | and 3. | ||
2442 | 16 | |||
2443 | 17 | Authors | ||
2444 | 18 | Nelson Chu <Nelson.Chu@itri.org.tw> | ||
2445 | 19 | |||
2446 | 20 | This program is free software: you can redistribute it and/or modify | ||
2447 | 21 | it under the terms of the GNU General Public License version 3, | ||
2448 | 22 | as published by the Free Software Foundation. | ||
2449 | 23 | |||
2450 | 24 | This program is distributed in the hope that it will be useful, | ||
2451 | 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2452 | 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2453 | 27 | GNU General Public License for more details. | ||
2454 | 28 | |||
2455 | 29 | You should have received a copy of the GNU General Public License | ||
2456 | 30 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2457 | 31 | |||
2458 | 32 | """ | ||
2459 | 33 | |||
2460 | 34 | import os | ||
2461 | 35 | import re | ||
2462 | 36 | import sys | ||
2463 | 37 | from subprocess import check_output | ||
2464 | 38 | from argparse import ArgumentParser, RawTextHelpFormatter | ||
2465 | 39 | |||
2466 | 40 | def run(device): | ||
2467 | 41 | return_code = 0 | ||
2468 | 42 | command = "smartctl -a {0}".format(device) | ||
2469 | 43 | |||
2470 | 44 | try: | ||
2471 | 45 | with open(os.devnull, "w") as NULL: | ||
2472 | 46 | smartctl_info = check_output(command, stderr=NULL, shell=True) | ||
2473 | 47 | except Exception as e: | ||
2474 | 48 | print(e.output.decode('utf-8')) | ||
2475 | 49 | return_code = 10 | ||
2476 | 50 | return return_code | ||
2477 | 51 | |||
2478 | 52 | smartctl_info = smartctl_info.decode('utf-8') | ||
2479 | 53 | |||
2480 | 54 | # Verify disk capacity match the criteria or not. | ||
2481 | 55 | capacity_match =re.search(r'User Capacity.*\[(2|4).*TB\]', smartctl_info) | ||
2482 | 56 | if not capacity_match: | ||
2483 | 57 | print("Disk capacity is not match 2TB or 4TB.") | ||
2484 | 58 | return_code = 20 | ||
2485 | 59 | return return_code | ||
2486 | 60 | |||
2487 | 61 | disk_capacity = int(capacity_match.group(1)) | ||
2488 | 62 | print("Disk capacity: %dTB" %(disk_capacity)) | ||
2489 | 63 | |||
2490 | 64 | # Verify disk temperature match the criteria or not. | ||
2491 | 65 | temperature_match = re.search(r'Temperature_Celsius.*\s(\d+)(\s\(|\n)', | ||
2492 | 66 | smartctl_info) | ||
2493 | 67 | if not temperature_match: | ||
2494 | 68 | temperature_match = re.search(r'Current Drive Temperature\D*(\d+)', | ||
2495 | 69 | smartctl_info) | ||
2496 | 70 | if not temperature_match: | ||
2497 | 71 | print("Cannot retrieve disk temperature.") | ||
2498 | 72 | return_code = 30 | ||
2499 | 73 | return return_code | ||
2500 | 74 | |||
2501 | 75 | disk_temperature = int(temperature_match.group(1)) | ||
2502 | 76 | print("Disk current temperature: %d degrees centigrade" | ||
2503 | 77 | %disk_temperature) | ||
2504 | 78 | if disk_temperature > 60: | ||
2505 | 79 | return_code = 40 | ||
2506 | 80 | |||
2507 | 81 | # Verify reallocated sectors match the criteria or not. | ||
2508 | 82 | reallocated_sector_match = re.search(r'Reallocated_Sector_Ct.*\s(\d+)\n', | ||
2509 | 83 | smartctl_info) | ||
2510 | 84 | if reallocated_sector_match: | ||
2511 | 85 | reallocated_sector = int(reallocated_sector_match.group(1)) | ||
2512 | 86 | print("Reallocated_Sector_Ct: %d" %reallocated_sector) | ||
2513 | 87 | if disk_capacity == 2 and reallocated_sector > 50: | ||
2514 | 88 | return_code = 50 | ||
2515 | 89 | if disk_capacity == 4 and reallocated_sector > 100: | ||
2516 | 90 | return_code = 60 | ||
2517 | 91 | |||
2518 | 92 | # Verify grown defect list match the criteria or not. | ||
2519 | 93 | grown_defect_match = re.search(r'Elements in grown defect list\:\s(\d+)\n', | ||
2520 | 94 | smartctl_info) | ||
2521 | 95 | if grown_defect_match: | ||
2522 | 96 | grown_defect_list = int(grown_defect_match.group(1)) | ||
2523 | 97 | print("Elements in grown defect list: %d" %grown_defect_list) | ||
2524 | 98 | if disk_capacity == 2 and grown_defect_list > 50: | ||
2525 | 99 | return_code = 70 | ||
2526 | 100 | if disk_capacity == 4 and grown_defect_list > 100: | ||
2527 | 101 | return_code = 80 | ||
2528 | 102 | |||
2529 | 103 | # Check current pending sectort. | ||
2530 | 104 | current_pending_match = re.search(r'Current_Pending_Sector.*\s(\d+)\n', | ||
2531 | 105 | smartctl_info) | ||
2532 | 106 | if current_pending_match: | ||
2533 | 107 | current_pending_sector = int(current_pending_match.group(1)) | ||
2534 | 108 | print("Current_Pending_Sector: %d" %current_pending_sector) | ||
2535 | 109 | if current_pending_sector != 0: | ||
2536 | 110 | return_code = 90 | ||
2537 | 111 | |||
2538 | 112 | # Check error counter log. | ||
2539 | 113 | total_uncorrected_errors = re.search( | ||
2540 | 114 | r'\nread.*\s(\d+)\nwrite.*\s(\d+)\nverify.*\s(\d+)', smartctl_info) | ||
2541 | 115 | if total_uncorrected_errors: | ||
2542 | 116 | read = int(total_uncorrected_errors.group(1)) | ||
2543 | 117 | write = int(total_uncorrected_errors.group(2)) | ||
2544 | 118 | verify = int(total_uncorrected_errors.group(3)) | ||
2545 | 119 | print("Total uncorrected errors: read=%d write=%d verify=%d" | ||
2546 | 120 | %(read, write, verify)) | ||
2547 | 121 | if read != 0 or write != 0 or verify != 0: | ||
2548 | 122 | return_code = 100 | ||
2549 | 123 | return return_code | ||
2550 | 124 | |||
2551 | 125 | def main(): | ||
2552 | 126 | parser = ArgumentParser(formatter_class=RawTextHelpFormatter) | ||
2553 | 127 | parser.add_argument('-d', '--device', type=str, required=True, | ||
2554 | 128 | help=("The device that wants to monitor health.")) | ||
2555 | 129 | args = parser.parse_args() | ||
2556 | 130 | |||
2557 | 131 | device = args.device | ||
2558 | 132 | if not device.startswith('/dev/'): | ||
2559 | 133 | device = '/dev/' + device | ||
2560 | 134 | |||
2561 | 135 | return run(device) | ||
2562 | 136 | |||
2563 | 137 | if __name__ == '__main__': | ||
2564 | 138 | sys.exit(main()) | ||
2565 | 0 | 139 | ||
2566 | === modified file 'bin/disk_info' | |||
2567 | --- bin/disk_info 2015-03-03 15:59:42 +0000 | |||
2568 | +++ bin/disk_info 2015-08-14 22:03:31 +0000 | |||
2569 | @@ -3,6 +3,8 @@ | |||
2570 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications |
2571 | 4 | Industrial Technology Research Institute | 4 | Industrial Technology Research Institute |
2572 | 5 | 5 | ||
2573 | 6 | It is NOT YET officially approved by OCP. | ||
2574 | 7 | |||
2575 | 6 | disk_info | 8 | disk_info |
2576 | 7 | 1. Use lshw command to gather disk information. | 9 | 1. Use lshw command to gather disk information. |
2577 | 8 | 2. The program will output disk type, vendor, product, capacity. | 10 | 2. The program will output disk type, vendor, product, capacity. |
2578 | 9 | 11 | ||
2579 | === added file 'bin/disk_info_leopard' | |||
2580 | --- bin/disk_info_leopard 1970-01-01 00:00:00 +0000 | |||
2581 | +++ bin/disk_info_leopard 2015-08-14 22:03:31 +0000 | |||
2582 | @@ -0,0 +1,67 @@ | |||
2583 | 1 | #!/usr/bin/env python3 | ||
2584 | 2 | """ | ||
2585 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
2586 | 4 | Industrial Technology Research Institute | ||
2587 | 5 | |||
2588 | 6 | It is NOT YET officially approved by OCP. | ||
2589 | 7 | |||
2590 | 8 | disk_info | ||
2591 | 9 | 1. Use lshw command to gather disk information. | ||
2592 | 10 | 2. The program will output disk type, vendor, product, capacity. | ||
2593 | 11 | 3. Criteria: must be able to retrieve disk information. | ||
2594 | 12 | |||
2595 | 13 | Authors | ||
2596 | 14 | Nelson Chu <Nelson.Chu@itri.org.tw> | ||
2597 | 15 | |||
2598 | 16 | This program is free software: you can redistribute it and/or modify | ||
2599 | 17 | it under the terms of the GNU General Public License version 3, | ||
2600 | 18 | as published by the Free Software Foundation. | ||
2601 | 19 | |||
2602 | 20 | This program is distributed in the hope that it will be useful, | ||
2603 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2604 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2605 | 23 | GNU General Public License for more details. | ||
2606 | 24 | |||
2607 | 25 | You should have received a copy of the GNU General Public License | ||
2608 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2609 | 27 | |||
2610 | 28 | """ | ||
2611 | 29 | |||
2612 | 30 | import sys | ||
2613 | 31 | import xml.etree.ElementTree as ET | ||
2614 | 32 | from subprocess import Popen, PIPE | ||
2615 | 33 | |||
2616 | 34 | def main(): | ||
2617 | 35 | attribute = ['description', 'product', 'size'] | ||
2618 | 36 | command = 'lshw -xml' | ||
2619 | 37 | hwinfo_xml = Popen(command, stdout=PIPE, stderr=PIPE, | ||
2620 | 38 | shell=True).communicate()[0] | ||
2621 | 39 | root = ET.fromstring(hwinfo_xml) | ||
2622 | 40 | |||
2623 | 41 | # Parse lshw XML for gathering disk information. | ||
2624 | 42 | disk_list = root.findall(".//node[@class='disk']") | ||
2625 | 43 | |||
2626 | 44 | if not disk_list: | ||
2627 | 45 | print("Cannot parse any disk information.", file=sys.stderr) | ||
2628 | 46 | return 10 | ||
2629 | 47 | |||
2630 | 48 | for disk in disk_list: | ||
2631 | 49 | for attr in attribute: | ||
2632 | 50 | if disk.find(attr) is None: | ||
2633 | 51 | print(("Cannot found disk %s") %attr, file=sys.stderr) | ||
2634 | 52 | return 20 | ||
2635 | 53 | |||
2636 | 54 | disk_size = int(disk.find('size').text) / (1000**3) | ||
2637 | 55 | for attr in attribute: | ||
2638 | 56 | if attr == 'description': | ||
2639 | 57 | print(("Type=\"%s\"") %disk.find(attr).text) | ||
2640 | 58 | continue | ||
2641 | 59 | elif attr == 'size': | ||
2642 | 60 | print(("%s=\"%dGB\"") %(attr.capitalize(), disk_size)) | ||
2643 | 61 | continue | ||
2644 | 62 | else: | ||
2645 | 63 | print(("%s=\"%s\"") %(attr.capitalize(), disk.find(attr).text)) | ||
2646 | 64 | return 0 | ||
2647 | 65 | |||
2648 | 66 | if __name__ == '__main__': | ||
2649 | 67 | sys.exit(main()) | ||
2650 | 0 | 68 | ||
2651 | === added file 'bin/ipmi_fru' | |||
2652 | --- bin/ipmi_fru 1970-01-01 00:00:00 +0000 | |||
2653 | +++ bin/ipmi_fru 2015-08-14 22:03:31 +0000 | |||
2654 | @@ -0,0 +1,163 @@ | |||
2655 | 1 | #!/usr/bin/env python3 | ||
2656 | 2 | """ | ||
2657 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
2658 | 4 | Industrial Technology Research Institute | ||
2659 | 5 | |||
2660 | 6 | File Name | ||
2661 | 7 | ipmi_fru | ||
2662 | 8 | |||
2663 | 9 | Description | ||
2664 | 10 | 1. Use ipmitool to retrieve FRU data. | ||
2665 | 11 | 2. The data contains product manufacture, product part number, product serial number, motherboard serial number. | ||
2666 | 12 | 3. Criteria: Above All data mentioned above must notshould not be null | ||
2667 | 13 | |||
2668 | 14 | Authors | ||
2669 | 15 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
2670 | 16 | |||
2671 | 17 | This program is free software: you can redistribute it and/or modify | ||
2672 | 18 | it under the terms of the GNU General Public License version 3, | ||
2673 | 19 | as published by the Free Software Foundation. | ||
2674 | 20 | |||
2675 | 21 | This program is distributed in the hope that it will be useful, | ||
2676 | 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2677 | 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2678 | 24 | GNU General Public License for more details. | ||
2679 | 25 | |||
2680 | 26 | You should have received a copy of the GNU General Public License | ||
2681 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2682 | 28 | |||
2683 | 29 | """ | ||
2684 | 30 | |||
2685 | 31 | from argparse import ( | ||
2686 | 32 | ArgumentParser, | ||
2687 | 33 | RawTextHelpFormatter | ||
2688 | 34 | ) | ||
2689 | 35 | |||
2690 | 36 | import sys | ||
2691 | 37 | import shlex | ||
2692 | 38 | import time | ||
2693 | 39 | import subprocess | ||
2694 | 40 | from subprocess import ( | ||
2695 | 41 | check_output, | ||
2696 | 42 | CalledProcessError | ||
2697 | 43 | ) | ||
2698 | 44 | import re | ||
2699 | 45 | import configparser | ||
2700 | 46 | |||
2701 | 47 | def get_system_manufacturer(output): | ||
2702 | 48 | system_manufacture = re.search(r'Product Manufacturer\s*:\s*([a-zA-Z0-9-._ ]+\n)', output) | ||
2703 | 49 | if system_manufacture == None: | ||
2704 | 50 | return 'Error' | ||
2705 | 51 | else: | ||
2706 | 52 | return system_manufacture.group(1).strip() | ||
2707 | 53 | |||
2708 | 54 | def get_system_part_number(output): | ||
2709 | 55 | system_part_number = re.search(r'Product Part Number\s*:\s*([a-zA-Z0-9-._ ]+\n)', output) | ||
2710 | 56 | if system_part_number == None: | ||
2711 | 57 | return 'Error' | ||
2712 | 58 | else: | ||
2713 | 59 | return system_part_number.group(1).strip() | ||
2714 | 60 | |||
2715 | 61 | def get_system_serial_number(output): | ||
2716 | 62 | system_serial_number = re.search(r'Product Serial\s*:\s*([a-zA-Z0-9-._ ]+\n)', output) | ||
2717 | 63 | if system_serial_number == None: | ||
2718 | 64 | return 'Error' | ||
2719 | 65 | else: | ||
2720 | 66 | return system_serial_number.group(1).strip() | ||
2721 | 67 | |||
2722 | 68 | def get_board_serial_number(output): | ||
2723 | 69 | board_serial_number = re.search(r'Board Serial\s*:\s*([a-zA-Z0-9-._ ]+\n)', output) | ||
2724 | 70 | if board_serial_number == None: | ||
2725 | 71 | return 'Error' | ||
2726 | 72 | else: | ||
2727 | 73 | return board_serial_number.group(1).strip() | ||
2728 | 74 | |||
2729 | 75 | def get_fru_info(host_ip, user, password): | ||
2730 | 76 | fru_cmd = 'ipmitool -H {} -U {} -P {} fru'.format(host_ip, user, password) | ||
2731 | 77 | fru_return = check_output(shlex.split(fru_cmd), universal_newlines=True) | ||
2732 | 78 | return fru_return | ||
2733 | 79 | |||
2734 | 80 | def ipmi_fru(args): | ||
2735 | 81 | #IPMI config file | ||
2736 | 82 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
2737 | 83 | |||
2738 | 84 | if not "config" in vars(args): | ||
2739 | 85 | config_file = DEFAULT_CFG | ||
2740 | 86 | else: | ||
2741 | 87 | config_file = args.config | ||
2742 | 88 | |||
2743 | 89 | config = configparser.RawConfigParser() | ||
2744 | 90 | |||
2745 | 91 | try: | ||
2746 | 92 | config.readfp(open(config_file)) | ||
2747 | 93 | except IOError: | ||
2748 | 94 | print("No config file found") | ||
2749 | 95 | return 10 | ||
2750 | 96 | |||
2751 | 97 | try: | ||
2752 | 98 | targets_options = config.options('Targets') | ||
2753 | 99 | targets_list = [] | ||
2754 | 100 | for target_key in targets_options: | ||
2755 | 101 | targets_list.append(config.get('Targets', target_key)) | ||
2756 | 102 | |||
2757 | 103 | if not targets_list: | ||
2758 | 104 | print("Invalid or Empty targets") | ||
2759 | 105 | return 20 | ||
2760 | 106 | |||
2761 | 107 | except configparser.Error: | ||
2762 | 108 | print("Invalid or Empty targets") | ||
2763 | 109 | return 30 | ||
2764 | 110 | |||
2765 | 111 | try: | ||
2766 | 112 | user_value = config.get('Account', 'USER') | ||
2767 | 113 | passwd_value = config.get('Account', 'PASSWORD') | ||
2768 | 114 | if not user_value or not passwd_value: | ||
2769 | 115 | print("Invalid or Empty credential info") | ||
2770 | 116 | return 40 | ||
2771 | 117 | |||
2772 | 118 | except configparser.Error: | ||
2773 | 119 | print("Invalid or Empty credential info") | ||
2774 | 120 | return 50 | ||
2775 | 121 | |||
2776 | 122 | inevntory_fru = {} | ||
2777 | 123 | flag = 0 | ||
2778 | 124 | for tg in targets_list: | ||
2779 | 125 | |||
2780 | 126 | if not tg or not user_value or not passwd_value: | ||
2781 | 127 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
2782 | 128 | return 60 | ||
2783 | 129 | else: | ||
2784 | 130 | print("SUT =", tg) | ||
2785 | 131 | try: | ||
2786 | 132 | fru_data = get_fru_info(tg, user_value, passwd_value) | ||
2787 | 133 | time.sleep(5) | ||
2788 | 134 | except CalledProcessError as ipmi_exception: | ||
2789 | 135 | print("Failed executing ipmi, Reason: %s" % ipmi_exception) | ||
2790 | 136 | return 70 | ||
2791 | 137 | |||
2792 | 138 | inevntory_fru.update({'Product Manufacturer':get_system_manufacturer(fru_data)}) | ||
2793 | 139 | inevntory_fru.update({'Product Part Number':get_system_part_number(fru_data)}) | ||
2794 | 140 | inevntory_fru.update({'Product Serial':get_system_serial_number(fru_data)}) | ||
2795 | 141 | inevntory_fru.update({'Board Serial':get_board_serial_number(fru_data)}) | ||
2796 | 142 | |||
2797 | 143 | inevntory_fru_list = ['Product Manufacturer', 'Product Part Number', 'Product Serial', 'Board Serial'] | ||
2798 | 144 | for item in inevntory_fru_list: | ||
2799 | 145 | print("{}: {}".format(item, inevntory_fru.get(item))) | ||
2800 | 146 | if inevntory_fru.get(item) == 'Error' or inevntory_fru.get(item) == '': | ||
2801 | 147 | flag = 1 | ||
2802 | 148 | if flag == 1: | ||
2803 | 149 | return 100 | ||
2804 | 150 | return 0 | ||
2805 | 151 | |||
2806 | 152 | def main(): | ||
2807 | 153 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
2808 | 154 | parser = ArgumentParser(description=intro_message, | ||
2809 | 155 | formatter_class=RawTextHelpFormatter) | ||
2810 | 156 | parser.add_argument('--config', type=str, | ||
2811 | 157 | default="/etc/checkbox.d/bmc.cfg", | ||
2812 | 158 | help="Supply config file for getting authentication info") | ||
2813 | 159 | args = parser.parse_args() | ||
2814 | 160 | return ipmi_fru(args) | ||
2815 | 161 | |||
2816 | 162 | if __name__ == '__main__': | ||
2817 | 163 | sys.exit(main()) | ||
2818 | 0 | 164 | ||
2819 | === added file 'bin/ipmi_inventory' | |||
2820 | --- bin/ipmi_inventory 1970-01-01 00:00:00 +0000 | |||
2821 | +++ bin/ipmi_inventory 2015-08-14 22:03:31 +0000 | |||
2822 | @@ -0,0 +1,214 @@ | |||
2823 | 1 | #!/usr/bin/env python3 | ||
2824 | 2 | """ | ||
2825 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
2826 | 4 | Industrial Technology Research Institute | ||
2827 | 5 | |||
2828 | 6 | File Name | ||
2829 | 7 | ipmi_inventory | ||
2830 | 8 | 1. Use ipmitool to collect inventory information including Asset Tag, Device ID, System GUID, Firmware Revision, IPMI Version, Management Controller ID. | ||
2831 | 9 | 2. Criteria: All information mentioned above must not should not be null. | ||
2832 | 10 | Authors | ||
2833 | 11 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
2834 | 12 | |||
2835 | 13 | This program is free software: you can redistribute it and/or modify | ||
2836 | 14 | it under the terms of the GNU General Public License version 3, | ||
2837 | 15 | as published by the Free Software Foundation. | ||
2838 | 16 | |||
2839 | 17 | This program is distributed in the hope that it will be useful, | ||
2840 | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2841 | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2842 | 20 | GNU General Public License for more details. | ||
2843 | 21 | |||
2844 | 22 | You should have received a copy of the GNU General Public License | ||
2845 | 23 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2846 | 24 | |||
2847 | 25 | """ | ||
2848 | 26 | |||
2849 | 27 | from argparse import ( | ||
2850 | 28 | ArgumentParser, | ||
2851 | 29 | RawTextHelpFormatter | ||
2852 | 30 | ) | ||
2853 | 31 | |||
2854 | 32 | import sys | ||
2855 | 33 | import shlex | ||
2856 | 34 | import time | ||
2857 | 35 | import subprocess | ||
2858 | 36 | from subprocess import ( | ||
2859 | 37 | check_output, | ||
2860 | 38 | CalledProcessError | ||
2861 | 39 | ) | ||
2862 | 40 | import re | ||
2863 | 41 | import configparser | ||
2864 | 42 | |||
2865 | 43 | |||
2866 | 44 | def get_mcinfo(host_ip, user, password): | ||
2867 | 45 | |||
2868 | 46 | try: | ||
2869 | 47 | cmd = 'ipmitool -H {} -U {} -P {} mc info'.format(host_ip, user, password) | ||
2870 | 48 | mcinfo_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
2871 | 49 | time.sleep(5) | ||
2872 | 50 | except CalledProcessError as command_exception: | ||
2873 | 51 | print("Failed executing ipmi command for getting mc info. Reason:%s" % command_exception) | ||
2874 | 52 | |||
2875 | 53 | try: | ||
2876 | 54 | |||
2877 | 55 | deviceid = re.search(r'Device ID\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return) | ||
2878 | 56 | if deviceid == None: | ||
2879 | 57 | deviceid = 'Error' | ||
2880 | 58 | else: | ||
2881 | 59 | deviceid = deviceid.group(1).strip() | ||
2882 | 60 | |||
2883 | 61 | Firm = re.search(r'Firmware Revision\s+\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return) | ||
2884 | 62 | if Firm == None: | ||
2885 | 63 | Firm = 'Error' | ||
2886 | 64 | else: | ||
2887 | 65 | Firm = Firm.group(1).strip() | ||
2888 | 66 | |||
2889 | 67 | IPMI_Ver = re.search(r'IPMI Version\s+\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return) | ||
2890 | 68 | if IPMI_Ver == None: | ||
2891 | 69 | IPMI_Ver = 'Error' | ||
2892 | 70 | else: | ||
2893 | 71 | IPMI_Ver = IPMI_Ver.group(1).strip() | ||
2894 | 72 | |||
2895 | 73 | return deviceid, Firm, IPMI_Ver | ||
2896 | 74 | |||
2897 | 75 | except: | ||
2898 | 76 | |||
2899 | 77 | return 'Error', 'Error', 'Error' | ||
2900 | 78 | |||
2901 | 79 | def get_asset_tag(host_ip, user, password): | ||
2902 | 80 | |||
2903 | 81 | try: | ||
2904 | 82 | cmd = 'ipmitool -H {} -U {} -P {} fru'.format(host_ip, user, password) | ||
2905 | 83 | asset_tag_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
2906 | 84 | time.sleep(5) | ||
2907 | 85 | except CalledProcessError as command_exception: | ||
2908 | 86 | print("Failed executing ipmi command for getting asset tag. Reason:%s" % command_exception) | ||
2909 | 87 | |||
2910 | 88 | try: | ||
2911 | 89 | asset_tag = re.search(r'Product Asset Tag\s*:\s*([a-zA-Z0-9-._ ]+)', asset_tag_return) | ||
2912 | 90 | if asset_tag == None: | ||
2913 | 91 | return 'Error' | ||
2914 | 92 | return asset_tag.group(1).strip() | ||
2915 | 93 | except: | ||
2916 | 94 | return 'Error' | ||
2917 | 95 | |||
2918 | 96 | def get_guid(host_ip, user, password): | ||
2919 | 97 | |||
2920 | 98 | try: | ||
2921 | 99 | cmd = 'ipmitool -H {} -U {} -P {} mc guid'.format(host_ip, user, password) | ||
2922 | 100 | guid_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
2923 | 101 | time.sleep(5) | ||
2924 | 102 | except CalledProcessError as command_exception: | ||
2925 | 103 | print("Failed executing ipmi command for getting guid. Reason:%s" % command_exception) | ||
2926 | 104 | |||
2927 | 105 | try: | ||
2928 | 106 | mcguid = re.search(r'System GUID\s*:\s*([a-zA-Z0-9-._ ]+)', guid_return) | ||
2929 | 107 | if mcguid == None: | ||
2930 | 108 | return 'Error' | ||
2931 | 109 | return mcguid.group(1).strip() | ||
2932 | 110 | except: | ||
2933 | 111 | return 'Error' | ||
2934 | 112 | |||
2935 | 113 | def get_mcid(host_ip, user, password): | ||
2936 | 114 | |||
2937 | 115 | try: | ||
2938 | 116 | cmd = 'ipmitool -H {} -U {} -P {} dcmi get_mc_id_string'.format(host_ip, user, password) | ||
2939 | 117 | mcid_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
2940 | 118 | time.sleep(5) | ||
2941 | 119 | except CalledProcessError as command_exception: | ||
2942 | 120 | print("Failed executing ipmi command for getting mc id. Reason:%s" % command_exception) | ||
2943 | 121 | |||
2944 | 122 | try: | ||
2945 | 123 | mcid = re.search(r'Get Management Controller Identifier String\s*:\s*([a-zA-Z0-9-._ ]+)', mcid_return) | ||
2946 | 124 | if mcid == None: | ||
2947 | 125 | return 'Error' | ||
2948 | 126 | return mcid.group(1).strip() | ||
2949 | 127 | except: | ||
2950 | 128 | return 'Error' | ||
2951 | 129 | |||
2952 | 130 | def inventory(args): | ||
2953 | 131 | |||
2954 | 132 | #IPMI config file | ||
2955 | 133 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
2956 | 134 | |||
2957 | 135 | if not "config" in vars(args): | ||
2958 | 136 | config_file = DEFAULT_CFG | ||
2959 | 137 | else: | ||
2960 | 138 | config_file = args.config | ||
2961 | 139 | |||
2962 | 140 | config = configparser.RawConfigParser() | ||
2963 | 141 | |||
2964 | 142 | try: | ||
2965 | 143 | config.readfp(open(config_file)) | ||
2966 | 144 | except IOError: | ||
2967 | 145 | print("No config file found") | ||
2968 | 146 | return 10 | ||
2969 | 147 | |||
2970 | 148 | try: | ||
2971 | 149 | targets_options = config.options('Targets') | ||
2972 | 150 | targets_list = [] | ||
2973 | 151 | for target_key in targets_options: | ||
2974 | 152 | targets_list.append(config.get('Targets', target_key)) | ||
2975 | 153 | |||
2976 | 154 | if not targets_list: | ||
2977 | 155 | print("Invalid or Empty targets") | ||
2978 | 156 | return 20 | ||
2979 | 157 | except configparser.Error: | ||
2980 | 158 | print("Invalid or Empty targets") | ||
2981 | 159 | return 30 | ||
2982 | 160 | |||
2983 | 161 | try: | ||
2984 | 162 | user_value = config.get('Account', 'USER') | ||
2985 | 163 | passwd_value = config.get('Account', 'PASSWORD') | ||
2986 | 164 | if not user_value or not passwd_value: | ||
2987 | 165 | print("Invalid or Empty credential info") | ||
2988 | 166 | return 40 | ||
2989 | 167 | |||
2990 | 168 | except configparser.Error: | ||
2991 | 169 | print("Invalid or Empty credential info") | ||
2992 | 170 | return 50 | ||
2993 | 171 | |||
2994 | 172 | |||
2995 | 173 | flag = 0 | ||
2996 | 174 | for tg in targets_list: | ||
2997 | 175 | |||
2998 | 176 | if not tg or not user_value or not passwd_value: | ||
2999 | 177 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3000 | 178 | return 60 | ||
3001 | 179 | else: | ||
3002 | 180 | print("SUT =", tg) | ||
3003 | 181 | inventory_dict = {} | ||
3004 | 182 | inventory_list = ['Asset Tag', 'System GUID', 'Get Management Controller Identifier String', 'Device ID', 'Firmware Revision', 'IPMI Version'] | ||
3005 | 183 | Device_ID, Firmware, IPMI_version = get_mcinfo(tg, user_value, passwd_value) | ||
3006 | 184 | inventory_dict.update({'Asset Tag':get_asset_tag(tg, user_value, passwd_value)}) | ||
3007 | 185 | inventory_dict.update({'System GUID':get_guid(tg, user_value, passwd_value)}) | ||
3008 | 186 | inventory_dict.update({'Get Management Controller Identifier String':get_mcid(tg, user_value, passwd_value)}) | ||
3009 | 187 | inventory_dict.update({'Device ID':Device_ID}) | ||
3010 | 188 | #inventory_dict.update({'Manufacturer Name':Manufacturer}) | ||
3011 | 189 | inventory_dict.update({'Firmware Revision':Firmware}) | ||
3012 | 190 | inventory_dict.update({'IPMI Version':IPMI_version}) | ||
3013 | 191 | |||
3014 | 192 | for item in inventory_list: | ||
3015 | 193 | if inventory_dict.get(item) == 'Error' or inventory_dict.get(item) == None: | ||
3016 | 194 | flag = 1 | ||
3017 | 195 | |||
3018 | 196 | print("{}: {}".format(item, inventory_dict.get(item))) | ||
3019 | 197 | |||
3020 | 198 | if flag == 1: | ||
3021 | 199 | return 1 | ||
3022 | 200 | return 0 | ||
3023 | 201 | |||
3024 | 202 | def main(): | ||
3025 | 203 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
3026 | 204 | parser = ArgumentParser(description=intro_message, | ||
3027 | 205 | formatter_class=RawTextHelpFormatter) | ||
3028 | 206 | parser.add_argument('--config', type=str, | ||
3029 | 207 | default="/etc/checkbox.d/bmc.cfg", | ||
3030 | 208 | help="Supply config file for getting authentication info") | ||
3031 | 209 | args = parser.parse_args() | ||
3032 | 210 | |||
3033 | 211 | return inventory(args) | ||
3034 | 212 | |||
3035 | 213 | if __name__ == '__main__': | ||
3036 | 214 | sys.exit(main()) | ||
3037 | 0 | 215 | ||
3038 | === added file 'bin/ipmi_power_draw' | |||
3039 | --- bin/ipmi_power_draw 1970-01-01 00:00:00 +0000 | |||
3040 | +++ bin/ipmi_power_draw 2015-08-14 22:03:31 +0000 | |||
3041 | @@ -0,0 +1,126 @@ | |||
3042 | 1 | #!/usr/bin/env python3 | ||
3043 | 2 | """ | ||
3044 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3045 | 4 | Industrial Technology Research Institute | ||
3046 | 5 | |||
3047 | 6 | File Name | ||
3048 | 7 | ipmi_power_draw | ||
3049 | 8 | 1. GatherRetrieving power draw datainfo via ipmitool | ||
3050 | 9 | 2. The datainfo contains "Minimum during sampling period", "Maximum during sampling period", "Average power reading over sample period", "IPMI timestamp", "Sampling period", "Power reading state". | ||
3051 | 10 | 3. Criteria: The return value of each item cannot be null | ||
3052 | 11 | |||
3053 | 12 | Authors | ||
3054 | 13 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3055 | 14 | |||
3056 | 15 | This program is free software: you can redistribute it and/or modify | ||
3057 | 16 | it under the terms of the GNU General Public License version 3, | ||
3058 | 17 | as published by the Free Software Foundation. | ||
3059 | 18 | |||
3060 | 19 | This program is distributed in the hope that it will be useful, | ||
3061 | 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3062 | 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3063 | 22 | GNU General Public License for more details. | ||
3064 | 23 | |||
3065 | 24 | You should have received a copy of the GNU General Public License | ||
3066 | 25 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3067 | 26 | |||
3068 | 27 | """ | ||
3069 | 28 | from argparse import ( | ||
3070 | 29 | ArgumentParser, | ||
3071 | 30 | RawTextHelpFormatter | ||
3072 | 31 | ) | ||
3073 | 32 | import sys | ||
3074 | 33 | import shlex | ||
3075 | 34 | import re | ||
3076 | 35 | import time | ||
3077 | 36 | import configparser | ||
3078 | 37 | import subprocess | ||
3079 | 38 | from subprocess import ( | ||
3080 | 39 | CalledProcessError, | ||
3081 | 40 | check_call, | ||
3082 | 41 | check_output | ||
3083 | 42 | ) | ||
3084 | 43 | |||
3085 | 44 | def get_power_draw(host_ip, user, password): | ||
3086 | 45 | cmd = 'ipmitool -H {} -U {} -P {} dcmi power reading'.format(host_ip, user, password) | ||
3087 | 46 | output = check_output(shlex.split(cmd), universal_newlines=True) | ||
3088 | 47 | return output | ||
3089 | 48 | |||
3090 | 49 | def power_draw_test(args): | ||
3091 | 50 | |||
3092 | 51 | #Default config file to config requirement info for DCMI in-band/out-of-band access | ||
3093 | 52 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | ||
3094 | 53 | if not "config" in vars(args): | ||
3095 | 54 | config_file = DEFAULT_CFG | ||
3096 | 55 | else: | ||
3097 | 56 | config_file = args.config | ||
3098 | 57 | |||
3099 | 58 | config = configparser.RawConfigParser() | ||
3100 | 59 | |||
3101 | 60 | try: | ||
3102 | 61 | config.readfp(open(config_file)) | ||
3103 | 62 | except IOError: | ||
3104 | 63 | print("No config file found") | ||
3105 | 64 | return 10 | ||
3106 | 65 | |||
3107 | 66 | # Acquire ME IP/Credential parameters from config file | ||
3108 | 67 | try: | ||
3109 | 68 | targets_options = config.options('Targets') | ||
3110 | 69 | targets_list = [] | ||
3111 | 70 | for target_key in targets_options: | ||
3112 | 71 | targets_list.append(config.get('Targets', target_key)) | ||
3113 | 72 | if not targets_list: | ||
3114 | 73 | print("Invalid or Empty targets") | ||
3115 | 74 | return 20 | ||
3116 | 75 | except configparser.Error: | ||
3117 | 76 | print("Invalid or Empty targets") | ||
3118 | 77 | return 30 | ||
3119 | 78 | |||
3120 | 79 | try: | ||
3121 | 80 | user_value = config.get('Account', 'USER') | ||
3122 | 81 | passwd_value = config.get('Account', 'PASSWORD') | ||
3123 | 82 | except configparser.Error: | ||
3124 | 83 | print("Invalid or Empty credential info") | ||
3125 | 84 | return 40 | ||
3126 | 85 | |||
3127 | 86 | flag = 0 | ||
3128 | 87 | for target in targets_list: | ||
3129 | 88 | |||
3130 | 89 | if not target or not user_value or not passwd_value: | ||
3131 | 90 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | ||
3132 | 91 | return 50 | ||
3133 | 92 | else: | ||
3134 | 93 | print("SUT =", target) | ||
3135 | 94 | |||
3136 | 95 | try: | ||
3137 | 96 | power_draw_return = get_power_draw(target, user_value, passwd_value) | ||
3138 | 97 | time.sleep(5) | ||
3139 | 98 | except CalledProcessError as command_exception: | ||
3140 | 99 | print("Failed executing dcmi command", command_exception) | ||
3141 | 100 | return 60 | ||
3142 | 101 | |||
3143 | 102 | power_list = ['Minimum during sampling period', 'Maximum during sampling period',\ | ||
3144 | 103 | 'Average power reading over sample period',\ | ||
3145 | 104 | 'IPMI timestamp', 'Sampling period', 'Power reading state is'] | ||
3146 | 105 | for i in power_list: | ||
3147 | 106 | value = re.search(i+':\s*([a-zA-Z0-9-: ]+)', power_draw_return) | ||
3148 | 107 | if value == None: | ||
3149 | 108 | print("{}: Error".format(i)) | ||
3150 | 109 | flag = 1 | ||
3151 | 110 | else: | ||
3152 | 111 | print("{}: {}".format(i, value.group(1))) | ||
3153 | 112 | if flag == 1: | ||
3154 | 113 | return 1 | ||
3155 | 114 | return 0 | ||
3156 | 115 | |||
3157 | 116 | def main(): | ||
3158 | 117 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | ||
3159 | 118 | parser = ArgumentParser(description=intro_message, | ||
3160 | 119 | formatter_class=RawTextHelpFormatter) | ||
3161 | 120 | parser.add_argument('--config', default="/etc/checkbox.d/me.cfg", | ||
3162 | 121 | help="Supply config file for getting authentication info") | ||
3163 | 122 | args = parser.parse_args() | ||
3164 | 123 | return power_draw_test(args) | ||
3165 | 124 | |||
3166 | 125 | if __name__ == '__main__': | ||
3167 | 126 | sys.exit(main()) | ||
3168 | 0 | 127 | ||
3169 | === added file 'bin/ipmi_power_off_on' | |||
3170 | --- bin/ipmi_power_off_on 1970-01-01 00:00:00 +0000 | |||
3171 | +++ bin/ipmi_power_off_on 2015-08-14 22:03:31 +0000 | |||
3172 | @@ -0,0 +1,193 @@ | |||
3173 | 1 | #! /usr/bin/env python3 | ||
3174 | 2 | """ | ||
3175 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3176 | 4 | Industrial Technology Research Institute | ||
3177 | 5 | |||
3178 | 6 | File Name | ||
3179 | 7 | ipmi_power_off_on | ||
3180 | 8 | |||
3181 | 9 | Description | ||
3182 | 10 | 1. Use ipmitool out-of-band access to turn on/off the SUT. | ||
3183 | 11 | 2. Criteria: the SUT can be powered on/off by ipmitool out-of-band access. | ||
3184 | 12 | |||
3185 | 13 | Authors | ||
3186 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3187 | 15 | |||
3188 | 16 | This program is free software: you can redistribute it and/or modify | ||
3189 | 17 | it under the terms of the GNU General Public License version 3, | ||
3190 | 18 | as published by the Free Software Foundation. | ||
3191 | 19 | |||
3192 | 20 | This program is distributed in the hope that it will be useful, | ||
3193 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3194 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3195 | 23 | GNU General Public License for more details. | ||
3196 | 24 | |||
3197 | 25 | You should have received a copy of the GNU General Public License | ||
3198 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3199 | 27 | |||
3200 | 28 | """ | ||
3201 | 29 | from argparse import ( | ||
3202 | 30 | ArgumentParser, | ||
3203 | 31 | RawTextHelpFormatter | ||
3204 | 32 | ) | ||
3205 | 33 | |||
3206 | 34 | import sys | ||
3207 | 35 | import configparser | ||
3208 | 36 | import shlex | ||
3209 | 37 | import subprocess | ||
3210 | 38 | import ast | ||
3211 | 39 | import time | ||
3212 | 40 | from subprocess import ( | ||
3213 | 41 | check_output, | ||
3214 | 42 | CalledProcessError | ||
3215 | 43 | ) | ||
3216 | 44 | |||
3217 | 45 | def check_power_status(host_ip, user, password): | ||
3218 | 46 | |||
3219 | 47 | cmd_status_on = 'ipmitool -H {} -U {} -P {} power status| grep -q "on"'\ | ||
3220 | 48 | .format(host_ip, user, password) | ||
3221 | 49 | check_on_value = subprocess.call(cmd_status_on, shell=True) | ||
3222 | 50 | time.sleep(5) | ||
3223 | 51 | |||
3224 | 52 | cmd_status_off = 'ipmitool -H {} -U {} -P {} power status| grep -q "off"'\ | ||
3225 | 53 | .format(host_ip, user, password) | ||
3226 | 54 | check_off_value = subprocess.call(cmd_status_off, shell=True) | ||
3227 | 55 | time.sleep(5) | ||
3228 | 56 | |||
3229 | 57 | if check_on_value == 0 and check_off_value == 1: | ||
3230 | 58 | check_status = 'on' | ||
3231 | 59 | |||
3232 | 60 | elif check_on_value == 1 and check_off_value == 0: | ||
3233 | 61 | check_status = 'off' | ||
3234 | 62 | |||
3235 | 63 | else: | ||
3236 | 64 | check_status = 'error' | ||
3237 | 65 | |||
3238 | 66 | return check_status | ||
3239 | 67 | |||
3240 | 68 | def run_power_off(host_ip, user, password): | ||
3241 | 69 | cmd_power_off = 'ipmitool -H {} -U {} -P {} power off'\ | ||
3242 | 70 | .format(host_ip, user, password) | ||
3243 | 71 | power_off_return_code = subprocess.call(cmd_power_off, shell=True) | ||
3244 | 72 | return power_off_return_code | ||
3245 | 73 | |||
3246 | 74 | def run_power_on(host_ip, user, password): | ||
3247 | 75 | cmd_power_on = 'ipmitool -H {} -U {} -P {} power on'\ | ||
3248 | 76 | .format(host_ip, user, password) | ||
3249 | 77 | power_on_return_code = subprocess.call(cmd_power_on, shell=True) | ||
3250 | 78 | return power_on_return_code | ||
3251 | 79 | |||
3252 | 80 | def ipmi_reset_oob(args): | ||
3253 | 81 | |||
3254 | 82 | #IPMI config file | ||
3255 | 83 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
3256 | 84 | if not "config" in vars(args): | ||
3257 | 85 | config_file = DEFAULT_CFG | ||
3258 | 86 | else: | ||
3259 | 87 | config_file = args.config | ||
3260 | 88 | |||
3261 | 89 | config = configparser.RawConfigParser() | ||
3262 | 90 | |||
3263 | 91 | try: | ||
3264 | 92 | config.readfp(open(config_file)) | ||
3265 | 93 | except IOError: | ||
3266 | 94 | print("No config file found") | ||
3267 | 95 | return 10 | ||
3268 | 96 | |||
3269 | 97 | try: | ||
3270 | 98 | targets_options = config.options('Targets') | ||
3271 | 99 | targets_list = [] | ||
3272 | 100 | for target_key in targets_options: | ||
3273 | 101 | targets_list.append(config.get('Targets', target_key)) | ||
3274 | 102 | |||
3275 | 103 | if not targets_list: | ||
3276 | 104 | print("Invalid or Empty targets") | ||
3277 | 105 | return 20 | ||
3278 | 106 | |||
3279 | 107 | except configparser.Error: | ||
3280 | 108 | print("Invalid or Empty targets") | ||
3281 | 109 | return 30 | ||
3282 | 110 | |||
3283 | 111 | try: | ||
3284 | 112 | user_value = config.get('Account', 'USER') | ||
3285 | 113 | passwd_value = config.get('Account', 'PASSWORD') | ||
3286 | 114 | if not user_value or not passwd_value: | ||
3287 | 115 | print("Invalid or Empty credential info") | ||
3288 | 116 | return 40 | ||
3289 | 117 | |||
3290 | 118 | except configparser.Error: | ||
3291 | 119 | print("Invalid or Empty credential info") | ||
3292 | 120 | return 50 | ||
3293 | 121 | |||
3294 | 122 | ping_flag = 0 | ||
3295 | 123 | for tg in targets_list: | ||
3296 | 124 | |||
3297 | 125 | if not tg or not user_value or not passwd_value: | ||
3298 | 126 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3299 | 127 | return 21 | ||
3300 | 128 | else: | ||
3301 | 129 | |||
3302 | 130 | print("SUT =", tg) | ||
3303 | 131 | print("USER =", user_value) | ||
3304 | 132 | print("PASSWORD =", passwd_value) | ||
3305 | 133 | |||
3306 | 134 | for n in range(2): | ||
3307 | 135 | |||
3308 | 136 | count = 0 | ||
3309 | 137 | while count < 10: | ||
3310 | 138 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
3311 | 139 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
3312 | 140 | if ping_rtn == 0: | ||
3313 | 141 | print("Destination Host Reachable") | ||
3314 | 142 | |||
3315 | 143 | #run test | ||
3316 | 144 | status = check_power_status(tg, user_value, passwd_value) | ||
3317 | 145 | |||
3318 | 146 | if status == 'on': | ||
3319 | 147 | #run power off | ||
3320 | 148 | power_off_result = run_power_off(tg, user_value, passwd_value) | ||
3321 | 149 | print(" ") | ||
3322 | 150 | if power_off_result == 1: | ||
3323 | 151 | print("Failed to power off SUT.") | ||
3324 | 152 | return 88 | ||
3325 | 153 | elif status == 'off': | ||
3326 | 154 | #run power on | ||
3327 | 155 | power_on_result = run_power_on(tg, user_value, passwd_value) | ||
3328 | 156 | print(" ") | ||
3329 | 157 | if power_on_result == 1: | ||
3330 | 158 | print("Failed to power on SUT.") | ||
3331 | 159 | return 99 | ||
3332 | 160 | else: | ||
3333 | 161 | #do nothing | ||
3334 | 162 | print("Failed to check power status") | ||
3335 | 163 | return 77 | ||
3336 | 164 | |||
3337 | 165 | time.sleep(180) | ||
3338 | 166 | break | ||
3339 | 167 | |||
3340 | 168 | else: | ||
3341 | 169 | time.sleep(10) | ||
3342 | 170 | count = count+1 | ||
3343 | 171 | print("Destination Host Unreachable") | ||
3344 | 172 | |||
3345 | 173 | if count == 10: | ||
3346 | 174 | print("Host Has No Response, End of Test") | ||
3347 | 175 | ping_flag = 100 | ||
3348 | 176 | |||
3349 | 177 | if ping_flag == 100: | ||
3350 | 178 | return 100 | ||
3351 | 179 | return 0 | ||
3352 | 180 | |||
3353 | 181 | def main(): | ||
3354 | 182 | |||
3355 | 183 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
3356 | 184 | parser = ArgumentParser(description=intro_message, | ||
3357 | 185 | formatter_class=RawTextHelpFormatter) | ||
3358 | 186 | parser.add_argument('--config', type=str, | ||
3359 | 187 | default="/etc/checkbox.d/bmc.cfg", | ||
3360 | 188 | help="Supply config file for getting authentication info") | ||
3361 | 189 | args = parser.parse_args() | ||
3362 | 190 | return ipmi_reset_oob(args) | ||
3363 | 191 | |||
3364 | 192 | if __name__ == "__main__": | ||
3365 | 193 | sys.exit(main()) | ||
3366 | 0 | 194 | ||
3367 | === added file 'bin/ipmi_power_policy' | |||
3368 | --- bin/ipmi_power_policy 1970-01-01 00:00:00 +0000 | |||
3369 | +++ bin/ipmi_power_policy 2015-08-14 22:03:31 +0000 | |||
3370 | @@ -0,0 +1,165 @@ | |||
3371 | 1 | #!/usr/bin/env python3 | ||
3372 | 2 | """ | ||
3373 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3374 | 4 | Industrial Technology Research Institute | ||
3375 | 5 | |||
3376 | 6 | File Name | ||
3377 | 7 | ipmi_power_policy | ||
3378 | 8 | |||
3379 | 9 | Description | ||
3380 | 10 | 1. Use ipmitool to set power on policy through OOB. | ||
3381 | 11 | 2. Criteria: the change of power policy should take effect without BMC firmware cold reset or system reboot. | ||
3382 | 12 | |||
3383 | 13 | Authors | ||
3384 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3385 | 15 | |||
3386 | 16 | This program is free software: you can redistribute it and/or modify | ||
3387 | 17 | it under the terms of the GNU General Public License version 3, | ||
3388 | 18 | as published by the Free Software Foundation. | ||
3389 | 19 | |||
3390 | 20 | This program is distributed in the hope that it will be useful, | ||
3391 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3392 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3393 | 23 | GNU General Public License for more details. | ||
3394 | 24 | |||
3395 | 25 | You should have received a copy of the GNU General Public License | ||
3396 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3397 | 27 | |||
3398 | 28 | """ | ||
3399 | 29 | |||
3400 | 30 | from argparse import ( | ||
3401 | 31 | ArgumentParser, | ||
3402 | 32 | RawTextHelpFormatter | ||
3403 | 33 | ) | ||
3404 | 34 | |||
3405 | 35 | import sys | ||
3406 | 36 | import shlex | ||
3407 | 37 | import time | ||
3408 | 38 | import subprocess | ||
3409 | 39 | from subprocess import ( | ||
3410 | 40 | check_output, | ||
3411 | 41 | CalledProcessError | ||
3412 | 42 | ) | ||
3413 | 43 | import re | ||
3414 | 44 | import configparser | ||
3415 | 45 | import os | ||
3416 | 46 | |||
3417 | 47 | def set_power_policy(host_ip, user, password, rule): | ||
3418 | 48 | os.system('ipmitool -H {} -U {} -P {} chassis policy {}'.format(host_ip, user, password, rule)) | ||
3419 | 49 | |||
3420 | 50 | def get_chassis_status(host_ip, user, password): | ||
3421 | 51 | cmd = 'ipmitool -H {} -U {} -P {} chassis status'.format(host_ip, user, password) | ||
3422 | 52 | output = check_output(shlex.split(cmd), universal_newlines=True) | ||
3423 | 53 | return output | ||
3424 | 54 | |||
3425 | 55 | def get_power_policy(host_ip, user, password): | ||
3426 | 56 | result = get_chassis_status(host_ip, user, password) | ||
3427 | 57 | policy = re.search(r'Power Restore Policy\s*:\s*([a-zA-Z0-9-._ ]+\n)', result) | ||
3428 | 58 | if policy == None: | ||
3429 | 59 | return 'Error' | ||
3430 | 60 | else: | ||
3431 | 61 | return policy.group(1).strip() | ||
3432 | 62 | |||
3433 | 63 | def check_policy(host_ip, user, password, rule): | ||
3434 | 64 | current_policy = get_power_policy(host_ip, user, password) | ||
3435 | 65 | if current_policy == rule: | ||
3436 | 66 | print("Successfully setting power policy") | ||
3437 | 67 | return 0 | ||
3438 | 68 | else: | ||
3439 | 69 | return 1 | ||
3440 | 70 | |||
3441 | 71 | def power_policy_test(args): | ||
3442 | 72 | |||
3443 | 73 | #IPMI config file | ||
3444 | 74 | policy_rule = args.rule | ||
3445 | 75 | if not policy_rule: | ||
3446 | 76 | print("No specified policy to set") | ||
3447 | 77 | return 88 | ||
3448 | 78 | |||
3449 | 79 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
3450 | 80 | |||
3451 | 81 | if not "config" in vars(args): | ||
3452 | 82 | config_file = DEFAULT_CFG | ||
3453 | 83 | else: | ||
3454 | 84 | config_file = args.config | ||
3455 | 85 | |||
3456 | 86 | config = configparser.RawConfigParser() | ||
3457 | 87 | |||
3458 | 88 | try: | ||
3459 | 89 | config.readfp(open(config_file)) | ||
3460 | 90 | except IOError: | ||
3461 | 91 | print("No config file found") | ||
3462 | 92 | return 10 | ||
3463 | 93 | |||
3464 | 94 | try: | ||
3465 | 95 | targets_options = config.options('Targets') | ||
3466 | 96 | targets_list = [] | ||
3467 | 97 | for target_key in targets_options: | ||
3468 | 98 | targets_list.append(config.get('Targets', target_key)) | ||
3469 | 99 | |||
3470 | 100 | if not targets_list: | ||
3471 | 101 | print("Invalid or Empty targets") | ||
3472 | 102 | return 20 | ||
3473 | 103 | |||
3474 | 104 | except configparser.Error: | ||
3475 | 105 | print("Invalid or Empty targets") | ||
3476 | 106 | return 30 | ||
3477 | 107 | |||
3478 | 108 | try: | ||
3479 | 109 | user_value = config.get('Account', 'USER') | ||
3480 | 110 | passwd_value = config.get('Account', 'PASSWORD') | ||
3481 | 111 | if not user_value or not passwd_value: | ||
3482 | 112 | print("Invalid or Empty credential info") | ||
3483 | 113 | return 40 | ||
3484 | 114 | |||
3485 | 115 | except configparser.Error: | ||
3486 | 116 | print("Invalid or Empty credential info") | ||
3487 | 117 | return 50 | ||
3488 | 118 | |||
3489 | 119 | flag = 0 | ||
3490 | 120 | for tg in targets_list: | ||
3491 | 121 | |||
3492 | 122 | if not tg or not user_value or not passwd_value: | ||
3493 | 123 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3494 | 124 | return 60 | ||
3495 | 125 | else: | ||
3496 | 126 | print("SUT =", tg) | ||
3497 | 127 | |||
3498 | 128 | try: | ||
3499 | 129 | set_power_policy(tg, user_value, passwd_value, policy_rule) | ||
3500 | 130 | except: | ||
3501 | 131 | print("Fail to set power policy") | ||
3502 | 132 | return 70 | ||
3503 | 133 | |||
3504 | 134 | time.sleep(5) | ||
3505 | 135 | |||
3506 | 136 | try: | ||
3507 | 137 | chassis_status = get_chassis_status(tg, user_value, passwd_value) | ||
3508 | 138 | except: | ||
3509 | 139 | print("Fail to get chassis status") | ||
3510 | 140 | return 80 | ||
3511 | 141 | |||
3512 | 142 | current_policy = get_power_policy(tg, user_value, passwd_value) | ||
3513 | 143 | |||
3514 | 144 | value = check_policy(tg, user_value, passwd_value, policy_rule) | ||
3515 | 145 | |||
3516 | 146 | if value == 1: | ||
3517 | 147 | flag = 1 | ||
3518 | 148 | |||
3519 | 149 | if flag == 1: | ||
3520 | 150 | return 1 | ||
3521 | 151 | return 0 | ||
3522 | 152 | |||
3523 | 153 | def main(): | ||
3524 | 154 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
3525 | 155 | parser = ArgumentParser(description=intro_message, | ||
3526 | 156 | formatter_class=RawTextHelpFormatter) | ||
3527 | 157 | parser.add_argument('--config', type=str, | ||
3528 | 158 | default="/etc/checkbox.d/bmc.cfg", | ||
3529 | 159 | help="Supply config file for getting authentication info") | ||
3530 | 160 | parser.add_argument('--rule', help="always-on, always-off or previous") | ||
3531 | 161 | args = parser.parse_args() | ||
3532 | 162 | return power_policy_test(args) | ||
3533 | 163 | |||
3534 | 164 | if __name__ == '__main__': | ||
3535 | 165 | sys.exit(main()) | ||
3536 | 0 | 166 | ||
3537 | === added file 'bin/ipmi_power_reset' | |||
3538 | --- bin/ipmi_power_reset 1970-01-01 00:00:00 +0000 | |||
3539 | +++ bin/ipmi_power_reset 2015-08-14 22:03:31 +0000 | |||
3540 | @@ -0,0 +1,142 @@ | |||
3541 | 1 | #!/usr/bin/env python3 | ||
3542 | 2 | """ | ||
3543 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3544 | 4 | Industrial Technology Research Institute | ||
3545 | 5 | |||
3546 | 6 | File Name | ||
3547 | 7 | ipmi_power_reset | ||
3548 | 8 | |||
3549 | 9 | Description | ||
3550 | 10 | 1. Use ipmitool out-of-band access to power hard reset the SUT 20 times. | ||
3551 | 11 | 2. Criteria: complete 20 power hard reset on SUT successfully using ipmitool out-of-band access. | ||
3552 | 12 | |||
3553 | 13 | Authors | ||
3554 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3555 | 15 | |||
3556 | 16 | This program is free software: you can redistribute it and/or modify | ||
3557 | 17 | it under the terms of the GNU General Public License version 3, | ||
3558 | 18 | as published by the Free Software Foundation. | ||
3559 | 19 | |||
3560 | 20 | This program is distributed in the hope that it will be useful, | ||
3561 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3562 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3563 | 23 | GNU General Public License for more details. | ||
3564 | 24 | |||
3565 | 25 | You should have received a copy of the GNU General Public License | ||
3566 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3567 | 27 | |||
3568 | 28 | """ | ||
3569 | 29 | |||
3570 | 30 | from argparse import ( | ||
3571 | 31 | ArgumentParser, | ||
3572 | 32 | RawTextHelpFormatter | ||
3573 | 33 | ) | ||
3574 | 34 | |||
3575 | 35 | import sys | ||
3576 | 36 | import configparser | ||
3577 | 37 | import shlex | ||
3578 | 38 | import subprocess | ||
3579 | 39 | import ast | ||
3580 | 40 | import time | ||
3581 | 41 | from subprocess import ( | ||
3582 | 42 | check_output, | ||
3583 | 43 | CalledProcessError | ||
3584 | 44 | ) | ||
3585 | 45 | |||
3586 | 46 | def run(host_ip, user, password): | ||
3587 | 47 | cmd = 'ipmitool -H {} -U {} -P {} power reset'.format(host_ip, user, password) | ||
3588 | 48 | power_reset_return = check_output(shlex.split(cmd), universal_newlines=True) | ||
3589 | 49 | return power_reset_return | ||
3590 | 50 | |||
3591 | 51 | def ipmi_reset_oob(args): | ||
3592 | 52 | |||
3593 | 53 | #IPMI config file | ||
3594 | 54 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
3595 | 55 | if not "config" in vars(args): | ||
3596 | 56 | config_file = DEFAULT_CFG | ||
3597 | 57 | else: | ||
3598 | 58 | config_file = args.config | ||
3599 | 59 | |||
3600 | 60 | config = configparser.RawConfigParser() | ||
3601 | 61 | try: | ||
3602 | 62 | config.readfp(open(config_file)) | ||
3603 | 63 | except IOError: | ||
3604 | 64 | print("No config file found") | ||
3605 | 65 | return 1 | ||
3606 | 66 | |||
3607 | 67 | try: | ||
3608 | 68 | targets_options = config.options('Targets') | ||
3609 | 69 | targets_list = [] | ||
3610 | 70 | for target_key in targets_options: | ||
3611 | 71 | targets_list.append(config.get('Targets', target_key)) | ||
3612 | 72 | if not targets_list: | ||
3613 | 73 | print("Invalid or Empty targets") | ||
3614 | 74 | return 2 | ||
3615 | 75 | except configparser.Error: | ||
3616 | 76 | print("Invalid or Empty targets") | ||
3617 | 77 | return 2 | ||
3618 | 78 | |||
3619 | 79 | try: | ||
3620 | 80 | user_value = config.get("Account", "USER") | ||
3621 | 81 | password_value = config.get("Account", "PASSWORD") | ||
3622 | 82 | except configparser.NoOptionError: | ||
3623 | 83 | print("Invalid or Empty credential info") | ||
3624 | 84 | return 3 | ||
3625 | 85 | |||
3626 | 86 | ping_flag = 0 | ||
3627 | 87 | for tg in targets_list: | ||
3628 | 88 | |||
3629 | 89 | if not tg or not user_value or not password_value: | ||
3630 | 90 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3631 | 91 | return 4 | ||
3632 | 92 | else: | ||
3633 | 93 | print("SUT =", tg) | ||
3634 | 94 | print("USER =", user_value) | ||
3635 | 95 | print("PASSWORD =", password_value) | ||
3636 | 96 | |||
3637 | 97 | for n in range(20): | ||
3638 | 98 | print("---------------- %s ----------------" % n) | ||
3639 | 99 | count = 0 | ||
3640 | 100 | while count < 10: | ||
3641 | 101 | print("+++++++++++ %s ++++++++++++" % count) | ||
3642 | 102 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
3643 | 103 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
3644 | 104 | |||
3645 | 105 | if ping_rtn == 0: | ||
3646 | 106 | print("Destination Host Reachable") | ||
3647 | 107 | |||
3648 | 108 | try: | ||
3649 | 109 | power_control = run(tg, user_value, password_value) | ||
3650 | 110 | print(power_control) | ||
3651 | 111 | except CalledProcessError as ipmi_exception: | ||
3652 | 112 | print("Failed executing ipmi, Reason: %s" % ipmi_exception) | ||
3653 | 113 | return 6 | ||
3654 | 114 | |||
3655 | 115 | time.sleep(180) | ||
3656 | 116 | break | ||
3657 | 117 | else: | ||
3658 | 118 | time.sleep(10) | ||
3659 | 119 | count = count+1 | ||
3660 | 120 | print("Destination Host Unreachable") | ||
3661 | 121 | |||
3662 | 122 | if count == 10: | ||
3663 | 123 | print("Host Has No Response, End of Test") | ||
3664 | 124 | ping_flag = 100 | ||
3665 | 125 | |||
3666 | 126 | if ping_flag == 100: | ||
3667 | 127 | return 100 | ||
3668 | 128 | return 0 | ||
3669 | 129 | |||
3670 | 130 | def main(): | ||
3671 | 131 | |||
3672 | 132 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
3673 | 133 | parser = ArgumentParser(description=intro_message, | ||
3674 | 134 | formatter_class=RawTextHelpFormatter) | ||
3675 | 135 | parser.add_argument('--config', | ||
3676 | 136 | default="/etc/checkbox.d/bmc.cfg", | ||
3677 | 137 | help="Supply config file for getting authentication info") | ||
3678 | 138 | args = parser.parse_args() | ||
3679 | 139 | return ipmi_reset_oob(args) | ||
3680 | 140 | |||
3681 | 141 | if __name__ == "__main__": | ||
3682 | 142 | sys.exit(main()) | ||
3683 | 0 | 143 | ||
3684 | === added file 'bin/ipmi_priv_admin' | |||
3685 | --- bin/ipmi_priv_admin 1970-01-01 00:00:00 +0000 | |||
3686 | +++ bin/ipmi_priv_admin 2015-08-14 22:03:31 +0000 | |||
3687 | @@ -0,0 +1,176 @@ | |||
3688 | 1 | #! /usr/bin/env python3 | ||
3689 | 2 | """ | ||
3690 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3691 | 4 | Industrial Technology Research Institute | ||
3692 | 5 | |||
3693 | 6 | File Name | ||
3694 | 7 | ipmi_priv_admin | ||
3695 | 8 | |||
3696 | 9 | Description | ||
3697 | 10 | 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account. | ||
3698 | 11 | 2. Criteria: reading power status, performing power reset and adding a user account must all be successful. | ||
3699 | 12 | |||
3700 | 13 | Authors | ||
3701 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3702 | 15 | |||
3703 | 16 | This program is free software: you can redistribute it and/or modify | ||
3704 | 17 | it under the terms of the GNU General Public License version 3, | ||
3705 | 18 | as published by the Free Software Foundation. | ||
3706 | 19 | |||
3707 | 20 | This program is distributed in the hope that it will be useful, | ||
3708 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3709 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3710 | 23 | GNU General Public License for more details. | ||
3711 | 24 | |||
3712 | 25 | You should have received a copy of the GNU General Public License | ||
3713 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3714 | 27 | |||
3715 | 28 | """ | ||
3716 | 29 | from argparse import ( | ||
3717 | 30 | ArgumentParser, | ||
3718 | 31 | RawTextHelpFormatter | ||
3719 | 32 | ) | ||
3720 | 33 | |||
3721 | 34 | import sys | ||
3722 | 35 | import configparser | ||
3723 | 36 | import shlex | ||
3724 | 37 | import subprocess | ||
3725 | 38 | import ast | ||
3726 | 39 | import time | ||
3727 | 40 | from subprocess import ( | ||
3728 | 41 | check_output, | ||
3729 | 42 | CalledProcessError | ||
3730 | 43 | ) | ||
3731 | 44 | |||
3732 | 45 | def get_power_status(host_ip, user, password): | ||
3733 | 46 | cmd_status = 'ipmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\ | ||
3734 | 47 | .format(host_ip, user, password) | ||
3735 | 48 | status_code = subprocess.call(cmd_status, shell=True) | ||
3736 | 49 | return status_code | ||
3737 | 50 | |||
3738 | 51 | def power_reset(host_ip, user, password): | ||
3739 | 52 | cmd_reset = 'ipmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\ | ||
3740 | 53 | .format(host_ip, user, password) | ||
3741 | 54 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
3742 | 55 | return reset_code | ||
3743 | 56 | |||
3744 | 57 | def add_user(host_ip, user, password, new_id, new_user): | ||
3745 | 58 | cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\ | ||
3746 | 59 | .format(host_ip, user, password, new_id, new_user) | ||
3747 | 60 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
3748 | 61 | return add_user_code | ||
3749 | 62 | |||
3750 | 63 | def ipmi_user_level_test(args): | ||
3751 | 64 | |||
3752 | 65 | #IPMI config file | ||
3753 | 66 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
3754 | 67 | if not "config" in vars(args): | ||
3755 | 68 | config_file = DEFAULT_CFG | ||
3756 | 69 | else: | ||
3757 | 70 | config_file = args.config | ||
3758 | 71 | config = configparser.RawConfigParser() | ||
3759 | 72 | try: | ||
3760 | 73 | config.readfp(open(config_file)) | ||
3761 | 74 | except IOError: | ||
3762 | 75 | print("No config file found") | ||
3763 | 76 | return 10 | ||
3764 | 77 | |||
3765 | 78 | try: | ||
3766 | 79 | targets_options = config.options('Targets') | ||
3767 | 80 | targets_list = [] | ||
3768 | 81 | for target_key in targets_options: | ||
3769 | 82 | targets_list.append(config.get('Targets', target_key)) | ||
3770 | 83 | if not targets_list: | ||
3771 | 84 | print("Invalid or Empty targets") | ||
3772 | 85 | return 20 | ||
3773 | 86 | except configparser.Error: | ||
3774 | 87 | print("Invalid or Empty targets") | ||
3775 | 88 | return 20 | ||
3776 | 89 | |||
3777 | 90 | try: | ||
3778 | 91 | user_value = config.get("Admin Level", "ADMIN_NAME") | ||
3779 | 92 | password_value = config.get("Admin Level", "ADMIN_PASSWD") | ||
3780 | 93 | except configparser.NoOptionError: | ||
3781 | 94 | print("Invalid or Empty credential info") | ||
3782 | 95 | print("Require Operator Level info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3783 | 96 | return 30 | ||
3784 | 97 | |||
3785 | 98 | try: | ||
3786 | 99 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
3787 | 100 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
3788 | 101 | except configparser.NoOptionError: | ||
3789 | 102 | print("Invalid or Empty new user info") | ||
3790 | 103 | print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3791 | 104 | return 40 | ||
3792 | 105 | |||
3793 | 106 | flag = 0 | ||
3794 | 107 | for tg in targets_list: | ||
3795 | 108 | |||
3796 | 109 | if not tg or not user_value or not password_value: | ||
3797 | 110 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3798 | 111 | return 50 | ||
3799 | 112 | else: | ||
3800 | 113 | print("SUT", tg) | ||
3801 | 114 | |||
3802 | 115 | ping_result = ping_test(tg) | ||
3803 | 116 | if ping_result != 0: | ||
3804 | 117 | return 88 | ||
3805 | 118 | |||
3806 | 119 | status_result = get_power_status(tg, user_value, password_value) | ||
3807 | 120 | time.sleep(5) | ||
3808 | 121 | |||
3809 | 122 | reset_result = power_reset(tg, user_value, password_value) | ||
3810 | 123 | time.sleep(180) | ||
3811 | 124 | if not new_user_value or not new_user_id_value: | ||
3812 | 125 | print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3813 | 126 | return 60 | ||
3814 | 127 | else: | ||
3815 | 128 | |||
3816 | 129 | ping_result = ping_test(tg) | ||
3817 | 130 | if ping_result != 0: | ||
3818 | 131 | return 88 | ||
3819 | 132 | |||
3820 | 133 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
3821 | 134 | time.sleep(5) | ||
3822 | 135 | |||
3823 | 136 | if status_result == 0 and reset_result == 0 and add_user_result == 0: | ||
3824 | 137 | print("User can read power status.") | ||
3825 | 138 | print("User can reset power.") | ||
3826 | 139 | print("User can add a new user.") | ||
3827 | 140 | else: | ||
3828 | 141 | print("Authentication: Not Administrator Level") | ||
3829 | 142 | flag = 1 | ||
3830 | 143 | |||
3831 | 144 | if flag == 1: | ||
3832 | 145 | return 100 | ||
3833 | 146 | return 0 | ||
3834 | 147 | |||
3835 | 148 | def ping_test(host_ip): | ||
3836 | 149 | count = 0 | ||
3837 | 150 | while count < 10: | ||
3838 | 151 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
3839 | 152 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
3840 | 153 | if ping_rtn == 0: | ||
3841 | 154 | return 0 | ||
3842 | 155 | else: | ||
3843 | 156 | print("Destination Host Unreachable") | ||
3844 | 157 | time.sleep(10) | ||
3845 | 158 | count = count+1 | ||
3846 | 159 | |||
3847 | 160 | if count == 10: | ||
3848 | 161 | print("Host Has No Response, End of Test") | ||
3849 | 162 | return 1 | ||
3850 | 163 | |||
3851 | 164 | |||
3852 | 165 | def main(): | ||
3853 | 166 | |||
3854 | 167 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
3855 | 168 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
3856 | 169 | parser.add_argument('--config', type=str, | ||
3857 | 170 | default="/etc/checkbox.d/bmc.cfg", | ||
3858 | 171 | help="Supply config file for getting authentication info") | ||
3859 | 172 | args = parser.parse_args() | ||
3860 | 173 | return ipmi_user_level_test(args) | ||
3861 | 174 | |||
3862 | 175 | if __name__ == "__main__": | ||
3863 | 176 | sys.exit(main()) | ||
3864 | 0 | 177 | ||
3865 | === added file 'bin/ipmi_priv_oper' | |||
3866 | --- bin/ipmi_priv_oper 1970-01-01 00:00:00 +0000 | |||
3867 | +++ bin/ipmi_priv_oper 2015-08-14 22:03:31 +0000 | |||
3868 | @@ -0,0 +1,174 @@ | |||
3869 | 1 | #! /usr/bin/env python3 | ||
3870 | 2 | """ | ||
3871 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
3872 | 4 | Industrial Technology Research Institute | ||
3873 | 5 | |||
3874 | 6 | File Name | ||
3875 | 7 | ipmi_priv_oper | ||
3876 | 8 | 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account. | ||
3877 | 9 | 2. Criteria: power status reading and power reset must be successful and must fail at adding a new user account. | ||
3878 | 10 | |||
3879 | 11 | Authors | ||
3880 | 12 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
3881 | 13 | |||
3882 | 14 | This program is free software: you can redistribute it and/or modify | ||
3883 | 15 | it under the terms of the GNU General Public License version 3, | ||
3884 | 16 | as published by the Free Software Foundation. | ||
3885 | 17 | |||
3886 | 18 | This program is distributed in the hope that it will be useful, | ||
3887 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3888 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3889 | 21 | GNU General Public License for more details. | ||
3890 | 22 | |||
3891 | 23 | You should have received a copy of the GNU General Public License | ||
3892 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3893 | 25 | |||
3894 | 26 | """ | ||
3895 | 27 | from argparse import ( | ||
3896 | 28 | ArgumentParser, | ||
3897 | 29 | RawTextHelpFormatter | ||
3898 | 30 | ) | ||
3899 | 31 | |||
3900 | 32 | import sys | ||
3901 | 33 | import configparser | ||
3902 | 34 | import shlex | ||
3903 | 35 | import subprocess | ||
3904 | 36 | import ast | ||
3905 | 37 | import time | ||
3906 | 38 | from subprocess import ( | ||
3907 | 39 | check_output, | ||
3908 | 40 | CalledProcessError | ||
3909 | 41 | ) | ||
3910 | 42 | |||
3911 | 43 | def get_power_status(host_ip, user, password): | ||
3912 | 44 | cmd_status = 'ipmitool -H {} -U {} -P {} power status -L operator 1>/dev/null 2>/dev/null'\ | ||
3913 | 45 | .format(host_ip, user, password) | ||
3914 | 46 | status_code = subprocess.call(cmd_status, shell=True) | ||
3915 | 47 | return status_code | ||
3916 | 48 | |||
3917 | 49 | def power_reset(host_ip, user, password): | ||
3918 | 50 | cmd_reset = 'ipmitool -H {} -U {} -P {} power reset -L operator 1>/dev/null 2>/dev/null'\ | ||
3919 | 51 | .format(host_ip, user, password) | ||
3920 | 52 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
3921 | 53 | return reset_code | ||
3922 | 54 | |||
3923 | 55 | def add_user(host_ip, user, password, new_id, new_user): | ||
3924 | 56 | cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} -L operator 1>/dev/null 2>/dev/null'\ | ||
3925 | 57 | .format(host_ip, user, password, new_id, new_user) | ||
3926 | 58 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
3927 | 59 | return add_user_code | ||
3928 | 60 | |||
3929 | 61 | def ipmi_user_level_test(args): | ||
3930 | 62 | |||
3931 | 63 | #IPMI config file | ||
3932 | 64 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
3933 | 65 | if not "config" in vars(args): | ||
3934 | 66 | config_file = DEFAULT_CFG | ||
3935 | 67 | else: | ||
3936 | 68 | config_file = args.config | ||
3937 | 69 | config = configparser.RawConfigParser() | ||
3938 | 70 | try: | ||
3939 | 71 | config.readfp(open(config_file)) | ||
3940 | 72 | except IOError: | ||
3941 | 73 | print("No config file found") | ||
3942 | 74 | return 10 | ||
3943 | 75 | |||
3944 | 76 | try: | ||
3945 | 77 | targets_options = config.options('Targets') | ||
3946 | 78 | targets_list = [] | ||
3947 | 79 | for target_key in targets_options: | ||
3948 | 80 | targets_list.append(config.get('Targets', target_key)) | ||
3949 | 81 | if not targets_list: | ||
3950 | 82 | print("Invalid or Empty targets") | ||
3951 | 83 | return 20 | ||
3952 | 84 | except configparser.Error: | ||
3953 | 85 | print("Invalid or Empty targets") | ||
3954 | 86 | return 20 | ||
3955 | 87 | |||
3956 | 88 | try: | ||
3957 | 89 | user_value = config.get("Operator Level", "OPER_NAME") | ||
3958 | 90 | password_value = config.get("Operator Level", "OPER_PASSWD") | ||
3959 | 91 | except configparser.NoOptionError: | ||
3960 | 92 | print("Invalid or Empty credential info") | ||
3961 | 93 | print("Require Operator Level info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3962 | 94 | return 30 | ||
3963 | 95 | |||
3964 | 96 | try: | ||
3965 | 97 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
3966 | 98 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
3967 | 99 | except configparser.NoOptionError: | ||
3968 | 100 | print("Invalid or Empty new user info") | ||
3969 | 101 | print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3970 | 102 | return 40 | ||
3971 | 103 | |||
3972 | 104 | flag = 0 | ||
3973 | 105 | for tg in targets_list: | ||
3974 | 106 | |||
3975 | 107 | if not tg or not user_value or not password_value: | ||
3976 | 108 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
3977 | 109 | return 50 | ||
3978 | 110 | else: | ||
3979 | 111 | print("SUT", tg) | ||
3980 | 112 | |||
3981 | 113 | ping_result = ping_test(tg) | ||
3982 | 114 | if ping_result != 0: | ||
3983 | 115 | return 88 | ||
3984 | 116 | |||
3985 | 117 | status_result = get_power_status(tg, user_value, password_value) | ||
3986 | 118 | time.sleep(5) | ||
3987 | 119 | |||
3988 | 120 | reset_result = power_reset(tg, user_value, password_value) | ||
3989 | 121 | time.sleep(180) | ||
3990 | 122 | if not new_user_value or not new_user_id_value: | ||
3991 | 123 | print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
3992 | 124 | return 60 | ||
3993 | 125 | else: | ||
3994 | 126 | |||
3995 | 127 | ping_result = ping_test(tg) | ||
3996 | 128 | if ping_result != 0: | ||
3997 | 129 | return 88 | ||
3998 | 130 | |||
3999 | 131 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
4000 | 132 | time.sleep(5) | ||
4001 | 133 | |||
4002 | 134 | if status_result == 0 and reset_result == 0 and add_user_result == 1: | ||
4003 | 135 | print("User can read power status.") | ||
4004 | 136 | print("User can reset power.") | ||
4005 | 137 | print("User can't add a new user.") | ||
4006 | 138 | else: | ||
4007 | 139 | print("Authentication: Not Operator Level") | ||
4008 | 140 | flag = 1 | ||
4009 | 141 | |||
4010 | 142 | if flag == 1: | ||
4011 | 143 | return 100 | ||
4012 | 144 | return 0 | ||
4013 | 145 | |||
4014 | 146 | def ping_test(host_ip): | ||
4015 | 147 | count = 0 | ||
4016 | 148 | while count < 10: | ||
4017 | 149 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
4018 | 150 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
4019 | 151 | if ping_rtn == 0: | ||
4020 | 152 | return 0 | ||
4021 | 153 | else: | ||
4022 | 154 | print("Destination Host Unreachable") | ||
4023 | 155 | time.sleep(10) | ||
4024 | 156 | count = count+1 | ||
4025 | 157 | |||
4026 | 158 | if count == 10: | ||
4027 | 159 | print("Host Has No Response, End of Test") | ||
4028 | 160 | return 1 | ||
4029 | 161 | |||
4030 | 162 | |||
4031 | 163 | def main(): | ||
4032 | 164 | |||
4033 | 165 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
4034 | 166 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
4035 | 167 | parser.add_argument('--config', type=str, | ||
4036 | 168 | default="/etc/checkbox.d/bmc.cfg", | ||
4037 | 169 | help="Supply config file for getting authentication info") | ||
4038 | 170 | args = parser.parse_args() | ||
4039 | 171 | return ipmi_user_level_test(args) | ||
4040 | 172 | |||
4041 | 173 | if __name__ == "__main__": | ||
4042 | 174 | sys.exit(main()) | ||
4043 | 0 | 175 | ||
4044 | === added file 'bin/ipmi_priv_user' | |||
4045 | --- bin/ipmi_priv_user 1970-01-01 00:00:00 +0000 | |||
4046 | +++ bin/ipmi_priv_user 2015-08-14 22:03:31 +0000 | |||
4047 | @@ -0,0 +1,176 @@ | |||
4048 | 1 | #! /usr/bin/env python3 | ||
4049 | 2 | """ | ||
4050 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
4051 | 4 | Industrial Technology Research Institute | ||
4052 | 5 | |||
4053 | 6 | File Name | ||
4054 | 7 | ipmi_priv_uesr | ||
4055 | 8 | |||
4056 | 9 | Description | ||
4057 | 10 | 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account. | ||
4058 | 11 | 2. Criteria: power status reading must be successful and must fail at power reset and adding a new user account. | ||
4059 | 12 | |||
4060 | 13 | Authors | ||
4061 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
4062 | 15 | |||
4063 | 16 | This program is free software: you can redistribute it and/or modify | ||
4064 | 17 | it under the terms of the GNU General Public License version 3, | ||
4065 | 18 | as published by the Free Software Foundation. | ||
4066 | 19 | |||
4067 | 20 | This program is distributed in the hope that it will be useful, | ||
4068 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4069 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4070 | 23 | GNU General Public License for more details. | ||
4071 | 24 | |||
4072 | 25 | You should have received a copy of the GNU General Public License | ||
4073 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4074 | 27 | |||
4075 | 28 | """ | ||
4076 | 29 | from argparse import ( | ||
4077 | 30 | ArgumentParser, | ||
4078 | 31 | RawTextHelpFormatter | ||
4079 | 32 | ) | ||
4080 | 33 | |||
4081 | 34 | import sys | ||
4082 | 35 | import configparser | ||
4083 | 36 | import shlex | ||
4084 | 37 | import subprocess | ||
4085 | 38 | import ast | ||
4086 | 39 | import time | ||
4087 | 40 | from subprocess import ( | ||
4088 | 41 | check_output, | ||
4089 | 42 | CalledProcessError | ||
4090 | 43 | ) | ||
4091 | 44 | |||
4092 | 45 | def get_power_status(host_ip, user, password): | ||
4093 | 46 | cmd_status = 'ipmitool -H {} -U {} -P {} power status -L user 1>/dev/null 2>/dev/null'\ | ||
4094 | 47 | .format(host_ip, user, password) | ||
4095 | 48 | status_code = subprocess.call(cmd_status, shell=True) | ||
4096 | 49 | return status_code | ||
4097 | 50 | |||
4098 | 51 | def power_reset(host_ip, user, password): | ||
4099 | 52 | cmd_reset = 'ipmitool -H {} -U {} -P {} power reset -L user 1>/dev/null 2>/dev/null'\ | ||
4100 | 53 | .format(host_ip, user, password) | ||
4101 | 54 | reset_code = subprocess.call(cmd_reset, shell=True) | ||
4102 | 55 | return reset_code | ||
4103 | 56 | |||
4104 | 57 | def add_user(host_ip, user, password, new_id, new_user): | ||
4105 | 58 | cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} -L user 1>/dev/null 2>/dev/null'\ | ||
4106 | 59 | .format(host_ip, user, password, new_id, new_user) | ||
4107 | 60 | add_user_code = subprocess.call(cmd_add_user, shell=True) | ||
4108 | 61 | return add_user_code | ||
4109 | 62 | |||
4110 | 63 | def ipmi_user_level_test(args): | ||
4111 | 64 | |||
4112 | 65 | #IPMI config file | ||
4113 | 66 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
4114 | 67 | if not "config" in vars(args): | ||
4115 | 68 | config_file = DEFAULT_CFG | ||
4116 | 69 | else: | ||
4117 | 70 | config_file = args.config | ||
4118 | 71 | config = configparser.RawConfigParser() | ||
4119 | 72 | try: | ||
4120 | 73 | config.readfp(open(config_file)) | ||
4121 | 74 | except IOError: | ||
4122 | 75 | print("No config file found") | ||
4123 | 76 | return 10 | ||
4124 | 77 | |||
4125 | 78 | try: | ||
4126 | 79 | targets_options = config.options('Targets') | ||
4127 | 80 | targets_list = [] | ||
4128 | 81 | for target_key in targets_options: | ||
4129 | 82 | targets_list.append(config.get('Targets', target_key)) | ||
4130 | 83 | if not targets_list: | ||
4131 | 84 | print("Invalid or Empty targets") | ||
4132 | 85 | return 20 | ||
4133 | 86 | except configparser.Error: | ||
4134 | 87 | print("Invalid or Empty targets") | ||
4135 | 88 | return 20 | ||
4136 | 89 | |||
4137 | 90 | try: | ||
4138 | 91 | user_value = config.get("User Level", "USER_NAME") | ||
4139 | 92 | password_value = config.get("User Level", "USER_PASSWD") | ||
4140 | 93 | except configparser.NoOptionError: | ||
4141 | 94 | print("Invalid or Empty credential info") | ||
4142 | 95 | print("Require User Level info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
4143 | 96 | return 30 | ||
4144 | 97 | |||
4145 | 98 | try: | ||
4146 | 99 | new_user_value = config.get("Add User Test", "NEW_USER_NAME") | ||
4147 | 100 | new_user_id_value = config.get("Add User Test", "NEW_USER_ID") | ||
4148 | 101 | except configparser.NoOptionError: | ||
4149 | 102 | print("Invalid or Empty new user info") | ||
4150 | 103 | print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
4151 | 104 | return 40 | ||
4152 | 105 | |||
4153 | 106 | flag = 0 | ||
4154 | 107 | for tg in targets_list: | ||
4155 | 108 | |||
4156 | 109 | if not tg or not user_value or not password_value: | ||
4157 | 110 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
4158 | 111 | return 50 | ||
4159 | 112 | else: | ||
4160 | 113 | print("SUT", tg) | ||
4161 | 114 | |||
4162 | 115 | ping_result = ping_test(tg) | ||
4163 | 116 | if ping_result != 0: | ||
4164 | 117 | return 88 | ||
4165 | 118 | |||
4166 | 119 | status_result = get_power_status(tg, user_value, password_value) | ||
4167 | 120 | time.sleep(5) | ||
4168 | 121 | |||
4169 | 122 | reset_result = power_reset(tg, user_value, password_value) | ||
4170 | 123 | time.sleep(180) | ||
4171 | 124 | if not new_user_value or not new_user_id_value: | ||
4172 | 125 | print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg") | ||
4173 | 126 | return 60 | ||
4174 | 127 | else: | ||
4175 | 128 | |||
4176 | 129 | ping_result = ping_test(tg) | ||
4177 | 130 | if ping_result != 0: | ||
4178 | 131 | return 88 | ||
4179 | 132 | |||
4180 | 133 | add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value) | ||
4181 | 134 | time.sleep(5) | ||
4182 | 135 | |||
4183 | 136 | if status_result == 0 and reset_result == 1 and add_user_result == 1: | ||
4184 | 137 | print("User can read power status.") | ||
4185 | 138 | print("User can't reset power.") | ||
4186 | 139 | print("User can't add a new user.") | ||
4187 | 140 | else: | ||
4188 | 141 | print("Authentication: Not User Level") | ||
4189 | 142 | flag = 1 | ||
4190 | 143 | |||
4191 | 144 | if flag == 1: | ||
4192 | 145 | return 100 | ||
4193 | 146 | return 0 | ||
4194 | 147 | |||
4195 | 148 | def ping_test(host_ip): | ||
4196 | 149 | count = 0 | ||
4197 | 150 | while count < 10: | ||
4198 | 151 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip) | ||
4199 | 152 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
4200 | 153 | if ping_rtn == 0: | ||
4201 | 154 | return 0 | ||
4202 | 155 | else: | ||
4203 | 156 | print("Destination Host Unreachable") | ||
4204 | 157 | time.sleep(10) | ||
4205 | 158 | count = count+1 | ||
4206 | 159 | |||
4207 | 160 | if count == 10: | ||
4208 | 161 | print("Host Has No Response, End of Test") | ||
4209 | 162 | return 1 | ||
4210 | 163 | |||
4211 | 164 | |||
4212 | 165 | def main(): | ||
4213 | 166 | |||
4214 | 167 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
4215 | 168 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
4216 | 169 | parser.add_argument('--config', type=str, | ||
4217 | 170 | default="/etc/checkbox.d/bmc.cfg", | ||
4218 | 171 | help="Supply config file for getting authentication info") | ||
4219 | 172 | args = parser.parse_args() | ||
4220 | 173 | return ipmi_user_level_test(args) | ||
4221 | 174 | |||
4222 | 175 | if __name__ == "__main__": | ||
4223 | 176 | sys.exit(main()) | ||
4224 | 0 | 177 | ||
4225 | === added file 'bin/ipmi_sampling' | |||
4226 | --- bin/ipmi_sampling 1970-01-01 00:00:00 +0000 | |||
4227 | +++ bin/ipmi_sampling 2015-08-14 22:03:31 +0000 | |||
4228 | @@ -0,0 +1,273 @@ | |||
4229 | 1 | #!/usr/bin/env python3 | ||
4230 | 2 | """ | ||
4231 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
4232 | 4 | Industrial Technology Research Institute | ||
4233 | 5 | |||
4234 | 6 | File Name | ||
4235 | 7 | ipmi_sampling | ||
4236 | 8 | |||
4237 | 9 | Description | ||
4238 | 10 | 1. Retrieve CPU and intake temperature 30 times at 3 second intervals using ipmitool | ||
4239 | 11 | 2. If failed to retrieve temperature at any time within 30 times, the test is considered failed | ||
4240 | 12 | |||
4241 | 13 | Authors | ||
4242 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
4243 | 15 | |||
4244 | 16 | This program is free software: you can redistribute it and/or modify | ||
4245 | 17 | it under the terms of the GNU General Public License version 3, | ||
4246 | 18 | as published by the Free Software Foundation. | ||
4247 | 19 | |||
4248 | 20 | This program is distributed in the hope that it will be useful, | ||
4249 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4250 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4251 | 23 | GNU General Public License for more details. | ||
4252 | 24 | |||
4253 | 25 | You should have received a copy of the GNU General Public License | ||
4254 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4255 | 27 | |||
4256 | 28 | """ | ||
4257 | 29 | import sys | ||
4258 | 30 | import time | ||
4259 | 31 | import re | ||
4260 | 32 | import configparser | ||
4261 | 33 | import shlex | ||
4262 | 34 | import subprocess | ||
4263 | 35 | from argparse import ( | ||
4264 | 36 | ArgumentParser, | ||
4265 | 37 | RawTextHelpFormatter | ||
4266 | 38 | ) | ||
4267 | 39 | from subprocess import ( | ||
4268 | 40 | check_output, | ||
4269 | 41 | CalledProcessError | ||
4270 | 42 | ) | ||
4271 | 43 | |||
4272 | 44 | def get_sdr_remote(host_ip, user, password): | ||
4273 | 45 | cmd = "ipmitool -H {} -U {} -P {} sdr".format(host_ip, user, password) | ||
4274 | 46 | sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT, | ||
4275 | 47 | universal_newlines=True) | ||
4276 | 48 | return sdr_return | ||
4277 | 49 | |||
4278 | 50 | def parse_sdr(output): | ||
4279 | 51 | output = output.strip() | ||
4280 | 52 | output_1Line = output.split("\n") | ||
4281 | 53 | data = {} | ||
4282 | 54 | |||
4283 | 55 | for line in output_1Line: | ||
4284 | 56 | sub_value = {} | ||
4285 | 57 | string_list = line.split("|") | ||
4286 | 58 | name = string_list[0].strip() | ||
4287 | 59 | sensor_output = string_list[1].strip() | ||
4288 | 60 | sub_value.update({'output':sensor_output}) | ||
4289 | 61 | status = string_list[2].strip() | ||
4290 | 62 | sub_value.update({'status':status}) | ||
4291 | 63 | data.update({name:sub_value}) | ||
4292 | 64 | return data | ||
4293 | 65 | |||
4294 | 66 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
4295 | 67 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
4296 | 68 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
4297 | 69 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
4298 | 70 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
4299 | 71 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
4300 | 72 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
4301 | 73 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
4302 | 74 | return str(CPU_temp)+' degrees C' | ||
4303 | 75 | else: | ||
4304 | 76 | return 'Error' | ||
4305 | 77 | else: | ||
4306 | 78 | return 'None' | ||
4307 | 79 | |||
4308 | 80 | def ipmi_sdr(args): | ||
4309 | 81 | |||
4310 | 82 | cmd_flag = 0 | ||
4311 | 83 | #IPMI config file | ||
4312 | 84 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
4313 | 85 | if not "config" in vars(args): | ||
4314 | 86 | config_file = DEFAULT_CFG | ||
4315 | 87 | else: | ||
4316 | 88 | config_file = args.config | ||
4317 | 89 | |||
4318 | 90 | config = configparser.RawConfigParser() | ||
4319 | 91 | |||
4320 | 92 | try: | ||
4321 | 93 | config.readfp(open(config_file)) | ||
4322 | 94 | except IOError: | ||
4323 | 95 | print("No config file found") | ||
4324 | 96 | return 10 | ||
4325 | 97 | |||
4326 | 98 | try: | ||
4327 | 99 | sensor_nick = config.options("SensorsForSampling") | ||
4328 | 100 | except configparser.NoSectionError: | ||
4329 | 101 | print("No Section: SensorsForSampling") | ||
4330 | 102 | return 20 | ||
4331 | 103 | |||
4332 | 104 | if sensor_nick: | ||
4333 | 105 | sensor_list = [] | ||
4334 | 106 | for id in sensor_nick: | ||
4335 | 107 | sensor_key = config.get("SensorsForSampling", id) | ||
4336 | 108 | if sensor_key: | ||
4337 | 109 | sensor_list.append(sensor_key) | ||
4338 | 110 | else: | ||
4339 | 111 | print("No Sensor ID specified in Config file") | ||
4340 | 112 | return 30 | ||
4341 | 113 | else: | ||
4342 | 114 | print("No key of Sensor ID specified in config file") | ||
4343 | 115 | return 40 | ||
4344 | 116 | |||
4345 | 117 | try: | ||
4346 | 118 | targets_options = config.options('Targets') | ||
4347 | 119 | targets_list = [] | ||
4348 | 120 | for target_key in targets_options: | ||
4349 | 121 | targets_list.append(config.get('Targets', target_key)) | ||
4350 | 122 | if not targets_list: | ||
4351 | 123 | print("Invalid or Empty targets") | ||
4352 | 124 | return 60 | ||
4353 | 125 | except configparser.Error: | ||
4354 | 126 | print("Invalid or Empty targets") | ||
4355 | 127 | return 60 | ||
4356 | 128 | |||
4357 | 129 | try: | ||
4358 | 130 | user_value = config.get("Account", "USER") | ||
4359 | 131 | password_value = config.get("Account", "PASSWORD") | ||
4360 | 132 | except configparser.NoOptionError: | ||
4361 | 133 | print("Invalid or Empty credential info") | ||
4362 | 134 | return 70 | ||
4363 | 135 | |||
4364 | 136 | for tg in targets_list: | ||
4365 | 137 | |||
4366 | 138 | if not tg or not user_value or not password_value: | ||
4367 | 139 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
4368 | 140 | return 80 | ||
4369 | 141 | else: | ||
4370 | 142 | |||
4371 | 143 | c = 0 | ||
4372 | 144 | while c < 10: | ||
4373 | 145 | ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg) | ||
4374 | 146 | ping_rtn = subprocess.call(ping_cmd, shell=True) | ||
4375 | 147 | if ping_rtn == 0: | ||
4376 | 148 | print("Destination Host Reachable") | ||
4377 | 149 | break | ||
4378 | 150 | else: | ||
4379 | 151 | time.sleep(10) | ||
4380 | 152 | c = c+1 | ||
4381 | 153 | print("Destination Host Unreachable") | ||
4382 | 154 | |||
4383 | 155 | if c == 10: | ||
4384 | 156 | print("Host Has No Response, End of Test") | ||
4385 | 157 | return 99 | ||
4386 | 158 | |||
4387 | 159 | |||
4388 | 160 | sampling_data = [] | ||
4389 | 161 | times = 30 | ||
4390 | 162 | for n in range(times): | ||
4391 | 163 | |||
4392 | 164 | try: | ||
4393 | 165 | sensor_data = get_sdr_remote(tg, user_value, password_value) | ||
4394 | 166 | time.sleep(3) | ||
4395 | 167 | except CalledProcessError as ipmi_exception: | ||
4396 | 168 | print("Failed executing ipmi, Reason: %s" % ipmi_exception) | ||
4397 | 169 | sensor_data = '' | ||
4398 | 170 | |||
4399 | 171 | sampling_data.append(sensor_data) | ||
4400 | 172 | |||
4401 | 173 | count = 0 | ||
4402 | 174 | prs_flag = 0 | ||
4403 | 175 | dis_flag = 0 | ||
4404 | 176 | for output in sampling_data: | ||
4405 | 177 | try: | ||
4406 | 178 | data = parse_sdr(output) | ||
4407 | 179 | except: | ||
4408 | 180 | print("Parsing output of sdr table error") | ||
4409 | 181 | print("=======================================================") | ||
4410 | 182 | prs_flag = 1 | ||
4411 | 183 | count = count+1 | ||
4412 | 184 | continue | ||
4413 | 185 | |||
4414 | 186 | disable = 0 | ||
4415 | 187 | need_data = {} | ||
4416 | 188 | |||
4417 | 189 | for need_id in sensor_list: | ||
4418 | 190 | |||
4419 | 191 | if data.get(need_id): | ||
4420 | 192 | need_value = data.get(need_id).get('output') | ||
4421 | 193 | need_data.update({need_id:need_value}) | ||
4422 | 194 | if data.get(need_id).get('status') != 'ok': | ||
4423 | 195 | disable = 1 | ||
4424 | 196 | else: | ||
4425 | 197 | |||
4426 | 198 | try: | ||
4427 | 199 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
4428 | 200 | except configparser.NoOptionError: | ||
4429 | 201 | CPUx_Temp = '' | ||
4430 | 202 | |||
4431 | 203 | try: | ||
4432 | 204 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
4433 | 205 | except configparser.NoOptionError: | ||
4434 | 206 | CPUy_Temp = '' | ||
4435 | 207 | |||
4436 | 208 | if need_id == CPUx_Temp: | ||
4437 | 209 | |||
4438 | 210 | try: | ||
4439 | 211 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
4440 | 212 | except configparser.NoOptionError: | ||
4441 | 213 | PxTM = '' | ||
4442 | 214 | |||
4443 | 215 | try: | ||
4444 | 216 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
4445 | 217 | except configparser.NoOptionError: | ||
4446 | 218 | CPUx_Tjmax = '' | ||
4447 | 219 | |||
4448 | 220 | if PxTM and CPUx_Tjmax: | ||
4449 | 221 | Px_temp = calculate_CPU_temp(data, PxTM, CPUx_Tjmax) | ||
4450 | 222 | need_data.update({CPUx_Temp:Px_temp}) | ||
4451 | 223 | if Px_temp == 'None' or Px_temp == 'Error': | ||
4452 | 224 | disable = 1 | ||
4453 | 225 | else: | ||
4454 | 226 | disable = 1 | ||
4455 | 227 | |||
4456 | 228 | elif need_id == CPUy_Temp: | ||
4457 | 229 | |||
4458 | 230 | try: | ||
4459 | 231 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
4460 | 232 | except configparser.NoOptionError: | ||
4461 | 233 | PyTM = '' | ||
4462 | 234 | |||
4463 | 235 | try: | ||
4464 | 236 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
4465 | 237 | except configparser.NoOptionError: | ||
4466 | 238 | CPUy_Tjmax = '' | ||
4467 | 239 | |||
4468 | 240 | if PyTM and CPUy_Tjmax: | ||
4469 | 241 | Py_temp = calculate_CPU_temp(data, PyTM, CPUy_Tjmax) | ||
4470 | 242 | need_data.update({CPUy_Temp:Py_temp}) | ||
4471 | 243 | if Py_temp == 'None' or Py_temp == 'Error': | ||
4472 | 244 | disable = 1 | ||
4473 | 245 | else: | ||
4474 | 246 | disable = 1 | ||
4475 | 247 | |||
4476 | 248 | else: | ||
4477 | 249 | need_data.update({need_id:'None'}) | ||
4478 | 250 | disable = 1 | ||
4479 | 251 | |||
4480 | 252 | if disable == 1: | ||
4481 | 253 | dis_flag = 1 | ||
4482 | 254 | print(need_data) | ||
4483 | 255 | print("=======================================================") | ||
4484 | 256 | count = count+1 | ||
4485 | 257 | print("Pass: %d" %(times-count)) | ||
4486 | 258 | print("Fail: %d" %(count)) | ||
4487 | 259 | |||
4488 | 260 | if cmd_flag == 1 or prs_flag == 1 or dis_flag == 1: | ||
4489 | 261 | return 100 | ||
4490 | 262 | return 0 | ||
4491 | 263 | |||
4492 | 264 | def main(): | ||
4493 | 265 | |||
4494 | 266 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
4495 | 267 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
4496 | 268 | parser.add_argument('--config', type=str, default="/etc/checkbox.d/bmc.cfg", help="Supply config file for sensor IDs parameters") | ||
4497 | 269 | args = parser.parse_args() | ||
4498 | 270 | return ipmi_sdr(args) | ||
4499 | 271 | |||
4500 | 272 | if __name__ == "__main__": | ||
4501 | 273 | sys.exit(main()) | ||
4502 | 0 | 274 | ||
4503 | === modified file 'bin/ipmi_sel_entries' | |||
4504 | --- bin/ipmi_sel_entries 2015-03-03 15:59:42 +0000 | |||
4505 | +++ bin/ipmi_sel_entries 2015-08-14 22:03:31 +0000 | |||
4506 | @@ -5,13 +5,11 @@ | |||
4507 | 5 | 5 | ||
4508 | 6 | File Name | 6 | File Name |
4509 | 7 | ipmi_sel_entries | 7 | ipmi_sel_entries |
4510 | 8 | |||
4511 | 9 | Description | ||
4512 | 8 | 1. Use ipmitool to collect event log information | 10 | 1. Use ipmitool to collect event log information |
4513 | 9 | 2. Calculate entries number of system event log | 11 | 2. Calculate entries number of system event log |
4519 | 10 | 3. Criteria: the A log must be capable of saving at least 256 entries | 12 | 3. Criteria: the log must be capable of saving at least 256 entries |
4515 | 11 | |||
4516 | 12 | Description | ||
4517 | 13 | Use ipmitool to get system event log info and calculate whether | ||
4518 | 14 | total number of entries is more than 256. | ||
4520 | 15 | 13 | ||
4521 | 16 | Authors | 14 | Authors |
4522 | 17 | Sophia Wu <Sophia.Wu@itri.org.tw> | 15 | Sophia Wu <Sophia.Wu@itri.org.tw> |
4523 | @@ -63,8 +61,8 @@ | |||
4524 | 63 | 61 | ||
4525 | 64 | def sel_entry_test(args): | 62 | def sel_entry_test(args): |
4526 | 65 | 63 | ||
4529 | 66 | #Default config file to config requirement info for DCMI in-band/out-of-band access | 64 | #Default config file to config requirement info for IPMI in-band/out-of-band access |
4530 | 67 | DEFAULT_CFG = "/etc/checkbox.d/me.cfg" | 65 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" |
4531 | 68 | if not "config" in vars(args): | 66 | if not "config" in vars(args): |
4532 | 69 | config_file = DEFAULT_CFG | 67 | config_file = DEFAULT_CFG |
4533 | 70 | else: | 68 | else: |
4534 | @@ -101,7 +99,7 @@ | |||
4535 | 101 | for target in targets_list: | 99 | for target in targets_list: |
4536 | 102 | 100 | ||
4537 | 103 | if not target or not user_value or not passwd_value: | 101 | if not target or not user_value or not passwd_value: |
4539 | 104 | print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access") | 102 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") |
4540 | 105 | return 50 | 103 | return 50 |
4541 | 106 | else: | 104 | else: |
4542 | 107 | print("SUT =", target) | 105 | print("SUT =", target) |
4543 | @@ -135,11 +133,11 @@ | |||
4544 | 135 | 133 | ||
4545 | 136 | def main(): | 134 | def main(): |
4546 | 137 | 135 | ||
4548 | 138 | intro_message = "Default config location is /etc/checkbox.d/me.cfg" | 136 | intro_message = "Default config location is /etc/xdg/bmc.cfg" |
4549 | 139 | parser = ArgumentParser(description=intro_message, | 137 | parser = ArgumentParser(description=intro_message, |
4550 | 140 | formatter_class=RawTextHelpFormatter) | 138 | formatter_class=RawTextHelpFormatter) |
4553 | 141 | parser.add_argument('--config', default="/etc/checkbox.d/me.cfg", | 139 | parser.add_argument('--config', default="/etc/checkbox.d/bmc.cfg", |
4554 | 142 | help="Supply config file for getting default credential") | 140 | help="Supply config file for getting authentication info") |
4555 | 143 | args = parser.parse_args() | 141 | args = parser.parse_args() |
4556 | 144 | return sel_entry_test(args) | 142 | return sel_entry_test(args) |
4557 | 145 | 143 | ||
4558 | 146 | 144 | ||
4559 | === added file 'bin/ipmi_sensors_ib' | |||
4560 | --- bin/ipmi_sensors_ib 1970-01-01 00:00:00 +0000 | |||
4561 | +++ bin/ipmi_sensors_ib 2015-08-14 22:03:31 +0000 | |||
4562 | @@ -0,0 +1,215 @@ | |||
4563 | 1 | #!/usr/bin/env python3 | ||
4564 | 2 | """ | ||
4565 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
4566 | 4 | Industrial Technology Research Institute | ||
4567 | 5 | |||
4568 | 6 | File Name | ||
4569 | 7 | ipmi_sensors_ib | ||
4570 | 8 | |||
4571 | 9 | Description | ||
4572 | 10 | 1. Use ipmitool/dcmitool to monitor analog sensors in SDR table through in-band access. | ||
4573 | 11 | 2. Criteria: the status of analog sensors should be "ok" and the data should not be null. | ||
4574 | 12 | |||
4575 | 13 | Authors | ||
4576 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
4577 | 15 | |||
4578 | 16 | This program is free software: you can redistribute it and/or modify | ||
4579 | 17 | it under the terms of the GNU General Public License version 3, | ||
4580 | 18 | as published by the Free Software Foundation. | ||
4581 | 19 | |||
4582 | 20 | This program is distributed in the hope that it will be useful, | ||
4583 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4584 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4585 | 23 | GNU General Public License for more details. | ||
4586 | 24 | |||
4587 | 25 | You should have received a copy of the GNU General Public License | ||
4588 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4589 | 27 | |||
4590 | 28 | """ | ||
4591 | 29 | import sys | ||
4592 | 30 | import time | ||
4593 | 31 | import re | ||
4594 | 32 | import configparser | ||
4595 | 33 | import shlex | ||
4596 | 34 | import subprocess | ||
4597 | 35 | import ast | ||
4598 | 36 | from argparse import ( | ||
4599 | 37 | ArgumentParser, | ||
4600 | 38 | RawTextHelpFormatter | ||
4601 | 39 | ) | ||
4602 | 40 | from subprocess import ( | ||
4603 | 41 | check_output, | ||
4604 | 42 | CalledProcessError | ||
4605 | 43 | ) | ||
4606 | 44 | |||
4607 | 45 | |||
4608 | 46 | def get_sdr(TOOL): | ||
4609 | 47 | cmd = "{} sdr".format(TOOL) | ||
4610 | 48 | sdr_return = subprocess.check_output(shlex.split(cmd), universal_newlines=True) | ||
4611 | 49 | return sdr_return | ||
4612 | 50 | |||
4613 | 51 | def parse_sdr(output): | ||
4614 | 52 | output = output.strip() | ||
4615 | 53 | output_1Line = output.split("\n") | ||
4616 | 54 | data = {} | ||
4617 | 55 | |||
4618 | 56 | for line in output_1Line: | ||
4619 | 57 | sub_value = {} | ||
4620 | 58 | string_list = line.split("|") | ||
4621 | 59 | name = string_list[0].strip() | ||
4622 | 60 | sensor_output = string_list[1].strip() | ||
4623 | 61 | sub_value.update({'output':sensor_output}) | ||
4624 | 62 | status = string_list[2].strip() | ||
4625 | 63 | sub_value.update({'status':status}) | ||
4626 | 64 | data.update({name:sub_value}) | ||
4627 | 65 | return data | ||
4628 | 66 | |||
4629 | 67 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
4630 | 68 | |||
4631 | 69 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
4632 | 70 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
4633 | 71 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
4634 | 72 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
4635 | 73 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
4636 | 74 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
4637 | 75 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
4638 | 76 | return str(CPU_temp)+' degrees C' | ||
4639 | 77 | else: | ||
4640 | 78 | return 'Error' | ||
4641 | 79 | else: | ||
4642 | 80 | return 'None' | ||
4643 | 81 | |||
4644 | 82 | def ipmi_sdr(args): | ||
4645 | 83 | |||
4646 | 84 | flag = 0 | ||
4647 | 85 | |||
4648 | 86 | tool_name = args.tool | ||
4649 | 87 | if not tool_name: | ||
4650 | 88 | print("No specified tool to use") | ||
4651 | 89 | return 99 | ||
4652 | 90 | |||
4653 | 91 | #IPMI/DCMI config file | ||
4654 | 92 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
4655 | 93 | if not "config" in vars(args): | ||
4656 | 94 | config_file = DEFAULT_CFG | ||
4657 | 95 | else: | ||
4658 | 96 | config_file = args.config | ||
4659 | 97 | config = configparser.RawConfigParser() | ||
4660 | 98 | |||
4661 | 99 | try: | ||
4662 | 100 | config.readfp(open(config_file)) | ||
4663 | 101 | except IOError: | ||
4664 | 102 | print("No config file found") | ||
4665 | 103 | return 10 | ||
4666 | 104 | |||
4667 | 105 | try: | ||
4668 | 106 | sensor_nick = config.options("Sensors") | ||
4669 | 107 | except configparser.NoSectionError: | ||
4670 | 108 | print("No Section: Sensors") | ||
4671 | 109 | return 20 | ||
4672 | 110 | |||
4673 | 111 | if sensor_nick: | ||
4674 | 112 | sensor_list = [] | ||
4675 | 113 | for id in sensor_nick: | ||
4676 | 114 | sensor_key = config.get("Sensors", id) | ||
4677 | 115 | if sensor_key: | ||
4678 | 116 | sensor_list.append(sensor_key) | ||
4679 | 117 | else: | ||
4680 | 118 | print("No Sensor ID specified in Config file") | ||
4681 | 119 | return 30 | ||
4682 | 120 | else: | ||
4683 | 121 | print("No key of Sensor ID specified in config file") | ||
4684 | 122 | return 40 | ||
4685 | 123 | |||
4686 | 124 | try: | ||
4687 | 125 | sensor_data = get_sdr(tool_name) | ||
4688 | 126 | time.sleep(5) | ||
4689 | 127 | except CalledProcessError as ipmi_exception: | ||
4690 | 128 | print("Failed executing ipmi, Reason: %s" % ipmi_exception) | ||
4691 | 129 | return 50 | ||
4692 | 130 | |||
4693 | 131 | try: | ||
4694 | 132 | data = parse_sdr(sensor_data) | ||
4695 | 133 | except: | ||
4696 | 134 | print("Parsing output of sdr table error") | ||
4697 | 135 | return 60 | ||
4698 | 136 | |||
4699 | 137 | need_data = {} | ||
4700 | 138 | for need_id in sensor_list: | ||
4701 | 139 | if data.get(need_id): | ||
4702 | 140 | need_value = data.get(need_id).get('output') | ||
4703 | 141 | need_data.update({need_id:need_value}) | ||
4704 | 142 | |||
4705 | 143 | if data.get(need_id).get('status') != 'ok': | ||
4706 | 144 | flag = 1 | ||
4707 | 145 | else: | ||
4708 | 146 | |||
4709 | 147 | try: | ||
4710 | 148 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
4711 | 149 | except configparser.NoOptionError: | ||
4712 | 150 | CPUx_Temp = '' | ||
4713 | 151 | |||
4714 | 152 | try: | ||
4715 | 153 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
4716 | 154 | except configparser.NoOptionError: | ||
4717 | 155 | CPUy_Temp = '' | ||
4718 | 156 | |||
4719 | 157 | if need_id == CPUx_Temp: | ||
4720 | 158 | |||
4721 | 159 | try: | ||
4722 | 160 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
4723 | 161 | except configparser.NoOptionError: | ||
4724 | 162 | PxTM = '' | ||
4725 | 163 | |||
4726 | 164 | try: | ||
4727 | 165 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
4728 | 166 | except configparser.NoOptionError: | ||
4729 | 167 | CPUx_Tjmax = '' | ||
4730 | 168 | |||
4731 | 169 | if PxTM and CPUx_Tjmax: | ||
4732 | 170 | need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)}) | ||
4733 | 171 | if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error': | ||
4734 | 172 | flag = 1 | ||
4735 | 173 | else: | ||
4736 | 174 | flag = 1 | ||
4737 | 175 | |||
4738 | 176 | elif need_id == CPUy_Temp: | ||
4739 | 177 | |||
4740 | 178 | try: | ||
4741 | 179 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
4742 | 180 | except configparser.NoOptionError: | ||
4743 | 181 | PyTM = '' | ||
4744 | 182 | |||
4745 | 183 | try: | ||
4746 | 184 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
4747 | 185 | except configparser.NoOptionError: | ||
4748 | 186 | CPUy_Tjmax = '' | ||
4749 | 187 | |||
4750 | 188 | |||
4751 | 189 | if PyTM and CPUy_Tjmax: | ||
4752 | 190 | need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)}) | ||
4753 | 191 | if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error': | ||
4754 | 192 | flag = 1 | ||
4755 | 193 | else: | ||
4756 | 194 | flag = 1 | ||
4757 | 195 | else: | ||
4758 | 196 | flag = 1 | ||
4759 | 197 | |||
4760 | 198 | print("%s: %s" %(need_id, need_data.get(need_id))) | ||
4761 | 199 | |||
4762 | 200 | if flag == 1: | ||
4763 | 201 | return 100 | ||
4764 | 202 | return 0 | ||
4765 | 203 | |||
4766 | 204 | def main(): | ||
4767 | 205 | |||
4768 | 206 | intro_message = "Default config location is /etc/checkbox.d/bmc.cfg" | ||
4769 | 207 | parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter) | ||
4770 | 208 | parser.add_argument('--config', type=str, default="/etc/checkbox.d/bmc.cfg", help="Supply config file for sensor IDs parameters") | ||
4771 | 209 | parser.add_argument('--tool', help="ipmitool or dcmitool") | ||
4772 | 210 | args = parser.parse_args() | ||
4773 | 211 | return ipmi_sdr(args) | ||
4774 | 212 | |||
4775 | 213 | if __name__ == "__main__": | ||
4776 | 214 | sys.exit(main()) | ||
4777 | 215 | |||
4778 | 0 | 216 | ||
4779 | === added file 'bin/ipmi_sensors_oob' | |||
4780 | --- bin/ipmi_sensors_oob 1970-01-01 00:00:00 +0000 | |||
4781 | +++ bin/ipmi_sensors_oob 2015-08-14 22:03:31 +0000 | |||
4782 | @@ -0,0 +1,240 @@ | |||
4783 | 1 | #!/usr/bin/env python3 | ||
4784 | 2 | """ | ||
4785 | 3 | Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications | ||
4786 | 4 | Industrial Technology Research Institute | ||
4787 | 5 | |||
4788 | 6 | File Name | ||
4789 | 7 | ipmi_sensors_oob | ||
4790 | 8 | |||
4791 | 9 | Description | ||
4792 | 10 | 1. Use ipmitool to monitor analog sensors in SDR table through OOB access. | ||
4793 | 11 | 2. Criteria: the status of analog sensors should be "ok" and the data should not be null. | ||
4794 | 12 | |||
4795 | 13 | Authors | ||
4796 | 14 | Sophia Wu <Sophia.Wu@itri.org.tw> | ||
4797 | 15 | |||
4798 | 16 | This program is free software: you can redistribute it and/or modify | ||
4799 | 17 | it under the terms of the GNU General Public License version 3, | ||
4800 | 18 | as published by the Free Software Foundation. | ||
4801 | 19 | |||
4802 | 20 | This program is distributed in the hope that it will be useful, | ||
4803 | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4804 | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4805 | 23 | GNU General Public License for more details. | ||
4806 | 24 | |||
4807 | 25 | You should have received a copy of the GNU General Public License | ||
4808 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
4809 | 27 | |||
4810 | 28 | """ | ||
4811 | 29 | import sys | ||
4812 | 30 | import time | ||
4813 | 31 | import re | ||
4814 | 32 | import configparser | ||
4815 | 33 | import shlex | ||
4816 | 34 | import subprocess | ||
4817 | 35 | import ast | ||
4818 | 36 | from argparse import ( | ||
4819 | 37 | ArgumentParser, | ||
4820 | 38 | RawTextHelpFormatter | ||
4821 | 39 | ) | ||
4822 | 40 | from subprocess import ( | ||
4823 | 41 | check_output, | ||
4824 | 42 | CalledProcessError | ||
4825 | 43 | ) | ||
4826 | 44 | |||
4827 | 45 | def get_sdr_remote(host_ip, user, password): | ||
4828 | 46 | cmd = "ipmitool -H {} -U {} -P {} sdr".format(host_ip, user, password) | ||
4829 | 47 | sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT, | ||
4830 | 48 | universal_newlines=True) | ||
4831 | 49 | return sdr_return | ||
4832 | 50 | |||
4833 | 51 | def parse_sdr(output): | ||
4834 | 52 | output = output.strip() | ||
4835 | 53 | output_1Line = output.split("\n") | ||
4836 | 54 | data = {} | ||
4837 | 55 | |||
4838 | 56 | for line in output_1Line: | ||
4839 | 57 | sub_value = {} | ||
4840 | 58 | string_list = line.split("|") | ||
4841 | 59 | name = string_list[0].strip() | ||
4842 | 60 | sensor_output = string_list[1].strip() | ||
4843 | 61 | sub_value.update({'output':sensor_output}) | ||
4844 | 62 | status = string_list[2].strip() | ||
4845 | 63 | sub_value.update({'status':status}) | ||
4846 | 64 | data.update({name:sub_value}) | ||
4847 | 65 | return data | ||
4848 | 66 | |||
4849 | 67 | def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id): | ||
4850 | 68 | |||
4851 | 69 | if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id): | ||
4852 | 70 | if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok': | ||
4853 | 71 | P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output') | ||
4854 | 72 | CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output') | ||
4855 | 73 | P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0) | ||
4856 | 74 | CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0) | ||
4857 | 75 | CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax) | ||
4858 | 76 | return str(CPU_temp)+' degrees C' | ||
4859 | 77 | else: | ||
4860 | 78 | return 'Error' | ||
4861 | 79 | else: | ||
4862 | 80 | return 'None' | ||
4863 | 81 | |||
4864 | 82 | def ipmi_sdr(args): | ||
4865 | 83 | |||
4866 | 84 | flag = 0 | ||
4867 | 85 | #IPMI config file | ||
4868 | 86 | DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg" | ||
4869 | 87 | if not "config" in vars(args): | ||
4870 | 88 | config_file = DEFAULT_CFG | ||
4871 | 89 | else: | ||
4872 | 90 | config_file = args.config | ||
4873 | 91 | |||
4874 | 92 | config = configparser.RawConfigParser() | ||
4875 | 93 | |||
4876 | 94 | try: | ||
4877 | 95 | config.readfp(open(config_file)) | ||
4878 | 96 | except IOError: | ||
4879 | 97 | print("No config file found") | ||
4880 | 98 | return 10 | ||
4881 | 99 | |||
4882 | 100 | try: | ||
4883 | 101 | sensor_nick = config.options("Sensors") | ||
4884 | 102 | except configparser.NoSectionError: | ||
4885 | 103 | print("No Section: Sensors") | ||
4886 | 104 | return 20 | ||
4887 | 105 | |||
4888 | 106 | if sensor_nick: | ||
4889 | 107 | sensor_list = [] | ||
4890 | 108 | for id in sensor_nick: | ||
4891 | 109 | sensor_key = config.get("Sensors", id) | ||
4892 | 110 | if sensor_key: | ||
4893 | 111 | sensor_list.append(sensor_key) | ||
4894 | 112 | else: | ||
4895 | 113 | print("No Sensor ID specified in Config file") | ||
4896 | 114 | return 30 | ||
4897 | 115 | else: | ||
4898 | 116 | print("No key of Sensor ID specified in config file") | ||
4899 | 117 | return 40 | ||
4900 | 118 | |||
4901 | 119 | try: | ||
4902 | 120 | targets_options = config.options('Targets') | ||
4903 | 121 | targets_list = [] | ||
4904 | 122 | for target_key in targets_options: | ||
4905 | 123 | targets_list.append(config.get('Targets', target_key)) | ||
4906 | 124 | if not targets_list: | ||
4907 | 125 | print("Invalid or Empty targets") | ||
4908 | 126 | return 60 | ||
4909 | 127 | except configparser.Error: | ||
4910 | 128 | print("Invalid or Empty targets") | ||
4911 | 129 | return 60 | ||
4912 | 130 | |||
4913 | 131 | try: | ||
4914 | 132 | user_value = config.get("Account", "USER") | ||
4915 | 133 | password_value = config.get("Account", "PASSWORD") | ||
4916 | 134 | except configparser.NoOptionError: | ||
4917 | 135 | print("Invalid or Empty credential info") | ||
4918 | 136 | return 70 | ||
4919 | 137 | |||
4920 | 138 | for tg in targets_list: | ||
4921 | 139 | |||
4922 | 140 | if not tg or not user_value or not password_value: | ||
4923 | 141 | print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access") | ||
4924 | 142 | return 80 | ||
4925 | 143 | else: | ||
4926 | 144 | |||
4927 | 145 | print("SUT =", tg) | ||
4928 | 146 | print("USER =", user_value) | ||
4929 | 147 | print("PASSWORD =", password_value) | ||
4930 | 148 | |||
4931 | 149 | try: | ||
4932 | 150 | sensor_data = get_sdr_remote(tg, user_value, password_value) | ||
4933 | 151 | time.sleep(5) | ||
4934 | 152 | except CalledProcessError as ipmi_exception: | ||
4935 | 153 | print("Failed executing ipmi, Reason: %s" % ipmi_exception) | ||
4936 | 154 | return 50 | ||
4937 | 155 | |||
4938 | 156 | try: | ||
4939 | 157 | data = parse_sdr(sensor_data) | ||
4940 | 158 | except: | ||
4941 | 159 | print("Parsing output of sdr table error") | ||
4942 | 160 | flag = 1 | ||
4943 | 161 | continue | ||
4944 | 162 | |||
4945 | 163 | need_data = {} | ||
4946 | 164 | for need_id in sensor_list: | ||
4947 | 165 | |||
4948 | 166 | if data.get(need_id): | ||
4949 | 167 | need_value = data.get(need_id).get('output') | ||
4950 | 168 | need_data.update({need_id:need_value}) | ||
4951 | 169 | |||
4952 | 170 | if data.get(need_id).get('status') != 'ok': | ||
4953 | 171 | flag = 1 | ||
4954 | 172 | else: | ||
4955 | 173 | |||
4956 | 174 | try: | ||
4957 | 175 | CPUx_Temp = config.get("Sensors", "CPUx") | ||
4958 | 176 | except configparser.NoOptionError: | ||
4959 | 177 | CPUx_Temp = '' | ||
4960 | 178 | |||
4961 | 179 | try: | ||
4962 | 180 | CPUy_Temp = config.get("Sensors", "CPUy") | ||
4963 | 181 | except configparser.NoOptionError: | ||
4964 | 182 | CPUy_Temp = '' | ||
4965 | 183 | |||
4966 | 184 | if need_id == CPUx_Temp: | ||
4967 | 185 | |||
4968 | 186 | try: | ||
4969 | 187 | PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin") | ||
4970 | 188 | except configparser.NoOptionError: | ||
4971 | 189 | PxTM = '' | ||
4972 | 190 | |||
4973 | 191 | try: | ||
4974 | 192 | CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax") | ||
4975 | 193 | except configparser.NoOptionError: | ||
4976 | 194 | CPUx_Tjmax = '' | ||
4977 | 195 | |||
4978 | 196 | if PxTM and CPUx_Tjmax: | ||
4979 | 197 | need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)}) | ||
4980 | 198 | if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error': | ||
4981 | 199 | flag = 1 | ||
4982 | 200 | else: | ||
4983 | 201 | flag = 1 | ||
4984 | 202 | |||
4985 | 203 | elif need_id == CPUy_Temp: | ||
4986 | 204 | |||
4987 | 205 | try: | ||
4988 | 206 | PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin") | ||
4989 | 207 | except configparser.NoOptionError: | ||
4990 | 208 | PyTM = '' | ||
4991 | 209 | |||
4992 | 210 | try: | ||
4993 | 211 | CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax") | ||
4994 | 212 | except configparser.NoOptionError: | ||
4995 | 213 | CPUy_Tjmax = '' | ||
4996 | 214 | |||
4997 | 215 | if PyTM and CPUy_Tjmax: | ||
4998 | 216 | need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)}) | ||
4999 | 217 | if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error': | ||
5000 | 218 | flag = 1 |
The diff has been truncated for viewing.
self approve... merge them all, let Jeff sort them out.