def cleanup(pre_factory: bool): """Remove/Delete all the data that was created after post install.""" conf_file = '/etc/cortx/message_bus.conf' if os.path.exists(conf_file): # delete message_types try: from cortx.utils.message_bus import MessageBusAdmin mb = MessageBusAdmin(admin_id='cleanup') message_types_list = mb.list_message_types() if message_types_list: mb.deregister_message_type(message_types_list) except MessageBusError as e: raise SetupError(e.rc, "Can not cleanup Message Bus. %s", e) except Exception as e: raise SetupError( errors.ERR_OP_FAILED, "Can not cleanup Message \ Bus. %s", e) config_files = ['/etc/cortx/message_bus.conf', \ '/etc/cortx/cluster.conf'] Utils._delete_files(config_files) if pre_factory: # deleting all log files as part of pre-factory cleanup cortx_utils_log_regex = '/var/log/cortx/utils/**/*.log' log_files = glob.glob(cortx_utils_log_regex, recursive=True) Utils._delete_files(log_files) return 0
def reset(): """ Remove/Delete all the data that was created after post install """ conf_file = '/etc/cortx/message_bus.conf' if os.path.exists(conf_file): # delete message_types from cortx.utils.message_bus import MessageBusAdmin try: mb = MessageBusAdmin(admin_id='reset') message_types_list = mb.list_message_types() if message_types_list: mb.deregister_message_type(message_types_list) except MessageBusError as e: raise SetupError(e.rc, "Can not reset Message Bus. %s", e) except Exception as e: raise SetupError(errors.ERR_OP_FAILED, "Can not reset Message Bus. \ %s", e) # Stop MessageBus Service cmd = SimpleProcess("systemctl stop cortx_message_bus") _, stderr, res_rc = cmd.run() if res_rc != 0: raise SetupError(res_rc, "Unable to stop MessageBus Service. \ %s", stderr.decode('utf-8')) return 0
def cleanup(pre_factory: bool, config_path: str): """Remove/Delete all the data that was created after post install.""" # delete message_types from cortx.utils.message_bus.error import MessageBusError try: # use gconf to clean and delete all message type in messagebus from cortx.utils.message_bus import MessageBus, MessageBusAdmin Conf.load(GCONF_INDEX, config_path, skip_reload=True) message_bus_backend = Conf.get(GCONF_INDEX, MSG_BUS_BACKEND_KEY) message_server_endpoints = Conf.get(GCONF_INDEX,\ f'{EXTERNAL_KEY}>{message_bus_backend}>endpoints') MessageBus.init(message_server_endpoints) mb = MessageBusAdmin(admin_id='cleanup') message_types_list = mb.list_message_types() if message_types_list: mb.deregister_message_type(message_types_list) except MessageBusError as e: raise SetupError(e.rc, "Can not cleanup Message Bus. %s", e) except Exception as e: raise SetupError( errors.ERR_OP_FAILED, "Can not cleanup Message \ Bus. %s", e) return 0
def cleanup(): """Remove/Delete all the data that was created after post install.""" conf_file = '/etc/cortx/message_bus.conf' if os.path.exists(conf_file): # delete message_types try: from cortx.utils.message_bus import MessageBusAdmin mb = MessageBusAdmin(admin_id='cleanup') message_types_list = mb.list_message_types() if message_types_list: mb.deregister_message_type(message_types_list) except MessageBusError as e: raise SetupError(e.rc, "Can not cleanup Message Bus. %s", e) except Exception as e: raise SetupError( errors.ERR_OP_FAILED, "Can not cleanup Message \ Bus. %s", e) config_files = ['/etc/cortx/message_bus.conf', \ '/etc/cortx/cluster.conf'] for each_file in config_files: if os.path.exists(each_file): # delete data/config stored try: os.remove(each_file) except OSError as e: raise SetupError( e.errno, "Error deleting config file %s, \ %s", each_file, e) return 0
def delete_topic(admin_id: str, message_types: list): """Delete given topic""" try: if S3CortxMsgBus._message_bus: mbadmin = MessageBusAdmin(S3CortxMsgBus._message_bus, admin_id) mbadmin.deregister_message_type(message_types=message_types) except: raise Exception("Failed to delete topic")
def deregister(message_type: str): """ Deregister message type to message bus. Args: message_type (str): Message type. """ admin = MessageBusAdmin(admin_id=MessageBus.ADMIN_ID) if message_type in admin.list_message_types(): admin.deregister_message_type(message_types=[message_type])
def __del__(self): # Delete the test message_type from cortx.utils.message_bus import MessageBusAdmin # deregister_message_type try: admin = MessageBusAdmin(admin_id='messageadmin') admin.deregister_message_type(message_types=['mytest']) list_message_type = admin.list_message_types() if 'mytest' in list_message_type: raise SetupError(errors.ERR_OP_FAILED, "Failed to test the" \ " config. Deregister message_type: mytest failed") except Exception as e: raise SetupError(errors.ERR_OP_FAILED, \ "Failed to test the config, %s", e)
def delete_topic(admin_id: str, message_types: list): """Delete given topic""" mbadmin = MessageBusAdmin(admin_id = admin_id) mbadmin.deregister_message_type(message_types = message_types)
def test_014_multiple_admins(): """Test multiple instances of admin interface.""" TestMessageBus._admin.register_message_type( message_types=['test_msg_type'], partitions=1) admin2 = MessageBusAdmin(admin_id='deregister') admin2.deregister_message_type(['test_msg_type'])
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}")