|
| 1 | +#!/usr/bin/python |
| 2 | +# IBM_PROLOG_BEGIN_TAG |
| 3 | +# This is an automatically generated prolog. |
| 4 | +# |
| 5 | +# $Source: op-test-framework/testcases/LightPathDiagnostics.py $ |
| 6 | +# |
| 7 | +# OpenPOWER Automated Test Project |
| 8 | +# |
| 9 | +# Contributors Listed Below - COPYRIGHT 2015 |
| 10 | +# [+] International Business Machines Corp. |
| 11 | +# |
| 12 | +# |
| 13 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | +# you may not use this file except in compliance with the License. |
| 15 | +# You may obtain a copy of the License at |
| 16 | +# |
| 17 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | +# |
| 19 | +# Unless required by applicable law or agreed to in writing, software |
| 20 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 22 | +# implied. See the License for the specific language governing |
| 23 | +# permissions and limitations under the License. |
| 24 | +# |
| 25 | +# IBM_PROLOG_END_TAG |
| 26 | + |
| 27 | +# @package LightPathDiagnostics |
| 28 | +# Currently runs only in FSP platforms |
| 29 | +# |
| 30 | + |
| 31 | +import time |
| 32 | +import subprocess |
| 33 | +import re |
| 34 | + |
| 35 | +from common.OpTestIPMI import OpTestIPMI |
| 36 | +from common.OpTestConstants import OpTestConstants as BMC_CONST |
| 37 | +from common.OpTestError import OpTestError |
| 38 | + |
| 39 | +import unittest |
| 40 | +import OpTestConfiguration |
| 41 | +from common.OpTestSystem import OpSystemState |
| 42 | + |
| 43 | +class LightPathDiagnostics(unittest.TestCase): |
| 44 | + def setUp(self): |
| 45 | + conf = OpTestConfiguration.conf |
| 46 | + self.cv_SYSTEM = conf.system() |
| 47 | + self.cv_FSP = self.cv_SYSTEM.bmc |
| 48 | + self.cv_HOST = conf.host() |
| 49 | + self.bmc_type = conf.args.bmc_type |
| 50 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 51 | + |
| 52 | + def tearDown(self): |
| 53 | + #self.cv_HOST.host_gather_opal_msg_log() |
| 54 | + #self.cv_HOST.host_gather_kernel_log() |
| 55 | + pass |
| 56 | + |
| 57 | + def lpd_init(self): |
| 58 | + # Check if system has LED support |
| 59 | + if not self.cv_SYSTEM.has_host_led_support(): |
| 60 | + self.skipTest("System has no LED support") |
| 61 | + |
| 62 | + self.assertTrue(self.cv_HOST.host_check_dt_node_exist("ibm,opal/leds"), |
| 63 | + "ibm,opal/leds DT Node doesn't exist") |
| 64 | + |
| 65 | + # If it has support, check for led's presence |
| 66 | + res = self.cv_HOST.host_run_command("ls /sys/class/leds/ | wc -l") |
| 67 | + self.assertNotEqual(int(res.strip()), 0, |
| 68 | + "No LED's found in sysfs /sys/class/leds/") |
| 69 | + |
| 70 | + self.cv_FSP.fsp_get_console() |
| 71 | + if not self.cv_FSP.mount_exists(): |
| 72 | + raise OpTestError("Please mount NFS and retry the test") |
| 73 | + |
| 74 | + def get_location_codes(self): |
| 75 | + res = self.cv_HOST.host_run_command("usysident") |
| 76 | + res = res.splitlines() |
| 77 | + loc_codes = [] |
| 78 | + for loc in res: |
| 79 | + loc_codes.append(loc.split("\t")[0]) |
| 80 | + return loc_codes |
| 81 | + |
| 82 | + def get_sysattn_indicator_loc(self): |
| 83 | + res = self.cv_HOST.host_run_command("usysattn") |
| 84 | + res = res.splitlines() |
| 85 | + loc_codes = [] |
| 86 | + for loc in res: |
| 87 | + loc_codes.append(loc.split("\t")[0]) |
| 88 | + return loc_codes[0] |
| 89 | + |
| 90 | +class UsysIdentifyTest(LightPathDiagnostics): |
| 91 | + |
| 92 | + ## |
| 93 | + # @brief This function tests usysident identification of LED's |
| 94 | + # |
| 95 | + def runTest(self): |
| 96 | + self.lpd_init() |
| 97 | + loc_codes = self.get_location_codes() |
| 98 | + print "Executing indicator identify tests" |
| 99 | + # Using -l option(Location code) Identifying a single device |
| 100 | + for loc in loc_codes: |
| 101 | + print "Turn on identification indicator %s from Host OS" % loc |
| 102 | + self.cv_HOST.host_run_command("usysident -l %s -s identify" % (loc)) |
| 103 | + tries = 20 |
| 104 | + for i in range(1, tries+1): |
| 105 | + response = self.cv_HOST.host_run_command("usysident -l %s" % (loc)) |
| 106 | + if "on" in response: |
| 107 | + break |
| 108 | + time.sleep(1) |
| 109 | + self.assertIn("on", response, |
| 110 | + "Turn ON of identification indicator %s is failed" % loc) |
| 111 | + print "Current identification state of %s is ON" % loc |
| 112 | + |
| 113 | + self.cv_HOST.host_run_command("usysident") |
| 114 | + |
| 115 | + # Setting to normal state of device(Turn off Device) |
| 116 | + for loc in loc_codes: |
| 117 | + print "Turn off identification indicator %s from Host OS" % loc |
| 118 | + self.cv_HOST.host_run_command("usysident -l %s -s normal" % (loc)) |
| 119 | + tries = 20 |
| 120 | + for i in range(1, tries+1): |
| 121 | + response = self.cv_HOST.host_run_command("usysident -l %s" % (loc)) |
| 122 | + if "off" in response: |
| 123 | + break |
| 124 | + time.sleep(1) |
| 125 | + self.assertIn("off", response, |
| 126 | + "Turn OFF of identification indicator %s is failed" % loc) |
| 127 | + print "Current identification state of %s is OFF" % loc |
| 128 | + |
| 129 | +class UsysAttnFSPTest(LightPathDiagnostics): |
| 130 | + |
| 131 | + ## |
| 132 | + # @brief This function tests system attention indicator LED |
| 133 | + # |
| 134 | + def runTest(self): |
| 135 | + self.lpd_init() |
| 136 | + loc_code = self.get_sysattn_indicator_loc() |
| 137 | + print "Executing system attention indicator tests" |
| 138 | + response = self.cv_FSP.fsp_run_command("ledscommandline -V") |
| 139 | + print response |
| 140 | + # Setting system attention indicator from FSP |
| 141 | + print "Setting system attention indicator from FSP" |
| 142 | + response = self.cv_FSP.fsp_run_command("ledscommandline -a -s") |
| 143 | + print response |
| 144 | + response = self.cv_FSP.fsp_run_command("ledscommandline -a -q") |
| 145 | + print response |
| 146 | + tries = 10 |
| 147 | + for i in range(1, tries+1): |
| 148 | + cmd = "usysattn -l %s" % loc_code |
| 149 | + response = self.cv_HOST.host_run_command(cmd) |
| 150 | + if "on" in response: |
| 151 | + break |
| 152 | + time.sleep(1) |
| 153 | + self.assertIn("on", response, |
| 154 | + "Turn ON of system attention indicator is failed") |
| 155 | + print "Current system attention indicator state is ON" |
| 156 | + |
| 157 | + # Clearing(resetting) system attention indicator from FSP |
| 158 | + print "Clearing system attention indicator from FSP" |
| 159 | + response = self.cv_FSP.fsp_run_command("ledscommandline -a -r") |
| 160 | + print response |
| 161 | + response = self.cv_FSP.fsp_run_command("ledscommandline -a -q") |
| 162 | + print response |
| 163 | + tries = 10 |
| 164 | + for i in range(1, tries+1): |
| 165 | + cmd = "usysattn -l %s" % loc_code |
| 166 | + response = self.cv_HOST.host_run_command(cmd) |
| 167 | + if "off" in response: |
| 168 | + break |
| 169 | + time.sleep(1) |
| 170 | + self.assertIn("off", response, |
| 171 | + "Turn OFF of system attention indicator is failed") |
| 172 | + print "Current system attention indicator state is OFF" |
| 173 | + |
| 174 | +class UsysAttnHostTest(LightPathDiagnostics): |
| 175 | + |
| 176 | + ## |
| 177 | + # @brief This function tests system attention indicator LED |
| 178 | + # |
| 179 | + def runTest(self): |
| 180 | + self.lpd_init() |
| 181 | + loc_code = self.get_sysattn_indicator_loc() |
| 182 | + print "Executing system attention indicator tests" |
| 183 | + # Setting system attention indicator from HOST |
| 184 | + print "Setting system attention indicator from Host" |
| 185 | + cmd = "echo 1 > /sys/class/leds/%s:attention/brightness" % loc_code |
| 186 | + self.cv_HOST.host_run_command(cmd) |
| 187 | + tries = 10 |
| 188 | + for i in range(1, tries+1): |
| 189 | + cmd = "usysattn -l %s" % loc_code |
| 190 | + response = self.cv_HOST.host_run_command(cmd) |
| 191 | + if "on" in response: |
| 192 | + break |
| 193 | + time.sleep(1) |
| 194 | + self.assertIn("on", response, |
| 195 | + "Turn ON of system attention indicator is failed") |
| 196 | + print "Current system attention indicator state is ON" |
| 197 | + |
| 198 | + # Clearing(resetting) system attention indicator |
| 199 | + print "Clearing system attention indicator from Host" |
| 200 | + cmd = "echo 0 > /sys/class/leds/%s:attention/brightness" % loc_code |
| 201 | + self.cv_HOST.host_run_command(cmd) |
| 202 | + tries = 10 |
| 203 | + for i in range(1, tries+1): |
| 204 | + cmd = "usysattn -l %s" % loc_code |
| 205 | + response = self.cv_HOST.host_run_command(cmd) |
| 206 | + if "off" in response: |
| 207 | + break |
| 208 | + time.sleep(1) |
| 209 | + self.assertIn("off", response, |
| 210 | + "Turn OFF of system attention indicator is failed") |
| 211 | + print "Current system attention indicator state is OFF" |
| 212 | + |
| 213 | +class UsysFaultTest(LightPathDiagnostics): |
| 214 | + |
| 215 | + ## |
| 216 | + # @brief This function tests usysfault identification of LED's |
| 217 | + # |
| 218 | + def runTest(self): |
| 219 | + self.lpd_init() |
| 220 | + loc_codes = self.get_location_codes() |
| 221 | + print "Executing fault indicator tests for all fault locators" |
| 222 | + for indicator in loc_codes: |
| 223 | + print "***************Test for %s locator*************" % indicator |
| 224 | + # Setting a fault indicator from HOST os |
| 225 | + print "Setting fault indicator %s from Host OS" % indicator |
| 226 | + cmd = "echo 1 > /sys/class/leds/%s:fault/brightness" % indicator |
| 227 | + self.cv_HOST.host_run_command(cmd) |
| 228 | + tries = 10 |
| 229 | + for i in range(1, tries+1): |
| 230 | + cmd = "usysattn -l %s" % indicator |
| 231 | + response = self.cv_HOST.host_run_command(cmd) |
| 232 | + if "on" in response: |
| 233 | + break |
| 234 | + time.sleep(1) |
| 235 | + self.assertIn("on", response, |
| 236 | + "Turn ON of fault indicator %s is failed" % indicator) |
| 237 | + print "Current fault indicator state of %s is ON" % indicator |
| 238 | + |
| 239 | + # Clearing fault indicator from Host OS |
| 240 | + print "Clearing fault indicator %s from Host OS" % indicator |
| 241 | + cmd = "usysattn -l %s -s normal" % indicator |
| 242 | + self.cv_HOST.host_run_command(cmd) |
| 243 | + tries = 10 |
| 244 | + for i in range(1, tries+1): |
| 245 | + cmd = "usysattn -l %s" % indicator |
| 246 | + response = self.cv_HOST.host_run_command(cmd) |
| 247 | + if "off" in response: |
| 248 | + break |
| 249 | + time.sleep(1) |
| 250 | + self.assertIn("off", response, |
| 251 | + "Turn OFF of fault indicator %s is failed" % indicator) |
| 252 | + print "Current fault indicator state of %s is OFF" % indicator |
| 253 | + |
| 254 | +def suite(): |
| 255 | + s = unittest.TestSuite() |
| 256 | + s.addTest(UsysIdentifyTest()) |
| 257 | + s.addTest(UsysAttnHostTest()) |
| 258 | + s.addTest(UsysFaultTest()) |
| 259 | + return s |
| 260 | + |
| 261 | +def extended_suite(): |
| 262 | + s = unittest.TestSuite() |
| 263 | + s.addTest(UsysIdentifyTest()) |
| 264 | + s.addTest(UsysAttnFSPTest()) |
| 265 | + s.addTest(UsysAttnHostTest()) |
| 266 | + s.addTest(UsysFaultTest()) |
| 267 | + return s |
| 268 | + |
0 commit comments