def prepare_scan_system(self):
        """
        Prepare system for scan.

        In case the result of previous assessment is detected, remove it
        and prepare new directory structure that will be used for next scan.
        Additionaly process scripts generating common data about the current
        system, generate final XCCDF compose from the original set of modules
        identified for run and in the end process initial script of modules to
        complete expected environment for the scan.
        """
        # First of all we need to delete the older one assessment
        self.clean_scan()
        self.prepare_scan_directories()
        self.common = Common(self.conf)
        if not self.conf.skip_common:
            if not self.common.common_results():
                return ReturnValues.SCRIPT_TXT_MISSING

        # Generate final XCCDF compose under self.module_set_copy_path
        xccdf_compose = XCCDFCompose(
            self.module_set_path, self.module_set_copy_path)
        ret_val = xccdf_compose.generate_xml()
        if ret_val != 0:
            return ret_val
        self.run_init()
        return 0
예제 #2
0
    def prepare_scan_system(self):
        """
        Prepare system for scan.

        In case the result of previous assessment is detected, remove it
        and prepare new directory structure that will be used for next scan.
        Additionaly process scripts generating common data about the current
        system, generate final XCCDF compose from the original set of modules
        identified for run and in the end process initial script of modules to
        complete expected environment for the scan.
        """
        # First of all we need to delete the older one assessment
        self.clean_scan()
        self.prepare_scan_directories()
        self.common = Common(self.conf)
        if not self.conf.skip_common:
            if not self.common.common_results():
                return ReturnValues.SCRIPT_TXT_MISSING

        # Generate final XCCDF compose under self.module_set_copy_path
        xccdf_compose = XCCDFCompose(self.module_set_path,
                                     self.module_set_copy_path)
        ret_val = xccdf_compose.generate_xml()
        if ret_val != 0:
            return ret_val
        self.run_init()
        return 0
예제 #3
0
    def generate_report(self):
        """Function generates report"""
        scenario = self.get_scenario()
        scenario_path = os.path.join(self.conf.source_dir, scenario)
        self.assessment_dir = os.path.join(self.conf.assessment_results_dir,
                                           self.get_proper_scenario(scenario))
        dir_util.copy_tree(scenario_path, self.assessment_dir)
        # Try copy directory with contents to /root/preupgrade
        # Call xccdf_compose API for generating all-xccdf.xml
        if not self.conf.contents:
            xccdf_compose = XCCDFCompose(self.assessment_dir)
            if xccdf_compose.generate_xml(generate_from_ini=False) != 0:
                return ReturnValues.SCENARIO
            if os.path.isdir(self.assessment_dir):
                shutil.rmtree(self.assessment_dir)
            shutil.move(xccdf_compose.get_compose_dir_name(),
                        self.assessment_dir)

        self.common.prep_symlinks(self.assessment_dir,
                                  scenario=self.get_proper_scenario(scenario))
        if not self.conf.contents:
            XccdfHelper.update_platform(
                os.path.join(self.assessment_dir, settings.content_file))
        else:
            XccdfHelper.update_platform(self.content)
            self.assessment_dir = os.path.dirname(self.content)
        return 0
    def test_final_compose(self):
        dir_name = os.path.join(self.temp_dir, FOO_DIR)
        ComposeXML().collect_group_xmls(dir_name, dir_name)

        xccdf_compose = XCCDFCompose(os.path.join(self.temp_dir, FOO_DIR))
        xccdf_compose.generate_xml()
        all_xccdf = os.path.join(self.result_dir,
                                 settings.all_xccdf_xml_filename)
        self.assertTrue(os.path.exists(all_xccdf))
        dummy_lines = FileHelper.get_file_content(all_xccdf, 'rb')
    def test_final_compose(self):
        expected_contents = ['failed', 'fixed', 'needs_action', 'needs_inspection', 'not_applicable', 'pass']
        for content in expected_contents:
            compose_xml = ComposeXML()
            dir_name = os.path.join(self.temp_dir, FOO_DIR, 'dummy')
            compose_xml.collect_group_xmls(dir_name, content=content)

        xccdf_compose = XCCDFCompose(os.path.join(self.temp_dir, FOO_DIR))
        xccdf_compose.generate_xml()
        all_xccdf = os.path.join(self.result_dir, settings.content_file)
        self.assertTrue(os.path.exists(all_xccdf))
        dummy_lines = FileHelper.get_file_content(all_xccdf, 'rb')
예제 #6
0
    def test_final_compose(self):
        expected_contents = [
            'failed', 'fixed', 'needs_action', 'needs_inspection',
            'not_applicable', 'pass'
        ]
        for content in expected_contents:
            compose_xml = ComposeXML()
            dir_name = os.path.join(self.temp_dir, FOO_DIR, 'dummy')
            compose_xml.collect_group_xmls(dir_name, content=content)

        xccdf_compose = XCCDFCompose(os.path.join(self.temp_dir, FOO_DIR))
        xccdf_compose.generate_xml()
        all_xccdf = os.path.join(self.result_dir, settings.content_file)
        self.assertTrue(os.path.exists(all_xccdf))
        dummy_lines = FileHelper.get_file_content(all_xccdf, 'rb')
    def generate_report(self):
        """Function generates report"""
        scenario = self.get_scenario()
        scenario_path = os.path.join(self.conf.source_dir, scenario)
        self.assessment_dir = os.path.join(self.conf.assessment_results_dir, self.get_proper_scenario(scenario))
        dir_util.copy_tree(scenario_path, self.assessment_dir)
        # Try copy directory with contents to /root/preupgrade
        # Call xccdf_compose API for generating all-xccdf.xml
        if not self.conf.contents:
            xccdf_compose = XCCDFCompose(self.assessment_dir)
            if xccdf_compose.generate_xml(generate_from_ini=False) != 0:
                return ReturnValues.SCENARIO
            if os.path.isdir(self.assessment_dir):
                shutil.rmtree(self.assessment_dir)
            shutil.move(xccdf_compose.get_compose_dir_name(), self.assessment_dir)

        self.common.prep_symlinks(self.assessment_dir,
                                  scenario=self.get_proper_scenario(scenario))
        if not self.conf.contents:
            XccdfHelper.update_platform(os.path.join(self.assessment_dir, settings.content_file))
        else:
            XccdfHelper.update_platform(self.content)
            self.assessment_dir = os.path.dirname(self.content)
        return 0