def fnc_solution_text(self, key, name): """Function updates a solution text.""" if name in key: self.solution_modification(key) else: self.update_values_list(self.rule, "{fix}", xml_tags.FIX_TEXT) self.update_values_list(self.rule, "{solution_text}", "text") self.update_values_list(self.rule, "{platform_id}", get_assessment_version(self.dirname)[1])
def scan_system(self): """The function is used for scanning system with all steps.""" self._set_devel_mode() self.prepare_scan_system() assessment_dir = self.generate_report() # Update source XML file in temporary directory self.content = os.path.join(assessment_dir, settings.content_file) try: self.report_parser = ReportParser(self.content) except IOError: log_message("Content {0} does not exist".format(self.content)) sys.exit(1) if not self.conf.contents: version = get_assessment_version(self.conf.scan) if version is None: log_message("Your scan have wrong format", level=logging.ERROR) log_message("Examples format is like RHEL6_7", level=logging.ERROR) sys.exit(1) self.report_parser.modify_platform_tag(version[0]) if self.conf.mode: try: lines = [i.rstrip() for i in get_file_content(os.path.join(os.path.dirname(self.path), self.conf.mode), 'rb', method=True)] except IOError: return self.report_parser.select_rules(lines) if self.conf.select_rules: lines = [i.strip() for i in self.conf.select_rules.split(',')] unknown_rules = self.report_parser.check_rules(lines) if unknown_rules: log_message(settings.unknown_rules % '\n'.join(unknown_rules)) self.report_parser.select_rules(lines) self.run_scan_process() main_report = self.scanning_progress.get_output_data() # This function prepare XML and generate HTML self.prepare_xml_for_html() third_party_dir_name = self.get_third_party_dir(assessment_dir) if os.path.exists(third_party_dir_name): self.run_third_party_modules(third_party_dir_name) self.copy_preupgrade_scripts(assessment_dir) # It prints out result in table format format_rules_to_table(main_report, "main contents") for target, report in six.iteritems(self.report_data): format_rules_to_table(report, "3rdparty content " + target) tar_ball_name = tarball_result_dir(self.conf.tarball_name, self.conf.result_dir, self.conf.verbose) log_message("Tarball with results is stored here %s ." % tar_ball_name) log_message("The latest assessment is stored in directory %s ." % self.conf.result_dir) # pack all configuration files to tarball return tar_ball_name
def run(self): """run analysis""" if self.conf.version: print ("Preupgrade Assistant version: %s" % VERSION) return 0 if not self.conf.scan and not self.conf.contents: cnt = 0 is_dir = lambda x: os.path.isdir(os.path.join(self.conf.source_dir, x)) dirs = os.listdir(self.conf.source_dir) for dir_name in filter(is_dir, dirs): if utils.get_assessment_version(dir_name): self.conf.scan = dir_name cnt += 1 if int(cnt) < 1: log_message("There were no contents found in directory %s. \ If you would like to use this tool, you have to install some." % settings.source_dir) return 1 if int(cnt) > 1: log_message("Preupgrade assistant detects more then 1 set of contents in directory%s. \ If you would like to use this tool, you have to specify correct upgrade path parameter like -s RHEL6_7." % settings.source_dir) return 1 if self.conf.list_contents_set: for dir_name, dummy_content in six.iteritems(list_contents(self.conf.source_dir)): log_message("{0}".format(dir_name)) return 0 if self.conf.list_rules: log_message(settings.list_rules % '\n'.join(utils.get_list_rules(self.conf.scan))) return 0 if self.conf.upload and self.conf.results: self.upload_results() return 0 if self.conf.mode and self.conf.select_rules: log_message(settings.options_not_allowed) return 1 if not self.conf.riskcheck and not self.conf.apply 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 and not show_message(settings.warning_text): # We do not want to continue return 0 if self.conf.text: # Test whether w3m, lynx and elinks packages are installed found = False for pkg in utils.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(utils.get_convertors()))) return 0 if os.geteuid() != 0: print("Need to be root", end="\n") if not self.conf.debug: return 2 if self.conf.cleanup: self.clean_preupgrade_environment() sys.exit(0) if self.conf.riskcheck: return_val = xccdf.check_inplace_risk(self.get_default_xml_result_path(), self.conf.verbose) return return_val if self.conf.kickstart: if not os.path.exists(self.get_default_xml_result_path()): log_message("'preupg' command was not run yet. Run them before kickstart generation.") return 1 kg = KickstartGenerator(settings.KS_DIR, self.get_preupgrade_kickstart()) KickstartGenerator.copy_kickstart_templates() dummy_ks = kg.generate() if dummy_ks: log_message(settings.kickstart_text % self.get_preupgrade_kickstart()) 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 correct upgrade path parameter like -s RHEL6_7') log_message('Upgrade path is provided by command preupg --list') return 1 if not os.path.isdir(os.path.join(self.conf.source_dir, self.conf.scan)): log_message('Specify correct upgrade path parameter like -s RHEL6_7') log_message('Upgrade path is provided by command preupg --list') return 1 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 1 if self.conf.scan or self.conf.contents: if not os.path.exists(self.binary): log_message("Oscap with SCE enabled is not installed") return 1 if not os.access(self.binary, os.X_OK): log_message("Oscap with SCE %s is not executable" % self.binary) return 1 current_dir = os.getcwd() os.chdir("/tmp") tarball_path = self.scan_system() self.summary_report(tarball_path) self.common.copy_common_files() KickstartGenerator.kickstart_scripts() utils.remove_home_issues() if self.conf.upload: self.upload_results(tarball_path) os.chdir(current_dir) return 0 log_message('Nothing to do. Give me a task, please.') self.conf.settings[2].parser.print_help() return 0
def test_wrong_prefix(self): version = utils.get_assessment_version("FOOBAR6_7") self.assertEqual(version, None)
def test_correct_prefix(self): version = utils.get_assessment_version("FOOBAR6_CENTOS6") self.assertEqual(version, ["6", "6"])
def test_wrong_prefix(self): version = utils.get_assessment_version('FOOBAR6_7') self.assertEqual(version, None)
def test_correct_prefix(self): version = utils.get_assessment_version('FOOBAR6_CENTOS6') self.assertEqual(version, ['6', '6'])