FIX: Allow configuration of IPMI privilege level 56/1256/1
authordave kormann <davek@research.att.com>
Wed, 24 Jul 2019 15:32:19 +0000 (11:32 -0400)
committerdave kormann <davek@research.att.com>
Wed, 24 Jul 2019 15:32:19 +0000 (11:32 -0400)
When invoking the ipmitool command, if an IPMI privilege level is not
specified, the default is 'ADMINISTRATOR'.  In installations where the
IPMI user does not have this privilege level, this will cause IPMI
requests to fail.  This change updates the remote installer's
invocations of ipmitool to pass a configured privilege level.  If a
privilege level is not supplied in the host configuration, the code
defaults to 'ADMINISTRATOR' to mirror the ipmitool behavior.

Previous changes added this functionality to the config-manager
components; this change brings the remote installer into line
with those components.

signed-off-by: dave kormann <davek@research.att.com>
Change-Id: I752e53e0289b919430c2478bb1303f85e70f80ae

src/remoteinstaller/installer/bmc_management/bmctools.py
src/remoteinstaller/installer/bmc_management/hw17.py
src/remoteinstaller/installer/bmc_management/oe19.py
src/remoteinstaller/installer/bmc_management/or18.py
src/remoteinstaller/installer/bmc_management/rm18.py
src/remoteinstaller/installer/catfile.py
src/remoteinstaller/installer/install.py

index 4a6e383..cbe9565 100644 (file)
@@ -22,10 +22,11 @@ class BMCException(Exception):
     pass
 
 class BMC(object):
     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._host = host
         self._user = user
         self._passwd = passwd
+        self._priv_level = priv_level
         if log_path:
             self._log_path = log_path
         else:
         if log_path:
             self._log_path = log_path
         else:
@@ -52,6 +53,9 @@ class BMC(object):
     def get_passwd(self):
         return self._passwd
 
     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())
 
     def reset(self):
         logging.info('Reset BMC of %s: %s', self.get_host_name(), self.get_host())
 
@@ -208,7 +212,7 @@ class BMC(object):
         return ''.join('{}'.format(c.decode('hex')) for c in hex_string)
 
     def _execute_ipmitool_command(self, ipmi_command):
         return ''.join('{}'.format(c.decode('hex')) for c in hex_string)
 
     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()
 
         p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
         out, _ = p.communicate()
@@ -257,12 +261,12 @@ class BMC(object):
     def _open_console(self):
         logging.debug('Open SOL console (log in %s)', self._log_path)
 
     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.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
 
 
         return expect_session
 
index a7b5bec..869a6a2 100644 (file)
@@ -20,8 +20,8 @@ class BMCException(Exception):
     pass
 
 class HW17(BMC):
     pass
 
 class HW17(BMC):
-    def __init__(self, host, user, passwd, log_path=None):
-        super(HW17, self).__init__(host, user, passwd, log_path)
+    def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
+        super(HW17, self).__init__(host, user, passwd, priv_level, log_path)
 
     def attach_virtual_cd(self, nfs_host, nfs_mount, boot_iso_filename):
         for _ in range(2):
 
     def attach_virtual_cd(self, nfs_host, nfs_mount, boot_iso_filename):
         for _ in range(2):
index b514fd5..958801c 100644 (file)
@@ -19,8 +19,8 @@ class BMCException(Exception):
     pass
 
 class OE19(OR18):
     pass
 
 class OE19(OR18):
-    def __init__(self, host, user, passwd, log_path=None):
-        super(OE19, self).__init__(host, user, passwd, log_path)
+    def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
+        super(OE19, self).__init__(host, user, passwd, priv_level, log_path)
 
     def _set_boot_from_virtual_media(self):
         logging.debug('Set boot from floppy (%s), and boot after that', self._host)
 
     def _set_boot_from_virtual_media(self):
         logging.debug('Set boot from floppy (%s), and boot after that', self._host)
index d41df4e..78606db 100644 (file)
@@ -20,8 +20,8 @@ class BMCException(Exception):
     pass
 
 class OR18(BMC):
     pass
 
 class OR18(BMC):
-    def __init__(self, host, user, passwd, log_path=None):
-        super(OR18, self).__init__(host, user, passwd, log_path)
+    def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
+        super(OR18, self).__init__(host, user, passwd, priv_level, log_path)
 
     def _clear_ris_configuration(self):
         # Clear RIS configuration
 
     def _clear_ris_configuration(self):
         # Clear RIS configuration
index e498129..7ca7881 100644 (file)
@@ -19,8 +19,8 @@ class BMCException(Exception):
     pass
 
 class RM18(OR18):
     pass
 
 class RM18(OR18):
-    def __init__(self, host, user, passwd, log_path=None):
-        super(RM18, self).__init__(host, user, passwd, log_path)
+    def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
+        super(RM18, self).__init__(host, user, passwd, priv_level, log_path)
 
     def _set_boot_from_virtual_media(self):
         logging.debug('Set boot from floppy (%s), and boot after that', self._host)
 
     def _set_boot_from_virtual_media(self):
         logging.debug('Set boot from floppy (%s), and boot after that', self._host)
index 5d4fe3b..e5d2147 100644 (file)
@@ -21,10 +21,11 @@ class CatFileException(Exception):
     pass
 
 class CatFile(object):
     pass
 
 class CatFile(object):
-    def __init__(self, bmc_host, bmc_user, bmc_password, login_user, login_password):
+    def __init__(self, bmc_host, bmc_user, bmc_password, bmc_priv_level='ADMINISTRATOR', login_user, login_password):
         self._host = bmc_host
         self._user = bmc_user
         self._password = bmc_password
         self._host = bmc_host
         self._user = bmc_user
         self._password = bmc_password
+        self._priv_level = bmc_priv_level
         self._sol = None
 
         self._login_user = login_user
         self._sol = None
 
         self._login_user = login_user
@@ -34,11 +35,11 @@ class CatFile(object):
         logging.info('Open SOL console')
 
         logging.debug('deactivate sol')
         logging.info('Open SOL console')
 
         logging.debug('deactivate sol')
-        expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} sol deactivate'.format(self._host, self._user, self._password))
+        expect_session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} -L {} sol deactivate'.format(self._host, self._user, self._password, self._priv_level))
         expect_session.expect(pexpect.EOF)
 
         logging.debug('activate sol, output will go to %s', log)
         expect_session.expect(pexpect.EOF)
 
         logging.debug('activate sol, output will go to %s', log)
-        self._sol = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} sol activate'.format(self._host, self._user, self._password), timeout=None)
+        self._sol = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} -L {} sol activate'.format(self._host, self._user, self._password, self._priv_level), timeout=None)
         logfile = open(log, 'wb')
         self._sol.logfile_read = logfile
 
         logfile = open(log, 'wb')
         self._sol.logfile_read = logfile
 
@@ -53,7 +54,7 @@ class CatFile(object):
             self._sol.terminate()
 
         logging.debug('deactivate sol')
             self._sol.terminate()
 
         logging.debug('deactivate sol')
-        session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} sol deactivate'.format(self._host, self._user, self._password))
+        session = pexpect.spawn('ipmitool -I lanplus -H {} -U {} -P {} -L {} sol deactivate'.format(self._host, self._user, self._password, self._priv_level))
         session.expect(pexpect.EOF)
 
     def _expect_cmd_prompt(self):
         session.expect(pexpect.EOF)
 
     def _expect_cmd_prompt(self):
@@ -116,6 +117,7 @@ def main():
     parser.add_argument('-H', '--bmc_host', required=True, help='BMC host')
     parser.add_argument('-U', '--bmc_user', required=True, help='BMC user')
     parser.add_argument('-P', '--bmc_password', required=True, help='BMC user password')
     parser.add_argument('-H', '--bmc_host', required=True, help='BMC host')
     parser.add_argument('-U', '--bmc_user', required=True, help='BMC user')
     parser.add_argument('-P', '--bmc_password', required=True, help='BMC user password')
+    parser.add_argument('-L', '--bmc_priv_level', required=False, default='ADMINISTRATOR', help='BMC user privilege level')
     parser.add_argument('-u', '--user', required=True, help='Login user')
     parser.add_argument('-p', '--password', required=True, help='Login user password')
     parser.add_argument('-f', '--file', required=True, help='File path to cat')
     parser.add_argument('-u', '--user', required=True, help='Login user')
     parser.add_argument('-p', '--password', required=True, help='Login user password')
     parser.add_argument('-f', '--file', required=True, help='File path to cat')
@@ -126,7 +128,7 @@ def main():
 
     logging.basicConfig(level=logging.DEBUG)
 
 
     logging.basicConfig(level=logging.DEBUG)
 
-    cat_file = CatFile(args.bmc_host, args.bmc_user, args.bmc_password, args.user, args.password)
+    cat_file = CatFile(args.bmc_host, args.bmc_user, args.bmc_password, args.user, bmc_priv_level, args.password)
     cat_file.cat(args.file, args.output_file, args.password)
 
 if __name__ == "__main__":
     cat_file.cat(args.file, args.output_file, args.password)
 
 if __name__ == "__main__":
index 86d8c0f..a5c099a 100644 (file)
@@ -154,7 +154,7 @@ class Installer(object):
         bmc_mod_name = 'remoteinstaller.installer.bmc_management.{}'.format(hw_data['product_family'].lower())
         bmc_mod = importlib.import_module(bmc_mod_name)
         bmc_class = getattr(bmc_mod, hw_data['product_family'])
         bmc_mod_name = 'remoteinstaller.installer.bmc_management.{}'.format(hw_data['product_family'].lower())
         bmc_mod = importlib.import_module(bmc_mod_name)
         bmc_class = getattr(bmc_mod, hw_data['product_family'])
-        bmc = bmc_class(host, user, passwd, bmc_log_path)
+        bmc = bmc_class(host, user, passwd, priv_level, bmc_log_path)
         bmc.set_host_name(hw)
 
         return bmc
         bmc.set_host_name(hw)
 
         return bmc
@@ -313,15 +313,16 @@ class Installer(object):
         bmc_host = bmc.get_host()
         bmc_user = bmc.get_user()
         bmc_passwd = bmc.get_passwd()
         bmc_host = bmc.get_host()
         bmc_user = bmc.get_user()
         bmc_passwd = bmc.get_passwd()
-
+        bmc_priv_level = bmc.get_priv_level()
+        
         log_file = '{}/cat_bootstrap.log'.format(self._logdir)
         try:
         log_file = '{}/cat_bootstrap.log'.format(self._logdir)
         try:
-            cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, admin_user, admin_passwd)
+            cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, admin_user, admin_passwd)
             cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
         except CatFileException as ex:
             logging.info('Could not cat file from console: %s', str(ex))
 
             cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
         except CatFileException as ex:
             logging.info('Could not cat file from console: %s', str(ex))
 
-            cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, 'root', 'root')
+            cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, 'root', 'root')
             cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
 
     def get_logs(self, admin_passwd):
             cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
 
     def get_logs(self, admin_passwd):