def _check_available_contents(self): cnt = 0 is_dir = lambda x: os.path.isdir(os.path.join(self.conf.source_dir, x)) dirs = os.listdir(self.conf.source_dir) self.list_scans = [] for dir_name in filter(is_dir, dirs): if SystemIdentification.get_assessment_version(dir_name): self.conf.scan = dir_name self.list_scans.append(dir_name) logger_debug.debug("Scan directory '%s'", self.conf.scan) cnt += 1 if int(cnt) < 1: log_message("There were no modules found in the %s directory. \ If you would like to use this tool, you have to install some." % settings.source_dir) return ReturnValues.SCENARIO if int(cnt) > 1: log_message("Preupgrade Assistant detects more " "than one set of modules in the %s directory.\n" % settings.source_dir) log_message("The list of sets of all available modules is: \n%s" % '\n'.join(self.list_scans)) log_message( "If you would like to use the tool, " "specify the correct upgrade path mentioned above with a parameter -s." ) return ReturnValues.SCENARIO return 0
def run_init(self): """ Run module set's init script if exists If module set provides executable called 'init', run it. Standard output is ignored. If either exit status is non-zero or error is printed, raise ModuleSetInitError. Note that exported environment variables need to be reviewed; current set is purely to make previous solution work and prevent regression. """ scenario = self.rename_custom_module_set(self.module_set_dirname) init = os.path.join(self.conf.source_dir, scenario, 'init') if os.access(init, os.F_OK): init_vars = { 'PREUPGM_INIT_ASSESSMENT_DIR': self.module_set_copy_path, 'PREUPGM_INIT_SCENARIO': scenario, 'PREUPGM_INIT_DST_ARCH': self.conf.dst_arch if self.conf.dst_arch else "", 'PREUPGM_INIT_CONTENTS': self.conf.contents if self.conf.contents else "", } logger_debug.debug("calling module init script with: %r" % init_vars) init_env = os.environ.copy() init_env.update(init_vars) try: p = subprocess.Popen( [init], env=init_env, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) out, err = p.communicate() except OSError as e: raise exception.ModuleSetFormatError("init script failed to execute", init, e) if p.returncode or err.strip(): raise exception.ModuleSetInitError(p.returncode, err)
def run_scan(self, function=None): """ The function is used for either scanning system or for applying changes on the target system """ cmd = self.openscap_helper.build_command() logger_debug.debug('running_command: %s', cmd) return ProcessHelper.run_subprocess(cmd, print_output=False, function=function)
def copy_modified_config_files(result_dir): """ Function copies all modified files to dirtyconf directory. (files which are not mentioned in cleanconf directory) """ etc_va_log = os.path.join(settings.cache_dir, settings.common_name, "rpm_etc_Va.log") try: lines = FileHelper.get_file_content(etc_va_log, "rb", method=True) except IOError: raise IOError("Error: File that lists modified configuration files" "'%s' is missing.\n" % etc_va_log) dirty_conf = os.path.join(result_dir, settings.dirty_conf_dir) clean_conf = os.path.join(result_dir, settings.clean_conf_dir) # Go through all changed config files for line in lines: try: (opts, flags, filename) = line.strip().split() if opts.strip() == 'missing': continue except ValueError: return logger_debug.debug("The '%s' file name to copy.", filename) new_filename = filename[1:] # Check whether config file exists in cleanconf directory cleanconf_file_name = os.path.join(clean_conf, new_filename) dirtyconf_file_name = os.path.join(dirty_conf, new_filename) # Check if config file does not exist in cleanconf directory if ConfigFilesHelper.check_cleanconf_dir(result_dir, cleanconf_file_name): if os.path.exists(dirtyconf_file_name): log_message( "The %s file exist in the %s directory" % (new_filename, dirty_conf), logging.DEBUG) os.unlink(dirtyconf_file_name) continue # Check if config file does not exists in dirtyconf directory check = ConfigFilesHelper.check_dirtyconf_dir( dirtyconf_file_name, filename) if check: try: shutil.copyfile(check, dirtyconf_file_name) except IOError: sys.stderr.write( "Warning: Could not copy '%s' to '%s'.\n" % (check, os.path.dirname(dirtyconf_file_name))) pass
def run_compose(cls, dir_name, content=None, generate_from_ini=True): target_tree = ComposeXML.get_xml_tree() settings.UPGRADE_PATH = dir_name if os.path.exists(os.path.join(dir_name, settings.file_list_rules)): os.unlink(os.path.join(dir_name, settings.file_list_rules)) group_xmls = cls.collect_group_xmls(dir_name, content=content, level=0, generate_from_ini=generate_from_ini) logger_debug.debug("Group xmls '%s'", group_xmls) if generate_from_ini: cls.perform_autoqa(dir_name, group_xmls) new_base_dir = dir_name cls.repath_group_xml_tree(dir_name, new_base_dir, group_xmls) cls.merge_trees(target_tree, target_tree, group_xmls) target_tree = cls.update_content_ref(target_tree, content) cls.resolve_selects(target_tree) cls.refresh_status(target_tree) cls.indent(target_tree) return target_tree
def run_compose(dir_name, generate_from_ini=True): target_tree = ComposeXML.get_xml_tree() settings.UPGRADE_PATH = dir_name if os.path.exists(os.path.join(dir_name, settings.file_list_rules)): os.unlink(os.path.join(dir_name, settings.file_list_rules)) group_xmls = ComposeXML.collect_group_xmls(dir_name, dir_name, generate_from_ini) logger_debug.debug("Group xmls '%s'", group_xmls) if generate_from_ini: ComposeXML.perform_autoqa(dir_name, group_xmls) new_base_dir = dir_name ComposeXML.repath_group_xml_tree(dir_name, new_base_dir, group_xmls) ComposeXML.merge_trees(target_tree, target_tree, group_xmls) ComposeXML.resolve_selects(target_tree) ComposeXML.refresh_status(target_tree) ComposeXML.indent(target_tree) return target_tree
def copy_modified_config_files(result_dir): """ Function copies all modified files to dirtyconf directory. (files which are not mentioned in cleanconf directory) """ etc_va_log = os.path.join(settings.cache_dir, settings.common_name, "rpm_etc_Va.log") try: lines = FileHelper.get_file_content(etc_va_log, "rb", method=True) except IOError: raise IOError("Error: File that lists modified configuration files" "'%s' is missing.\n" % etc_va_log) dirty_conf = os.path.join(result_dir, settings.dirty_conf_dir) clean_conf = os.path.join(result_dir, settings.clean_conf_dir) # Go through all changed config files for line in lines: try: (opts, flags, filename) = line.strip().split() if opts.strip() == 'missing': continue except ValueError: return logger_debug.debug("The '%s' file name to copy.", filename) new_filename = filename[1:] # Check whether config file exists in cleanconf directory cleanconf_file_name = os.path.join(clean_conf, new_filename) dirtyconf_file_name = os.path.join(dirty_conf, new_filename) # Check if config file does not exist in cleanconf directory if ConfigFilesHelper.check_cleanconf_dir(result_dir, cleanconf_file_name): if os.path.exists(dirtyconf_file_name): log_message("The %s file exist in the %s directory" % (new_filename, dirty_conf), logging.DEBUG) os.unlink(dirtyconf_file_name) continue # Check if config file does not exists in dirtyconf directory check = ConfigFilesHelper.check_dirtyconf_dir(dirtyconf_file_name, filename) if check: try: shutil.copyfile(check, dirtyconf_file_name) except IOError: sys.stderr.write("Warning: Could not copy '%s' to '%s'.\n" % (check, os.path.dirname(dirtyconf_file_name))) pass
def _check_available_contents(self): cnt = 0 is_dir = lambda x: os.path.isdir(os.path.join(self.conf.source_dir, x)) dirs = os.listdir(self.conf.source_dir) self.list_scans = [] for dir_name in filter(is_dir, dirs): if SystemIdentification.get_assessment_version(dir_name): self.conf.scan = dir_name self.list_scans.append(dir_name) logger_debug.debug("Scan directory '%s'", self.conf.scan) cnt += 1 if int(cnt) < 1: log_message("There were no modules found in the %s directory. \ If you would like to use this tool, you have to install some." % settings.source_dir) return ReturnValues.SCENARIO if int(cnt) > 1: log_message("Preupgrade Assistant detects more " "than one set of modules in the %s directory.\n" % settings.source_dir) log_message("The list of sets of all available modules is: \n%s" % '\n'.join(self.list_scans)) log_message("If you would like to use the tool, " "specify the correct upgrade path mentioned above with a parameter -s.") return ReturnValues.SCENARIO return 0
def generate_xml(self, generate_from_ini=True): """ Copy files to result directory and if specified generate all-xccdf.xml file @param {bool} generate_from_ini - True if xccdf-compose tool is used, decide if all-xccdf.xml file will(True) be created or not(False) @throws {IOError} - when creation of all-xccdf.xml file fails @return {int} - 0 success !0 error """ try: ModuleSetUtils.get_module_set_os_versions(self.src_path) except EnvironmentError as err: sys.stderr.write("{0}\n".format(str(err))) return ReturnValues.SCENARIO # e.g. /root/preupgrade/RHEL6_7 -> /root/preupgrade/RHEL6_7-results dir_util.copy_tree(self.src_path, self.dst_path) # create content for all-xccdf.xml file as ElementTree object target_tree = ComposeXML.run_compose( self.dst_path, generate_from_ini=generate_from_ini) # path where all-xccdf.xml is going to be generated report_filename = os.path.join(self.dst_path, settings.all_xccdf_xml_filename) if generate_from_ini: try: FileHelper.write_to_file( report_filename, "wb", ElementTree.tostring(target_tree, "utf-8"), False ) logger_debug.debug('Generated: %s' % report_filename) except IOError: raise IOError("Error: Problem with writing file %s" % report_filename) return 0
def run(self): """run analysis""" version_msg = "Preupgrade Assistant version: %s" % VERSION if self.conf.version: print(version_msg) return 0 logger_debug.debug(version_msg) if self.conf.list_contents_set: for dir_name, dummy_content in iter( get_installed_module_sets(self.conf.source_dir).items()): log_message("%s" % dir_name) return 0 if self.conf.riskcheck: result_xml_path = os.path.join(settings.assessment_results_dir, settings.xml_result_name) if not os.path.exists(result_xml_path): log_message("System assessment needs to be performed first.") return ReturnValues.PREUPG_BEFORE_RISKCHECK return XccdfHelper.check_inplace_risk(result_xml_path, self.conf.verbose) if self.conf.upload and self.conf.results: if not self.upload_results(): return ReturnValues.SEND_REPORT_TO_UI return 0 if self.conf.cleanup: if not self.executed_under_root(): return ReturnValues.ROOT self.clean_preupgrade_environment() return 0 if self.conf.text: # Test whether w3m, lynx and elinks packages are installed found = False for pkg in SystemIdentification.get_convertors(): if xml_manager.get_package_version(pkg): self.text_convertor = pkg found = True break if not found: log_message( settings.converter_message.format(' '.join( SystemIdentification.get_convertors()))) return ReturnValues.MISSING_TEXT_CONVERTOR return_code = self.determine_module_set_location() if return_code: return return_code self.determine_module_set_copy_location() if self.conf.list_rules: rules = [ x for x in XccdfHelper.get_list_rules(self.all_xccdf_xml_path) ] log_message('\n'.join(rules)) return 0 if self.conf.mode and self.conf.select_rules: log_message(settings.options_not_allowed) return ReturnValues.MODE_SELECT_RULES # If force option is not mentioned and user selects NO then exit if not self.conf.force: text = "" if self.conf.dst_arch: correct_option = [ x for x in settings.migration_options if self.conf.dst_arch == x ] if not correct_option: sys.stderr.write( "Error: Specify correct value for --dst-arch" " option.\nValid are: %s.\n" % ", ".join(settings.migration_options)) return ReturnValues.INVALID_CLI_OPTION if SystemIdentification.get_arch() == "i386" or \ SystemIdentification.get_arch() == "i686": if not self.conf.dst_arch: text = '\n' + settings.migration_text logger_debug.debug("Architecture '%s'. Text '%s'.", SystemIdentification.get_arch(), text) if not show_message(settings.warning_text + text): # User does not want to continue return ReturnValues.USER_ABORT self.openscap_helper = OpenSCAPHelper(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.all_xccdf_xml_path) if not self.executed_under_root(): return ReturnValues.ROOT if not os.path.exists(settings.openscap_binary): log_message("Oscap with SCE enabled is not installed") return ReturnValues.MISSING_OPENSCAP if not os.access(settings.openscap_binary, os.X_OK): log_message("Oscap with SCE %s is not executable" % settings.openscap_binary) return ReturnValues.MISSING_OPENSCAP self.execution_dir = os.getcwd() os.chdir("/tmp") retval = self.scan_system() if retval != 0: return retval retval = self.summary_report(self.tar_ball_name) self.common.copy_common_files() KickstartGenerator.kickstart_scripts() FileHelper.remove_home_issues() if self.conf.upload: if not self.upload_results(): retval = ReturnValues.SEND_REPORT_TO_UI os.chdir(self.execution_dir) return retval
def run(self): """run analysis""" version_msg = "Preupgrade Assistant version: %s" % VERSION if self.conf.version: print (version_msg) return 0 logger_debug.debug(version_msg) if self.conf.list_contents_set: for dir_name, dummy_content in six.iteritems(list_contents(self.conf.source_dir)): log_message("%s" % dir_name) return 0 if not self.conf.scan and not self.conf.contents and not self.conf.list_rules: ret_val = self._check_available_contents() if int(ret_val) != 0: return ret_val if self.conf.list_rules: ret_val = self._check_available_contents() if int(ret_val) != 0: return ret_val rules = [self.conf.scan + ':' + x for x in XccdfHelper.get_list_rules(self.conf.scan)] log_message('\n'.join(rules)) return 0 if self.conf.upload: if not self.upload_results(): return ReturnValues.SEND_REPORT_TO_UI return 0 if self.conf.mode and self.conf.select_rules: log_message(settings.options_not_allowed) return ReturnValues.MODE_SELECT_RULES if not self.conf.riskcheck and not self.conf.cleanup and not self.conf.kickstart: # If force option is not mentioned and user select NO then exits if not self.conf.force: text = "" if self.conf.dst_arch: correct_option = [x for x in settings.migration_options if self.conf.dst_arch == x] if not correct_option: log_message("Specify the correct --dst-arch option.") log_message("There are '%s' or '%s' available." % (settings.migration_options[0], settings.migration_options[1])) return ReturnValues.RISK_CLEANUP_KICKSTART if SystemIdentification.get_arch() == "i386" or SystemIdentification.get_arch() == "i686": if not self.conf.dst_arch: text = '\n' + settings.migration_text logger_debug.debug("Architecture '%s'. Text '%s'.", SystemIdentification.get_arch(), text) if not show_message(settings.warning_text + text): # We do not want to continue return ReturnValues.RISK_CLEANUP_KICKSTART if self.conf.text: # Test whether w3m, lynx and elinks packages are installed found = False for pkg in SystemIdentification.get_convertors(): if xml_manager.get_package_version(pkg): self.text_convertor = pkg found = True break if not found: log_message(settings.converter_message.format(' '.join(SystemIdentification.get_convertors()))) return ReturnValues.MISSING_TEXT_CONVERTOR if os.geteuid() != 0: print("Need to be root", end="\n") if not self.conf.debug: return ReturnValues.ROOT if self.conf.cleanup: self.clean_preupgrade_environment() return 0 self.openscap_helper = OpenSCAPHelper(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.content) if self.conf.riskcheck: if not os.path.exists(self.openscap_helper.get_default_xml_result_path()): log_message("The 'preupg' command was not run yet. Run it to check for possible risks.") return ReturnValues.PREUPG_BEFORE_KICKSTART return_val = XccdfHelper.check_inplace_risk(self.openscap_helper.get_default_xml_result_path(), self.conf.verbose) return return_val if self.conf.kickstart: if not os.path.exists(self.openscap_helper.get_default_xml_result_path()): log_message("The 'preupg' command was not run yet. Run it before the Kickstart generation.") return ReturnValues.PREUPG_BEFORE_KICKSTART kg = KickstartGenerator(self.conf, settings.KS_DIR, settings.KS_PATH) kg.main() return 0 if self.conf.scan: self.content = os.path.join(self.conf.source_dir, self.conf.scan, settings.content_file) if self.conf.scan.startswith("/"): log_message('Specify the correct upgrade path parameter like -s RHEL6_7') log_message("Upgrade path is provided by the 'preupg --list' command.") self._check_available_contents() log_message("The available upgrade paths: '%s'" % '\n'.join(self.list_scans)) return ReturnValues.SCENARIO if not os.path.isdir(os.path.join(self.conf.source_dir, self.conf.scan)): log_message('Specify the correct upgrade path parameter like -s RHEL6_7') self._check_available_contents() log_message("Upgrade path is provided by the 'preupg --list' command.") log_message("The available upgrade paths: '%s'" % '\n'.join(self.list_scans)) return ReturnValues.SCENARIO if self.conf.contents: self.content = os.path.join(os.getcwd(), self.conf.contents) # From content path like content-users/RHEL6_7 we need # to get content-users dir content_dir = self.conf.contents[:self.conf.contents.find(self.get_scenario())] self.conf.source_dir = os.path.join(os.getcwd(), content_dir) self.common = Common(self.conf) if not self.conf.skip_common: if not self.common.common_results(): return ReturnValues.SCRIPT_TXT_MISSING if self.conf.scan or self.conf.contents: if not os.path.exists(settings.openscap_binary): log_message("Oscap with SCE enabled is not installed") return ReturnValues.MISSING_OPENSCAP if not os.access(settings.openscap_binary, os.X_OK): log_message("Oscap with SCE %s is not executable" % settings.openscap_binary) return ReturnValues.MISSING_OPENSCAP current_dir = os.getcwd() os.chdir("/tmp") retval = self.scan_system() if int(retval) != 0: return retval self.summary_report(self.tar_ball_name) self.common.copy_common_files() KickstartGenerator.kickstart_scripts() FileHelper.remove_home_issues() if self.conf.upload: self.upload_results(self.tar_ball_name) os.chdir(current_dir) return self.report_return_value log_message('Nothing to do. Give me a task, please.') self.conf.settings[2].parser.print_help() return 0
def run(self): """run analysis""" version_msg = "Preupgrade Assistant version: %s" % VERSION if self.conf.version: print (version_msg) return 0 logger_debug.debug(version_msg) if self.conf.list_contents_set: for dir_name, dummy_content in iter(get_installed_module_sets( self.conf.source_dir).items()): log_message("%s" % dir_name) return 0 if self.conf.riskcheck: result_xml_path = os.path.join(settings.assessment_results_dir, settings.xml_result_name) if not os.path.exists(result_xml_path): log_message("System assessment needs to be performed first.") return ReturnValues.PREUPG_BEFORE_RISKCHECK return XccdfHelper.check_inplace_risk(result_xml_path, self.conf.verbose) if self.conf.upload and self.conf.results: if not self.upload_results(): return ReturnValues.SEND_REPORT_TO_UI return 0 if self.conf.cleanup: if not self.executed_under_root(): return ReturnValues.ROOT self.clean_preupgrade_environment() return 0 if self.conf.text: # Test whether w3m, lynx and elinks packages are installed found = False for pkg in SystemIdentification.get_convertors(): if xml_manager.get_package_version(pkg): self.text_convertor = pkg found = True break if not found: log_message(settings.converter_message.format( ' '.join(SystemIdentification.get_convertors()))) return ReturnValues.MISSING_TEXT_CONVERTOR return_code = self.determine_module_set_location() if return_code: return return_code self.determine_module_set_copy_location() if self.conf.list_rules: rules = [x for x in XccdfHelper.get_list_rules(self.all_xccdf_xml_path)] log_message('\n'.join(rules)) return 0 if self.conf.mode and self.conf.select_rules: log_message(settings.options_not_allowed) return ReturnValues.MODE_SELECT_RULES # If force option is not mentioned and user selects NO then exit if not self.conf.force: text = "" if self.conf.dst_arch: correct_option = [x for x in settings.migration_options if self.conf.dst_arch == x] if not correct_option: sys.stderr.write( "Error: Specify correct value for --dst-arch" " option.\nValid are: %s.\n" % ", ".join(settings.migration_options) ) return ReturnValues.INVALID_CLI_OPTION if SystemIdentification.get_arch() == "i386" or \ SystemIdentification.get_arch() == "i686": if not self.conf.dst_arch: text = '\n' + settings.migration_text logger_debug.debug("Architecture '%s'. Text '%s'.", SystemIdentification.get_arch(), text) if not show_message(settings.warning_text + text): # User does not want to continue return ReturnValues.USER_ABORT self.openscap_helper = OpenSCAPHelper(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.all_xccdf_xml_path) if not self.executed_under_root(): return ReturnValues.ROOT if not os.path.exists(settings.openscap_binary): log_message("Oscap with SCE enabled is not installed") return ReturnValues.MISSING_OPENSCAP if not os.access(settings.openscap_binary, os.X_OK): log_message("Oscap with SCE %s is not executable" % settings.openscap_binary) return ReturnValues.MISSING_OPENSCAP self.execution_dir = os.getcwd() os.chdir("/tmp") retval = self.scan_system() if retval != 0: return retval retval = self.summary_report(self.tar_ball_name) self.common.copy_common_files() KickstartGenerator.kickstart_scripts() FileHelper.remove_home_issues() if self.conf.upload: if not self.upload_results(): retval = ReturnValues.SEND_REPORT_TO_UI os.chdir(self.execution_dir) return retval
def run(self): """run analysis""" version_msg = "Preupgrade Assistant version: %s" % VERSION if self.conf.version: print(version_msg) return 0 logger_debug.debug(version_msg) if self.conf.list_contents_set: for dir_name, dummy_content in six.iteritems( list_contents(self.conf.source_dir)): log_message("%s" % dir_name) return 0 if not self.conf.scan and not self.conf.contents and not self.conf.list_rules: ret_val = self._check_available_contents() if int(ret_val) != 0: return ret_val if self.conf.list_rules: ret_val = self._check_available_contents() if int(ret_val) != 0: return ret_val rules = [ self.conf.scan + ':' + x for x in XccdfHelper.get_list_rules(self.conf.scan) ] log_message('\n'.join(rules)) return 0 if self.conf.upload: if not self.upload_results(): return ReturnValues.SEND_REPORT_TO_UI return 0 if self.conf.mode and self.conf.select_rules: log_message(settings.options_not_allowed) return ReturnValues.MODE_SELECT_RULES if not self.conf.riskcheck and not self.conf.cleanup and not self.conf.kickstart: # If force option is not mentioned and user select NO then exits if not self.conf.force: text = "" if self.conf.dst_arch: correct_option = [ x for x in settings.migration_options if self.conf.dst_arch == x ] if not correct_option: log_message("Specify the correct --dst-arch option.") log_message("There are '%s' or '%s' available." % (settings.migration_options[0], settings.migration_options[1])) return ReturnValues.RISK_CLEANUP_KICKSTART if SystemIdentification.get_arch( ) == "i386" or SystemIdentification.get_arch() == "i686": if not self.conf.dst_arch: text = '\n' + settings.migration_text logger_debug.debug("Architecture '%s'. Text '%s'.", SystemIdentification.get_arch(), text) if not show_message(settings.warning_text + text): # We do not want to continue return ReturnValues.RISK_CLEANUP_KICKSTART if self.conf.text: # Test whether w3m, lynx and elinks packages are installed found = False for pkg in SystemIdentification.get_convertors(): if xml_manager.get_package_version(pkg): self.text_convertor = pkg found = True break if not found: log_message( settings.converter_message.format(' '.join( SystemIdentification.get_convertors()))) return ReturnValues.MISSING_TEXT_CONVERTOR if os.geteuid() != 0: print("Need to be root", end="\n") if not self.conf.debug: return ReturnValues.ROOT if self.conf.cleanup: self.clean_preupgrade_environment() return 0 self.openscap_helper = OpenSCAPHelper(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.content) if self.conf.riskcheck: if not os.path.exists( self.openscap_helper.get_default_xml_result_path()): log_message( "The 'preupg' command was not run yet. Run it to check for possible risks." ) return ReturnValues.PREUPG_BEFORE_KICKSTART return_val = XccdfHelper.check_inplace_risk( self.openscap_helper.get_default_xml_result_path(), self.conf.verbose) return return_val if self.conf.kickstart: if not os.path.exists( self.openscap_helper.get_default_xml_result_path()): log_message( "The 'preupg' command was not run yet. Run it before the Kickstart generation." ) return ReturnValues.PREUPG_BEFORE_KICKSTART kg = KickstartGenerator(self.conf, settings.KS_DIR, settings.KS_PATH) kg.main() return 0 if self.conf.scan: self.content = os.path.join(self.conf.source_dir, self.conf.scan, settings.content_file) if self.conf.scan.startswith("/"): log_message( 'Specify the correct upgrade path parameter like -s RHEL6_7' ) log_message( "Upgrade path is provided by the 'preupg --list' command.") self._check_available_contents() log_message("The available upgrade paths: '%s'" % '\n'.join(self.list_scans)) return ReturnValues.SCENARIO if not os.path.isdir( os.path.join(self.conf.source_dir, self.conf.scan)): log_message( 'Specify the correct upgrade path parameter like -s RHEL6_7' ) self._check_available_contents() log_message( "Upgrade path is provided by the 'preupg --list' command.") log_message("The available upgrade paths: '%s'" % '\n'.join(self.list_scans)) return ReturnValues.SCENARIO if self.conf.contents: self.content = os.path.join(os.getcwd(), self.conf.contents) # From content path like content-users/RHEL6_7 we need # to get content-users dir content_dir = self.conf.contents[:self.conf.contents. find(self.get_scenario())] self.conf.source_dir = os.path.join(os.getcwd(), content_dir) self.common = Common(self.conf) if not self.conf.skip_common: if not self.common.common_results(): return ReturnValues.SCRIPT_TXT_MISSING if self.conf.scan or self.conf.contents: if not os.path.exists(settings.openscap_binary): log_message("Oscap with SCE enabled is not installed") return ReturnValues.MISSING_OPENSCAP if not os.access(settings.openscap_binary, os.X_OK): log_message("Oscap with SCE %s is not executable" % settings.openscap_binary) return ReturnValues.MISSING_OPENSCAP current_dir = os.getcwd() os.chdir("/tmp") retval = self.scan_system() if int(retval) != 0: return retval self.summary_report(self.tar_ball_name) self.common.copy_common_files() KickstartGenerator.kickstart_scripts() FileHelper.remove_home_issues() if self.conf.upload: self.upload_results(self.tar_ball_name) os.chdir(current_dir) return self.report_return_value log_message('Nothing to do. Give me a task, please.') self.conf.settings[2].parser.print_help() return 0