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 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}", SystemIdentification.get_assessment_version(self.dirname)[1])
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}", SystemIdentification.get_assessment_version(self.dirname)[1])
def update_platform(full_path): file_lines = FileHelper.get_file_content(full_path, 'rb', method=True) platform = '' platform_id = '' if not SystemIdentification.get_system(): platform = settings.CPE_RHEL else: platform = settings.CPE_FEDORA platform_id = SystemIdentification.get_assessment_version(full_path) for index, line in enumerate(file_lines): if 'PLATFORM_NAME' in line: line = line.replace('PLATFORM_NAME', platform) if 'PLATFORM_ID' in line: line = line.replace('PLATFORM_ID', platform_id[0]) file_lines[index] = line FileHelper.write_to_file(full_path, 'wb', file_lines)
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 scan_system(self): """The function is used for scanning system with all steps.""" self._set_devel_mode() if int(self.prepare_scan_system()) != 0: return ReturnValues.SCENARIO if int(self.generate_report()) != 0: return ReturnValues.SCENARIO # Update source XML file in temporary directory self.content = os.path.join(self.assessment_dir, settings.content_file) self.openscap_helper.update_variables(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.content) try: self.report_parser = ReportParser(self.content) except IOError: log_message("The module {0} does not exist.".format(self.content)) return ReturnValues.SCENARIO if not self.conf.contents: version = SystemIdentification.get_assessment_version(self.conf.scan) if version is None: log_message("Your scan is in a wrong format %s." % version, level=logging.ERROR) log_message("It should be like 'RHEL6_7' for upgrade from RHEL 6->7.", level=logging.ERROR) return ReturnValues.SCENARIO self.report_parser.modify_platform_tag(version[0]) if self.conf.mode: try: lines = [i.rstrip() for i in FileHelper.get_file_content(os.path.join(self.assessment_dir, 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(self.assessment_dir) if os.path.exists(third_party_dir_name): self.run_third_party_modules(third_party_dir_name) self.copy_preupgrade_scripts(self.assessment_dir) ConfigFilesHelper.copy_modified_config_files(settings.assessment_results_dir) # It prints out result in table format ScanningHelper.format_rules_to_table(main_report, "main contents") for target, report in six.iteritems(self.report_data): ScanningHelper.format_rules_to_table(report, "3rdparty content " + target) self.tar_ball_name = TarballHelper.tarball_result_dir(self.conf.tarball_name, self.conf.assessment_results_dir, self.conf.verbose) log_message("The tarball with results is stored in '%s' ." % self.tar_ball_name) log_message("The latest assessment is stored in the '%s' directory." % self.conf.assessment_results_dir) # pack all configuration files to tarball return 0
def test_wrong_prefix(self): version = SystemIdentification.get_assessment_version("FOOBAR6_7") self.assertEqual(version, None)
def test_correct_prefix(self): version = SystemIdentification.get_assessment_version("FOOBAR6_CENTOS6") self.assertEqual(version, ["6", "6"])
def test_wrong_prefix(self): version = SystemIdentification.get_assessment_version('FOOBAR6_7') self.assertEqual(version, None)
def test_correct_prefix(self): version = SystemIdentification.get_assessment_version( 'FOOBAR6_CENTOS6') self.assertEqual(version, ['6', '6'])
def scan_system(self): """The function is used for scanning system with all steps.""" self._set_devel_mode() if int(self.prepare_scan_system()) != 0: return ReturnValues.SCENARIO if int(self.generate_report()) != 0: return ReturnValues.SCENARIO # Update source XML file in temporary directory self.content = os.path.join(self.assessment_dir, settings.content_file) self.openscap_helper.update_variables(self.conf.assessment_results_dir, self.conf.result_prefix, self.conf.xml_result_name, self.conf.html_result_name, self.content) try: self.report_parser = ReportParser(self.content) except IOError: log_message("The module {0} does not exist.".format(self.content)) return ReturnValues.SCENARIO if not self.conf.contents: version = SystemIdentification.get_assessment_version( self.conf.scan) if version is None: log_message("Your scan is in a wrong format %s." % version, level=logging.ERROR) log_message( "It should be like 'RHEL6_7' for upgrade from RHEL 6->7.", level=logging.ERROR) return ReturnValues.SCENARIO self.report_parser.modify_platform_tag(version[0]) if self.conf.mode: try: lines = [ i.rstrip() for i in FileHelper.get_file_content(os.path.join( self.assessment_dir, 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(self.assessment_dir) if os.path.exists(third_party_dir_name): self.run_third_party_modules(third_party_dir_name) self.copy_preupgrade_scripts(self.assessment_dir) ConfigFilesHelper.copy_modified_config_files( settings.assessment_results_dir) # It prints out result in table format ScanningHelper.format_rules_to_table(main_report, "main contents") for target, report in six.iteritems(self.report_data): ScanningHelper.format_rules_to_table(report, "3rdparty content " + target) self.tar_ball_name = TarballHelper.tarball_result_dir( self.conf.tarball_name, self.conf.assessment_results_dir, self.conf.verbose) log_message("The tarball with results is stored in '%s' ." % self.tar_ball_name) log_message("The latest assessment is stored in the '%s' directory." % self.conf.assessment_results_dir) # pack all configuration files to tarball return 0