Merge lp:~bladernr/opencompute/merge-github-junk into lp:opencompute/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
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Review via email: mp+268148@code.launchpad.net

Description of the change

Merges in all the stuff ITRI put into github.

To post a comment you must log in.
Revision history for this message
Jeff Lane  (bladernr) wrote :

self approve... merge them all, let Jeff sort them out.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'README.tips'
--- README.tips 1970-01-01 00:00:00 +0000
+++ README.tips 2015-08-14 22:03:31 +0000
@@ -0,0 +1,121 @@
1############User manual and installation guide################
2Note: Please use Ubuntu 12.04 or lately.
3
4######[Run Checkbox]######
5$ opencompute-certification
6Note, sudo is not necessary, you should be prompted for a root password.
7
8######[Important directory]######
9Runtime Logs: $HOME/.cache/plainbox/
10Results: $HOME/.local/plainbox/
11
12##############################################################################################
13Before running ME/BMC test, please fill in related information in configuration file.
14Each section exists in configuration file has its own purpose.
15The following will explain how to fill in settings in each section.
16
17Note:
181. Path of configuration file: /etc/xdg/bmc.cfg or /etc/xdg/me.cfg
192. Without these settings pre-setting in configuration file, you won't start tests smoothly.
20
21##############################################################################################
22
23
24############User manual of each section################
25
26######[Targets]######
27For remotely access via IPMI/DCMI, you need to fill in ME/BMC IP address of SUT.
28For example, ME/BMC IP: 10.2.107.5
29[Targets]
30Target1: 10.2.107.5
31
32######[Account]######
33For remotely access via IPMI/DCMI, you need to fill in ME/BMC account here.
34For example, USER/PASSWORD: OCP/OCP. Then, the settings in this section must be
35[Account]
36USER: OCP
37PASSWORD: OCP
38
39######[Sensors] and [SensorsForCPUTemp]######
40For thermal tests of ME/BMC sensors, you need to check and set Sensor ID before starting tests.
41Refers to TC-001-0006-Hardware_Monitoring.txt.in,
42there are five kinds of sensors to monitor, so please write corresponding sensor ID to this field.
43For example, the sensor ID related to these five kinds of sensors on Winterfell
44are "outlet Temp", "inlet Temp", "PCH Temp", "P0 DIMM Temp", "P1 DIMM Temp", "P0 Therm Margin",
45"P1 Therm Margin", "CPU0 Tjmax", "CPU1 Tjmax"
46[Sensors]
47Outlet: Outlet Temp
48Inlet: Inlet Temp
49PCH: PCH Temp
50Px DIMM: P0 DIMM Temp
51Py DIMM: P1 DIMM Temp
52CPUx: CPU0 Temp
53CPUy: CPU1 Temp
54
55Note:
56 Case1. There are CPU sensors to monitor CPU temperature directly.
57 You just fill in sensor IDs behind key "CPUx" and "CPUy" and
58 don't care the section [SensorsForCPUTemp] at all.
59 Case2. There are no CPU sensors to monitor CPU temperature directly.
60 CPUx temperature is derived from Px Therm Margin and CPUx Tjmax.
61 ie,"CPU0 Temp" = "P0 Therm Margin" + "CPU0 Tjmax"
62 (It still requires "PU0 Temp" marked behind key "CPUx")
63 Besides, please also fill in "P0 Therm Margin", "PU0 Tjmax"
64 to corresponding section presented as below.
65 [SensorsForCPUTemp]
66 Px Therm Margin: P0 Therm Margin
67 Py Therm Margin: P1 Therm Margin
68 CPUx Tjmax: CPU0 Tjmax
69 CPUy Tjmax: CPU1 Tjmax
70
71
72######[SensorsForSampling]######
73Refers to test case TC-002-0008-001-Temp_Sampling_Increment, the description is to retrieve CPU and intake temperature 30 times.
74For example, the related sensor IDs on Winterfell are "Inlet Temp", "P0 Therm Margin", "P1 Therm Margin", "CPU0 Tjmax", "CPU1 Tjmax".
75[SensorsForSampling]
76Inlet: Inlet Temp
77CPUx: CPU0 Temp
78CPUy: CPU1 Temp
79Note: if the CPU0 temperature derives from "P0 therm Margin" and "CPU0 Tjmax",
80you have to give a string "CPU0 temp" behind key "CPUx". And also remember to fill in the sensor ID in section [SensorsForCPUTemp].
81Please refer to section [Sensors].
82
83
84##############################################################################################
85The following four sections [Admin Level], [Operator Level], [User Level] and [Add User Test] are for User level test.
86Please refer to TC-002-0009-User_Levels.txt.in. In these four sections, you don't need to modify settings here.
87
88######[Admin Level]######
89[Admin Level]
90ADMIN_NAME: ccma_admin
91ADMIN_PASSWD: ccma_admin
92priv_level: 4
93user_id: 3
94channel_num: 1
95Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test.
96
97######[Operator Level]######
98[Operator Level]
99OPER_NAME: ccma_oper
100OPER_PASSWD: ccma_oper
101priv_level: 3
102user_id: 4
103channel_num: 1
104Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test.
105
106######[User Level]######
107[User Level]
108USER_NAME: ccma_user
109USER_PASSWD: ccma_user
110priv_level: 2
111user_id: 5
112channel_num: 1
113Note: But please set the settings in the section using ipmitool/dcmitool manually on SUT before starting user level test.
114
115
116######[Add User Test]######
117[Add User Test]
118NEW_USER_NAME: ccma_test
119NEW_USER_ID: 6
120Note: Do not need to create this account manually
121
0122
=== added file 'bin/bad_block_test'
--- bin/bad_block_test 1970-01-01 00:00:00 +0000
+++ bin/bad_block_test 2015-08-14 22:03:31 +0000
@@ -0,0 +1,72 @@
1#!/usr/bin/env python3
2
3"""
4Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
5Industrial Technology Research Institute
6
7It is NOT YET officially approved by OCP.
8
9bad_block_test
10 1. Use badblocks command to perform a full disk bad block scan
11 with given pattern.
12 2. The duration of the test is under 24 hours.
13 3. Criteria: pass if no hard disk error.
14
15Authors
16 Nelson Chu <Nelson.Chu@itri.org.tw>
17
18This program is free software: you can redistribute it and/or modify
19it under the terms of the GNU General Public License version 3,
20as published by the Free Software Foundation.
21
22This program is distributed in the hope that it will be useful,
23but WITHOUT ANY WARRANTY; without even the implied warranty of
24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25GNU General Public License for more details.
26
27You should have received a copy of the GNU General Public License
28along with this program. If not, see <http://www.gnu.org/licenses/>.
29
30"""
31
32import os
33import re
34import sys
35from subprocess import check_output, STDOUT
36from argparse import ArgumentParser, RawTextHelpFormatter
37
38def run(pattern, device):
39 return_code = 0
40 command = "badblocks -wsvf -t {0} {1}".format(pattern, device)
41
42 try:
43 with open(os.devnull, "w") as NULL:
44 output = check_output(command, stderr=STDOUT, shell=True)
45 output = output.decode('utf-8')
46 except Exception as e:
47 print(e.output.decode('utf-8'))
48 return_code = 10
49 return return_code
50
51 bad_blocks_match = re.search(r'\n(Pass completed\,\s(\d+)\s.*)\n$', output)
52 if bad_blocks_match:
53 print(bad_blocks_match.group(1))
54 if int(bad_blocks_match.group(2)) != 0:
55 return_code = 20
56 else:
57 print("Cannot parse badblocks output.")
58 return_code = 30
59 return return_code
60
61def main():
62 parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
63 parser.add_argument('-t', '--pattern', type=str, required=True,
64 help=("Specify a test pattern to be read \n"
65 + "(and written) to disk blocks."))
66 parser.add_argument('-d', '--device', type=str, required=True,
67 help=("The device which tests in badblocks."))
68 args = parser.parse_args()
69 return run(args.pattern, args.device)
70
71if __name__ == '__main__':
72 sys.exit(main())
073
=== modified file 'bin/bios_info'
--- bin/bios_info 2015-03-03 15:59:42 +0000
+++ bin/bios_info 2015-08-14 22:03:31 +0000
@@ -3,6 +3,8 @@
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute4Industrial Technology Research Institute
55
6It is NOT YET officially approved by OCP.
7
6bios_info8bios_info
7 1. Use lshw command to gather BIOS information.9 1. Use lshw command to gather BIOS information.
8 2. The program will output BIOS vendor, version and release date.10 2. The program will output BIOS vendor, version and release date.
911
=== added file 'bin/block_device_resource'
--- bin/block_device_resource 1970-01-01 00:00:00 +0000
+++ bin/block_device_resource 2015-08-14 22:03:31 +0000
@@ -0,0 +1,80 @@
1#!/usr/bin/env python3
2
3import os
4import re
5from glob import glob
6
7rootdir_pattern = re.compile('^.*?/devices')
8
9def device_state(name):
10 """
11 Follow pmount policy to determine whether a device is removable or internal.
12 """
13 with open('/sys/block/%s/device/block/%s/removable' % (name, name)) as f:
14 if f.read(1) == '1':
15 return 'removable'
16
17 path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name))
18 hotplug_buses = ("usb", "ieee1394", "mmc", "pcmcia", "firewire")
19 for bus in hotplug_buses:
20 if os.path.exists('/sys/bus/%s' % bus):
21 for device_bus in os.listdir('/sys/bus/%s/devices' % bus):
22 device_link = rootdir_pattern.sub('', os.readlink(
23 '/sys/bus/%s/devices/%s' % (bus, device_bus)))
24 if re.search(device_link, path):
25 return 'removable'
26
27 return 'internal'
28
29
30def usb_support(name, version):
31 """
32 Check the USB specification number for both hub port and device
33 """
34 path = rootdir_pattern.sub('', os.readlink('/sys/block/%s' % name))
35
36 # Remove the usb config.interface part of the path
37 m = re.match('((.*usb\d+).*\/)\d-[\d\.:\-]+\/.*', path)
38 if m:
39 device_path = m.group(1)
40 hub_port_path = m.group(2)
41
42 # Check the highest version of USB the device supports
43 with open('/sys/devices/%s/version' %device_path) as f:
44 if float(f.readline()) < version:
45 return 'unsupported'
46
47 # Check the highest version of USB the hub supports
48 with open('/sys/devices/%s/version' %hub_port_path) as f:
49 if float(f.readline()) < version:
50 return 'unsupported'
51
52 return 'supported'
53
54 return 'unsupported'
55
56def device_rotation(name):
57 with open('/sys/block/%s/device/block/%s/queue/rotational' % (name, name)) as f:
58 if f.read(1) == '1':
59 return 'yes'
60
61 return 'no'
62
63for path in glob('/sys/block/*/device'):
64 name = re.sub('.*/(.*?)/device', '\g<1>', path)
65 state = device_state(name)
66 usb2 = usb_support(name, 2.00)
67 usb3 = usb_support(name, 3.00)
68 rotation = device_rotation(name)
69 # FIXME: Remove leading block device name when the requirements
70 # checking code in Checkbox allows it
71 print("""\
72%(name)s_state: %(state)s
73%(name)s_usb2: %(usb2)s
74%(name)s_usb3: %(usb3)s
75%(name)s_rotation: %(rotation)s
76""" % {"name": name,
77 "state": state,
78 "usb2": usb2,
79 "usb3": usb3,
80 "rotation": rotation})
081
=== modified file 'bin/check_sata_port'
--- bin/check_sata_port 2015-03-03 15:59:42 +0000
+++ bin/check_sata_port 2015-08-14 22:03:31 +0000
@@ -3,6 +3,8 @@
3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4# Industrial Technology Research Institute4# Industrial Technology Research Institute
5#5#
6# It is NOT YET officially approved by OCP.
7#
6# check_sata_port8# check_sata_port
7# 1. Use dmesg command to gather SATA information.9# 1. Use dmesg command to gather SATA information.
8# 2. Criteria: SATA port speed up to 6.0Gps.10# 2. Criteria: SATA port speed up to 6.0Gps.
911
=== added file 'bin/check_sata_port_leopard'
--- bin/check_sata_port_leopard 1970-01-01 00:00:00 +0000
+++ bin/check_sata_port_leopard 2015-08-14 22:03:31 +0000
@@ -0,0 +1,38 @@
1#!/bin/bash
2#
3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4# Industrial Technology Research Institute
5#
6# It is NOT YET officially approved by OCP.
7#
8# check_sata_port
9# 1. Retrieve dmesg log to gather SATA information.
10# 2. Criteria: SATA port speed up to 6.0Gps.
11#
12# Authors
13# Nelson Chu <Nelson.Chu@itri.org.tw>
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License version 3,
17# as published by the Free Software Foundation.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program. If not, see <http://www.gnu.org/licenses/>.
26#
27
28output=(`cat /var/log/dmesg |grep -i "SATA link up"| awk '{print $7}'`)
29
30for ((i=0; i<${#output[@]}; i++)); do
31 if [ "$output" != "6.0" ]; then
32 echo "Do not support SATA 6Gps ports"
33 exit 1
34 fi
35done
36
37echo "Support SATA 6Gps ports"
38exit 0
039
=== modified file 'bin/check_usb_port'
--- bin/check_usb_port 2015-03-03 15:59:42 +0000
+++ bin/check_usb_port 2015-08-14 22:03:31 +0000
@@ -3,6 +3,8 @@
3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4# Industrial Technology Research Institute4# Industrial Technology Research Institute
5#5#
6# It is NOT YET officially approved by OCP.
7#
6# check_usb_port8# check_usb_port
7# 1. Use dmesg command to gather USB information.9# 1. Use dmesg command to gather USB information.
8# 2. Criteria: USB version must be 2.0.10# 2. Criteria: USB version must be 2.0.
911
=== added file 'bin/check_usb_port_leopard'
--- bin/check_usb_port_leopard 1970-01-01 00:00:00 +0000
+++ bin/check_usb_port_leopard 2015-08-14 22:03:31 +0000
@@ -0,0 +1,43 @@
1#!/bin/bash
2#
3# Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4# Industrial Technology Research Institute
5#
6# It is NOT YET officially approved by OCP.
7#
8# check_usb_port
9# 1. Retrieve dmesg log to gather USB information.
10# 2. Criteria: USB version must be 2.0 or higher.
11#
12# Authors
13# Nelson Chu <Nelson.Chu@itri.org.tw>
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License version 3,
17# as published by the Free Software Foundation.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program. If not, see <http://www.gnu.org/licenses/>.
26#
27
28support_usb_3=`cat /var/log/dmesg |grep -i "xhci_hcd" -c`
29
30if [ "$support_usb_3" -gt "0" ]; then
31 echo "Support USB 3.0 ports."
32 exit 0
33fi
34
35output=`cat /var/log/dmesg |grep -i ehci_hcd:| awk '{print $5}'`
36
37if [ "$output" = "2.0" ]; then
38 echo "Support USB 2.0 ports."
39 exit 0
40fi
41
42echo "Do not support USB 2.0 ports or higher."
43exit 1
044
=== modified file 'bin/cpu_info'
--- bin/cpu_info 2015-03-03 15:59:42 +0000
+++ bin/cpu_info 2015-08-14 22:03:31 +0000
@@ -3,6 +3,8 @@
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications 3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute4Industrial Technology Research Institute
55
6It is NOT YET officially approved by OCP.
7
6cpu_info8cpu_info
7 Use lshw command to gather CPU information.9 Use lshw command to gather CPU information.
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.
911
=== added file 'bin/cpu_info_leopard'
--- bin/cpu_info_leopard 1970-01-01 00:00:00 +0000
+++ bin/cpu_info_leopard 2015-08-14 22:03:31 +0000
@@ -0,0 +1,83 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6It is NOT YET officially approved by OCP.
7
8cpu_info
9 Use dmidecode command to gather CPU information.
10 The program will output CPU model and L1, L2, L3 cache size.
11 Criteria: CPU model and product family must match user's input.
12
13Authors
14 Nelson Chu <Nelson.Chu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29
30import os
31import re
32import sys
33import xml.etree.ElementTree as ET
34from subprocess import check_output
35from argparse import ArgumentParser, RawTextHelpFormatter
36
37def run(product, family):
38 command = "dmidecode -t processor |grep -E 'Version|Cache'"
39 with open(os.devnull, 'w') as NULL:
40 output = check_output(command, stderr=NULL, shell=True)
41 output = output.decode('utf-8').strip()
42
43 cpu_attr = []
44 for item in output.split('\n'):
45 cpu_attr.append(item.strip())
46
47 for attr in cpu_attr:
48 if attr.startswith("Version"):
49 processor = attr.split(':')[1].strip()
50 print(processor)
51 match = re.search(product + '.*' + family, processor)
52 if not match:
53 print("Fail: Cannot match CPU %s %s family." %(product, family)
54 ,file=sys.stderr)
55 return 1
56 else:
57 cache_handle = attr.split(':')[1].strip()
58 command = "dmidecode -t cache|grep -a6 {0}".format(cache_handle) +\
59 "|grep -E 'Socket Designation|Installed Size'"
60 with open(os.devnull, 'w') as NULL:
61 output = check_output(command, stderr=NULL, shell=True)
62 output = output.decode('utf-8').strip()
63 print(output.split('\n')[0].split(':')[1].strip(),":", end="")
64 print(output.split('\n')[1].split(':')[1].strip())
65
66 return 0
67
68def main():
69 parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
70
71 parser.add_argument('-p', '--product', type=str, required=True,
72 help=("The CPU product name. [Example: Xeon]"))
73 parser.add_argument('-f', '--family', type=str, required=True,
74 help=("Processor family. [Example: E5]"))
75
76 args = parser.parse_args()
77
78 product = args.product.title()
79 family = args.family.title()
80 return run(product, family)
81
82if __name__ == '__main__':
83 sys.exit(main())
084
=== added file 'bin/create_raid'
--- bin/create_raid 1970-01-01 00:00:00 +0000
+++ bin/create_raid 2015-08-14 22:03:31 +0000
@@ -0,0 +1,140 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6It is NOT YET officially approved by OCP.
7
8create_raid
9 Use megacli command to build user desired RAID on JBOD.
10
11 Warning: Make sure there is no RAID configuration in LSI RAID card
12 before this program is performed.
13
14Authors
15 Nelson Chu <Nelson.Chu@itri.org.tw>
16
17This program is free software: you can redistribute it and/or modify
18it under the terms of the GNU General Public License version 3,
19as published by the Free Software Foundation.
20
21This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program. If not, see <http://www.gnu.org/licenses/>.
28
29"""
30
31import os
32import re
33import sys
34from time import sleep
35from subprocess import check_output, STDOUT, CalledProcessError
36from argparse import ArgumentParser, RawTextHelpFormatter
37
38def get_adapter():
39 """
40 Gather all adapter number if there are multiple RAID cards.
41 """
42
43 command = 'megacli -CfgDsply -Aall|grep Adapter'
44 adapter_list = []
45
46 adapter_info = check_output(command, shell=True)
47 adapter_info = adapter_info.decode('utf-8')
48
49 for adapter in adapter_info.strip().split('\n'):
50 adapter_list.append(adapter.strip().split(' ')[-1])
51 return adapter_list
52
53
54def get_all_disk(adapter):
55 """
56 Gather all disks Enclosure and Slot number, and make a
57 Enclosure:Slot pair list.
58 """
59
60 command = 'megacli -PDList -A{0}'.format(adapter) \
61 + '|grep -E "Enclosure Device ID|Slot Number"'
62
63 disk_list = []
64 disk_info = check_output(command, shell=True)
65 disk_info = disk_info.decode('utf-8')
66
67 for line in disk_info.strip().split('\n'):
68 if line.startswith('Enclosure'):
69 match = re.search(r'\d+', line)
70 disk_list.append(match.group(0))
71 if line.startswith('Slot'):
72 match = re.search(r'\d+', line)
73 enclosure = disk_list.pop()
74 E_S = '%s:%s' %(enclosure, match.group(0))
75 disk_list.append(E_S)
76 return disk_list
77
78
79def build_raid(raid_type, adapter, disk_list):
80 """
81 Use all disks creatd RAID.
82 If RAID type is 6 then set last disk as hot spare.
83 """
84
85 if raid_type == 0:
86 disk = ','.join(disk_list)
87 command = 'megacli -CfgLDadd -r{0} [{1}] WB Direct -a{2}'.format(
88 raid_type, disk, adapter)
89
90 if raid_type == 6:
91 # use the last disk as hot spare
92 spare = disk_list.pop()
93
94 disk = ','.join(disk_list)
95 command = 'megacli -CfgLDadd -r{0} [{1}] WB Direct -Hsp[{2}] -a{3}'.format(
96 raid_type, disk, spare, adapter)
97
98 output = check_output(command, stderr=STDOUT, shell=True)
99 output = output.decode('utf-8')
100 # wait for raid created
101 sleep(5)
102 print(output)
103
104
105def main():
106 parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
107 parser.add_argument('-t', '--type', type=int, required=True,
108 help=("The RAID type which want to create. "
109 "[Example: 0 or 6]"))
110 args = parser.parse_args()
111 knox_dict = {}
112
113 # get RAID card adapter number
114 try:
115 adapter_list = get_adapter()
116 except CalledProcessError as e:
117 print(e.output.decode('utf-8'))
118 return 10
119
120 # get all disks in JBOD
121 try:
122 for adapter in adapter_list:
123 knox_dict[adapter] = get_all_disk(adapter)
124 except CalledProcessError as e:
125 print(e.output.decode('utf-8'))
126 return 20
127
128 # use all HDDs to build RAID
129 try:
130 for adapter, disk_list in knox_dict.items():
131 build_raid(args.type, adapter, disk_list)
132 except CalledProcessError as e:
133 print(e.output.decode('utf-8'))
134 return 30
135
136 return 0
137
138
139if __name__ == '__main__':
140 sys.exit(main())
0141
=== added file 'bin/dcmi_inventory'
--- bin/dcmi_inventory 1970-01-01 00:00:00 +0000
+++ bin/dcmi_inventory 2015-08-14 22:03:31 +0000
@@ -0,0 +1,136 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_inventory
8 1. Use dcmitool to collect inventory information including Asset Tag, Device ID, System GUI, Firmware/Software Information, Management Controller ID
9 2. Criteria: All information mentioned above must not should not be null
10Authors
11 Sophia Wu <Sophia.Wu@itri.org.tw>
12
13This program is free software: you can redistribute it and/or modify
14it under the terms of the GNU General Public License version 3,
15as published by the Free Software Foundation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25"""
26
27import sys
28import time
29import shlex
30import subprocess
31import re
32import subprocess
33from subprocess import (
34 CalledProcessError,
35 check_call,
36 check_output
37)
38
39def get_asset_tag():
40
41 try:
42 cmd = 'dcmitool dcmi asset_tag'
43 dcmi_asset_tag_return = check_output(shlex.split(cmd), universal_newlines=True)
44 time.sleep(5)
45 except CalledProcessError as command_exception:
46 print("Failed executing dcmi command for getting asset tag. Reason:%s" % command_exception)
47
48 try:
49 asset_tag = re.search(r'Asset tag\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_asset_tag_return)
50 if asset_tag == None:
51 return 'Error'
52 return asset_tag.group(1).strip()
53 except:
54 return 'Error'
55
56def get_guid():
57
58 try:
59 cmd = 'dcmitool mc guid'
60 dcmi_guid_return = check_output(shlex.split(cmd), universal_newlines=True)
61 time.sleep(5)
62 except CalledProcessError as command_exception:
63 print("Failed executing dcmi command for getting guid. Reason:%s" % command_exception)
64
65 try:
66 mcguid = re.search(r'System GUID\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_guid_return)
67 if mcguid == None:
68 return 'Error'
69 return mcguid.group(1).strip()
70 except:
71 return 'Error'
72
73def get_mcid():
74
75 try:
76 cmd = 'dcmitool dcmi get_mc_id_string'
77 dcmi_mcid_return = check_output(shlex.split(cmd), universal_newlines=True)
78 time.sleep(5)
79 except CalledProcessError as command_exception:
80 print("Failed executing dcmi command for getting mc id. Reason:%s" % command_exception)
81
82 try:
83 mcid = re.search(r'Get Management Controller Identifier String\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcid_return)
84 if mcid == None:
85 return 'Error'
86 return mcid.group(1).strip()
87 except:
88 return 'Error'
89
90def get_mcinfo():
91
92 try:
93 cmd = 'dcmitool mc info'
94 dcmi_mcinfo_return = check_output(shlex.split(cmd), universal_newlines=True)
95 time.sleep(5)
96 except CalledProcessError as command_exception:
97 print("Failed executing dcmi command for getting mc info. Reason:%s" % command_exception)
98
99 try:
100 deviceid = re.search(r'Device ID\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcinfo_return)
101 Manufac = re.search(r'Manufacturer Name\s*:\s*([a-zA-Z-._ ]+)', dcmi_mcinfo_return)
102 Firm = re.search(r'Firmware Revision\s+\s*:\s*([a-zA-Z0-9-._ ]+)', dcmi_mcinfo_return)
103
104 if deviceid == None or Manufac == None or Firm == None:
105 return 'Error', 'Error', 'Error'
106 return (deviceid.group(1).strip(), Manufac.group(1).strip(), Firm.group(1).strip())
107 except:
108 return 'Error', 'Error', 'Error'
109
110def main():
111
112 flag = 0
113 inventory_dict = {}
114 inventory_list = ['Asset Tag', 'System GUID', 'Get Management Controller Identifier String', 'Device ID', 'Manufacturer Name', 'Firmware Revision']
115 Device_ID, Manufacturer, Firmware = get_mcinfo()
116 inventory_dict.update({'Asset Tag':get_asset_tag()})
117 inventory_dict.update({'System GUID':get_guid()})
118 inventory_dict.update({'Get Management Controller Identifier String':get_mcid()})
119 inventory_dict.update({'Device ID':Device_ID})
120 inventory_dict.update({'Manufacturer Name':Manufacturer})
121 inventory_dict.update({'Firmware Revision':Firmware})
122
123 for item in inventory_list:
124 if inventory_dict.get(item) == 'Error':
125 flag = 1
126 else:
127 print("{}: {}".format(item, inventory_dict.get(item)))
128
129 if flag == 1:
130 return 1
131 return 0
132
133if __name__ == '__main__':
134 sys.exit(main())
135
136
0137
=== added file 'bin/dcmi_power_off_on'
--- bin/dcmi_power_off_on 1970-01-01 00:00:00 +0000
+++ bin/dcmi_power_off_on 2015-08-14 22:03:31 +0000
@@ -0,0 +1,190 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_power_off_on
8 Use dcmitool out-of-band access to turn on/off the SUT
9
10Authors
11 Sophia Wu <Sophia.Wu@itri.org.tw>
12
13This program is free software: you can redistribute it and/or modify
14it under the terms of the GNU General Public License version 3,
15as published by the Free Software Foundation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25"""
26from argparse import (
27 ArgumentParser,
28 RawTextHelpFormatter
29)
30
31import sys
32import configparser
33import shlex
34import subprocess
35import ast
36import time
37from subprocess import (
38 check_output,
39 CalledProcessError
40)
41
42def check_power_status(host_ip, user, password):
43
44 cmd_status_on = 'dcmitool -H {} -U {} -P {} power status| grep -q "on"'\
45 .format(host_ip, user, password)
46 check_on_value = subprocess.call(cmd_status_on, shell=True)
47 time.sleep(5)
48
49 cmd_status_off = 'dcmitool -H {} -U {} -P {} power status| grep -q "off"'\
50 .format(host_ip, user, password)
51 check_off_value = subprocess.call(cmd_status_off, shell=True)
52 time.sleep(5)
53
54 if check_on_value == 0 and check_off_value == 1:
55 check_status = 'on'
56
57 elif check_on_value == 1 and check_off_value == 0:
58 check_status = 'off'
59
60 else:
61 check_status = 'error'
62
63 return check_status
64
65def run_power_off(host_ip, user, password):
66 cmd_power_off = 'dcmitool -H {} -U {} -P {} power off'\
67 .format(host_ip, user, password)
68 power_off_return_code = subprocess.call(cmd_power_off, shell=True)
69 return power_off_return_code
70
71def run_power_on(host_ip, user, password):
72 cmd_power_on = 'dcmitool -H {} -U {} -P {} power on'\
73 .format(host_ip, user, password)
74 power_on_return_code = subprocess.call(cmd_power_on, shell=True)
75 return power_on_return_code
76
77def dcmi_reset_oob(args):
78
79 #DCMI config file
80 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
81 if not "config" in vars(args):
82 config_file = DEFAULT_CFG
83 else:
84 config_file = args.config
85
86 config = configparser.RawConfigParser()
87
88 try:
89 config.readfp(open(config_file))
90 except IOError:
91 print("No config file found")
92 return 10
93
94 try:
95 targets_options = config.options('Targets')
96 targets_list = []
97 for target_key in targets_options:
98 targets_list.append(config.get('Targets', target_key))
99
100 if not targets_list:
101 print("Invalid or Empty targets")
102 return 20
103
104 except configparser.Error:
105 print("Invalid or Empty targets")
106 return 30
107
108 try:
109 user_value = config.get('Account', 'USER')
110 passwd_value = config.get('Account', 'PASSWORD')
111 if not user_value or not passwd_value:
112 print("Invalid or Empty credential info")
113 return 40
114
115 except configparser.Error:
116 print("Invalid or Empty credential info")
117 return 50
118
119 ping_flag = 0
120 for tg in targets_list:
121
122 if not tg or not user_value or not passwd_value:
123 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
124 return 21
125 else:
126
127 print("SUT =", tg)
128 print("USER =", user_value)
129 print("PASSWORD =", passwd_value)
130
131 for n in range(2):
132
133 count = 0
134 while count < 10:
135 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
136 ping_rtn = subprocess.call(ping_cmd, shell=True)
137 if ping_rtn == 0:
138 print("Destination Host Reachable")
139
140 #run test
141 status = check_power_status(tg, user_value, passwd_value)
142
143 if status == 'on':
144 #run power off
145 power_off_result = run_power_off(tg, user_value, passwd_value)
146 print(" ")
147 if power_off_result == 1:
148 print("Failed to power off SUT.")
149 return 88
150 elif status == 'off':
151 #run power on
152 power_on_result = run_power_on(tg, user_value, passwd_value)
153 print(" ")
154 if power_on_result == 1:
155 print("Failed to power on SUT.")
156 return 99
157 else:
158 #do nothing
159 print("Failed to check power status")
160 return 77
161
162 time.sleep(30)
163 break
164
165 else:
166 time.sleep(10)
167 count = count+1
168 print("Destination Host Unreachable")
169
170 if count == 10:
171 print("Host Has No Response, End of Test")
172 ping_flag = 100
173
174 if ping_flag == 100:
175 return 100
176 return 0
177
178def main():
179
180 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
181 parser = ArgumentParser(description=intro_message,
182 formatter_class=RawTextHelpFormatter)
183 parser.add_argument('--config', type=str,
184 default="/etc/checkbox.d/me.cfg",
185 help="Supply config file for getting authentication info")
186 args = parser.parse_args()
187 return dcmi_reset_oob(args)
188
189if __name__ == "__main__":
190 sys.exit(main())
0191
=== added file 'bin/dcmi_power_reset'
--- bin/dcmi_power_reset 1970-01-01 00:00:00 +0000
+++ bin/dcmi_power_reset 2015-08-14 22:03:31 +0000
@@ -0,0 +1,139 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_power_reset
8 Complete 20 power reset on SUT successfully using dcmitool out-of-band access
9
10Authors
11 Sophia Wu <Sophia.Wu@itri.org.tw>
12
13This program is free software: you can redistribute it and/or modify
14it under the terms of the GNU General Public License version 3,
15as published by the Free Software Foundation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25"""
26
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import configparser
34import shlex
35import subprocess
36import ast
37import time
38from subprocess import (
39 check_output,
40 CalledProcessError
41)
42
43def run(host_ip, user, password):
44 cmd = 'dcmitool -H {} -U {} -P {} power reset'.format(host_ip, user, password)
45 power_reset_return = check_output(shlex.split(cmd), universal_newlines=True)
46 return power_reset_return
47
48def dcmi_reset_oob(args):
49
50 #DCMI config file
51 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
52 if not "config" in vars(args):
53 config_file = DEFAULT_CFG
54 else:
55 config_file = args.config
56
57 config = configparser.RawConfigParser()
58 try:
59 config.readfp(open(config_file))
60 except IOError:
61 print("No config file found")
62 return 1
63
64 try:
65 targets_options = config.options('Targets')
66 targets_list = []
67 for target_key in targets_options:
68 targets_list.append(config.get('Targets', target_key))
69 if not targets_list:
70 print("Invalid or Empty targets")
71 return 2
72 except configparser.Error:
73 print("Invalid or Empty targets")
74 return 2
75
76 try:
77 user_value = config.get("Account", "USER")
78 password_value = config.get("Account", "PASSWORD")
79 except configparser.NoOptionError:
80 print("Invalid or Empty credential info")
81 return 3
82
83 ping_flag = 0
84 for tg in targets_list:
85
86 if not tg or not user_value or not password_value:
87 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
88 return 4
89 else:
90 print("SUT =", tg)
91 print("USER =", user_value)
92 print("PASSWORD =", password_value)
93
94 for n in range(20):
95 print("---------------- %s ----------------" % n)
96 count = 0
97 while count < 10:
98 print("+++++++++++ %s ++++++++++++" % count)
99 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
100 ping_rtn = subprocess.call(ping_cmd, shell=True)
101
102 if ping_rtn == 0:
103 print("Destination Host Reachable")
104
105 try:
106 power_control = run(tg, user_value, password_value)
107 print(power_control)
108 except CalledProcessError as dcmi_exception:
109 print("Failed executing dcmi, Reason: %s" % dcmi_exception)
110 return 6
111
112 time.sleep(30)
113 break
114 else:
115 time.sleep(10)
116 count = count+1
117 print("Destination Host Unreachable")
118
119 if count == 10:
120 print("Host Has No Response, End of Test")
121 ping_flag = 100
122
123 if ping_flag == 100:
124 return 100
125 return 0
126
127def main():
128
129 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
130 parser = ArgumentParser(description=intro_message,
131 formatter_class=RawTextHelpFormatter)
132 parser.add_argument('--config',
133 default="/etc/checkbox.d/me.cfg",
134 help="Supply config file for getting authentication info")
135 args = parser.parse_args()
136 return dcmi_reset_oob(args)
137
138if __name__ == "__main__":
139 sys.exit(main())
0140
=== added file 'bin/dcmi_priv_admin'
--- bin/dcmi_priv_admin 1970-01-01 00:00:00 +0000
+++ bin/dcmi_priv_admin 2015-08-14 22:03:31 +0000
@@ -0,0 +1,174 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_priv_admin
8 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account
9 2. Criteria: Reading power status, performing power reset and adding a user account must all be successful
10
11Authors
12 Sophia Wu <Sophia.Wu@itri.org.tw>
13
14This program is free software: you can redistribute it and/or modify
15it under the terms of the GNU General Public License version 3,
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26"""
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import configparser
34import shlex
35import subprocess
36import ast
37import time
38from subprocess import (
39 check_output,
40 CalledProcessError
41)
42
43def get_power_status(host_ip, user, password):
44 cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\
45 .format(host_ip, user, password)
46 status_code = subprocess.call(cmd_status, shell=True)
47 return status_code
48
49def power_reset(host_ip, user, password):
50 cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\
51 .format(host_ip, user, password)
52 reset_code = subprocess.call(cmd_reset, shell=True)
53 return reset_code
54
55def add_user(host_ip, user, password, new_id, new_user):
56 cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\
57 .format(host_ip, user, password, new_id, new_user)
58 add_user_code = subprocess.call(cmd_add_user, shell=True)
59 return add_user_code
60
61def dcmi_user_level_test(args):
62
63 #DCMI config file
64 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
65 if not "config" in vars(args):
66 config_file = DEFAULT_CFG
67 else:
68 config_file = args.config
69 config = configparser.RawConfigParser()
70 try:
71 config.readfp(open(config_file))
72 except IOError:
73 print("No config file found")
74 return 10
75
76 try:
77 targets_options = config.options('Targets')
78 targets_list = []
79 for target_key in targets_options:
80 targets_list.append(config.get('Targets', target_key))
81 if not targets_list:
82 print("Invalid or Empty targets")
83 return 20
84 except configparser.Error:
85 print("Invalid or Empty targets")
86 return 20
87
88 try:
89 user_value = config.get("Admin Level", "ADMIN_NAME")
90 password_value = config.get("Admin Level", "ADMIN_PASSWD")
91 except configparser.NoOptionError:
92 print("Invalid or Empty credential info")
93 print("Require Operator Level info pre-configured in /etc/checkbox.d/me.cfg")
94 return 30
95
96 try:
97 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
98 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
99 except configparser.NoOptionError:
100 print("Invalid or Empty new user info")
101 print("Require new User info pre-configured in /etc/checkbox.d/me.cfg")
102 return 40
103
104 flag = 0
105 for tg in targets_list:
106
107 if not tg or not user_value or not password_value:
108 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
109 return 50
110 else:
111 print("SUT", tg)
112
113 ping_result = ping_test(tg)
114 if ping_result != 0:
115 return 88
116
117 status_result = get_power_status(tg, user_value, password_value)
118 time.sleep(5)
119
120 reset_result = power_reset(tg, user_value, password_value)
121 time.sleep(5)
122 if not new_user_value or not new_user_id_value:
123 print("Require new user info pre-configured in /etc/checkbox.d/me.cfg")
124 return 60
125 else:
126
127 ping_result = ping_test(tg)
128 if ping_result != 0:
129 return 88
130
131 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
132 time.sleep(5)
133
134 if status_result == 0 and reset_result == 0 and add_user_result == 0:
135 print("User can read power status.")
136 print("User can reset power.")
137 print("User can add a new user.")
138 else:
139 print("Authentication: Not Administrator Level")
140 flag = 1
141
142 if flag == 1:
143 return 100
144 return 0
145
146def ping_test(host_ip):
147 count = 0
148 while count < 10:
149 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
150 ping_rtn = subprocess.call(ping_cmd, shell=True)
151 if ping_rtn == 0:
152 return 0
153 else:
154 print("Destination Host Unreachable")
155 time.sleep(10)
156 count = count+1
157
158 if count == 10:
159 print("Host Has No Response, End of Test")
160 return 1
161
162
163def main():
164
165 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
166 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
167 parser.add_argument('--config', type=str,
168 default="/etc/checkbox.d/me.cfg",
169 help="Supply config file for getting authentication info")
170 args = parser.parse_args()
171 return dcmi_user_level_test(args)
172
173if __name__ == "__main__":
174 sys.exit(main())
0175
=== added file 'bin/dcmi_priv_oper'
--- bin/dcmi_priv_oper 1970-01-01 00:00:00 +0000
+++ bin/dcmi_priv_oper 2015-08-14 22:03:31 +0000
@@ -0,0 +1,174 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_priv_oper
8 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account
9 2. Criteria: power status reading and power reset must be successful and must fail at adding a new user account
10
11Authors
12 Sophia Wu <Sophia.Wu@itri.org.tw>
13
14This program is free software: you can redistribute it and/or modify
15it under the terms of the GNU General Public License version 3,
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26"""
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import configparser
34import shlex
35import subprocess
36import ast
37import time
38from subprocess import (
39 check_output,
40 CalledProcessError
41)
42
43def get_power_status(host_ip, user, password):
44 cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\
45 .format(host_ip, user, password)
46 status_code = subprocess.call(cmd_status, shell=True)
47 return status_code
48
49def power_reset(host_ip, user, password):
50 cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\
51 .format(host_ip, user, password)
52 reset_code = subprocess.call(cmd_reset, shell=True)
53 return reset_code
54
55def add_user(host_ip, user, password, new_id, new_user):
56 cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\
57 .format(host_ip, user, password, new_id, new_user)
58 add_user_code = subprocess.call(cmd_add_user, shell=True)
59 return add_user_code
60
61def dcmi_user_level_test(args):
62
63 #DCMI config file
64 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
65 if not "config" in vars(args):
66 config_file = DEFAULT_CFG
67 else:
68 config_file = args.config
69 config = configparser.RawConfigParser()
70 try:
71 config.readfp(open(config_file))
72 except IOError:
73 print("No config file found")
74 return 10
75
76 try:
77 targets_options = config.options('Targets')
78 targets_list = []
79 for target_key in targets_options:
80 targets_list.append(config.get('Targets', target_key))
81 if not targets_list:
82 print("Invalid or Empty targets")
83 return 20
84 except configparser.Error:
85 print("Invalid or Empty targets")
86 return 20
87
88 try:
89 user_value = config.get("Operator Level", "OPER_NAME")
90 password_value = config.get("Operator Level", "OPER_PASSWD")
91 except configparser.NoOptionError:
92 print("Invalid or Empty credential info")
93 print("Require Operator Level info pre-configured in /etc/checkbox.d/me.cfg")
94 return 30
95
96 try:
97 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
98 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
99 except configparser.NoOptionError:
100 print("Invalid or Empty new user info")
101 print("Require new User info pre-configured in /etc/checkbox.d/me.cfg")
102 return 40
103
104 flag = 0
105 for tg in targets_list:
106
107 if not tg or not user_value or not password_value:
108 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
109 return 50
110 else:
111 print("SUT", tg)
112
113 ping_result = ping_test(tg)
114 if ping_result != 0:
115 return 88
116
117 status_result = get_power_status(tg, user_value, password_value)
118 time.sleep(5)
119
120 reset_result = power_reset(tg, user_value, password_value)
121 time.sleep(5)
122 if not new_user_value or not new_user_id_value:
123 print("Require new user info pre-configured in /etc/checkbox.d/me.cfg")
124 return 60
125 else:
126
127 ping_result = ping_test(tg)
128 if ping_result != 0:
129 return 88
130
131 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
132 time.sleep(5)
133
134 if status_result == 0 and reset_result == 0 and add_user_result == 1:
135 print("User can read power status.")
136 print("User can reset power.")
137 print("User can't add a new user.")
138 else:
139 print("Authentication: Not Operator Level")
140 flag = 1
141
142 if flag == 1:
143 return 100
144 return 0
145
146def ping_test(host_ip):
147 count = 0
148 while count < 10:
149 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
150 ping_rtn = subprocess.call(ping_cmd, shell=True)
151 if ping_rtn == 0:
152 return 0
153 else:
154 print("Destination Host Unreachable")
155 time.sleep(10)
156 count = count+1
157
158 if count == 10:
159 print("Host Has No Response, End of Test")
160 return 1
161
162
163def main():
164
165 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
166 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
167 parser.add_argument('--config', type=str,
168 default="/etc/checkbox.d/me.cfg",
169 help="Supply config file for getting authentication info")
170 args = parser.parse_args()
171 return dcmi_user_level_test(args)
172
173if __name__ == "__main__":
174 sys.exit(main())
0175
=== added file 'bin/dcmi_priv_user'
--- bin/dcmi_priv_user 1970-01-01 00:00:00 +0000
+++ bin/dcmi_priv_user 2015-08-14 22:03:31 +0000
@@ -0,0 +1,174 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_priv_uesr
8 1. Use dcmitool out-of-band to read power status, to perform power reset and add a new user account
9 2. Criteria: power status reading must be successful and must fail at power reset and adding a new user account
10
11Authors
12 Sophia Wu <Sophia.Wu@itri.org.tw>
13
14This program is free software: you can redistribute it and/or modify
15it under the terms of the GNU General Public License version 3,
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26"""
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import configparser
34import shlex
35import subprocess
36import ast
37import time
38from subprocess import (
39 check_output,
40 CalledProcessError
41)
42
43def get_power_status(host_ip, user, password):
44 cmd_status = 'dcmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\
45 .format(host_ip, user, password)
46 status_code = subprocess.call(cmd_status, shell=True)
47 return status_code
48
49def power_reset(host_ip, user, password):
50 cmd_reset = 'dcmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\
51 .format(host_ip, user, password)
52 reset_code = subprocess.call(cmd_reset, shell=True)
53 return reset_code
54
55def add_user(host_ip, user, password, new_id, new_user):
56 cmd_add_user = 'dcmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\
57 .format(host_ip, user, password, new_id, new_user)
58 add_user_code = subprocess.call(cmd_add_user, shell=True)
59 return add_user_code
60
61def dcmi_user_level_test(args):
62
63 #DCMI config file
64 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
65 if not "config" in vars(args):
66 config_file = DEFAULT_CFG
67 else:
68 config_file = args.config
69 config = configparser.RawConfigParser()
70 try:
71 config.readfp(open(config_file))
72 except IOError:
73 print("No config file found")
74 return 10
75
76 try:
77 targets_options = config.options('Targets')
78 targets_list = []
79 for target_key in targets_options:
80 targets_list.append(config.get('Targets', target_key))
81 if not targets_list:
82 print("Invalid or Empty targets")
83 return 20
84 except configparser.Error:
85 print("Invalid or Empty targets")
86 return 20
87
88 try:
89 user_value = config.get("User Level", "USER_NAME")
90 password_value = config.get("User Level", "USER_PASSWD")
91 except configparser.NoOptionError:
92 print("Invalid or Empty credential info")
93 print("Require User Level info pre-configured in /etc/checkbox.d/me.cfg")
94 return 30
95
96 try:
97 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
98 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
99 except configparser.NoOptionError:
100 print("Invalid or Empty new user info")
101 print("Require new User info pre-configured in /etc/checkbox.d/me.cfg")
102 return 40
103
104 flag = 0
105 for tg in targets_list:
106
107 if not tg or not user_value or not password_value:
108 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
109 return 50
110 else:
111 print("SUT", tg)
112
113 ping_result = ping_test(tg)
114 if ping_result != 0:
115 return 88
116
117 status_result = get_power_status(tg, user_value, password_value)
118 time.sleep(5)
119
120 reset_result = power_reset(tg, user_value, password_value)
121 time.sleep(5)
122 if not new_user_value or not new_user_id_value:
123 print("Require new user info pre-configured in /etc/checkbox.d/me.cfg")
124 return 60
125 else:
126
127 ping_result = ping_test(tg)
128 if ping_result != 0:
129 return 88
130
131 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
132 time.sleep(5)
133
134 if status_result == 0 and reset_result == 1 and add_user_result == 1:
135 print("User can read power status.")
136 print("User can't reset power.")
137 print("User can't add a new user.")
138 else:
139 print("Authentication: Not User Level")
140 flag = 1
141
142 if flag == 1:
143 return 100
144 return 0
145
146def ping_test(host_ip):
147 count = 0
148 while count < 10:
149 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
150 ping_rtn = subprocess.call(ping_cmd, shell=True)
151 if ping_rtn == 0:
152 return 0
153 else:
154 print("Destination Host Unreachable")
155 time.sleep(10)
156 count = count+1
157
158 if count == 10:
159 print("Host Has No Response, End of Test")
160 return 1
161
162
163def main():
164
165 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
166 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
167 parser.add_argument('--config', type=str,
168 default="/etc/checkbox.d/me.cfg",
169 help="Supply config file for getting authentication info")
170 args = parser.parse_args()
171 return dcmi_user_level_test(args)
172
173if __name__ == "__main__":
174 sys.exit(main())
0175
=== added file 'bin/dcmi_sampling'
--- bin/dcmi_sampling 1970-01-01 00:00:00 +0000
+++ bin/dcmi_sampling 2015-08-14 22:03:31 +0000
@@ -0,0 +1,271 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_sampling
8 1. Retrieve CPU and intake temperature 30 times at 3 second intervals using dcmitool
9 2. If failed to retrieve temperature at any time within 30 times, the test is considered failed
10
11Authors
12 Sophia Wu <Sophia.Wu@itri.org.tw>
13
14This program is free software: you can redistribute it and/or modify
15it under the terms of the GNU General Public License version 3,
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26"""
27import sys
28import time
29import re
30import configparser
31import shlex
32import subprocess
33from argparse import (
34 ArgumentParser,
35 RawTextHelpFormatter
36)
37from subprocess import (
38 check_output,
39 CalledProcessError
40)
41
42def get_sdr_remote(host_ip, user, password):
43 cmd = "dcmitool -H {} -U {} -P {} sdr".format(host_ip, user, password)
44 sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT,
45 universal_newlines=True)
46 return sdr_return
47
48def parse_sdr(output):
49 output = output.strip()
50 output_1Line = output.split("\n")
51 data = {}
52
53 for line in output_1Line:
54 sub_value = {}
55 string_list = line.split("|")
56 name = string_list[0].strip()
57 sensor_output = string_list[1].strip()
58 sub_value.update({'output':sensor_output})
59 status = string_list[2].strip()
60 sub_value.update({'status':status})
61 data.update({name:sub_value})
62 return data
63
64def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
65 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
66 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
67 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
68 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
69 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
70 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
71 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
72 return str(CPU_temp)+' degrees C'
73 else:
74 return 'Error'
75 else:
76 return 'None'
77
78def dcmi_sdr(args):
79
80 cmd_flag = 0
81 #DCMI config file
82 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
83 if not "config" in vars(args):
84 config_file = DEFAULT_CFG
85 else:
86 config_file = args.config
87
88 config = configparser.RawConfigParser()
89
90 try:
91 config.readfp(open(config_file))
92 except IOError:
93 print("No config file found")
94 return 10
95
96 try:
97 sensor_nick = config.options("SensorsForSampling")
98 except configparser.NoSectionError:
99 print("No Section: SensorsForSampling")
100 return 20
101
102 if sensor_nick:
103 sensor_list = []
104 for id in sensor_nick:
105 sensor_key = config.get("SensorsForSampling", id)
106 if sensor_key:
107 sensor_list.append(sensor_key)
108 else:
109 print("No Sensor ID specified in Config file")
110 return 30
111 else:
112 print("No key of Sensor ID specified in config file")
113 return 40
114
115 try:
116 targets_options = config.options('Targets')
117 targets_list = []
118 for target_key in targets_options:
119 targets_list.append(config.get('Targets', target_key))
120 if not targets_list:
121 print("Invalid or Empty targets")
122 return 60
123 except configparser.Error:
124 print("Invalid or Empty targets")
125 return 60
126
127 try:
128 user_value = config.get("Account", "USER")
129 password_value = config.get("Account", "PASSWORD")
130 except configparser.NoOptionError:
131 print("Invalid or Empty credential info")
132 return 70
133
134 for tg in targets_list:
135
136 if not tg or not user_value or not password_value:
137 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
138 return 80
139 else:
140
141 c = 0
142 while c < 10:
143 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
144 ping_rtn = subprocess.call(ping_cmd, shell=True)
145 if ping_rtn == 0:
146 print("Destination Host Reachable")
147 break
148 else:
149 time.sleep(10)
150 c = c+1
151 print("Destination Host Unreachable")
152
153 if c == 10:
154 print("Host Has No Response, End of Test")
155 return 99
156
157
158 sampling_data = []
159 times = 30
160 for n in range(times):
161
162 try:
163 sensor_data = get_sdr_remote(tg, user_value, password_value)
164 time.sleep(3)
165 except CalledProcessError as dcmi_exception:
166 print("Failed executing dcmi, Reason: %s" % dcmi_exception)
167 sensor_data = ''
168
169 sampling_data.append(sensor_data)
170
171 count = 0
172 prs_flag = 0
173 dis_flag = 0
174 for output in sampling_data:
175 try:
176 data = parse_sdr(output)
177 except:
178 print("Parsing output of sdr table error")
179 print("=======================================================")
180 prs_flag = 1
181 count = count+1
182 continue
183
184 disable = 0
185 need_data = {}
186
187 for need_id in sensor_list:
188
189 if data.get(need_id):
190 need_value = data.get(need_id).get('output')
191 need_data.update({need_id:need_value})
192 if data.get(need_id).get('status') != 'ok':
193 disable = 1
194 else:
195
196 try:
197 CPUx_Temp = config.get("Sensors", "CPUx")
198 except configparser.NoOptionError:
199 CPUx_Temp = ''
200
201 try:
202 CPUy_Temp = config.get("Sensors", "CPUy")
203 except configparser.NoOptionError:
204 CPUy_Temp = ''
205
206 if need_id == CPUx_Temp:
207
208 try:
209 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
210 except configparser.NoOptionError:
211 PxTM = ''
212
213 try:
214 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
215 except configparser.NoOptionError:
216 CPUx_Tjmax = ''
217
218 if PxTM and CPUx_Tjmax:
219 Px_temp = calculate_CPU_temp(data, PxTM, CPUx_Tjmax)
220 need_data.update({CPUx_Temp:Px_temp})
221 if Px_temp == 'None' or Px_temp == 'Error':
222 disable = 1
223 else:
224 disable = 1
225
226 elif need_id == CPUy_Temp:
227
228 try:
229 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
230 except configparser.NoOptionError:
231 PyTM = ''
232
233 try:
234 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
235 except configparser.NoOptionError:
236 CPUy_Tjmax = ''
237
238 if PyTM and CPUy_Tjmax:
239 Py_temp = calculate_CPU_temp(data, PyTM, CPUy_Tjmax)
240 need_data.update({CPUy_Temp:Py_temp})
241 if Py_temp == 'None' or Py_temp == 'Error':
242 disable = 1
243 else:
244 disable = 1
245
246 else:
247 need_data.update({need_id:'None'})
248 disable = 1
249
250 if disable == 1:
251 dis_flag = 1
252 print(need_data)
253 print("=======================================================")
254 count = count+1
255 print("Pass: %d" %(times-count))
256 print("Fail: %d" %(count))
257
258 if cmd_flag == 1 or prs_flag == 1 or dis_flag == 1:
259 return 100
260 return 0
261
262def main():
263
264 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
265 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
266 parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters")
267 args = parser.parse_args()
268 return dcmi_sdr(args)
269
270if __name__ == "__main__":
271 sys.exit(main())
0272
=== added file 'bin/dcmi_thermal_ib'
--- bin/dcmi_thermal_ib 1970-01-01 00:00:00 +0000
+++ bin/dcmi_thermal_ib 2015-08-14 22:03:31 +0000
@@ -0,0 +1,212 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_thermal_ib
8 1. Retrieve CPU, DIMM, chipset, inlet and outlet temperatures via DCMI in-band access using dcmitool.
9 2. The motherboard has five thermal sensors:
10 Two for CPU0 and CPU1 temperatures,
11 Two for CPU0 DIMM group and CPU1 DIMM group temperatures,
12 One for PCH temperature,
13 One for Inlet temperature,
14 One for outlet temperature.
15 3. Criteria: Must retrieve temperatures from all abovementioned thermal sensors via DCMI in-band access.
16
17Authors
18 Sophia Wu <Sophia.Wu@itri.org.tw>
19
20This program is free software: you can redistribute it and/or modify
21it under the terms of the GNU General Public License version 3,
22as published by the Free Software Foundation.
23
24This program is distributed in the hope that it will be useful,
25but WITHOUT ANY WARRANTY; without even the implied warranty of
26MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License
30along with this program. If not, see <http://www.gnu.org/licenses/>.
31
32"""
33import sys
34import time
35import re
36import configparser
37import shlex
38import subprocess
39import ast
40from argparse import (
41 ArgumentParser,
42 RawTextHelpFormatter
43)
44from subprocess import (
45 check_output,
46 CalledProcessError
47)
48
49
50def get_sdr():
51 cmd = "dcmitool sdr"
52 sdr_return = subprocess.check_output(shlex.split(cmd), universal_newlines=True)
53 return sdr_return
54
55def parse_sdr(output):
56 output = output.strip()
57 output_1Line = output.split("\n")
58 data = {}
59
60 for line in output_1Line:
61 sub_value = {}
62 string_list = line.split("|")
63 name = string_list[0].strip()
64 sensor_output = string_list[1].strip()
65 sub_value.update({'output':sensor_output})
66 status = string_list[2].strip()
67 sub_value.update({'status':status})
68 data.update({name:sub_value})
69 return data
70
71def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
72
73 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
74 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
75 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
76 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
77 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
78 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
79 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
80 return str(CPU_temp)+' degrees C'
81 else:
82 return 'Error'
83 else:
84 return 'None'
85
86def dcmi_sdr(args):
87
88 flag = 0
89 #DCMI config file
90 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
91 if not "config" in vars(args):
92 config_file = DEFAULT_CFG
93 else:
94 config_file = args.config
95 config = configparser.RawConfigParser()
96
97 try:
98 config.readfp(open(config_file))
99 except IOError:
100 print("No config file found")
101 return 10
102
103 try:
104 sensor_nick = config.options("Sensors")
105 except configparser.NoSectionError:
106 print("No Section: Sensors")
107 return 20
108
109 if sensor_nick:
110 sensor_list = []
111 for id in sensor_nick:
112 sensor_key = config.get("Sensors", id)
113 if sensor_key:
114 sensor_list.append(sensor_key)
115 else:
116 print("No Sensor ID specified in Config file")
117 return 30
118 else:
119 print("No key of Sensor ID specified in config file")
120 return 40
121
122 try:
123 sensor_data = get_sdr()
124 time.sleep(5)
125 except CalledProcessError as dcmi_exception:
126 print("Failed executing dcmi, Reason: %s" % dcmi_exception)
127 return 50
128
129 try:
130 data = parse_sdr(sensor_data)
131 except:
132 print("Parsing output of sdr table error")
133 return 60
134
135 need_data = {}
136 for need_id in sensor_list:
137 if data.get(need_id):
138 need_value = data.get(need_id).get('output')
139 need_data.update({need_id:need_value})
140
141 if data.get(need_id).get('status') != 'ok':
142 flag = 1
143 else:
144
145 try:
146 CPUx_Temp = config.get("Sensors", "CPUx")
147 except configparser.NoOptionError:
148 CPUx_Temp = ''
149
150 try:
151 CPUy_Temp = config.get("Sensors", "CPUy")
152 except configparser.NoOptionError:
153 CPUy_Temp = ''
154
155 if need_id == CPUx_Temp:
156
157 try:
158 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
159 except configparser.NoOptionError:
160 PxTM = ''
161
162 try:
163 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
164 except configparser.NoOptionError:
165 CPUx_Tjmax = ''
166
167 if PxTM and CPUx_Tjmax:
168 need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)})
169 if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error':
170 flag = 1
171 else:
172 flag = 1
173
174 elif need_id == CPUy_Temp:
175
176 try:
177 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
178 except configparser.NoOptionError:
179 PyTM = ''
180
181 try:
182 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
183 except configparser.NoOptionError:
184 CPUy_Tjmax = ''
185
186
187 if PyTM and CPUy_Tjmax:
188 need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)})
189 if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error':
190 flag = 1
191 else:
192 flag = 1
193 else:
194 flag = 1
195
196 print("%s: %s" %(need_id, need_data.get(need_id)))
197
198 if flag == 1:
199 return 100
200 return 0
201
202def main():
203
204 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
205 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
206 parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters")
207 args = parser.parse_args()
208 return dcmi_sdr(args)
209
210if __name__ == "__main__":
211 sys.exit(main())
212
0213
=== added file 'bin/dcmi_thermal_oob'
--- bin/dcmi_thermal_oob 1970-01-01 00:00:00 +0000
+++ bin/dcmi_thermal_oob 2015-08-14 22:03:31 +0000
@@ -0,0 +1,243 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 dcmi_thermal_oob
8 1. Retrieving CPU, DIMM, chipset, inlet, outlet temperature via DCMI out-of-band access using dcmitool.
9 2. The motherboard has five thermal sensors: Two for CPU0 and CPU1 temperatures,
10 Two for CPU0 DIMM group and CPU1 DIMM group temperatures,
11 One for PCH temperature,
12 One for Inlet temperature,
13 One for outlet temperature.
14 3. Criteria: Must retrieve temperatures from all abovementioned thermal sensors via DCMI out-of-band access.
15
16Authors
17 Sophia Wu <Sophia.Wu@itri.org.tw>
18
19This program is free software: you can redistribute it and/or modify
20it under the terms of the GNU General Public License version 3,
21as published by the Free Software Foundation.
22
23This program is distributed in the hope that it will be useful,
24but WITHOUT ANY WARRANTY; without even the implied warranty of
25MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26GNU General Public License for more details.
27
28You should have received a copy of the GNU General Public License
29along with this program. If not, see <http://www.gnu.org/licenses/>.
30
31"""
32import sys
33import time
34import re
35import configparser
36import shlex
37import subprocess
38import ast
39from argparse import (
40 ArgumentParser,
41 RawTextHelpFormatter
42)
43from subprocess import (
44 check_output,
45 CalledProcessError
46)
47
48def get_sdr_remote(host_ip, user, password):
49 cmd = "dcmitool -H {} -U {} -P {} sdr".format(host_ip, user, password)
50 sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT,
51 universal_newlines=True)
52 return sdr_return
53
54def parse_sdr(output):
55 output = output.strip()
56 output_1Line = output.split("\n")
57 data = {}
58
59 for line in output_1Line:
60 sub_value = {}
61 string_list = line.split("|")
62 name = string_list[0].strip()
63 sensor_output = string_list[1].strip()
64 sub_value.update({'output':sensor_output})
65 status = string_list[2].strip()
66 sub_value.update({'status':status})
67 data.update({name:sub_value})
68 return data
69
70def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
71
72 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
73 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
74 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
75 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
76 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
77 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
78 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
79 return str(CPU_temp)+' degrees C'
80 else:
81 return 'Error'
82 else:
83 return 'None'
84
85def dcmi_sdr(args):
86
87 flag = 0
88 #DCMI config file
89 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
90 if not "config" in vars(args):
91 config_file = DEFAULT_CFG
92 else:
93 config_file = args.config
94
95 config = configparser.RawConfigParser()
96
97 try:
98 config.readfp(open(config_file))
99 except IOError:
100 print("No config file found")
101 return 10
102
103 try:
104 sensor_nick = config.options("Sensors")
105 except configparser.NoSectionError:
106 print("No Section: Sensors")
107 return 20
108
109 if sensor_nick:
110 sensor_list = []
111 for id in sensor_nick:
112 sensor_key = config.get("Sensors", id)
113 if sensor_key:
114 sensor_list.append(sensor_key)
115 else:
116 print("No Sensor ID specified in Config file")
117 return 30
118 else:
119 print("No key of Sensor ID specified in config file")
120 return 40
121
122 try:
123 targets_options = config.options('Targets')
124 targets_list = []
125 for target_key in targets_options:
126 targets_list.append(config.get('Targets', target_key))
127 if not targets_list:
128 print("Invalid or Empty targets")
129 return 60
130 except configparser.Error:
131 print("Invalid or Empty targets")
132 return 60
133
134 try:
135 user_value = config.get("Account", "USER")
136 password_value = config.get("Account", "PASSWORD")
137 except configparser.NoOptionError:
138 print("Invalid or Empty credential info")
139 return 70
140
141 for tg in targets_list:
142
143 if not tg or not user_value or not password_value:
144 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
145 return 80
146 else:
147
148 print("SUT =", tg)
149 print("USER =", user_value)
150 print("PASSWORD =", password_value)
151
152 try:
153 sensor_data = get_sdr_remote(tg, user_value, password_value)
154 time.sleep(5)
155 except CalledProcessError as dcmi_exception:
156 print("Failed executing dcmi, Reason: %s" % dcmi_exception)
157 return 50
158
159 try:
160 data = parse_sdr(sensor_data)
161 except:
162 print("Parsing output of sdr table error")
163 flag = 1
164 continue
165
166 need_data = {}
167 for need_id in sensor_list:
168
169 if data.get(need_id):
170 need_value = data.get(need_id).get('output')
171 need_data.update({need_id:need_value})
172
173 if data.get(need_id).get('status') != 'ok':
174 flag = 1
175 else:
176
177 try:
178 CPUx_Temp = config.get("Sensors", "CPUx")
179 except configparser.NoOptionError:
180 CPUx_Temp = ''
181
182 try:
183 CPUy_Temp = config.get("Sensors", "CPUy")
184 except configparser.NoOptionError:
185 CPUy_Temp = ''
186
187 if need_id == CPUx_Temp:
188
189 try:
190 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
191 except configparser.NoOptionError:
192 PxTM = ''
193
194 try:
195 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
196 except configparser.NoOptionError:
197 CPUx_Tjmax = ''
198
199 if PxTM and CPUx_Tjmax:
200 need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)})
201 if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error':
202 flag = 1
203 else:
204 flag = 1
205
206 elif need_id == CPUy_Temp:
207
208 try:
209 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
210 except configparser.NoOptionError:
211 PyTM = ''
212
213 try:
214 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
215 except configparser.NoOptionError:
216 CPUy_Tjmax = ''
217
218 if PyTM and CPUy_Tjmax:
219 need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)})
220 if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error':
221 flag = 1
222 else:
223 flag = 1
224 else:
225 #need_data.update({need_id:'None'})
226 flag = 1
227
228 print("%s: %s" %(need_id, need_data.get(need_id)))
229
230 if flag == 1:
231 return 100
232 return 0
233
234def main():
235
236 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
237 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
238 parser.add_argument('--config', type=str, default="/etc/checkbox.d/me.cfg", help="Supply config file for sensor IDs parameters")
239 args = parser.parse_args()
240 return dcmi_sdr(args)
241
242if __name__ == "__main__":
243 sys.exit(main())
0244
=== added file 'bin/disk_health'
--- bin/disk_health 1970-01-01 00:00:00 +0000
+++ bin/disk_health 2015-08-14 22:03:31 +0000
@@ -0,0 +1,138 @@
1#!/usr/bin/env python3
2
3"""
4Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
5Industrial Technology Research Institute
6
7It is NOT YET officially approved by OCP.
8
9disk_health
10 1. Use smartmontools to monitor disk health.
11 2. SMART threshold, grown defect list (glist or reallocated sectors)
12 <= 100 for 4TB, glist <=50 for 2TB for all vendors.
13 3. SMART HDD temp <= 60 degrees centigrade.
14 4. Criteria: all threshold must not exceed the criteria listed in item 2
15 and 3.
16
17Authors
18 Nelson Chu <Nelson.Chu@itri.org.tw>
19
20This program is free software: you can redistribute it and/or modify
21it under the terms of the GNU General Public License version 3,
22as published by the Free Software Foundation.
23
24This program is distributed in the hope that it will be useful,
25but WITHOUT ANY WARRANTY; without even the implied warranty of
26MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27GNU General Public License for more details.
28
29You should have received a copy of the GNU General Public License
30along with this program. If not, see <http://www.gnu.org/licenses/>.
31
32"""
33
34import os
35import re
36import sys
37from subprocess import check_output
38from argparse import ArgumentParser, RawTextHelpFormatter
39
40def run(device):
41 return_code = 0
42 command = "smartctl -a {0}".format(device)
43
44 try:
45 with open(os.devnull, "w") as NULL:
46 smartctl_info = check_output(command, stderr=NULL, shell=True)
47 except Exception as e:
48 print(e.output.decode('utf-8'))
49 return_code = 10
50 return return_code
51
52 smartctl_info = smartctl_info.decode('utf-8')
53
54 # Verify disk capacity match the criteria or not.
55 capacity_match =re.search(r'User Capacity.*\[(2|4).*TB\]', smartctl_info)
56 if not capacity_match:
57 print("Disk capacity is not match 2TB or 4TB.")
58 return_code = 20
59 return return_code
60
61 disk_capacity = int(capacity_match.group(1))
62 print("Disk capacity: %dTB" %(disk_capacity))
63
64 # Verify disk temperature match the criteria or not.
65 temperature_match = re.search(r'Temperature_Celsius.*\s(\d+)(\s\(|\n)',
66 smartctl_info)
67 if not temperature_match:
68 temperature_match = re.search(r'Current Drive Temperature\D*(\d+)',
69 smartctl_info)
70 if not temperature_match:
71 print("Cannot retrieve disk temperature.")
72 return_code = 30
73 return return_code
74
75 disk_temperature = int(temperature_match.group(1))
76 print("Disk current temperature: %d degrees centigrade"
77 %disk_temperature)
78 if disk_temperature > 60:
79 return_code = 40
80
81 # Verify reallocated sectors match the criteria or not.
82 reallocated_sector_match = re.search(r'Reallocated_Sector_Ct.*\s(\d+)\n',
83 smartctl_info)
84 if reallocated_sector_match:
85 reallocated_sector = int(reallocated_sector_match.group(1))
86 print("Reallocated_Sector_Ct: %d" %reallocated_sector)
87 if disk_capacity == 2 and reallocated_sector > 50:
88 return_code = 50
89 if disk_capacity == 4 and reallocated_sector > 100:
90 return_code = 60
91
92 # Verify grown defect list match the criteria or not.
93 grown_defect_match = re.search(r'Elements in grown defect list\:\s(\d+)\n',
94 smartctl_info)
95 if grown_defect_match:
96 grown_defect_list = int(grown_defect_match.group(1))
97 print("Elements in grown defect list: %d" %grown_defect_list)
98 if disk_capacity == 2 and grown_defect_list > 50:
99 return_code = 70
100 if disk_capacity == 4 and grown_defect_list > 100:
101 return_code = 80
102
103 # Check current pending sectort.
104 current_pending_match = re.search(r'Current_Pending_Sector.*\s(\d+)\n',
105 smartctl_info)
106 if current_pending_match:
107 current_pending_sector = int(current_pending_match.group(1))
108 print("Current_Pending_Sector: %d" %current_pending_sector)
109 if current_pending_sector != 0:
110 return_code = 90
111
112 # Check error counter log.
113 total_uncorrected_errors = re.search(
114 r'\nread.*\s(\d+)\nwrite.*\s(\d+)\nverify.*\s(\d+)', smartctl_info)
115 if total_uncorrected_errors:
116 read = int(total_uncorrected_errors.group(1))
117 write = int(total_uncorrected_errors.group(2))
118 verify = int(total_uncorrected_errors.group(3))
119 print("Total uncorrected errors: read=%d write=%d verify=%d"
120 %(read, write, verify))
121 if read != 0 or write != 0 or verify != 0:
122 return_code = 100
123 return return_code
124
125def main():
126 parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
127 parser.add_argument('-d', '--device', type=str, required=True,
128 help=("The device that wants to monitor health."))
129 args = parser.parse_args()
130
131 device = args.device
132 if not device.startswith('/dev/'):
133 device = '/dev/' + device
134
135 return run(device)
136
137if __name__ == '__main__':
138 sys.exit(main())
0139
=== modified file 'bin/disk_info'
--- bin/disk_info 2015-03-03 15:59:42 +0000
+++ bin/disk_info 2015-08-14 22:03:31 +0000
@@ -3,6 +3,8 @@
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute4Industrial Technology Research Institute
55
6It is NOT YET officially approved by OCP.
7
6disk_info8disk_info
7 1. Use lshw command to gather disk information.9 1. Use lshw command to gather disk information.
8 2. The program will output disk type, vendor, product, capacity.10 2. The program will output disk type, vendor, product, capacity.
911
=== added file 'bin/disk_info_leopard'
--- bin/disk_info_leopard 1970-01-01 00:00:00 +0000
+++ bin/disk_info_leopard 2015-08-14 22:03:31 +0000
@@ -0,0 +1,67 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6It is NOT YET officially approved by OCP.
7
8disk_info
9 1. Use lshw command to gather disk information.
10 2. The program will output disk type, vendor, product, capacity.
11 3. Criteria: must be able to retrieve disk information.
12
13Authors
14 Nelson Chu <Nelson.Chu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29
30import sys
31import xml.etree.ElementTree as ET
32from subprocess import Popen, PIPE
33
34def main():
35 attribute = ['description', 'product', 'size']
36 command = 'lshw -xml'
37 hwinfo_xml = Popen(command, stdout=PIPE, stderr=PIPE,
38 shell=True).communicate()[0]
39 root = ET.fromstring(hwinfo_xml)
40
41 # Parse lshw XML for gathering disk information.
42 disk_list = root.findall(".//node[@class='disk']")
43
44 if not disk_list:
45 print("Cannot parse any disk information.", file=sys.stderr)
46 return 10
47
48 for disk in disk_list:
49 for attr in attribute:
50 if disk.find(attr) is None:
51 print(("Cannot found disk %s") %attr, file=sys.stderr)
52 return 20
53
54 disk_size = int(disk.find('size').text) / (1000**3)
55 for attr in attribute:
56 if attr == 'description':
57 print(("Type=\"%s\"") %disk.find(attr).text)
58 continue
59 elif attr == 'size':
60 print(("%s=\"%dGB\"") %(attr.capitalize(), disk_size))
61 continue
62 else:
63 print(("%s=\"%s\"") %(attr.capitalize(), disk.find(attr).text))
64 return 0
65
66if __name__ == '__main__':
67 sys.exit(main())
068
=== added file 'bin/ipmi_fru'
--- bin/ipmi_fru 1970-01-01 00:00:00 +0000
+++ bin/ipmi_fru 2015-08-14 22:03:31 +0000
@@ -0,0 +1,163 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_fru
8
9Description
10 1. Use ipmitool to retrieve FRU data.
11 2. The data contains product manufacture, product part number, product serial number, motherboard serial number.
12 3. Criteria: Above All data mentioned above must notshould not be null
13
14Authors
15 Sophia Wu <Sophia.Wu@itri.org.tw>
16
17This program is free software: you can redistribute it and/or modify
18it under the terms of the GNU General Public License version 3,
19as published by the Free Software Foundation.
20
21This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program. If not, see <http://www.gnu.org/licenses/>.
28
29"""
30
31from argparse import (
32 ArgumentParser,
33 RawTextHelpFormatter
34)
35
36import sys
37import shlex
38import time
39import subprocess
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44import re
45import configparser
46
47def get_system_manufacturer(output):
48 system_manufacture = re.search(r'Product Manufacturer\s*:\s*([a-zA-Z0-9-._ ]+\n)', output)
49 if system_manufacture == None:
50 return 'Error'
51 else:
52 return system_manufacture.group(1).strip()
53
54def get_system_part_number(output):
55 system_part_number = re.search(r'Product Part Number\s*:\s*([a-zA-Z0-9-._ ]+\n)', output)
56 if system_part_number == None:
57 return 'Error'
58 else:
59 return system_part_number.group(1).strip()
60
61def get_system_serial_number(output):
62 system_serial_number = re.search(r'Product Serial\s*:\s*([a-zA-Z0-9-._ ]+\n)', output)
63 if system_serial_number == None:
64 return 'Error'
65 else:
66 return system_serial_number.group(1).strip()
67
68def get_board_serial_number(output):
69 board_serial_number = re.search(r'Board Serial\s*:\s*([a-zA-Z0-9-._ ]+\n)', output)
70 if board_serial_number == None:
71 return 'Error'
72 else:
73 return board_serial_number.group(1).strip()
74
75def get_fru_info(host_ip, user, password):
76 fru_cmd = 'ipmitool -H {} -U {} -P {} fru'.format(host_ip, user, password)
77 fru_return = check_output(shlex.split(fru_cmd), universal_newlines=True)
78 return fru_return
79
80def ipmi_fru(args):
81 #IPMI config file
82 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
83
84 if not "config" in vars(args):
85 config_file = DEFAULT_CFG
86 else:
87 config_file = args.config
88
89 config = configparser.RawConfigParser()
90
91 try:
92 config.readfp(open(config_file))
93 except IOError:
94 print("No config file found")
95 return 10
96
97 try:
98 targets_options = config.options('Targets')
99 targets_list = []
100 for target_key in targets_options:
101 targets_list.append(config.get('Targets', target_key))
102
103 if not targets_list:
104 print("Invalid or Empty targets")
105 return 20
106
107 except configparser.Error:
108 print("Invalid or Empty targets")
109 return 30
110
111 try:
112 user_value = config.get('Account', 'USER')
113 passwd_value = config.get('Account', 'PASSWORD')
114 if not user_value or not passwd_value:
115 print("Invalid or Empty credential info")
116 return 40
117
118 except configparser.Error:
119 print("Invalid or Empty credential info")
120 return 50
121
122 inevntory_fru = {}
123 flag = 0
124 for tg in targets_list:
125
126 if not tg or not user_value or not passwd_value:
127 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
128 return 60
129 else:
130 print("SUT =", tg)
131 try:
132 fru_data = get_fru_info(tg, user_value, passwd_value)
133 time.sleep(5)
134 except CalledProcessError as ipmi_exception:
135 print("Failed executing ipmi, Reason: %s" % ipmi_exception)
136 return 70
137
138 inevntory_fru.update({'Product Manufacturer':get_system_manufacturer(fru_data)})
139 inevntory_fru.update({'Product Part Number':get_system_part_number(fru_data)})
140 inevntory_fru.update({'Product Serial':get_system_serial_number(fru_data)})
141 inevntory_fru.update({'Board Serial':get_board_serial_number(fru_data)})
142
143 inevntory_fru_list = ['Product Manufacturer', 'Product Part Number', 'Product Serial', 'Board Serial']
144 for item in inevntory_fru_list:
145 print("{}: {}".format(item, inevntory_fru.get(item)))
146 if inevntory_fru.get(item) == 'Error' or inevntory_fru.get(item) == '':
147 flag = 1
148 if flag == 1:
149 return 100
150 return 0
151
152def main():
153 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
154 parser = ArgumentParser(description=intro_message,
155 formatter_class=RawTextHelpFormatter)
156 parser.add_argument('--config', type=str,
157 default="/etc/checkbox.d/bmc.cfg",
158 help="Supply config file for getting authentication info")
159 args = parser.parse_args()
160 return ipmi_fru(args)
161
162if __name__ == '__main__':
163 sys.exit(main())
0164
=== added file 'bin/ipmi_inventory'
--- bin/ipmi_inventory 1970-01-01 00:00:00 +0000
+++ bin/ipmi_inventory 2015-08-14 22:03:31 +0000
@@ -0,0 +1,214 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_inventory
8 1. Use ipmitool to collect inventory information including Asset Tag, Device ID, System GUID, Firmware Revision, IPMI Version, Management Controller ID.
9 2. Criteria: All information mentioned above must not should not be null.
10Authors
11 Sophia Wu <Sophia.Wu@itri.org.tw>
12
13This program is free software: you can redistribute it and/or modify
14it under the terms of the GNU General Public License version 3,
15as published by the Free Software Foundation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>.
24
25"""
26
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import shlex
34import time
35import subprocess
36from subprocess import (
37 check_output,
38 CalledProcessError
39)
40import re
41import configparser
42
43
44def get_mcinfo(host_ip, user, password):
45
46 try:
47 cmd = 'ipmitool -H {} -U {} -P {} mc info'.format(host_ip, user, password)
48 mcinfo_return = check_output(shlex.split(cmd), universal_newlines=True)
49 time.sleep(5)
50 except CalledProcessError as command_exception:
51 print("Failed executing ipmi command for getting mc info. Reason:%s" % command_exception)
52
53 try:
54
55 deviceid = re.search(r'Device ID\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return)
56 if deviceid == None:
57 deviceid = 'Error'
58 else:
59 deviceid = deviceid.group(1).strip()
60
61 Firm = re.search(r'Firmware Revision\s+\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return)
62 if Firm == None:
63 Firm = 'Error'
64 else:
65 Firm = Firm.group(1).strip()
66
67 IPMI_Ver = re.search(r'IPMI Version\s+\s*:\s*([a-zA-Z0-9-._ ]+)', mcinfo_return)
68 if IPMI_Ver == None:
69 IPMI_Ver = 'Error'
70 else:
71 IPMI_Ver = IPMI_Ver.group(1).strip()
72
73 return deviceid, Firm, IPMI_Ver
74
75 except:
76
77 return 'Error', 'Error', 'Error'
78
79def get_asset_tag(host_ip, user, password):
80
81 try:
82 cmd = 'ipmitool -H {} -U {} -P {} fru'.format(host_ip, user, password)
83 asset_tag_return = check_output(shlex.split(cmd), universal_newlines=True)
84 time.sleep(5)
85 except CalledProcessError as command_exception:
86 print("Failed executing ipmi command for getting asset tag. Reason:%s" % command_exception)
87
88 try:
89 asset_tag = re.search(r'Product Asset Tag\s*:\s*([a-zA-Z0-9-._ ]+)', asset_tag_return)
90 if asset_tag == None:
91 return 'Error'
92 return asset_tag.group(1).strip()
93 except:
94 return 'Error'
95
96def get_guid(host_ip, user, password):
97
98 try:
99 cmd = 'ipmitool -H {} -U {} -P {} mc guid'.format(host_ip, user, password)
100 guid_return = check_output(shlex.split(cmd), universal_newlines=True)
101 time.sleep(5)
102 except CalledProcessError as command_exception:
103 print("Failed executing ipmi command for getting guid. Reason:%s" % command_exception)
104
105 try:
106 mcguid = re.search(r'System GUID\s*:\s*([a-zA-Z0-9-._ ]+)', guid_return)
107 if mcguid == None:
108 return 'Error'
109 return mcguid.group(1).strip()
110 except:
111 return 'Error'
112
113def get_mcid(host_ip, user, password):
114
115 try:
116 cmd = 'ipmitool -H {} -U {} -P {} dcmi get_mc_id_string'.format(host_ip, user, password)
117 mcid_return = check_output(shlex.split(cmd), universal_newlines=True)
118 time.sleep(5)
119 except CalledProcessError as command_exception:
120 print("Failed executing ipmi command for getting mc id. Reason:%s" % command_exception)
121
122 try:
123 mcid = re.search(r'Get Management Controller Identifier String\s*:\s*([a-zA-Z0-9-._ ]+)', mcid_return)
124 if mcid == None:
125 return 'Error'
126 return mcid.group(1).strip()
127 except:
128 return 'Error'
129
130def inventory(args):
131
132 #IPMI config file
133 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
134
135 if not "config" in vars(args):
136 config_file = DEFAULT_CFG
137 else:
138 config_file = args.config
139
140 config = configparser.RawConfigParser()
141
142 try:
143 config.readfp(open(config_file))
144 except IOError:
145 print("No config file found")
146 return 10
147
148 try:
149 targets_options = config.options('Targets')
150 targets_list = []
151 for target_key in targets_options:
152 targets_list.append(config.get('Targets', target_key))
153
154 if not targets_list:
155 print("Invalid or Empty targets")
156 return 20
157 except configparser.Error:
158 print("Invalid or Empty targets")
159 return 30
160
161 try:
162 user_value = config.get('Account', 'USER')
163 passwd_value = config.get('Account', 'PASSWORD')
164 if not user_value or not passwd_value:
165 print("Invalid or Empty credential info")
166 return 40
167
168 except configparser.Error:
169 print("Invalid or Empty credential info")
170 return 50
171
172
173 flag = 0
174 for tg in targets_list:
175
176 if not tg or not user_value or not passwd_value:
177 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
178 return 60
179 else:
180 print("SUT =", tg)
181 inventory_dict = {}
182 inventory_list = ['Asset Tag', 'System GUID', 'Get Management Controller Identifier String', 'Device ID', 'Firmware Revision', 'IPMI Version']
183 Device_ID, Firmware, IPMI_version = get_mcinfo(tg, user_value, passwd_value)
184 inventory_dict.update({'Asset Tag':get_asset_tag(tg, user_value, passwd_value)})
185 inventory_dict.update({'System GUID':get_guid(tg, user_value, passwd_value)})
186 inventory_dict.update({'Get Management Controller Identifier String':get_mcid(tg, user_value, passwd_value)})
187 inventory_dict.update({'Device ID':Device_ID})
188 #inventory_dict.update({'Manufacturer Name':Manufacturer})
189 inventory_dict.update({'Firmware Revision':Firmware})
190 inventory_dict.update({'IPMI Version':IPMI_version})
191
192 for item in inventory_list:
193 if inventory_dict.get(item) == 'Error' or inventory_dict.get(item) == None:
194 flag = 1
195
196 print("{}: {}".format(item, inventory_dict.get(item)))
197
198 if flag == 1:
199 return 1
200 return 0
201
202def main():
203 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
204 parser = ArgumentParser(description=intro_message,
205 formatter_class=RawTextHelpFormatter)
206 parser.add_argument('--config', type=str,
207 default="/etc/checkbox.d/bmc.cfg",
208 help="Supply config file for getting authentication info")
209 args = parser.parse_args()
210
211 return inventory(args)
212
213if __name__ == '__main__':
214 sys.exit(main())
0215
=== added file 'bin/ipmi_power_draw'
--- bin/ipmi_power_draw 1970-01-01 00:00:00 +0000
+++ bin/ipmi_power_draw 2015-08-14 22:03:31 +0000
@@ -0,0 +1,126 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_power_draw
8 1. GatherRetrieving power draw datainfo via ipmitool
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".
10 3. Criteria: The return value of each item cannot be null
11
12Authors
13 Sophia Wu <Sophia.Wu@itri.org.tw>
14
15This program is free software: you can redistribute it and/or modify
16it under the terms of the GNU General Public License version 3,
17as published by the Free Software Foundation.
18
19This program is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22GNU General Public License for more details.
23
24You should have received a copy of the GNU General Public License
25along with this program. If not, see <http://www.gnu.org/licenses/>.
26
27"""
28from argparse import (
29 ArgumentParser,
30 RawTextHelpFormatter
31)
32import sys
33import shlex
34import re
35import time
36import configparser
37import subprocess
38from subprocess import (
39 CalledProcessError,
40 check_call,
41 check_output
42)
43
44def get_power_draw(host_ip, user, password):
45 cmd = 'ipmitool -H {} -U {} -P {} dcmi power reading'.format(host_ip, user, password)
46 output = check_output(shlex.split(cmd), universal_newlines=True)
47 return output
48
49def power_draw_test(args):
50
51 #Default config file to config requirement info for DCMI in-band/out-of-band access
52 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
53 if not "config" in vars(args):
54 config_file = DEFAULT_CFG
55 else:
56 config_file = args.config
57
58 config = configparser.RawConfigParser()
59
60 try:
61 config.readfp(open(config_file))
62 except IOError:
63 print("No config file found")
64 return 10
65
66 # Acquire ME IP/Credential parameters from config file
67 try:
68 targets_options = config.options('Targets')
69 targets_list = []
70 for target_key in targets_options:
71 targets_list.append(config.get('Targets', target_key))
72 if not targets_list:
73 print("Invalid or Empty targets")
74 return 20
75 except configparser.Error:
76 print("Invalid or Empty targets")
77 return 30
78
79 try:
80 user_value = config.get('Account', 'USER')
81 passwd_value = config.get('Account', 'PASSWORD')
82 except configparser.Error:
83 print("Invalid or Empty credential info")
84 return 40
85
86 flag = 0
87 for target in targets_list:
88
89 if not target or not user_value or not passwd_value:
90 print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
91 return 50
92 else:
93 print("SUT =", target)
94
95 try:
96 power_draw_return = get_power_draw(target, user_value, passwd_value)
97 time.sleep(5)
98 except CalledProcessError as command_exception:
99 print("Failed executing dcmi command", command_exception)
100 return 60
101
102 power_list = ['Minimum during sampling period', 'Maximum during sampling period',\
103 'Average power reading over sample period',\
104 'IPMI timestamp', 'Sampling period', 'Power reading state is']
105 for i in power_list:
106 value = re.search(i+':\s*([a-zA-Z0-9-: ]+)', power_draw_return)
107 if value == None:
108 print("{}: Error".format(i))
109 flag = 1
110 else:
111 print("{}: {}".format(i, value.group(1)))
112 if flag == 1:
113 return 1
114 return 0
115
116def main():
117 intro_message = "Default config location is /etc/checkbox.d/me.cfg"
118 parser = ArgumentParser(description=intro_message,
119 formatter_class=RawTextHelpFormatter)
120 parser.add_argument('--config', default="/etc/checkbox.d/me.cfg",
121 help="Supply config file for getting authentication info")
122 args = parser.parse_args()
123 return power_draw_test(args)
124
125if __name__ == '__main__':
126 sys.exit(main())
0127
=== added file 'bin/ipmi_power_off_on'
--- bin/ipmi_power_off_on 1970-01-01 00:00:00 +0000
+++ bin/ipmi_power_off_on 2015-08-14 22:03:31 +0000
@@ -0,0 +1,193 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_power_off_on
8
9Description
10 1. Use ipmitool out-of-band access to turn on/off the SUT.
11 2. Criteria: the SUT can be powered on/off by ipmitool out-of-band access.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29from argparse import (
30 ArgumentParser,
31 RawTextHelpFormatter
32)
33
34import sys
35import configparser
36import shlex
37import subprocess
38import ast
39import time
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44
45def check_power_status(host_ip, user, password):
46
47 cmd_status_on = 'ipmitool -H {} -U {} -P {} power status| grep -q "on"'\
48 .format(host_ip, user, password)
49 check_on_value = subprocess.call(cmd_status_on, shell=True)
50 time.sleep(5)
51
52 cmd_status_off = 'ipmitool -H {} -U {} -P {} power status| grep -q "off"'\
53 .format(host_ip, user, password)
54 check_off_value = subprocess.call(cmd_status_off, shell=True)
55 time.sleep(5)
56
57 if check_on_value == 0 and check_off_value == 1:
58 check_status = 'on'
59
60 elif check_on_value == 1 and check_off_value == 0:
61 check_status = 'off'
62
63 else:
64 check_status = 'error'
65
66 return check_status
67
68def run_power_off(host_ip, user, password):
69 cmd_power_off = 'ipmitool -H {} -U {} -P {} power off'\
70 .format(host_ip, user, password)
71 power_off_return_code = subprocess.call(cmd_power_off, shell=True)
72 return power_off_return_code
73
74def run_power_on(host_ip, user, password):
75 cmd_power_on = 'ipmitool -H {} -U {} -P {} power on'\
76 .format(host_ip, user, password)
77 power_on_return_code = subprocess.call(cmd_power_on, shell=True)
78 return power_on_return_code
79
80def ipmi_reset_oob(args):
81
82 #IPMI config file
83 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
84 if not "config" in vars(args):
85 config_file = DEFAULT_CFG
86 else:
87 config_file = args.config
88
89 config = configparser.RawConfigParser()
90
91 try:
92 config.readfp(open(config_file))
93 except IOError:
94 print("No config file found")
95 return 10
96
97 try:
98 targets_options = config.options('Targets')
99 targets_list = []
100 for target_key in targets_options:
101 targets_list.append(config.get('Targets', target_key))
102
103 if not targets_list:
104 print("Invalid or Empty targets")
105 return 20
106
107 except configparser.Error:
108 print("Invalid or Empty targets")
109 return 30
110
111 try:
112 user_value = config.get('Account', 'USER')
113 passwd_value = config.get('Account', 'PASSWORD')
114 if not user_value or not passwd_value:
115 print("Invalid or Empty credential info")
116 return 40
117
118 except configparser.Error:
119 print("Invalid or Empty credential info")
120 return 50
121
122 ping_flag = 0
123 for tg in targets_list:
124
125 if not tg or not user_value or not passwd_value:
126 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
127 return 21
128 else:
129
130 print("SUT =", tg)
131 print("USER =", user_value)
132 print("PASSWORD =", passwd_value)
133
134 for n in range(2):
135
136 count = 0
137 while count < 10:
138 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
139 ping_rtn = subprocess.call(ping_cmd, shell=True)
140 if ping_rtn == 0:
141 print("Destination Host Reachable")
142
143 #run test
144 status = check_power_status(tg, user_value, passwd_value)
145
146 if status == 'on':
147 #run power off
148 power_off_result = run_power_off(tg, user_value, passwd_value)
149 print(" ")
150 if power_off_result == 1:
151 print("Failed to power off SUT.")
152 return 88
153 elif status == 'off':
154 #run power on
155 power_on_result = run_power_on(tg, user_value, passwd_value)
156 print(" ")
157 if power_on_result == 1:
158 print("Failed to power on SUT.")
159 return 99
160 else:
161 #do nothing
162 print("Failed to check power status")
163 return 77
164
165 time.sleep(180)
166 break
167
168 else:
169 time.sleep(10)
170 count = count+1
171 print("Destination Host Unreachable")
172
173 if count == 10:
174 print("Host Has No Response, End of Test")
175 ping_flag = 100
176
177 if ping_flag == 100:
178 return 100
179 return 0
180
181def main():
182
183 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
184 parser = ArgumentParser(description=intro_message,
185 formatter_class=RawTextHelpFormatter)
186 parser.add_argument('--config', type=str,
187 default="/etc/checkbox.d/bmc.cfg",
188 help="Supply config file for getting authentication info")
189 args = parser.parse_args()
190 return ipmi_reset_oob(args)
191
192if __name__ == "__main__":
193 sys.exit(main())
0194
=== added file 'bin/ipmi_power_policy'
--- bin/ipmi_power_policy 1970-01-01 00:00:00 +0000
+++ bin/ipmi_power_policy 2015-08-14 22:03:31 +0000
@@ -0,0 +1,165 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_power_policy
8
9Description
10 1. Use ipmitool to set power on policy through OOB.
11 2. Criteria: the change of power policy should take effect without BMC firmware cold reset or system reboot.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29
30from argparse import (
31 ArgumentParser,
32 RawTextHelpFormatter
33)
34
35import sys
36import shlex
37import time
38import subprocess
39from subprocess import (
40 check_output,
41 CalledProcessError
42)
43import re
44import configparser
45import os
46
47def set_power_policy(host_ip, user, password, rule):
48 os.system('ipmitool -H {} -U {} -P {} chassis policy {}'.format(host_ip, user, password, rule))
49
50def get_chassis_status(host_ip, user, password):
51 cmd = 'ipmitool -H {} -U {} -P {} chassis status'.format(host_ip, user, password)
52 output = check_output(shlex.split(cmd), universal_newlines=True)
53 return output
54
55def get_power_policy(host_ip, user, password):
56 result = get_chassis_status(host_ip, user, password)
57 policy = re.search(r'Power Restore Policy\s*:\s*([a-zA-Z0-9-._ ]+\n)', result)
58 if policy == None:
59 return 'Error'
60 else:
61 return policy.group(1).strip()
62
63def check_policy(host_ip, user, password, rule):
64 current_policy = get_power_policy(host_ip, user, password)
65 if current_policy == rule:
66 print("Successfully setting power policy")
67 return 0
68 else:
69 return 1
70
71def power_policy_test(args):
72
73 #IPMI config file
74 policy_rule = args.rule
75 if not policy_rule:
76 print("No specified policy to set")
77 return 88
78
79 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
80
81 if not "config" in vars(args):
82 config_file = DEFAULT_CFG
83 else:
84 config_file = args.config
85
86 config = configparser.RawConfigParser()
87
88 try:
89 config.readfp(open(config_file))
90 except IOError:
91 print("No config file found")
92 return 10
93
94 try:
95 targets_options = config.options('Targets')
96 targets_list = []
97 for target_key in targets_options:
98 targets_list.append(config.get('Targets', target_key))
99
100 if not targets_list:
101 print("Invalid or Empty targets")
102 return 20
103
104 except configparser.Error:
105 print("Invalid or Empty targets")
106 return 30
107
108 try:
109 user_value = config.get('Account', 'USER')
110 passwd_value = config.get('Account', 'PASSWORD')
111 if not user_value or not passwd_value:
112 print("Invalid or Empty credential info")
113 return 40
114
115 except configparser.Error:
116 print("Invalid or Empty credential info")
117 return 50
118
119 flag = 0
120 for tg in targets_list:
121
122 if not tg or not user_value or not passwd_value:
123 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
124 return 60
125 else:
126 print("SUT =", tg)
127
128 try:
129 set_power_policy(tg, user_value, passwd_value, policy_rule)
130 except:
131 print("Fail to set power policy")
132 return 70
133
134 time.sleep(5)
135
136 try:
137 chassis_status = get_chassis_status(tg, user_value, passwd_value)
138 except:
139 print("Fail to get chassis status")
140 return 80
141
142 current_policy = get_power_policy(tg, user_value, passwd_value)
143
144 value = check_policy(tg, user_value, passwd_value, policy_rule)
145
146 if value == 1:
147 flag = 1
148
149 if flag == 1:
150 return 1
151 return 0
152
153def main():
154 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
155 parser = ArgumentParser(description=intro_message,
156 formatter_class=RawTextHelpFormatter)
157 parser.add_argument('--config', type=str,
158 default="/etc/checkbox.d/bmc.cfg",
159 help="Supply config file for getting authentication info")
160 parser.add_argument('--rule', help="always-on, always-off or previous")
161 args = parser.parse_args()
162 return power_policy_test(args)
163
164if __name__ == '__main__':
165 sys.exit(main())
0166
=== added file 'bin/ipmi_power_reset'
--- bin/ipmi_power_reset 1970-01-01 00:00:00 +0000
+++ bin/ipmi_power_reset 2015-08-14 22:03:31 +0000
@@ -0,0 +1,142 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_power_reset
8
9Description
10 1. Use ipmitool out-of-band access to power hard reset the SUT 20 times.
11 2. Criteria: complete 20 power hard reset on SUT successfully using ipmitool out-of-band access.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29
30from argparse import (
31 ArgumentParser,
32 RawTextHelpFormatter
33)
34
35import sys
36import configparser
37import shlex
38import subprocess
39import ast
40import time
41from subprocess import (
42 check_output,
43 CalledProcessError
44)
45
46def run(host_ip, user, password):
47 cmd = 'ipmitool -H {} -U {} -P {} power reset'.format(host_ip, user, password)
48 power_reset_return = check_output(shlex.split(cmd), universal_newlines=True)
49 return power_reset_return
50
51def ipmi_reset_oob(args):
52
53 #IPMI config file
54 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
55 if not "config" in vars(args):
56 config_file = DEFAULT_CFG
57 else:
58 config_file = args.config
59
60 config = configparser.RawConfigParser()
61 try:
62 config.readfp(open(config_file))
63 except IOError:
64 print("No config file found")
65 return 1
66
67 try:
68 targets_options = config.options('Targets')
69 targets_list = []
70 for target_key in targets_options:
71 targets_list.append(config.get('Targets', target_key))
72 if not targets_list:
73 print("Invalid or Empty targets")
74 return 2
75 except configparser.Error:
76 print("Invalid or Empty targets")
77 return 2
78
79 try:
80 user_value = config.get("Account", "USER")
81 password_value = config.get("Account", "PASSWORD")
82 except configparser.NoOptionError:
83 print("Invalid or Empty credential info")
84 return 3
85
86 ping_flag = 0
87 for tg in targets_list:
88
89 if not tg or not user_value or not password_value:
90 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
91 return 4
92 else:
93 print("SUT =", tg)
94 print("USER =", user_value)
95 print("PASSWORD =", password_value)
96
97 for n in range(20):
98 print("---------------- %s ----------------" % n)
99 count = 0
100 while count < 10:
101 print("+++++++++++ %s ++++++++++++" % count)
102 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
103 ping_rtn = subprocess.call(ping_cmd, shell=True)
104
105 if ping_rtn == 0:
106 print("Destination Host Reachable")
107
108 try:
109 power_control = run(tg, user_value, password_value)
110 print(power_control)
111 except CalledProcessError as ipmi_exception:
112 print("Failed executing ipmi, Reason: %s" % ipmi_exception)
113 return 6
114
115 time.sleep(180)
116 break
117 else:
118 time.sleep(10)
119 count = count+1
120 print("Destination Host Unreachable")
121
122 if count == 10:
123 print("Host Has No Response, End of Test")
124 ping_flag = 100
125
126 if ping_flag == 100:
127 return 100
128 return 0
129
130def main():
131
132 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
133 parser = ArgumentParser(description=intro_message,
134 formatter_class=RawTextHelpFormatter)
135 parser.add_argument('--config',
136 default="/etc/checkbox.d/bmc.cfg",
137 help="Supply config file for getting authentication info")
138 args = parser.parse_args()
139 return ipmi_reset_oob(args)
140
141if __name__ == "__main__":
142 sys.exit(main())
0143
=== added file 'bin/ipmi_priv_admin'
--- bin/ipmi_priv_admin 1970-01-01 00:00:00 +0000
+++ bin/ipmi_priv_admin 2015-08-14 22:03:31 +0000
@@ -0,0 +1,176 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_priv_admin
8
9Description
10 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account.
11 2. Criteria: reading power status, performing power reset and adding a user account must all be successful.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29from argparse import (
30 ArgumentParser,
31 RawTextHelpFormatter
32)
33
34import sys
35import configparser
36import shlex
37import subprocess
38import ast
39import time
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44
45def get_power_status(host_ip, user, password):
46 cmd_status = 'ipmitool -H {} -U {} -P {} power status 1>/dev/null 2>/dev/null'\
47 .format(host_ip, user, password)
48 status_code = subprocess.call(cmd_status, shell=True)
49 return status_code
50
51def power_reset(host_ip, user, password):
52 cmd_reset = 'ipmitool -H {} -U {} -P {} power reset 1>/dev/null 2>/dev/null'\
53 .format(host_ip, user, password)
54 reset_code = subprocess.call(cmd_reset, shell=True)
55 return reset_code
56
57def add_user(host_ip, user, password, new_id, new_user):
58 cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} 1>/dev/null 2>/dev/null'\
59 .format(host_ip, user, password, new_id, new_user)
60 add_user_code = subprocess.call(cmd_add_user, shell=True)
61 return add_user_code
62
63def ipmi_user_level_test(args):
64
65 #IPMI config file
66 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
67 if not "config" in vars(args):
68 config_file = DEFAULT_CFG
69 else:
70 config_file = args.config
71 config = configparser.RawConfigParser()
72 try:
73 config.readfp(open(config_file))
74 except IOError:
75 print("No config file found")
76 return 10
77
78 try:
79 targets_options = config.options('Targets')
80 targets_list = []
81 for target_key in targets_options:
82 targets_list.append(config.get('Targets', target_key))
83 if not targets_list:
84 print("Invalid or Empty targets")
85 return 20
86 except configparser.Error:
87 print("Invalid or Empty targets")
88 return 20
89
90 try:
91 user_value = config.get("Admin Level", "ADMIN_NAME")
92 password_value = config.get("Admin Level", "ADMIN_PASSWD")
93 except configparser.NoOptionError:
94 print("Invalid or Empty credential info")
95 print("Require Operator Level info pre-configured in /etc/checkbox.d/bmc.cfg")
96 return 30
97
98 try:
99 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
100 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
101 except configparser.NoOptionError:
102 print("Invalid or Empty new user info")
103 print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg")
104 return 40
105
106 flag = 0
107 for tg in targets_list:
108
109 if not tg or not user_value or not password_value:
110 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
111 return 50
112 else:
113 print("SUT", tg)
114
115 ping_result = ping_test(tg)
116 if ping_result != 0:
117 return 88
118
119 status_result = get_power_status(tg, user_value, password_value)
120 time.sleep(5)
121
122 reset_result = power_reset(tg, user_value, password_value)
123 time.sleep(180)
124 if not new_user_value or not new_user_id_value:
125 print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg")
126 return 60
127 else:
128
129 ping_result = ping_test(tg)
130 if ping_result != 0:
131 return 88
132
133 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
134 time.sleep(5)
135
136 if status_result == 0 and reset_result == 0 and add_user_result == 0:
137 print("User can read power status.")
138 print("User can reset power.")
139 print("User can add a new user.")
140 else:
141 print("Authentication: Not Administrator Level")
142 flag = 1
143
144 if flag == 1:
145 return 100
146 return 0
147
148def ping_test(host_ip):
149 count = 0
150 while count < 10:
151 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
152 ping_rtn = subprocess.call(ping_cmd, shell=True)
153 if ping_rtn == 0:
154 return 0
155 else:
156 print("Destination Host Unreachable")
157 time.sleep(10)
158 count = count+1
159
160 if count == 10:
161 print("Host Has No Response, End of Test")
162 return 1
163
164
165def main():
166
167 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
168 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
169 parser.add_argument('--config', type=str,
170 default="/etc/checkbox.d/bmc.cfg",
171 help="Supply config file for getting authentication info")
172 args = parser.parse_args()
173 return ipmi_user_level_test(args)
174
175if __name__ == "__main__":
176 sys.exit(main())
0177
=== added file 'bin/ipmi_priv_oper'
--- bin/ipmi_priv_oper 1970-01-01 00:00:00 +0000
+++ bin/ipmi_priv_oper 2015-08-14 22:03:31 +0000
@@ -0,0 +1,174 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_priv_oper
8 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account.
9 2. Criteria: power status reading and power reset must be successful and must fail at adding a new user account.
10
11Authors
12 Sophia Wu <Sophia.Wu@itri.org.tw>
13
14This program is free software: you can redistribute it and/or modify
15it under the terms of the GNU General Public License version 3,
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26"""
27from argparse import (
28 ArgumentParser,
29 RawTextHelpFormatter
30)
31
32import sys
33import configparser
34import shlex
35import subprocess
36import ast
37import time
38from subprocess import (
39 check_output,
40 CalledProcessError
41)
42
43def get_power_status(host_ip, user, password):
44 cmd_status = 'ipmitool -H {} -U {} -P {} power status -L operator 1>/dev/null 2>/dev/null'\
45 .format(host_ip, user, password)
46 status_code = subprocess.call(cmd_status, shell=True)
47 return status_code
48
49def power_reset(host_ip, user, password):
50 cmd_reset = 'ipmitool -H {} -U {} -P {} power reset -L operator 1>/dev/null 2>/dev/null'\
51 .format(host_ip, user, password)
52 reset_code = subprocess.call(cmd_reset, shell=True)
53 return reset_code
54
55def add_user(host_ip, user, password, new_id, new_user):
56 cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} -L operator 1>/dev/null 2>/dev/null'\
57 .format(host_ip, user, password, new_id, new_user)
58 add_user_code = subprocess.call(cmd_add_user, shell=True)
59 return add_user_code
60
61def ipmi_user_level_test(args):
62
63 #IPMI config file
64 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
65 if not "config" in vars(args):
66 config_file = DEFAULT_CFG
67 else:
68 config_file = args.config
69 config = configparser.RawConfigParser()
70 try:
71 config.readfp(open(config_file))
72 except IOError:
73 print("No config file found")
74 return 10
75
76 try:
77 targets_options = config.options('Targets')
78 targets_list = []
79 for target_key in targets_options:
80 targets_list.append(config.get('Targets', target_key))
81 if not targets_list:
82 print("Invalid or Empty targets")
83 return 20
84 except configparser.Error:
85 print("Invalid or Empty targets")
86 return 20
87
88 try:
89 user_value = config.get("Operator Level", "OPER_NAME")
90 password_value = config.get("Operator Level", "OPER_PASSWD")
91 except configparser.NoOptionError:
92 print("Invalid or Empty credential info")
93 print("Require Operator Level info pre-configured in /etc/checkbox.d/bmc.cfg")
94 return 30
95
96 try:
97 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
98 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
99 except configparser.NoOptionError:
100 print("Invalid or Empty new user info")
101 print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg")
102 return 40
103
104 flag = 0
105 for tg in targets_list:
106
107 if not tg or not user_value or not password_value:
108 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
109 return 50
110 else:
111 print("SUT", tg)
112
113 ping_result = ping_test(tg)
114 if ping_result != 0:
115 return 88
116
117 status_result = get_power_status(tg, user_value, password_value)
118 time.sleep(5)
119
120 reset_result = power_reset(tg, user_value, password_value)
121 time.sleep(180)
122 if not new_user_value or not new_user_id_value:
123 print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg")
124 return 60
125 else:
126
127 ping_result = ping_test(tg)
128 if ping_result != 0:
129 return 88
130
131 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
132 time.sleep(5)
133
134 if status_result == 0 and reset_result == 0 and add_user_result == 1:
135 print("User can read power status.")
136 print("User can reset power.")
137 print("User can't add a new user.")
138 else:
139 print("Authentication: Not Operator Level")
140 flag = 1
141
142 if flag == 1:
143 return 100
144 return 0
145
146def ping_test(host_ip):
147 count = 0
148 while count < 10:
149 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
150 ping_rtn = subprocess.call(ping_cmd, shell=True)
151 if ping_rtn == 0:
152 return 0
153 else:
154 print("Destination Host Unreachable")
155 time.sleep(10)
156 count = count+1
157
158 if count == 10:
159 print("Host Has No Response, End of Test")
160 return 1
161
162
163def main():
164
165 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
166 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
167 parser.add_argument('--config', type=str,
168 default="/etc/checkbox.d/bmc.cfg",
169 help="Supply config file for getting authentication info")
170 args = parser.parse_args()
171 return ipmi_user_level_test(args)
172
173if __name__ == "__main__":
174 sys.exit(main())
0175
=== added file 'bin/ipmi_priv_user'
--- bin/ipmi_priv_user 1970-01-01 00:00:00 +0000
+++ bin/ipmi_priv_user 2015-08-14 22:03:31 +0000
@@ -0,0 +1,176 @@
1#! /usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_priv_uesr
8
9Description
10 1. Use ipmitool out-of-band to read power status, to perform power reset and add a new user account.
11 2. Criteria: power status reading must be successful and must fail at power reset and adding a new user account.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29from argparse import (
30 ArgumentParser,
31 RawTextHelpFormatter
32)
33
34import sys
35import configparser
36import shlex
37import subprocess
38import ast
39import time
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44
45def get_power_status(host_ip, user, password):
46 cmd_status = 'ipmitool -H {} -U {} -P {} power status -L user 1>/dev/null 2>/dev/null'\
47 .format(host_ip, user, password)
48 status_code = subprocess.call(cmd_status, shell=True)
49 return status_code
50
51def power_reset(host_ip, user, password):
52 cmd_reset = 'ipmitool -H {} -U {} -P {} power reset -L user 1>/dev/null 2>/dev/null'\
53 .format(host_ip, user, password)
54 reset_code = subprocess.call(cmd_reset, shell=True)
55 return reset_code
56
57def add_user(host_ip, user, password, new_id, new_user):
58 cmd_add_user = 'ipmitool -H {} -U {} -P {} user set name {} {} -L user 1>/dev/null 2>/dev/null'\
59 .format(host_ip, user, password, new_id, new_user)
60 add_user_code = subprocess.call(cmd_add_user, shell=True)
61 return add_user_code
62
63def ipmi_user_level_test(args):
64
65 #IPMI config file
66 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
67 if not "config" in vars(args):
68 config_file = DEFAULT_CFG
69 else:
70 config_file = args.config
71 config = configparser.RawConfigParser()
72 try:
73 config.readfp(open(config_file))
74 except IOError:
75 print("No config file found")
76 return 10
77
78 try:
79 targets_options = config.options('Targets')
80 targets_list = []
81 for target_key in targets_options:
82 targets_list.append(config.get('Targets', target_key))
83 if not targets_list:
84 print("Invalid or Empty targets")
85 return 20
86 except configparser.Error:
87 print("Invalid or Empty targets")
88 return 20
89
90 try:
91 user_value = config.get("User Level", "USER_NAME")
92 password_value = config.get("User Level", "USER_PASSWD")
93 except configparser.NoOptionError:
94 print("Invalid or Empty credential info")
95 print("Require User Level info pre-configured in /etc/checkbox.d/bmc.cfg")
96 return 30
97
98 try:
99 new_user_value = config.get("Add User Test", "NEW_USER_NAME")
100 new_user_id_value = config.get("Add User Test", "NEW_USER_ID")
101 except configparser.NoOptionError:
102 print("Invalid or Empty new user info")
103 print("Require new User info pre-configured in /etc/checkbox.d/bmc.cfg")
104 return 40
105
106 flag = 0
107 for tg in targets_list:
108
109 if not tg or not user_value or not password_value:
110 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
111 return 50
112 else:
113 print("SUT", tg)
114
115 ping_result = ping_test(tg)
116 if ping_result != 0:
117 return 88
118
119 status_result = get_power_status(tg, user_value, password_value)
120 time.sleep(5)
121
122 reset_result = power_reset(tg, user_value, password_value)
123 time.sleep(180)
124 if not new_user_value or not new_user_id_value:
125 print("Require new user info pre-configured in /etc/checkbox.d/bmc.cfg")
126 return 60
127 else:
128
129 ping_result = ping_test(tg)
130 if ping_result != 0:
131 return 88
132
133 add_user_result = add_user(tg, user_value, password_value, new_user_id_value, new_user_value)
134 time.sleep(5)
135
136 if status_result == 0 and reset_result == 1 and add_user_result == 1:
137 print("User can read power status.")
138 print("User can't reset power.")
139 print("User can't add a new user.")
140 else:
141 print("Authentication: Not User Level")
142 flag = 1
143
144 if flag == 1:
145 return 100
146 return 0
147
148def ping_test(host_ip):
149 count = 0
150 while count < 10:
151 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(host_ip)
152 ping_rtn = subprocess.call(ping_cmd, shell=True)
153 if ping_rtn == 0:
154 return 0
155 else:
156 print("Destination Host Unreachable")
157 time.sleep(10)
158 count = count+1
159
160 if count == 10:
161 print("Host Has No Response, End of Test")
162 return 1
163
164
165def main():
166
167 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
168 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
169 parser.add_argument('--config', type=str,
170 default="/etc/checkbox.d/bmc.cfg",
171 help="Supply config file for getting authentication info")
172 args = parser.parse_args()
173 return ipmi_user_level_test(args)
174
175if __name__ == "__main__":
176 sys.exit(main())
0177
=== added file 'bin/ipmi_sampling'
--- bin/ipmi_sampling 1970-01-01 00:00:00 +0000
+++ bin/ipmi_sampling 2015-08-14 22:03:31 +0000
@@ -0,0 +1,273 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_sampling
8
9Description
10 1. Retrieve CPU and intake temperature 30 times at 3 second intervals using ipmitool
11 2. If failed to retrieve temperature at any time within 30 times, the test is considered failed
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29import sys
30import time
31import re
32import configparser
33import shlex
34import subprocess
35from argparse import (
36 ArgumentParser,
37 RawTextHelpFormatter
38)
39from subprocess import (
40 check_output,
41 CalledProcessError
42)
43
44def get_sdr_remote(host_ip, user, password):
45 cmd = "ipmitool -H {} -U {} -P {} sdr".format(host_ip, user, password)
46 sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT,
47 universal_newlines=True)
48 return sdr_return
49
50def parse_sdr(output):
51 output = output.strip()
52 output_1Line = output.split("\n")
53 data = {}
54
55 for line in output_1Line:
56 sub_value = {}
57 string_list = line.split("|")
58 name = string_list[0].strip()
59 sensor_output = string_list[1].strip()
60 sub_value.update({'output':sensor_output})
61 status = string_list[2].strip()
62 sub_value.update({'status':status})
63 data.update({name:sub_value})
64 return data
65
66def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
67 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
68 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
69 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
70 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
71 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
72 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
73 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
74 return str(CPU_temp)+' degrees C'
75 else:
76 return 'Error'
77 else:
78 return 'None'
79
80def ipmi_sdr(args):
81
82 cmd_flag = 0
83 #IPMI config file
84 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
85 if not "config" in vars(args):
86 config_file = DEFAULT_CFG
87 else:
88 config_file = args.config
89
90 config = configparser.RawConfigParser()
91
92 try:
93 config.readfp(open(config_file))
94 except IOError:
95 print("No config file found")
96 return 10
97
98 try:
99 sensor_nick = config.options("SensorsForSampling")
100 except configparser.NoSectionError:
101 print("No Section: SensorsForSampling")
102 return 20
103
104 if sensor_nick:
105 sensor_list = []
106 for id in sensor_nick:
107 sensor_key = config.get("SensorsForSampling", id)
108 if sensor_key:
109 sensor_list.append(sensor_key)
110 else:
111 print("No Sensor ID specified in Config file")
112 return 30
113 else:
114 print("No key of Sensor ID specified in config file")
115 return 40
116
117 try:
118 targets_options = config.options('Targets')
119 targets_list = []
120 for target_key in targets_options:
121 targets_list.append(config.get('Targets', target_key))
122 if not targets_list:
123 print("Invalid or Empty targets")
124 return 60
125 except configparser.Error:
126 print("Invalid or Empty targets")
127 return 60
128
129 try:
130 user_value = config.get("Account", "USER")
131 password_value = config.get("Account", "PASSWORD")
132 except configparser.NoOptionError:
133 print("Invalid or Empty credential info")
134 return 70
135
136 for tg in targets_list:
137
138 if not tg or not user_value or not password_value:
139 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
140 return 80
141 else:
142
143 c = 0
144 while c < 10:
145 ping_cmd = 'ping -c 1 {}>/dev/null 2>/dev/null'.format(tg)
146 ping_rtn = subprocess.call(ping_cmd, shell=True)
147 if ping_rtn == 0:
148 print("Destination Host Reachable")
149 break
150 else:
151 time.sleep(10)
152 c = c+1
153 print("Destination Host Unreachable")
154
155 if c == 10:
156 print("Host Has No Response, End of Test")
157 return 99
158
159
160 sampling_data = []
161 times = 30
162 for n in range(times):
163
164 try:
165 sensor_data = get_sdr_remote(tg, user_value, password_value)
166 time.sleep(3)
167 except CalledProcessError as ipmi_exception:
168 print("Failed executing ipmi, Reason: %s" % ipmi_exception)
169 sensor_data = ''
170
171 sampling_data.append(sensor_data)
172
173 count = 0
174 prs_flag = 0
175 dis_flag = 0
176 for output in sampling_data:
177 try:
178 data = parse_sdr(output)
179 except:
180 print("Parsing output of sdr table error")
181 print("=======================================================")
182 prs_flag = 1
183 count = count+1
184 continue
185
186 disable = 0
187 need_data = {}
188
189 for need_id in sensor_list:
190
191 if data.get(need_id):
192 need_value = data.get(need_id).get('output')
193 need_data.update({need_id:need_value})
194 if data.get(need_id).get('status') != 'ok':
195 disable = 1
196 else:
197
198 try:
199 CPUx_Temp = config.get("Sensors", "CPUx")
200 except configparser.NoOptionError:
201 CPUx_Temp = ''
202
203 try:
204 CPUy_Temp = config.get("Sensors", "CPUy")
205 except configparser.NoOptionError:
206 CPUy_Temp = ''
207
208 if need_id == CPUx_Temp:
209
210 try:
211 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
212 except configparser.NoOptionError:
213 PxTM = ''
214
215 try:
216 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
217 except configparser.NoOptionError:
218 CPUx_Tjmax = ''
219
220 if PxTM and CPUx_Tjmax:
221 Px_temp = calculate_CPU_temp(data, PxTM, CPUx_Tjmax)
222 need_data.update({CPUx_Temp:Px_temp})
223 if Px_temp == 'None' or Px_temp == 'Error':
224 disable = 1
225 else:
226 disable = 1
227
228 elif need_id == CPUy_Temp:
229
230 try:
231 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
232 except configparser.NoOptionError:
233 PyTM = ''
234
235 try:
236 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
237 except configparser.NoOptionError:
238 CPUy_Tjmax = ''
239
240 if PyTM and CPUy_Tjmax:
241 Py_temp = calculate_CPU_temp(data, PyTM, CPUy_Tjmax)
242 need_data.update({CPUy_Temp:Py_temp})
243 if Py_temp == 'None' or Py_temp == 'Error':
244 disable = 1
245 else:
246 disable = 1
247
248 else:
249 need_data.update({need_id:'None'})
250 disable = 1
251
252 if disable == 1:
253 dis_flag = 1
254 print(need_data)
255 print("=======================================================")
256 count = count+1
257 print("Pass: %d" %(times-count))
258 print("Fail: %d" %(count))
259
260 if cmd_flag == 1 or prs_flag == 1 or dis_flag == 1:
261 return 100
262 return 0
263
264def main():
265
266 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
267 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
268 parser.add_argument('--config', type=str, default="/etc/checkbox.d/bmc.cfg", help="Supply config file for sensor IDs parameters")
269 args = parser.parse_args()
270 return ipmi_sdr(args)
271
272if __name__ == "__main__":
273 sys.exit(main())
0274
=== modified file 'bin/ipmi_sel_entries'
--- bin/ipmi_sel_entries 2015-03-03 15:59:42 +0000
+++ bin/ipmi_sel_entries 2015-08-14 22:03:31 +0000
@@ -5,13 +5,11 @@
55
6File Name6File Name
7 ipmi_sel_entries7 ipmi_sel_entries
8
9Description
8 1. Use ipmitool to collect event log information10 1. Use ipmitool to collect event log information
9 2. Calculate entries number of system event log11 2. Calculate entries number of system event log
10 3. Criteria: the A log must be capable of saving at least 256 entries12 3. Criteria: the log must be capable of saving at least 256 entries
11
12Description
13 Use ipmitool to get system event log info and calculate whether
14 total number of entries is more than 256.
1513
16Authors14Authors
17 Sophia Wu <Sophia.Wu@itri.org.tw>15 Sophia Wu <Sophia.Wu@itri.org.tw>
@@ -63,8 +61,8 @@
6361
64def sel_entry_test(args):62def sel_entry_test(args):
6563
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
67 DEFAULT_CFG = "/etc/checkbox.d/me.cfg"65 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
68 if not "config" in vars(args):66 if not "config" in vars(args):
69 config_file = DEFAULT_CFG67 config_file = DEFAULT_CFG
70 else:68 else:
@@ -101,7 +99,7 @@
101 for target in targets_list:99 for target in targets_list:
102100
103 if not target or not user_value or not passwd_value:101 if not target or not user_value or not passwd_value:
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")
105 return 50103 return 50
106 else:104 else:
107 print("SUT =", target)105 print("SUT =", target)
@@ -135,11 +133,11 @@
135133
136def main():134def main():
137135
138 intro_message = "Default config location is /etc/checkbox.d/me.cfg"136 intro_message = "Default config location is /etc/xdg/bmc.cfg"
139 parser = ArgumentParser(description=intro_message,137 parser = ArgumentParser(description=intro_message,
140 formatter_class=RawTextHelpFormatter)138 formatter_class=RawTextHelpFormatter)
141 parser.add_argument('--config', default="/etc/checkbox.d/me.cfg",139 parser.add_argument('--config', default="/etc/checkbox.d/bmc.cfg",
142 help="Supply config file for getting default credential")140 help="Supply config file for getting authentication info")
143 args = parser.parse_args()141 args = parser.parse_args()
144 return sel_entry_test(args)142 return sel_entry_test(args)
145143
146144
=== added file 'bin/ipmi_sensors_ib'
--- bin/ipmi_sensors_ib 1970-01-01 00:00:00 +0000
+++ bin/ipmi_sensors_ib 2015-08-14 22:03:31 +0000
@@ -0,0 +1,215 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_sensors_ib
8
9Description
10 1. Use ipmitool/dcmitool to monitor analog sensors in SDR table through in-band access.
11 2. Criteria: the status of analog sensors should be "ok" and the data should not be null.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29import sys
30import time
31import re
32import configparser
33import shlex
34import subprocess
35import ast
36from argparse import (
37 ArgumentParser,
38 RawTextHelpFormatter
39)
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44
45
46def get_sdr(TOOL):
47 cmd = "{} sdr".format(TOOL)
48 sdr_return = subprocess.check_output(shlex.split(cmd), universal_newlines=True)
49 return sdr_return
50
51def parse_sdr(output):
52 output = output.strip()
53 output_1Line = output.split("\n")
54 data = {}
55
56 for line in output_1Line:
57 sub_value = {}
58 string_list = line.split("|")
59 name = string_list[0].strip()
60 sensor_output = string_list[1].strip()
61 sub_value.update({'output':sensor_output})
62 status = string_list[2].strip()
63 sub_value.update({'status':status})
64 data.update({name:sub_value})
65 return data
66
67def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
68
69 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
70 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
71 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
72 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
73 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
74 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
75 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
76 return str(CPU_temp)+' degrees C'
77 else:
78 return 'Error'
79 else:
80 return 'None'
81
82def ipmi_sdr(args):
83
84 flag = 0
85
86 tool_name = args.tool
87 if not tool_name:
88 print("No specified tool to use")
89 return 99
90
91 #IPMI/DCMI config file
92 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
93 if not "config" in vars(args):
94 config_file = DEFAULT_CFG
95 else:
96 config_file = args.config
97 config = configparser.RawConfigParser()
98
99 try:
100 config.readfp(open(config_file))
101 except IOError:
102 print("No config file found")
103 return 10
104
105 try:
106 sensor_nick = config.options("Sensors")
107 except configparser.NoSectionError:
108 print("No Section: Sensors")
109 return 20
110
111 if sensor_nick:
112 sensor_list = []
113 for id in sensor_nick:
114 sensor_key = config.get("Sensors", id)
115 if sensor_key:
116 sensor_list.append(sensor_key)
117 else:
118 print("No Sensor ID specified in Config file")
119 return 30
120 else:
121 print("No key of Sensor ID specified in config file")
122 return 40
123
124 try:
125 sensor_data = get_sdr(tool_name)
126 time.sleep(5)
127 except CalledProcessError as ipmi_exception:
128 print("Failed executing ipmi, Reason: %s" % ipmi_exception)
129 return 50
130
131 try:
132 data = parse_sdr(sensor_data)
133 except:
134 print("Parsing output of sdr table error")
135 return 60
136
137 need_data = {}
138 for need_id in sensor_list:
139 if data.get(need_id):
140 need_value = data.get(need_id).get('output')
141 need_data.update({need_id:need_value})
142
143 if data.get(need_id).get('status') != 'ok':
144 flag = 1
145 else:
146
147 try:
148 CPUx_Temp = config.get("Sensors", "CPUx")
149 except configparser.NoOptionError:
150 CPUx_Temp = ''
151
152 try:
153 CPUy_Temp = config.get("Sensors", "CPUy")
154 except configparser.NoOptionError:
155 CPUy_Temp = ''
156
157 if need_id == CPUx_Temp:
158
159 try:
160 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
161 except configparser.NoOptionError:
162 PxTM = ''
163
164 try:
165 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
166 except configparser.NoOptionError:
167 CPUx_Tjmax = ''
168
169 if PxTM and CPUx_Tjmax:
170 need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)})
171 if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error':
172 flag = 1
173 else:
174 flag = 1
175
176 elif need_id == CPUy_Temp:
177
178 try:
179 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
180 except configparser.NoOptionError:
181 PyTM = ''
182
183 try:
184 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
185 except configparser.NoOptionError:
186 CPUy_Tjmax = ''
187
188
189 if PyTM and CPUy_Tjmax:
190 need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)})
191 if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error':
192 flag = 1
193 else:
194 flag = 1
195 else:
196 flag = 1
197
198 print("%s: %s" %(need_id, need_data.get(need_id)))
199
200 if flag == 1:
201 return 100
202 return 0
203
204def main():
205
206 intro_message = "Default config location is /etc/checkbox.d/bmc.cfg"
207 parser = ArgumentParser(description=intro_message, formatter_class=RawTextHelpFormatter)
208 parser.add_argument('--config', type=str, default="/etc/checkbox.d/bmc.cfg", help="Supply config file for sensor IDs parameters")
209 parser.add_argument('--tool', help="ipmitool or dcmitool")
210 args = parser.parse_args()
211 return ipmi_sdr(args)
212
213if __name__ == "__main__":
214 sys.exit(main())
215
0216
=== added file 'bin/ipmi_sensors_oob'
--- bin/ipmi_sensors_oob 1970-01-01 00:00:00 +0000
+++ bin/ipmi_sensors_oob 2015-08-14 22:03:31 +0000
@@ -0,0 +1,240 @@
1#!/usr/bin/env python3
2"""
3Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
4Industrial Technology Research Institute
5
6File Name
7 ipmi_sensors_oob
8
9Description
10 1. Use ipmitool to monitor analog sensors in SDR table through OOB access.
11 2. Criteria: the status of analog sensors should be "ok" and the data should not be null.
12
13Authors
14 Sophia Wu <Sophia.Wu@itri.org.tw>
15
16This program is free software: you can redistribute it and/or modify
17it under the terms of the GNU General Public License version 3,
18as published by the Free Software Foundation.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28"""
29import sys
30import time
31import re
32import configparser
33import shlex
34import subprocess
35import ast
36from argparse import (
37 ArgumentParser,
38 RawTextHelpFormatter
39)
40from subprocess import (
41 check_output,
42 CalledProcessError
43)
44
45def get_sdr_remote(host_ip, user, password):
46 cmd = "ipmitool -H {} -U {} -P {} sdr".format(host_ip, user, password)
47 sdr_return = subprocess.check_output(shlex.split(cmd), stderr=subprocess.STDOUT,
48 universal_newlines=True)
49 return sdr_return
50
51def parse_sdr(output):
52 output = output.strip()
53 output_1Line = output.split("\n")
54 data = {}
55
56 for line in output_1Line:
57 sub_value = {}
58 string_list = line.split("|")
59 name = string_list[0].strip()
60 sensor_output = string_list[1].strip()
61 sub_value.update({'output':sensor_output})
62 status = string_list[2].strip()
63 sub_value.update({'status':status})
64 data.update({name:sub_value})
65 return data
66
67def calculate_CPU_temp(data_dict, CPU_Therm_Margin_id, CPU_Tjmax_id):
68
69 if data_dict.get(CPU_Therm_Margin_id) and data_dict.get(CPU_Tjmax_id):
70 if data_dict.get(CPU_Therm_Margin_id).get('status') == 'ok' and data_dict.get(CPU_Tjmax_id).get('status') == 'ok':
71 P_Therm_Margin_output = data_dict.get(CPU_Therm_Margin_id).get('output')
72 CPU_Tjmax_output = data_dict.get(CPU_Tjmax_id).get('output')
73 P_Therm_Margin = re.search(r'[0-9-]+', P_Therm_Margin_output).group(0)
74 CPU_Tjmax = re.search(r'[0-9-]+', CPU_Tjmax_output).group(0)
75 CPU_temp = int(P_Therm_Margin)+int(CPU_Tjmax)
76 return str(CPU_temp)+' degrees C'
77 else:
78 return 'Error'
79 else:
80 return 'None'
81
82def ipmi_sdr(args):
83
84 flag = 0
85 #IPMI config file
86 DEFAULT_CFG = "/etc/checkbox.d/bmc.cfg"
87 if not "config" in vars(args):
88 config_file = DEFAULT_CFG
89 else:
90 config_file = args.config
91
92 config = configparser.RawConfigParser()
93
94 try:
95 config.readfp(open(config_file))
96 except IOError:
97 print("No config file found")
98 return 10
99
100 try:
101 sensor_nick = config.options("Sensors")
102 except configparser.NoSectionError:
103 print("No Section: Sensors")
104 return 20
105
106 if sensor_nick:
107 sensor_list = []
108 for id in sensor_nick:
109 sensor_key = config.get("Sensors", id)
110 if sensor_key:
111 sensor_list.append(sensor_key)
112 else:
113 print("No Sensor ID specified in Config file")
114 return 30
115 else:
116 print("No key of Sensor ID specified in config file")
117 return 40
118
119 try:
120 targets_options = config.options('Targets')
121 targets_list = []
122 for target_key in targets_options:
123 targets_list.append(config.get('Targets', target_key))
124 if not targets_list:
125 print("Invalid or Empty targets")
126 return 60
127 except configparser.Error:
128 print("Invalid or Empty targets")
129 return 60
130
131 try:
132 user_value = config.get("Account", "USER")
133 password_value = config.get("Account", "PASSWORD")
134 except configparser.NoOptionError:
135 print("Invalid or Empty credential info")
136 return 70
137
138 for tg in targets_list:
139
140 if not tg or not user_value or not password_value:
141 print("Require Taget IP, Account(USER/PASSWORD) for IPMI out-of-band access")
142 return 80
143 else:
144
145 print("SUT =", tg)
146 print("USER =", user_value)
147 print("PASSWORD =", password_value)
148
149 try:
150 sensor_data = get_sdr_remote(tg, user_value, password_value)
151 time.sleep(5)
152 except CalledProcessError as ipmi_exception:
153 print("Failed executing ipmi, Reason: %s" % ipmi_exception)
154 return 50
155
156 try:
157 data = parse_sdr(sensor_data)
158 except:
159 print("Parsing output of sdr table error")
160 flag = 1
161 continue
162
163 need_data = {}
164 for need_id in sensor_list:
165
166 if data.get(need_id):
167 need_value = data.get(need_id).get('output')
168 need_data.update({need_id:need_value})
169
170 if data.get(need_id).get('status') != 'ok':
171 flag = 1
172 else:
173
174 try:
175 CPUx_Temp = config.get("Sensors", "CPUx")
176 except configparser.NoOptionError:
177 CPUx_Temp = ''
178
179 try:
180 CPUy_Temp = config.get("Sensors", "CPUy")
181 except configparser.NoOptionError:
182 CPUy_Temp = ''
183
184 if need_id == CPUx_Temp:
185
186 try:
187 PxTM = config.get("SensorsForCPUTemp", "Px Therm Margin")
188 except configparser.NoOptionError:
189 PxTM = ''
190
191 try:
192 CPUx_Tjmax = config.get("SensorsForCPUTemp", "CPUx Tjmax")
193 except configparser.NoOptionError:
194 CPUx_Tjmax = ''
195
196 if PxTM and CPUx_Tjmax:
197 need_data.update({CPUx_Temp:calculate_CPU_temp(data, PxTM, CPUx_Tjmax)})
198 if calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'None' or calculate_CPU_temp(data, PxTM, CPUx_Tjmax) == 'Error':
199 flag = 1
200 else:
201 flag = 1
202
203 elif need_id == CPUy_Temp:
204
205 try:
206 PyTM = config.get("SensorsForCPUTemp", "Py Therm Margin")
207 except configparser.NoOptionError:
208 PyTM = ''
209
210 try:
211 CPUy_Tjmax = config.get("SensorsForCPUTemp", "CPUy Tjmax")
212 except configparser.NoOptionError:
213 CPUy_Tjmax = ''
214
215 if PyTM and CPUy_Tjmax:
216 need_data.update({CPUy_Temp:calculate_CPU_temp(data, PyTM, CPUy_Tjmax)})
217 if calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'None' or calculate_CPU_temp(data, PyTM, CPUy_Tjmax) == 'Error':
218 flag = 1
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches