Exemple #1
0
 def common_results(self):
     """run common scripts"""
     log_message("Gathering logs used by preupgrade assistant:")
     self.switch_dir()
     try:
         max_length = max(
             max([len(x.split("=", 4)[3]) for x in self.lines]),
             len(settings.assessment_text))
         # Log files which will not be updated
         # when RPM database is not changed
         for counter, line in enumerate(self.lines):
             line = line.strip()
             if line.startswith("#"):
                 continue
             cmd, log_file, dummy_bash_value, name, values = line.split(
                 "=", 4)
             log_message(
                 "%s : %.2d/%d ...running" %
                 (name.ljust(max_length), counter + 1, len(self.lines)),
                 new_line=False,
                 log=False)
             start_time = datetime.datetime.now()
             common_file_path = self.common_logfiles(log_file)
             utils.run_subprocess(cmd, output=common_file_path, shell=True)
             end_time = datetime.datetime.now()
             diff = end_time - start_time
             log_message(" %sfinished (time %.2d:%.2ds)" %
                         ('\b' * 8, diff.seconds / 60, diff.seconds % 60),
                         log=False)
             # os.chmod(common_file_path, 0640)
         self.switch_back_dir()
     except IOError:
         return 0
     else:
         return 1
def postupgrade_scripts(verbose, dirname):
    """
    The function runs postupgrade directory

    If dir does not exists the report and return
    """
    if not os.path.exists(dirname):
        log_message('There is no any %s directory' % settings.postupgrade_dir,
                    level=logging.WARNING)
        return

    postupg_scripts = get_all_postupgrade_files(verbose, dirname)
    if not postupg_scripts:
        return

    #max_length = max(list([len(x) for x in postupg_scripts]))

    log_message('Running postupgrade scripts:')
    for scr in sorted(postupg_scripts):
        interpreter = get_interpreter(scr, verbose=verbose)
        if interpreter is None:
            continue
        log_message('Executing script %s' % scr)
        cmd = "{0} {1}".format(interpreter, scr)
        run_subprocess(cmd, print_output=False, shell=True)
        log_message("Executing script %s ...done" % scr)
 def common_results(self):
     """run common scripts"""
     log_message("Gathering logs used by preupgrade assistant:")
     self.switch_dir()
     try:
         max_length = max(max([len(x.split("=", 4)[3]) for x in self.lines]), len(settings.assessment_text))
         # Log files which will not be updated
         # when RPM database is not changed
         for counter, line in enumerate(self.lines):
             line = line.strip()
             if line.startswith("#"):
                 continue
             cmd, log_file, dummy_bash_value, name, values = line.split("=", 4)
             log_message("%s : %.2d/%d ...running" % (name.ljust(max_length),
                                                      counter+1,
                                                      len(self.lines)),
                         new_line=False, log=False)
             start_time = datetime.datetime.now()
             common_file_path = self.common_logfiles(log_file)
             utils.run_subprocess(cmd, output=common_file_path, shell=True)
             end_time = datetime.datetime.now()
             diff = end_time - start_time
             log_message(" %sfinished (time %.2d:%.2ds)" % ('\b' * 8,
                                                            diff.seconds / 60,
                                                            diff.seconds % 60),
                         log=False)
             # os.chmod(common_file_path, 0640)
         self.switch_back_dir()
     except IOError:
         return 0
     else:
         return 1
def postupgrade_scripts(verbose, dirname):
    """
    The function runs postupgrade directory

    If dir does not exists the report and return
    """
    if not os.path.exists(dirname):
        log_message('There is no any %s directory' % settings.postupgrade_dir,
                    level=logging.WARNING)
        return

    postupg_scripts = get_all_postupgrade_files(verbose, dirname)
    if not postupg_scripts:
        return

    #max_length = max(list([len(x) for x in postupg_scripts]))

    log_message('Running postupgrade scripts:')
    for scr in sorted(postupg_scripts):
        interpreter = get_interpreter(scr, verbose=verbose)
        if interpreter is None:
            continue
        log_message('Executing script %s' % scr)
        cmd = "{0} {1}".format(interpreter, scr)
        run_subprocess(cmd, print_output=False, shell=True)
        log_message("Executing script %s ...done" % scr)
Exemple #5
0
 def run_generate(self, xml_file, html_file):
     """
     The function generates result.html file from result.xml file
     which was modified by preupgrade assistant
     """
     cmd = self.build_generate_command(xml_file, html_file)
     return run_subprocess(cmd, print_output=True)
Exemple #6
0
 def kickstart_scripts():
     try:
         lines = utils.get_file_content(os.path.join(
             settings.common_dir, settings.KS_SCRIPTS),
                                        "rb",
                                        method=True)
         for counter, line in enumerate(lines):
             line = line.strip()
             if line.startswith("#"):
                 continue
             if 'is not installed' in line:
                 continue
             cmd, name = line.split("=", 2)
             kickstart_file = os.path.join(settings.KS_DIR, name)
             utils.run_subprocess(cmd, output=kickstart_file, shell=True)
     except IOError:
         pass
 def kickstart_scripts():
     try:
         lines = utils.get_file_content(os.path.join(settings.common_dir,
                                                     settings.KS_SCRIPTS),
                                        "rb",
                                        method=True)
         for counter, line in enumerate(lines):
             line = line.strip()
             if line.startswith("#"):
                 continue
             if 'is not installed' in line:
                 continue
             cmd, name = line.split("=", 2)
             kickstart_file = os.path.join(settings.KS_DIR, name)
             utils.run_subprocess(cmd, output=kickstart_file, shell=True)
     except IOError:
         pass
Exemple #8
0
 def run_scan(self, function=None):
     """
     The function is used for either scanning system or
     for applying changes on the target system
     """
     cmd = self.build_command()
     #log(self.conf.verbose, "running command:\n%s", ' '.join(cmd))
     # fail if openscap wasn't successful; if debug, continue
     return run_subprocess(cmd, print_output=False, function=function)
Exemple #9
0
    def prepare_xml_for_html(self):
        """The function prepares a XML file for HTML creation"""
        # Reload XML file
        self.report_parser.reload_xml(self.get_default_xml_result_path())
        # Replace fail in case of none or slight risk with needs_inspection
        self.report_parser.replace_inplace_risk(scanning_results=self.scanning_progress)
        if not self.conf.debug:
            self.report_parser.remove_debug_info()
        self.report_parser.reload_xml(self.get_default_xml_result_path())
        self.report_parser.update_check_description()
        self.prepare_for_generation()

        if not self.conf.verbose:
            self.xml_mgr.remove_html_information()
        # This function finalize XML operations
        self.finalize_xml_files()
        if self.conf.text:
            run_subprocess(self.get_cmd_convertor(),
                           print_output=False,
                           shell=True)
 def test_pass(self):
     """
     Basic test for PASS SCE
     """
     generate_test_xml(self.result_name, self.name)
     # Delete platform tags
     test_log = 'test_log'
     a = prepare_cli(self.temp_dir, self.result_name)
     return_string = utils.run_subprocess(' '.join(a.build_command()), shell=True, output=test_log)
     self.assertEqual(return_string, 0)
     lines = utils.get_file_content(test_log, perms='rb')
     os.unlink(test_log)
     self.assertEqual(a.run_scan(), 0)
     value = get_result_tag(self.temp_dir)
     self.assertTrue(value)
     self.assertEqual(value, "pass")
Exemple #11
0
 def test_pass(self):
     """
     Basic test for PASS SCE
     """
     generate_test_xml(self.result_name, self.name)
     # Delete platform tags
     test_log = 'test_log'
     a = prepare_cli(self.temp_dir, self.result_name)
     return_string = utils.run_subprocess(' '.join(a.build_command()),
                                          shell=True,
                                          output=test_log)
     self.assertEqual(return_string, 0)
     lines = utils.get_file_content(test_log, perms='rb')
     os.unlink(test_log)
     self.assertEqual(a.run_scan(), 0)
     value = get_result_tag(self.temp_dir)
     self.assertTrue(value)
     self.assertEqual(value, "pass")
Exemple #12
0
def check_rpm_to(check_rpm="", check_bin=""):
    not_applicable = 0

    if check_rpm != "":
        rpms = check_rpm.split(',')
        lines = get_file_content(VALUE_RPM_QA, "rb", True)
        for rpm in rpms:
            lst = filter(lambda x: rpm == x.split('\t')[0], lines)
            if not lst:
                log_info("Package %s is not installed" % rpm)
                not_applicable = 1

    if check_bin != "":
        binaries = check_bin.split(',')
        for binary in binaries:
            cmd = "which %s" % binary
            if utils.run_subprocess(cmd, print_output=False, shell=True) != 0:
                not_applicable = 1

    if not_applicable:
        exit_fail()