X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fremote-installer.git;a=blobdiff_plain;f=src%2Fremoteinstaller%2Finstaller%2Fbmc_management%2Fbmctools.py;h=f7d635838deda81a28dfcc0b507fcd7c3f825abf;hp=dfdeaea5e97abbe84a9ee89b7d9447a9ca11f84a;hb=f67d243ed72be60eb02dacad2584eb189cf6f4b7;hpb=f9adb9143ef94b16ae16941652e75deccad506ef diff --git a/src/remoteinstaller/installer/bmc_management/bmctools.py b/src/remoteinstaller/installer/bmc_management/bmctools.py index dfdeaea..f7d6358 100644 --- a/src/remoteinstaller/installer/bmc_management/bmctools.py +++ b/src/remoteinstaller/installer/bmc_management/bmctools.py @@ -1,5 +1,6 @@ # Copyright 2019 Nokia - +# Copyright 2020 ENEA +# # 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 @@ -22,10 +23,11 @@ class BMCException(Exception): pass class BMC(object): - def __init__(self, host, user, passwd, log_path=None): + def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None): self._host = host self._user = user self._passwd = passwd + self._priv_level = priv_level if log_path: self._log_path = log_path else: @@ -52,12 +54,15 @@ class BMC(object): def get_passwd(self): return self._passwd + def get_priv_level(self): + return self._priv_level + def reset(self): logging.info('Reset BMC of %s: %s', self.get_host_name(), self.get_host()) self._run_ipmitool_command('bmc reset cold') - success = self._wait_for_bmc_reset(180) + success = self._wait_for_bmc_reset(360) if not success: raise BMCException('BMC reset failed, BMC did not come up') @@ -197,18 +202,16 @@ class BMC(object): @staticmethod def _convert_to_hex(ascii_string, padding=False, length=0): - hex_value = ''.join('0x{} '.format(c.encode('hex')) for c in ascii_string).strip() - if padding and (len(ascii_string) < length): - hex_value += ''.join(' 0x00' for _ in range(len(ascii_string), length)) - - return hex_value + if padding: + ascii_string = ascii_string.ljust(length, '\0') + return ' '.join('0x{}'.format(c.encode('hex')) for c in ascii_string) @staticmethod def _convert_to_ascii(hex_string): - return ''.join('{}'.format(c.decode('hex')) for c in hex_string) + return hex_string.replace('0x','').replace(' ','').decode('hex') def _execute_ipmitool_command(self, ipmi_command): - command = 'ipmitool -I lanplus -H {} -U {} -P {} {}'.format(self._host, self._user, self._passwd, ipmi_command) + command = 'ipmitool -I lanplus -H {} -U {} -P {} -L {} {}'.format(self._host, self._user, self._passwd, self._priv_level, ipmi_command) p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = p.communicate() @@ -257,12 +260,12 @@ class BMC(object): def _open_console(self): logging.debug('Open SOL console (log in %s)', self._log_path) - expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} sol deactivate'.format(self._host, self._user, self._passwd)) + expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} -L {} sol deactivate'.format(self._host, self._user, self._passwd, self._priv_level)) expect_session.expect(pexpect.EOF) logfile = open(self._log_path, 'ab') - expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} sol activate'.format(self._host, self._user, self._passwd), timeout=None, logfile=logfile) + expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} -L {} sol activate'.format(self._host, self._user, self._passwd, self._priv_level), timeout=None, logfile=logfile) return expect_session @@ -306,6 +309,8 @@ class BMC(object): logging.info('Retry to expect a flag in console, %s seconds remaining', remaining_time) self.close() + raise BMCException('Expected message in console did not occur in time ({})'.format(flags)) + def _wait_for_bios_settings_done(self): logging.debug('Wait until BIOS settings are updated')