diff --git a/servicereportpkg/repair/plugins/rsct_repair.py b/servicereportpkg/repair/plugins/rsct_repair.py new file mode 100644 index 0000000..e54ca24 --- /dev/null +++ b/servicereportpkg/repair/plugins/rsct_repair.py @@ -0,0 +1,110 @@ +#SPDX-License-Identifier: GPL-2.0-only +# +# (C) Copyright IBM Corp. 2020 +# Author: Seeteena Thoufeek + +"""Plugin to repair the rsct configuration check""" + + +from servicereportpkg.repair.plugins import RepairPlugin +from servicereportpkg.check import Notes +from servicereportpkg.utils import execute_command +from servicereportpkg.validate.schemes.schemes import PSeriesScheme +from servicereportpkg.utils import install_package + + +class RSCTRepair(RepairPlugin, PSeriesScheme): + """Plugin to repair the RSCT configuration check""" + + def __init__(self): + RepairPlugin.__init__(self) + self.name = 'RSCT' + self.optional = True + + def enable_subsystem(self, plugin_obj, check): + """Enables the subsystem if not active""" + + subsys_list = check.get_service() + for subsystem in subsys_list: + subsystem_status = subsystem[1] + if subsystem_status is False: + command = ["startsrc", "-s", subsystem[0]] + execute_command(command) + re_check = plugin_obj.check_rsct_subsystem_check() + if re_check.get_status(): + self.log.debug("Subsystems active") + check.set_status(True) + check.set_note(Notes.FIXED) + else: + self.log.debug("Subsystems not active") + check.set_note(Notes.FAIL_TO_FIX) + + def fix_rsct_package(self, plugin_obj, check): + """fix rsct package""" + + self.log.info("RSCT package repair") + pkg_list = check.get_package_name() + for package in pkg_list: + install_package(package[0]) + re_check = plugin_obj.check_rsct_package_check() + if re_check.get_status(): + check.set_status(True) + check.set_note(Notes.FIXED) + else: + check.set_note(Notes.FAIL_TO_FIX) + + def fix_rsct_install_path(self, plugin_obj, check): + """Fix rsct install path""" + + re_check = plugin_obj.check_rsct_installation_path() + if re_check.get_status(): + check.set_status(True) + check.set_note(Notes.FIXED) + else: + check.set_note(Notes.FAIL_TO_FIX) + + def repair(self, plugin_obj, checks): + """Repair rsct subsystem checks""" + + self.log.info("RSCT Subsystem Repair") + check_dir = {} + for check in checks: + check_dir[check.get_name()] = check + + rsct_package_check = check_dir["RSCT package check"] + self.log.debug("package_check: %s", rsct_package_check.get_name()) + if not rsct_package_check.get_status(): + rsct_power_repo_check = \ + check_dir["IBM Power Repo Package Check"] + self.log.debug("rsct_power_repo_check %s", + rsct_power_repo_check.get_name()) + if not rsct_power_repo_check.get_status(): + rsct_power_repo_check.set_note(Notes.NOT_FIXABLE + "\n \n \ +WARNING!!!! ibm-power-repo package needs to be enabled to install rsct \ +packages on this machine. \n Please follow below steps to install \ +ibm-power-repo package. \n 1. Download and install ibm-power-repo package. \ +\n 2. run /opt/ibm/lop/configure to agree with the license. \ +\n Refer https://www.ibm.com/support/pages/service-and-productivity-tools \ +for more details") + return + if rsct_package_check.get_status() is False: + self.fix_rsct_package(plugin_obj, rsct_package_check) + elif rsct_package_check.get_status() is None: + rsct_package_check.set_note(Notes.FAIL_TO_FIX) + + if "RSCT Installation path" in check_dir.keys(): + rsct_install_exists = check_dir["RSCT Installation path"] + if rsct_install_exists.get_status() is False: + self.fix_rsct_install_path(plugin_obj, rsct_install_exists) + elif rsct_install_exists.get_status() is None: + rsct_install_exists.set_note(Notes.FAIL_TO_FIX) + + if "RSCT service status" in check_dir.keys(): + rsct_service_check = check_dir["RSCT service status"] + self.log.debug("rsct_service_check %s %s", + rsct_service_check.get_status(), + rsct_service_check.get_service()) + if rsct_service_check.get_status() is False: + self.enable_subsystem(plugin_obj, rsct_service_check) + elif rsct_service_check.get_status() is None: + rsct_service_check.set_note(Notes.FAIL_TO_FIX) diff --git a/servicereportpkg/validate/plugins/rsct.py b/servicereportpkg/validate/plugins/rsct.py new file mode 100644 index 0000000..fadf5af --- /dev/null +++ b/servicereportpkg/validate/plugins/rsct.py @@ -0,0 +1,116 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# (C) Copyright IBM Corp. 2020 +# Author: Seeteena Thoufeek + +"""Plugin to check RSCT configuration""" + +import os + +from servicereportpkg.check import Check +from servicereportpkg.validate.plugins import Plugin +from servicereportpkg.utils import execute_command +from servicereportpkg.check import PackageCheck, ServiceCheck +from servicereportpkg.utils import is_package_installed +from servicereportpkg.validate.schemes.schemes import PSeriesScheme + + +class RSCT(Plugin, PSeriesScheme): + """RSCT configuration check""" + + def __init__(self): + Plugin.__init__(self) + self.name = RSCT.__name__ + self.description = RSCT.__doc__ + self.optional = True + self.installation_path = "/opt/rsct/bin" + self.packages = [ + "rsct.core", + "rsct.core.utils", + "rsct.basic", + "src", + "devices.chrp.base.ServiceRM", + "DynamicRM", + ] + self.subsystems = ["ctrmc", "IBM.DRM", "IBM.HostRM", + "IBM.ServiceRM", "IBM.MgmtDomainRM"] + + def check_rsct_installation_path(self): + """RSCT Installation path""" + + installation_path_exists = True + self.log.info("RSCT Installation path check") + if not os.path.isdir(self.installation_path): + self.log.error("Missing RSCT installation directory %s", + self.installation_path) + installation_path_exists = False + + return Check(self.check_rsct_installation_path.__doc__, + installation_path_exists) + + def get_subsystem_status(self, subsystem): + """Checks the subsystem status""" + + command = ["lssrc", "-s", subsystem] + (return_code, stdout, err) = execute_command(command) + + if return_code is None or ("active" not in str(stdout)): + self.log.info("Subsystem %s error %s", subsystem, str(err)) + return False + + return True + + def check_rsct_subsystem_check(self): + """RSCT service status""" + + subsys_list = [] + subsys_status = True + status = True + self.log.info("RSCT Subsystem status check") + for subsystem in self.subsystems: + if not self.get_subsystem_status(subsystem): + self.log.debug("%s Subsystem is not active", subsystem) + subsys_status = False + status = False + subsys_list.append((subsystem, subsys_status)) + else: + subsys_status = True + subsys_list.append((subsystem, subsys_status)) + + return ServiceCheck(self.check_rsct_subsystem_check.__doc__, + subsys_list, status) + + def check_rsct_package_check(self): + """RSCT package check""" + + pkg_list = [] + pkg_status = True + status = True + self.log.info("RSCT Package check") + for package in self.packages: + if not is_package_installed(package): + self.log.error("%s package is not installed", package) + status = False + pkg_status = False + pkg_list.append((package, pkg_status)) + else: + pkg_status = True + pkg_list.append((package, pkg_status)) + + return PackageCheck(self.check_rsct_package_check.__doc__, + pkg_list, status) + + + def check_rsct_warning_check(self): + """IBM Power Repo Package Check""" + + status = True + power_repo_package = "ibm-power-repo" + self.log.info("ibm-power-repo Package check") + if not is_package_installed(power_repo_package): + self.log.error("ibm-power-repo package is not installed") + status = False + + return PackageCheck(self.check_rsct_warning_check.__doc__, + power_repo_package, status) +