def collect_ocs_logs(dir_name, ocp=True, ocs=True, mcg=False): """ Collects OCS logs Args: dir_name (str): directory name to store OCS logs. Logs will be stored in dir_name suffix with _ocs_logs. ocp (bool): Whether to gather OCP logs ocs (bool): Whether to gather OCS logs mcg (bool): True for collecting MCG logs (noobaa db dump) """ if not ('KUBECONFIG' in os.environ or os.path.exists(os.path.expanduser('~/.kube/config'))): log.warning("Cannot find $KUBECONFIG or ~/.kube/config; " "skipping log collection") return log_dir_path = os.path.join( os.path.expanduser(ocsci_config.RUN['log_dir']), f"failed_testcase_ocs_logs_{ocsci_config.RUN['run_id']}", f"{dir_name}_ocs_logs") if ocs: latest_tag = ocsci_config.REPORTING.get( 'ocs_must_gather_latest_tag', ocsci_config.REPORTING.get( 'default_ocs_must_gather_latest_tag', ocsci_config.DEPLOYMENT['default_latest_tag'])) ocs_log_dir_path = os.path.join(log_dir_path, 'ocs_must_gather') ocs_must_gather_image = ocsci_config.REPORTING['ocs_must_gather_image'] ocs_must_gather_image_and_tag = f"{ocs_must_gather_image}:{latest_tag}" if ocsci_config.DEPLOYMENT.get('disconnected'): ocs_must_gather_image_and_tag = ( mirror_image(ocs_must_gather_image_and_tag)) run_must_gather(ocs_log_dir_path, ocs_must_gather_image_and_tag) if ocp: ocp_log_dir_path = os.path.join(log_dir_path, 'ocp_must_gather') ocp_must_gather_image = ocsci_config.REPORTING['ocp_must_gather_image'] if ocsci_config.DEPLOYMENT.get('disconnected'): ocp_must_gather_image = (mirror_image(ocp_must_gather_image)) run_must_gather(ocp_log_dir_path, ocp_must_gather_image) run_must_gather(ocp_log_dir_path, ocp_must_gather_image, '/usr/bin/gather_service_logs worker') if mcg: counter = 0 while counter < 5: counter += 1 try: collect_noobaa_db_dump(log_dir_path) break except CommandFailed as ex: log.error(f"Failed to dump noobaa DB! Error: {ex}") sleep(30)
def collect_ocs_logs(dir_name, ocp=True, ocs=True, mcg=False, status_failure=True): """ Collects OCS logs Args: dir_name (str): directory name to store OCS logs. Logs will be stored in dir_name suffix with _ocs_logs. ocp (bool): Whether to gather OCP logs ocs (bool): Whether to gather OCS logs mcg (bool): True for collecting MCG logs (noobaa db dump) status_failure (bool): Whether the collection is after success or failure, allows better naming for folders under logs directory """ if not ("KUBECONFIG" in os.environ or os.path.exists(os.path.expanduser("~/.kube/config"))): log.warning("Cannot find $KUBECONFIG or ~/.kube/config; " "skipping log collection") return if status_failure: log_dir_path = os.path.join( os.path.expanduser(ocsci_config.RUN["log_dir"]), f"failed_testcase_ocs_logs_{ocsci_config.RUN['run_id']}", f"{dir_name}_ocs_logs", ) else: log_dir_path = os.path.join( os.path.expanduser(ocsci_config.RUN["log_dir"]), f"{dir_name}_{ocsci_config.RUN['run_id']}", ) if ocs: latest_tag = ocsci_config.REPORTING.get( "ocs_must_gather_latest_tag", ocsci_config.REPORTING.get( "default_ocs_must_gather_latest_tag", ocsci_config.DEPLOYMENT["default_latest_tag"], ), ) ocs_log_dir_path = os.path.join(log_dir_path, "ocs_must_gather") ocs_must_gather_image = ocsci_config.REPORTING.get( "ocs_must_gather_image", ocsci_config.REPORTING["default_ocs_must_gather_image"], ) ocs_must_gather_image_and_tag = f"{ocs_must_gather_image}:{latest_tag}" if ocsci_config.DEPLOYMENT.get("disconnected"): ocs_must_gather_image_and_tag = mirror_image( ocs_must_gather_image_and_tag) mg_output = run_must_gather(ocs_log_dir_path, ocs_must_gather_image_and_tag) if (ocsci_config.DEPLOYMENT.get("disconnected") and "cannot stat 'jq'" in mg_output): raise ValueError( f"must-gather fails in an disconnected environment bz-1974959\n{mg_output}" ) if ocp: ocp_log_dir_path = os.path.join(log_dir_path, "ocp_must_gather") ocp_must_gather_image = ocsci_config.REPORTING["ocp_must_gather_image"] if ocsci_config.DEPLOYMENT.get("disconnected"): ocp_must_gather_image = mirror_image(ocp_must_gather_image) run_must_gather(ocp_log_dir_path, ocp_must_gather_image) run_must_gather( ocp_log_dir_path, ocp_must_gather_image, "/usr/bin/gather_service_logs worker", ) if mcg: counter = 0 while counter < 5: counter += 1 try: collect_noobaa_db_dump(log_dir_path) break except CommandFailed as ex: log.error(f"Failed to dump noobaa DB! Error: {ex}") sleep(30)