|
| 1 | +#!/usr/bin/python |
| 2 | +# IBM_PROLOG_BEGIN_TAG |
| 3 | +# This is an automatically generated prolog. |
| 4 | +# |
| 5 | +# OpenPOWER Automated Test Project |
| 6 | +# |
| 7 | +# Contributors Listed Below - COPYRIGHT 2015,2017 |
| 8 | +# [+] International Business Machines Corp. |
| 9 | +# |
| 10 | +# |
| 11 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 | +# you may not use this file except in compliance with the License. |
| 13 | +# You may obtain a copy of the License at |
| 14 | +# |
| 15 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | +# |
| 17 | +# Unless required by applicable law or agreed to in writing, software |
| 18 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 20 | +# implied. See the License for the specific language governing |
| 21 | +# permissions and limitations under the License. |
| 22 | +# |
| 23 | +# IBM_PROLOG_END_TAG |
| 24 | + |
| 25 | +# Corrupt TOD and check host boot and runtime behaviours |
| 26 | +# |
| 27 | + |
| 28 | +import time |
| 29 | +import subprocess |
| 30 | +import re |
| 31 | +import commands |
| 32 | + |
| 33 | +from common.OpTestIPMI import OpTestIPMI |
| 34 | +from common.OpTestConstants import OpTestConstants as BMC_CONST |
| 35 | +from common.OpTestError import OpTestError |
| 36 | + |
| 37 | +import unittest |
| 38 | +import OpTestConfiguration |
| 39 | +from common.OpTestSystem import OpSystemState |
| 40 | +from common.OpTestHost import SSHConnectionState |
| 41 | + |
| 42 | + |
| 43 | +class fspTODCorruption(): |
| 44 | + def setUp(self): |
| 45 | + conf = OpTestConfiguration.conf |
| 46 | + self.cv_IPMI = conf.ipmi() |
| 47 | + self.cv_SYSTEM = conf.system() |
| 48 | + self.cv_FSP = self.cv_SYSTEM.bmc |
| 49 | + self.cv_HOST = conf.host() |
| 50 | + self.util = self.cv_SYSTEM.util |
| 51 | + self.bmc_type = conf.args.bmc_type |
| 52 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 53 | + |
| 54 | + def tearDown(self): |
| 55 | + self.cv_HOST.host_gather_opal_msg_log() |
| 56 | + self.cv_HOST.host_gather_kernel_log() |
| 57 | + |
| 58 | + def get_tod(self): |
| 59 | + print "Running command on FSP: rtim timeofday" |
| 60 | + res = self.cv_FSP.fsp_run_command("rtim timeofday") |
| 61 | + return res |
| 62 | + |
| 63 | + def set_tod(self): |
| 64 | + time = commands.getoutput('date +"%Y%m%d%H%M%S"') |
| 65 | + print "Setting back the system time using rtim timeofday yyyyMMddhhmmss" |
| 66 | + cmd = "rtim timeofday %s" % time |
| 67 | + print "Running command on FSP: %s" % cmd |
| 68 | + self.cv_FSP.fsp_run_command(cmd) |
| 69 | + self.get_tod() |
| 70 | + |
| 71 | + def tod_force_clock(self): |
| 72 | + res = self.get_tod() |
| 73 | + if "valid" in res: |
| 74 | + print "system time is VALID" |
| 75 | + else: |
| 76 | + raise Exception("System time is invalid,exiting...,please set time and rerun") |
| 77 | + |
| 78 | + print "Running command on FSP: rtim forceClockValue" |
| 79 | + out = self.cv_FSP.fsp_run_command("rtim forceClockValue") |
| 80 | + print out |
| 81 | + res = self.get_tod() |
| 82 | + if "INVALID" in res: |
| 83 | + print "system time is INVALID" |
| 84 | + else: |
| 85 | + raise Exception("rtim: forceClockValue interface not forcing tod value to invalid") |
| 86 | + |
| 87 | + def check_hwclock(self): |
| 88 | + self.cv_HOST.host_read_hwclock() |
| 89 | + self.cv_HOST.host_set_hwclock_time("2015-01-01 10:10:10") |
| 90 | + self.cv_HOST.host_read_hwclock() |
| 91 | + self.cv_HOST.host_set_hwclock_time("2016-01-01 20:20:20") |
| 92 | + self.cv_HOST.host_read_hwclock() |
| 93 | + |
| 94 | + |
| 95 | +class TOD_CORRUPTION(fspTODCorruption, unittest.TestCase): |
| 96 | + |
| 97 | + ## |
| 98 | + # @brief This function tests Boot and runtime behaviour |
| 99 | + # when TOD is corrupted. |
| 100 | + # |
| 101 | + def runTest(self): |
| 102 | + if "FSP" not in self.bmc_type: |
| 103 | + self.skipTest("FSP Platform OPAL specific TOD Corruption tests") |
| 104 | + self.cv_FSP.fsp_get_console() |
| 105 | + if not self.cv_FSP.mount_exists(): |
| 106 | + raise OpTestError("Please mount NFS and retry the test") |
| 107 | + |
| 108 | + print self.cv_FSP.fsp_run_command("smgr mfgState") |
| 109 | + self.cv_FSP.clear_fsp_errors() |
| 110 | + self.tod_force_clock() |
| 111 | + self.check_hwclock() |
| 112 | + self.tearDown() |
| 113 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 114 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 115 | + self.cv_HOST.ssh.state = SSHConnectionState.DISCONNECTED |
| 116 | + self.check_hwclock() |
| 117 | + self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
| 118 | + self.cv_HOST.ssh.state = SSHConnectionState.DISCONNECTED |
| 119 | + self.set_tod() |
| 120 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 121 | + self.check_hwclock() |
| 122 | + |
| 123 | +def suite(): |
| 124 | + s = unittest.TestSuite() |
| 125 | + s.addTest(TOD_CORRUPTION()) |
| 126 | + return s |
0 commit comments