|
| 1 | +#!/usr/bin/python |
| 2 | +# IBM_PROLOG_BEGIN_TAG |
| 3 | +# This is an automatically generated prolog. |
| 4 | +# |
| 5 | +# $Source: op-test-framework/testcases/OpalGard.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 opal-gard |
| 28 | +# Test different OPAL GARD Related functionality |
| 29 | +# |
| 30 | + |
| 31 | +import re |
| 32 | +import random |
| 33 | + |
| 34 | + |
| 35 | +from common.OpTestConstants import OpTestConstants as BMC_CONST |
| 36 | +import unittest |
| 37 | + |
| 38 | +import OpTestConfiguration |
| 39 | +from common.OpTestSystem import OpSystemState |
| 40 | +from common.Exceptions import CommandFailed |
| 41 | + |
| 42 | +class OpalGard(unittest.TestCase): |
| 43 | + def setUp(self): |
| 44 | + conf = OpTestConfiguration.conf |
| 45 | + self.cv_IPMI = conf.ipmi() |
| 46 | + self.cv_SYSTEM = conf.system() |
| 47 | + self.cv_HOST = conf.host() |
| 48 | + self.bmc_type = conf.args.bmc_type |
| 49 | + self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 50 | + |
| 51 | + |
| 52 | + def list_gard_records(self): |
| 53 | + cmd = "PATH=/usr/local/sbin:$PATH opal-gard list all" |
| 54 | + try: |
| 55 | + res = self.c.run_command(cmd,timeout=120) |
| 56 | + except CommandFailed as cf: |
| 57 | + self.assertEqual(cf.exitcode, 0, "List gard records operation failed: %s" % str(cf)) |
| 58 | + |
| 59 | + def clear_gard_records(self): |
| 60 | + cmd = "PATH=/usr/local/sbin:$PATH opal-gard clear all" |
| 61 | + try: |
| 62 | + res = self.c.run_command(cmd,timeout=120) |
| 63 | + except CommandFailed as cf: |
| 64 | + self.assertEqual(cf.exitcode, 0, "Clear gard records operation failed: %s" % str(cf)) |
| 65 | + |
| 66 | + def show_gard_record(self, id): |
| 67 | + cmd = "PATH=/usr/local/sbin:$PATH opal-gard show %s" % id |
| 68 | + try: |
| 69 | + res = self.c.run_command(cmd,timeout=120) |
| 70 | + except CommandFailed as cf: |
| 71 | + self.assertEqual(cf.exitcode, 0, "show gard records operation failed: %s" % str(cf)) |
| 72 | + |
| 73 | + def tearDown(self): |
| 74 | + cmd = "dmesg -T --level=alert,crit,err,warn" |
| 75 | + res = self.c.run_command_ignore_fail(cmd, timeout=120) |
| 76 | + self.c.run_command_ignore_fail("grep ',[0-4]\]' /sys/firmware/opal/msglog") |
| 77 | + |
| 78 | + def runTest(self): |
| 79 | + # opal-gard from host is not supported in FSP systems |
| 80 | + if "FSP" in self.bmc_type: |
| 81 | + self.skipTest("OpenPOWER BMC specific") |
| 82 | + |
| 83 | + self.c = self.cv_SYSTEM.sys_get_ipmi_console() |
| 84 | + self.cv_SYSTEM.host_console_login() |
| 85 | + self.cv_SYSTEM.host_console_unique_prompt() |
| 86 | + self.cv_HOST.host_check_command("pflash") |
| 87 | + self.cv_HOST.host_copy_fake_gard() |
| 88 | + self.c.run_command("dmesg -D") |
| 89 | + self.cpu = ''.join(self.c.run_command("grep '^cpu' /proc/cpuinfo |uniq|sed -e 's/^.*: //;s/ .*//;'")) |
| 90 | + |
| 91 | + if self.cpu not in ["POWER8", "POWER8E", "POWER9"]: |
| 92 | + self.skipTest("Unknown CPU type %s" % self.cpu) |
| 93 | + data = self.cv_HOST.host_pflash_get_partition("GUARD") |
| 94 | + offset = hex(int(data["offset"])/16) |
| 95 | + for i in range(0, 11): |
| 96 | + self.list_gard_records() |
| 97 | + self.c.run_command("dd if=/tmp/fake.gard of=/dev/mtd0 bs=$((0x10)) seek=$((%s)) conv=notrunc" % offset) |
| 98 | + self.list_gard_records() |
| 99 | + self.show_gard_record("00000001") |
| 100 | + self.clear_gard_records() |
0 commit comments