-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathOpTestIPMI.py
1433 lines (1223 loc) · 50.2 KB
/
OpTestIPMI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# encoding=utf8
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: op-test-framework/common/OpTestIPMI.py $
#
# OpenPOWER Automated Test Project
#
# Contributors Listed Below - COPYRIGHT 2015
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
'''
OpTestIPMI
----------
IPMI package which contains all BMC related IPMI commands
This class encapsulates all function which deals with the BMC over IPMI
in OpenPower systems
'''
import time
import subprocess
import os
import pexpect
import sys
import re
from .OpTestConstants import OpTestConstants as BMC_CONST
from .OpTestError import OpTestError
from .OpTestUtil import OpTestUtil
from . import OpTestSystem
from .Exceptions import CommandFailed
from .Exceptions import BMCDisconnected
from . import OPexpect
from .SerialConsole import SerialConsole
import logging
import OpTestLogger
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
class IPMITool():
'''
Run (locally) some command using ipmitool.
This wrapper class takes care of all the login/method details for
the caller.
'''
def __init__(self, method='lanplus', binary='ipmitool', alg_id='17',
ip=None, username=None, password=None, logfile=sys.stdout):
self.method = 'lanplus'
self.ip = ip
self.username = username
self.password = password
self.binary = binary
self.logfile = logfile
self.alg_id = alg_id
def binary_name(self):
return self.binary
def arguments(self):
s = ' -H %s -I %s -C %s' % (self.ip, self.method, self.alg_id)
if self.username:
s += ' -U %s' % (self.username)
if self.password:
s += ' -P %s' % (self.password)
s += ' '
return s
def run(self, cmd, background=False, cmdprefix=None):
'''
Run a ipmitool cmd.
:throws: :class:`common.Execptions.CommandFailed`
'''
if cmdprefix:
cmd = cmdprefix + self.binary + self.arguments() + cmd
else:
cmd = self.binary + self.arguments() + cmd
log.debug(cmd)
if background:
try:
child = subprocess.Popen(
cmd, shell=True, universal_newlines=True, encoding='utf-8')
except Exception as e:
raise CommandFailed(
"Unable to spawn process {}".format(cmd), e, -1)
return child
else:
# TODO - need python 2.7
# output = check_output(cmd, stderr=subprocess.STDOUT, shell=True)
try:
cmd = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, shell=True,
universal_newlines=True, encoding='utf-8')
except:
raise CommandFailed(cmd, "Failed to spawn subprocess", -1)
output = cmd.communicate()[0]
log.debug("pUpdate output={}".format(output))
return output
class pUpdate():
def __init__(self, method='lan', binary='pUpdate',
ip=None, username=None, password=None):
self.method = 'lan'
self.ip = ip
self.username = username
self.password = password
self.binary = binary
def set_binary(self, binary):
self.binary = binary
def binary_name(self):
return self.binary
def arguments(self):
s = ' -h %s -i %s' % (self.ip, self.method)
if self.username:
s += ' -u %s' % (self.username)
if self.password:
s += ' -p %s' % (self.password)
s += ' '
return s
def run(self, cmd, background=False, cmdprefix=None):
if cmdprefix:
cmd = cmdprefix + self.binary + self.arguments() + cmd
else:
cmd = self.binary + self.arguments() + cmd
log.debug("Running pUpdate cmd={}".format(cmd))
if background:
try:
child = subprocess.Popen(
cmd, shell=True, universal_newlines=True, encoding='utf-8')
except:
l_msg = "pUpdate Command Failed: {}".format(cmd)
log.error(l_msg)
raise OpTestError(l_msg)
return child
else:
# TODO - need python 2.7
# output = check_output(cmd, stderr=subprocess.STDOUT, shell=True)
try:
cmd = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, shell=True,
universal_newlines=True, encoding='utf-8')
except:
l_msg = "pUpdate Command Failed: {}".format(cmd)
log.error(l_msg)
raise OpTestError(l_msg)
output = cmd.communicate()[0]
log.debug(output)
return output
class IPMIConsoleState():
DISCONNECTED = 0
CONNECTED = 1
def set_system_to_UNKNOWN_BAD(system):
s = system.get_state()
system.set_state(OpTestSystem.OpSystemState.UNKNOWN_BAD)
return s
class IPMIConsole():
def __init__(self, ipmitool=None, logfile=sys.stdout, prompt=None,
block_setup_term=None, delaybeforesend=None):
self.logfile = logfile
self.ipmitool = ipmitool
self.state = IPMIConsoleState.DISCONNECTED
self.delaybeforesend = delaybeforesend
self.system = None
# OpTestUtil instance is NOT conf's
self.util = OpTestUtil()
self.prompt = prompt
self.expect_prompt = self.util.build_prompt(prompt) + "$"
self.pty = None
self.delaybeforesend = delaybeforesend
# allows caller specific control of when to block setup_term
self.block_setup_term = block_setup_term
# tells setup_term to not throw exceptions, like when system off
self.setup_term_quiet = 0
# flags the object to abandon setup_term operations, like when system off
self.setup_term_disable = 0
# FUTURE - System Console currently tracked in System Object
# state tracking, reset on boot and state changes
self.PS1_set = -1
self.LOGIN_set = -1
self.SUDO_set = -1
def set_system(self, system):
self.system = system
def set_system_setup_term(self, flag):
self.system.block_setup_term = flag
def get_system_setup_term(self):
return self.system.block_setup_term
def set_block_setup_term(self, flag):
self.block_setup_term = flag
def get_block_setup_term(self):
return self.block_setup_term
def enable_setup_term_quiet(self):
self.setup_term_quiet = 1
self.setup_term_disable = 0
def disable_setup_term_quiet(self):
self.setup_term_quiet = 0
self.setup_term_disable = 0
def close(self):
self.util.clear_state(self)
if self.state == IPMIConsoleState.DISCONNECTED:
return
try:
self.pty.send("\r")
self.pty.send('~.')
close_rc = self.pty.expect(
['[terminated ipmitool]', pexpect.TIMEOUT, pexpect.EOF], timeout=10)
log.debug("CLOSE Expect Buffer ID={}".format(hex(id(self.pty))))
rc_child = self.pty.close()
self.state = IPMIConsoleState.DISCONNECTED
exitCode = signalstatus = None
if self.pty.status != -1: # leaving for future debug
if os.WIFEXITED(self.pty.status):
exitCode = os.WEXITSTATUS(self.pty.status)
else:
signalstatus = os.WTERMSIG(self.pty.status)
except pexpect.ExceptionPexpect:
self.state = IPMIConsoleState.DISCONNECTED
raise OpTestError("IPMI: failed to close ipmi console")
except Exception as e:
self.state = IPMIConsoleState.DISCONNECTED
pass
def connect(self, logger=None):
if self.state == IPMIConsoleState.CONNECTED:
rc_child = self.close()
else:
self.util.clear_state(self)
try:
self.ipmitool.run('sol deactivate')
except OpTestError:
log.info('SOL already deactivated')
cmd = self.ipmitool.binary_name() + self.ipmitool.arguments() + ' sol activate'
try:
self.pty = OPexpect.spawn(cmd,
logfile=self.logfile,
failure_callback=set_system_to_UNKNOWN_BAD,
failure_callback_data=self.system)
except Exception as e:
self.state = IPMIConsoleState.DISCONNECTED
raise CommandFailed(
'OPexpect.spawn', "OPexpect.spawn encountered a problem, command was '{}'".format(cmd), -1)
log.debug("#IPMI SOL CONNECT")
self.state = IPMIConsoleState.CONNECTED
self.pty.setwinsize(1000, 1000)
if logger:
self.pty.logfile_read = OpTestLogger.FileLikeLogger(logger)
else:
self.pty.logfile_read = OpTestLogger.FileLikeLogger(log)
if self.delaybeforesend:
self.pty.delaybeforesend = self.delaybeforesend
rc = self.pty.expect_exact(
['[SOL Session operational. Use ~? for help]', pexpect.TIMEOUT, pexpect.EOF], timeout=10)
log.debug("rc={}".format(rc))
if rc == 0:
if self.system.SUDO_set != 1 or self.system.LOGIN_set != 1 or self.system.PS1_set != 1:
self.util.setup_term(self.system, self.pty,
None, self.system.block_setup_term)
time.sleep(0.2)
log.debug("CONNECT starts Expect Buffer ID={}".format(
hex(id(self.pty))))
return self.pty
if rc == 1:
self.pty.close()
time.sleep(60) # give things a minute to clear
raise CommandFailed('sol activate',
"IPMI: pexpect.TIMEOUT while trying to establish"
" connection, command was '{}'"
.format(cmd), -1)
if rc == 2:
self.pty.close()
time.sleep(60) # give things a minute to clear
raise CommandFailed('sol activate',
"IPMI: insufficient resources for session, unable"
" to establish IPMI v2 / RMCP+ session, command was '{}'"
.format(cmd), -1)
def get_console(self, logger=None):
if self.state == IPMIConsoleState.DISCONNECTED:
self.connect(logger)
count = 0
while (not self.pty.isalive()):
log.warning('# Reconnecting')
if (count > 0):
time.sleep(BMC_CONST.IPMI_SOL_ACTIVATE_TIME)
self.connect()
count += 1
if count > 120:
raise("IPMI: not able to get sol console")
if self.system.SUDO_set != 1 or self.system.LOGIN_set != 1 or self.system.PS1_set != 1:
self.util.setup_term(self.system, self.pty,
None, self.system.block_setup_term)
return self.pty
def run_command(self, command, timeout=60, retry=0):
return self.util.run_command(self, command, timeout, retry)
def run_command_ignore_fail(self, command, timeout=60, retry=0):
return self.util.run_command_ignore_fail(self, command, timeout, retry)
class OpTestIPMI():
def __init__(self, i_bmcIP, i_bmcUser, i_bmcPwd, logfile=sys.stdout,
host=None, delaybeforesend=None, host_console_command=None):
self.cv_bmcIP = i_bmcIP
self.cv_bmcUser = i_bmcUser
self.cv_bmcPwd = i_bmcPwd
self.logfile = logfile
self.ipmitool = IPMITool(method='lanplus',
ip=i_bmcIP,
username=i_bmcUser,
password=i_bmcPwd,
logfile=logfile)
self.pUpdate = pUpdate(method='lan',
ip=i_bmcIP,
username=i_bmcUser,
password=i_bmcPwd)
if host_console_command:
self.console = SerialConsole(console_command=host_console_command,
logfile=self.logfile,
delaybeforesend=delaybeforesend)
else:
self.console = IPMIConsole(ipmitool=self.ipmitool,
logfile=self.logfile,
delaybeforesend=delaybeforesend)
# OpTestUtil instance is NOT conf's
self.util = OpTestUtil()
self.host = host
def set_system(self, system):
self.console.set_system(system)
def get_host_console(self):
'''
Get the IPMIConsole object, to run commands on the host etc.
'''
return self.console
def ipmi_sdr_clear(self):
'''
This function clears the sensor data.
'''
output = self.ipmitool.run('sel clear')
if 'Clearing SEL' in output:
# FIXME: This code should instead check for 'erasure completed'
# and the status of the erasure, rather than this crude loop
retries = 20
while (retries > 0):
output = self.ipmitool.run('sel elist')
if 'no entries' in output:
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Sensor data still has entries!"
log.error(l_msg)
retries -= 1
if (retries == 0):
raise OpTestError(l_msg)
time.sleep(1)
else:
l_msg = "Clearing the sensor data Failed"
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_power_off(self):
'''
This function sends the chassis power off ipmitool command.
'''
output = self.ipmitool.run('chassis power off')
if 'Down/Off' in output:
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Power OFF Failed: {}".format(output)
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_power_on(self):
'''
This function sends the chassis power on ipmitool command
'''
output = self.ipmitool.run('chassis power on')
if 'Up/On' in output:
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Power ON Failed"
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_power_soft(self):
'''
This function sends the chassis power soft ipmitool command
'''
output = self.ipmitool.run('chassis power soft')
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
if "Chassis Power Control: Soft" in output:
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Power Soft Failed"
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_power_cycle(self):
'''
This function sends the chassis power cycle ipmitool command
'''
output = self.ipmitool.run('chassis power cycle')
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
if "Chassis Power Control: Cycle" in output:
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Power Cycle Failed"
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_power_reset(self):
'''
This function sends the chassis power reset ipmitool command.
'''
r = self.ipmitool.run('chassis power reset')
self.console.close()
if not BMC_CONST.CHASSIS_POWER_RESET in r:
raise Exception("IPMI 'chassis power reset' failed: %s " % r)
def ipmi_power_diag(self):
'''
This function sends the chassis power diag ipmitool command.
'''
r = self.ipmitool.run('chassis power diag')
if not "Chassis Power Control: Diag" in r:
raise Exception("IPMI 'chassis power diag' failed: %s " % r)
##
#
# @return BMC_CONST.FW_SUCCESS or raise OpTestError
#
def ipl_wait_for_working_state(self, timeout=10):
'''
This function starts the sol capture and waits for the IPL to end. The
marker for IPL completion is the Host Status sensor which reflects the ACPI
power state of the system. When it reads S0/G0: working it means that the
petitboot is has began loading. The overall timeout for the IPL is defined
in the test configuration options.
:param timeout: The number of minutes to wait for IPL to complete,
i.e. How long to poll the ACPI sensor for working
state before giving up.
:type timeout: int
'''
timeout = time.time() + 60*timeout
cmd = 'sdr elist |grep \'Host Status\''
output = self.ipmitool.run(cmd)
if not "Host Status" in output:
return BMC_CONST.FW_PARAMETER
while True:
output = self.ipmitool.run(cmd)
if 'S0/G0: working' in output:
log.debug("Host Status is S0/G0: working, IPL finished")
break
if time.time() > timeout:
l_msg = "IPL timeout"
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(5)
try:
self.ipmitool.run('sol deactivate')
self.console.close()
except subprocess.CalledProcessError:
l_msg = 'SOL already deactivated'
log.error(l_msg)
self.console.close()
raise OpTestError(l_msg)
return BMC_CONST.FW_SUCCESS
def ipmi_ipl_wait_for_working_state_v1(self, timeout=10):
'''
This function waits for the IPL to end. The marker for IPL completion is the
Host Status sensor which reflects the ACPI power state of the system. When it
reads S0/G0: working it means that the petitboot is has began loading.
:param timeout: The number of minutes to wait for IPL to complete,
i.e. How long to poll the ACPI sensor for working
state before giving up.
:type timeout: int
'''
timeout = time.time() + 60*timeout
cmd = 'sdr elist |grep \'Host Status\''
output = self.ipmitool.run(cmd)
if not "Host Status" in output:
return BMC_CONST.FW_PARAMETER
while True:
if 'S0/G0: working' in output:
log.debug("Host Status is S0/G0: working, IPL finished")
break
if time.time() > timeout:
l_msg = "IPL timeout"
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(5)
output = self.ipmitool.run(cmd)
return BMC_CONST.FW_SUCCESS
def ipmi_wait_for_standby_state(self, i_timeout=120):
'''
This function waits for system to reach standby state or soft off. The
marker for standby state is the Host Status sensor which reflects the ACPI
power state of the system. When it reads S5/G2: soft-off it means that the
system reached standby or soft-off state. The overall timeout for the standby is defined
in the test configuration options.
:param i_timeout: The number of seconds to wait for system to reach standby,
i.e. How long to poll the ACPI sensor for soft-off
state before giving up.
:type i_timeout: int
'''
l_timeout = time.time() + i_timeout
l_cmd = ' power status '
wait_for = 'Chassis Power is off'
while True:
l_output = self.ipmitool.run(l_cmd)
if wait_for in l_output:
log.debug("Host power is off, system reached standby")
break
if time.time() > l_timeout:
l_msg = "Standby timeout"
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(BMC_CONST.SHORT_WAIT_STANDBY_DELAY)
return BMC_CONST.FW_SUCCESS
def ipmi_wait_for_os_boot_complete(self, i_timeout=10):
'''
This function waits for the Host OS Boot(IPL) to end. The
marker for IPL completion is the OS Boot sensor which reflects status
of host OS Boot. When it reads boot completed it means that the
Host OS Booted successfully. The overall timeout for the IPL is defined
in the test configuration options.
:param i_timeout: The number of minutes to wait for IPL to complete or Boot time,
i.e. How long to poll the OS Boot sensor for working
state before giving up.
:type i_timeout: int
'''
l_timeout = time.time() + 60*i_timeout
l_cmd = 'sdr elist |grep \'OS Boot\''
output = self.ipmitool.run(l_cmd)
if not "OS Boot" in output:
return BMC_CONST.FW_PARAMETER
while True:
l_output = self.ipmitool.run(l_cmd)
if BMC_CONST.OS_BOOT_COMPLETE in l_output:
log.debug("Host OS is booted")
break
if time.time() > l_timeout:
l_msg = "IPL timeout"
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
return BMC_CONST.FW_SUCCESS
def ipmi_wait_for_os_boot_complete_v1(self, i_timeout=10):
'''
This function waits for the Host OS Boot(IPL) to end. The
marker for IPL completion is the OS Boot sensor which reflects status
of host OS Boot. When it reads boot completed it means that the
Host OS Booted successfully.
:param i_timeout: The number of minutes to wait for IPL to complete or Boot time,
i.e. How long to poll the OS Boot sensor for working state before giving up.
:type i_timeout: int
'''
l_timeout = time.time() + 60*i_timeout
l_cmd = 'sdr elist |grep \'OS Boot\''
l_output = self.ipmitool.run(l_cmd)
if not "OS Boot" in l_output:
return BMC_CONST.FW_PARAMETER
while True:
if BMC_CONST.OS_BOOT_COMPLETE in l_output:
log.debug("Host OS is booted")
break
if time.time() > l_timeout:
l_msg = "IPL timeout"
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
l_output = self.ipmitool.run(l_cmd)
return BMC_CONST.FW_SUCCESS
def ipmi_sel_check(self, i_string="Transition to Non-recoverable"):
'''
This function dumps the sel log and looks for specific hostboot error
log string
'''
output = self.ipmitool.run('sel elist')
if self.logfile:
for line in output:
self.logfile.write(line)
if i_string in output:
raise OpTestError('Error log(s) detected during IPL: %s' % output)
else:
return BMC_CONST.FW_SUCCESS
def ipmi_sel_elist(self, dump=False):
'''
This function dumps the sel elist
'''
output = self.ipmitool.run('sel elist')
if dump:
print(
"\n----------------------------------------------------------------------")
print("SELs")
print(
"----------------------------------------------------------------------")
print(("{}".format(output)))
print(
"----------------------------------------------------------------------")
return output
def ipmi_power_status(self):
'''
Determines the power status of the bmc
:returns: string: Power status of bmc
"Chassis Power is on" or "Chassis Power is off"
'''
l_output = self.ipmitool.run('chassis power status')
if('on' in l_output):
return BMC_CONST.CHASSIS_POWER_ON
elif('off' in l_output):
return BMC_CONST.CHASSIS_POWER_OFF
else:
raise OpTestError(
"Can't recognize chassis power status: " + str(l_output))
def ipmi_cold_reset(self):
'''
Performs a cold reset onto the bmc
'''
l_initstatus = self.ipmi_power_status()
log.debug("Applying Cold reset.")
rc = self.ipmitool.run(BMC_CONST.BMC_COLD_RESET)
if BMC_CONST.BMC_PASS_COLD_RESET in rc:
self.console.close()
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
self.util.PingFunc(
self.cv_bmcIP, totalSleepTime=BMC_CONST.PING_RETRY_FOR_STABILITY)
self.ipmi_wait_for_bmc_runtime()
l_finalstatus = self.ipmi_power_status()
if (l_initstatus != l_finalstatus):
log.debug('initial status ' + str(l_initstatus))
log.debug('final status ' + str(l_finalstatus))
log.debug('Power status changed during cold reset')
raise OpTestError('Power status changed')
return BMC_CONST.FW_SUCCESS
else:
log.error("Cold reset failed, rc={}".format(rc))
raise OpTestError(rc)
def ipmi_wait_for_bmc_runtime(self, i_timeout=10):
'''
This function waits until BMC Boot finishes after a BMC Cold reset
0x00
Boot Complete
0xC0
Not Complete
Here AMI systems returns 00 and SMC Systems return NULL for success
'''
l_timeout = time.time() + 60*i_timeout
l_cmd = ' raw 0x3a 0x0a '
while True:
try:
l_output = self.ipmitool.run(l_cmd)
log.debug(l_output)
except:
continue
if "0xc0"in l_output:
log.info("BMC Still booting...")
elif "00" in l_output: # AMI BMC returns 00 as output
log.info("BMC Completed booting...")
break
else: # SMC BMC returns empty as output
log.info("BMC Completed booting...")
break
if time.time() > l_timeout:
l_msg = "BMC Boot timeout..."
log.error(l_msg)
raise OpTestError(l_msg)
time.sleep(BMC_CONST.SHORT_WAIT_IPL)
return BMC_CONST.FW_SUCCESS
def ipmi_warm_reset(self):
'''
Performs a warm reset onto the bmc
'''
l_initstatus = self.ipmi_power_status()
l_cmd = BMC_CONST.BMC_WARM_RESET
log.info("Applying Warm reset. Wait for "
+ str(BMC_CONST.BMC_WARM_RESET_DELAY) + "sec")
rc = self.ipmitool.run(l_cmd)
if BMC_CONST.BMC_PASS_WARM_RESET in rc:
log.info("Warm reset result: {}".format(rc))
self.console.close()
time.sleep(BMC_CONST.BMC_WARM_RESET_DELAY)
self.util.PingFunc(
self.cv_bmcIP, totalSleepTime=BMC_CONST.PING_RETRY_FOR_STABILITY)
l_finalstatus = self.ipmi_power_status()
if (l_initstatus != l_finalstatus):
log.debug('initial status ' + str(l_initstatus))
log.debug('final status ' + str(l_finalstatus))
log.debug('Power status changed during cold reset')
raise OpTestError('Power status changed')
return BMC_CONST.FW_SUCCESS
else:
l_msg = "Warm reset Failed"
log.error(l_msg)
raise OpTestError(l_msg)
def ipmi_preserve_network_setting(self):
'''
Preserves the network setting
'''
log.info("Protecting BMC network setting")
l_cmd = BMC_CONST.BMC_PRESRV_LAN
rc = self.ipmitool.run(l_cmd)
if BMC_CONST.BMC_ERROR_LAN in rc:
l_msg = "Can't protect setting! Please preserve setting manually"
log.error(l_msg)
raise OpTestError(l_msg)
return BMC_CONST.FW_SUCCESS
def ipmi_code_update(self, i_image, i_imagecomponent):
'''
Flashes image using ipmitool
:param i_image: hpm file including location
:param i_imagecomponent: component to be updated from the hpm file
BMC_CONST.BMC_FW_IMAGE_UPDATE
or BMC_CONST.BMC_PNOR_IMAGE
'''
self.ipmi_cold_reset()
time.sleep(5)
l_cmd = BMC_CONST.BMC_HPM_UPDATE + i_image + " " + i_imagecomponent
# We need to do a re-try of hpm code update if it fails for the first time
# As AMI systems are some times failed to flash for the first time.
count = 0
while (count < 2):
self.ipmi_preserve_network_setting()
time.sleep(5)
rc = self.ipmitool.run(
l_cmd, background=False, cmdprefix="echo y |")
log.info("IPMI code update result: {}".format(rc))
if(rc.__contains__("Firmware upgrade procedure successful")):
return BMC_CONST.FW_SUCCESS
elif count == 1:
l_msg = "Code Update Failed"
log.error(l_msg)
raise OpTestError(l_msg)
else:
count = count + 1
continue
def ipmi_get_side_activated(self):
'''
Get information on active sides for both BMC and PNOR
- 0x0080 indicates primary side is activated
- 0x0180 indicates golden side is activated
:returns: the active sides for BMC and PNOR chip (that are either primary of golden)
l_bmc_side, l_pnor_side
'''
l_result = self.ipmitool.run(
BMC_CONST.BMC_ACTIVE_SIDE).strip().split('\n')
for i in range(len(l_result)):
if('BIOS' in l_result[i]):
if(l_result[i].__contains__(BMC_CONST.PRIMARY_SIDE)):
log.info("Primary side of PNOR is active")
l_pnor_side = BMC_CONST.PRIMARY_SIDE
elif(BMC_CONST.GOLDEN_SIDE in l_result[i]):
log.info("Golden side of PNOR is active")
l_pnor_side = BMC_CONST.GOLDEN_SIDE
else:
l_msg = "Error determining active side: " + l_result
log.error(l_msg)
raise OpTestError(l_msg)
elif('BMC' in l_result[i]):
if(l_result[i].__contains__(BMC_CONST.PRIMARY_SIDE)):
log.info("Primary side of BMC is active")
l_bmc_side = BMC_CONST.PRIMARY_SIDE
elif(BMC_CONST.GOLDEN_SIDE in l_result[i]):
log.info("Golden side of BMC is active")
l_bmc_side = BMC_CONST.GOLDEN_SIDE
else:
l_msg = "Error determining active side: " + l_result
log.error(l_msg)
raise OpTestError(l_msg)
else:
l_msg = "Error determining active side: " + + l_result
log.error(l_msg)
raise OpTestError(l_msg)
return l_bmc_side, l_pnor_side
def ipmi_get_PNOR_level(self):
'''
Get PNOR level
'''
l_rc = self.ipmitool.run(BMC_CONST.BMC_MCHBLD)
return l_rc
def ipmi_get_bmc_golden_side_version(self):
'''
This function gets the BMC golden side firmware version.
Below are the fields to decode the version of firmware
1. Completion code
- 0x00 – success
- 0x81 – Not a valid image in golden SPI.
- 0xff – Reading Golden side SPI failed.
2. Device ID (0x02)
3. IPMI Dev version (0x01)
4. Firmware Revision 1 (Major )
5. Firmware Revision 2 (Minor)
6. IPMI Version
7. Additional Device support refer IPMI spec.
8. Manufacture ID
9. Manufacture ID
10. Manufacture ID
11. Product ID
12. Product ID
13. Auxiliary Firmware Revision
14. Auxiliary Firmware Revision
15. Auxiliary Firmware Revision
16. Auxiliary Firmware Revision
:returns: BMC golden side firmware version
::
ipmitool -I lanplus -H <BMC-IP> -U ADMIN -P admin raw 0x3a 0x1a
20 01 02 16 02 bf 00 00 00 bb aa 4d 4c 01 00
'''
log.debug("IPMI: Getting the BMC Golden side version")
l_rc = self.ipmitool.run(BMC_CONST.IPMI_GET_BMC_GOLDEN_SIDE_VERSION)
return l_rc
def ipmi_get_pnor_partition_size(self, i_part):
'''
This function gets the size of pnor partition
:param i_part: partition name to retrieve the size.
partition can be NVRAM, GUARD and BOOTKERNEL
TODO: Add support for remaining partitions.
:returns: size of partition raise OpTestError when fails
::
ipmitool -I lanplus -H <BMC-IP> -U ADMIN -P admin raw 0x3a 0x0c
0x42 0x4f 0x4f 0x54 0x4b 0x45 0x52 0x4e 0x45 0x4c 0x00 0x00 0x00 0x00 0x0 0x0 0x0
00 00 f0 00
This function will return "00 00 f0 00"
'''
log.debug("IPMI: Getting the size of %s PNOR Partition" % i_part)
if i_part == BMC_CONST.PNOR_NVRAM_PART:
l_rc = self.ipmitool.run(BMC_CONST.IPMI_GET_NVRAM_PARTITION_SIZE)
elif i_part == BMC_CONST.PNOR_GUARD_PART:
l_rc = self.ipmitool.run(BMC_CONST.IPMI_GET_GUARD_PARTITION_SIZE)
elif i_part == BMC_CONST.PNOR_BOOTKERNEL_PART:
l_rc = self.ipmitool.run(
BMC_CONST.IPMI_GET_BOOTKERNEL_PARTITION_SIZE)
else:
l_msg = "please provide valid partition eye catcher name ({} is invalid)".format(
i_part)
log.error(l_msg)
raise OpTestError(l_msg)
return l_rc
def ipmi_get_bmc_boot_completion_status(self):
'''
This function is used to check whether BMC Completed Booting.
BMC Booting Status:
00h
Booting Completed.
C0h
Still Booting.
:returns: output of command or raise OpTestError
::
ipmitool -I lanplus -H <BMC-IP> -U ADMIN -P admin raw 0x3a 0x0a
00
It returns 00 if BMC completed booting else it gives C0
'''
log.debug("IPMI: Getting the BMC Boot completion status")
l_res = self.ipmitool.run(BMC_CONST.IPMI_HAS_BMC_BOOT_COMPLETED)
return l_res
def ipmi_get_fault_led_state(self):
'''
This command is used to get the State of Fault RollUP LED. ::
Fault RollUP LED 0x00
:returns: output of command or raise OpTestError
::
ipmitool -I lanplus -H <BMC-IP> -U ADMIN -P admin raw 0x3a 0x02 0x00
00
LED State Table: Below are the states it can get
0x0 LED OFF
0x1 LED ON
0x2 LED Standby Blink Rate
0x3 LED Slow Blink rate.
'''
log.debug("IPMI: Getting the fault rollup LED state")
l_res = self.ipmitool.run(BMC_CONST.IPMI_GET_LED_STATE_FAULT_ROLLUP)
return l_res
def ipmi_get_power_on_led_state(self):
'''
This command is used to get the State of Power ON LED. ::
Power ON LED 0x01
:returns: output of command or raise OpTestError
::
ipmitool -I lanplus -H <BMC-IP> -U ADMIN -P admin raw 0x3a 0x02 0x01