def process(self):
        dbus_service = DbusServiceHandler()
        # Stop SSPL service if state is active
        service_state = dbus_service.get_state('sspl-ll.service')
        if service_state._state == 'active':
            logger.warning ("SSPL service should have been stopped,"
                            f"before {self.name} interface is invoked")
            logger.warning("Stopping SSPL service now...")
            dbus_service.stop('sspl-ll.service')

        # Remove sspl data
        shutil.rmtree(DATA_PATH, ignore_errors=True)

        # Clear log data from log files and delete 'log.gz' files
        FileStore().truncate(f"/var/log/{PRODUCT_FAMILY}/sspl/", '.log')
        FileStore().truncate(f"/var/log/{PRODUCT_FAMILY}/iem/", '.log')
        FileStore().delete(
            f"/var/log/{PRODUCT_FAMILY}/sspl/", '.log.gz')
        FileStore().delete(
            f"/var/log/{PRODUCT_FAMILY}/iem/", '.log.gz')
Example #2
0
    def get_store():
        if StorFactory.__store == None:
            try:
                store_type = os.getenv('SSPL_STORE_TYPE', SSPL_STORE_TYPE)
                if store_type == StoreTypes.FILE.value:
                    StorFactory.__store = FileStore()
                elif store_type == StoreTypes.CONSUL.value:
                    host = os.getenv('CONSUL_HOST', CONSUL_HOST)
                    port = os.getenv('CONSUL_PORT', CONSUL_PORT)
                    StorFactory.__store = ConsulStore(host, port)
                else:
                    raise Exception("{} type store is not supported".format(store_type))

                return StorFactory.__store
            except Exception as serror:
                print("Error in connecting either with file or consul store: {}".format(serror))
                print("Exiting ...")
                sys.exit(os.EX_USAGE)
        return StorFactory.__store
    def process(self, product):
        """Reset and cleanup config.

        if self.pre_factory:
            Cleanup sspl log and config files and rollback all steps executed
            in post_install stage.
        else:
            Reset sspl config.
        """
        try:
            if os.path.exists(file_store_config_path):
                FileStore().delete(
                    file_store_config_path)
            shutil.copyfile("%s/conf/sspl.conf.%s.yaml" % (
                SSPL_BASE_DIR, product), file_store_config_path)
            if self.pre_factory:
                self.cleanup_log_and_config()
        except OSError as e:
            logger.error(f"Failed in Cleanup. ERROR: {e}")
Example #4
0
    @staticmethod
    def get_store():
        if StorFactory.__store == None:
            try:
                store_type = os.getenv('SSPL_STORE_TYPE', SSPL_STORE_TYPE)
                if store_type == StoreTypes.FILE.value:
                    StorFactory.__store = FileStore()
                    StorFactory.__store.read(file_store_config_path)
                elif store_type == StoreTypes.CONSUL.value:
                    host = os.getenv('CONSUL_HOST', CONSUL_HOST)
                    port = os.getenv('CONSUL_PORT', CONSUL_PORT)
                    StorFactory.__store = ConsulStore(host, port)
                else:
                    raise Exception(
                        "{} type store is not supported".format(store_type))

                return StorFactory.__store
            except Exception as serror:
                print(
                    "Error in connecting either with file or consul store: {}".
                    format(serror))
                print("Exiting ...")
                sys.exit(os.EX_USAGE)
        return StorFactory.__store


file_store = FileStore()
#store based on configuration
store = StorFactory.get_store()
    def cleanup_log_and_config():
        """--pre-factory cleanup : Cleanup logs, config files and
        undo everything whatever was done in post-install Mini-Provisioner
        Interface."""
        Conf.load(SSPL_CONFIG_INDEX, sspl_config_path)
        sspl_log_file_path = Utility.get_config_value(
            SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>sspl_log_file_path")
        iem_log_file_path = Utility.get_config_value(
            SSPL_CONFIG_INDEX, "IEMSENSOR>log_file_path")
        message_types = [
            Utility.get_config_value(SSPL_CONFIG_INDEX, "INGRESSPROCESSOR>message_type"),
            Utility.get_config_value(SSPL_CONFIG_INDEX, "EGRESSPROCESSOR>message_type")]

        # Directories and file which needs to deleted.
        directories = [
            f'/var/{PRODUCT_FAMILY}/sspl', f'/var/{PRODUCT_FAMILY}/iem/',
            f'/var/log/{PRODUCT_FAMILY}/sspl/', f'/var/log/{PRODUCT_FAMILY}/iem/',
            '/etc/sspl-ll/', f'{PRODUCT_BASE_DIR}/iem/iec_mapping']

        sspl_sudoers_file = '/etc/sudoers.d/sspl'
        sspl_dbus_policy_rules = '/etc/polkit-1/rules.d/sspl-ll_dbus_policy.rules'
        sspl_dbus_policy_conf = '/etc/dbus-1/system.d/sspl-ll_dbus_policy.conf'
        sspl_service_file = '/etc/systemd/system/sspl-ll.service'
        sspl_test_backup = '/etc/sspl_tests.conf.back'
        sspl_test_file_path = '/etc/sspl_test_gc_url.yaml'
        sspl_sb_log_file_path = sspl_log_file_path.replace(
            "/sspl.log", "/sspl_support_bundle.log")
        manifest_log_file_path = sspl_log_file_path.replace(
            "/sspl.log", "/manifest.log")

        # symlinks created during post_install
        sspl_ll_cli = "/usr/bin/sspl_ll_cli"

        # Remove SSPL config other config/log files which were
        # created during post_install.
        for filepath in [
                sspl_ll_cli, sspl_test_backup, sspl_test_file_path,
                file_store_config_path, global_config_file_path,
                sspl_log_file_path, iem_log_file_path, sspl_sb_log_file_path,
                manifest_log_file_path, RSYSLOG_IEM_CONF, IEM_LOGROTATE_CONF,
                sspl_dbus_policy_conf, sspl_dbus_policy_rules,
                sspl_sudoers_file, sspl_service_file]:
            FileStore().delete(filepath)

        # Delete directories which were created during post_install.
        for directory in directories:
            FileStore().delete(directory)
        logger.info("Deleted config/log files and directories.")

        # Delete sspl-ll user
        usernames = [x[0] for x in pwd.getpwall()]
        if USER in usernames:
            _, err, rc = SimpleProcess("/usr/sbin/userdel -f %s" % USER).run()
            if rc != 0:
                logger.info("Error occurref while deleteing %s user. ERROR: %s"
                    %(USER, err))
            else:
                logger.info("Deleted %s user." % USER)

        # Delete topic
        mbadmin = MessageBusAdmin(admin_id="admin")
        try:
            mbadmin.deregister_message_type(message_types)
            logger.info("Delete kafka %s topics." % message_types)
        except MessageBusError as e:
            logger.error(f"MessageBusError occurred while deleting topic:{e}")