Completed
Pull Request — master (#6005)
by
unknown
01:54
created

ssg_test_suite.profile.ProfileChecker._run_test()   A

Complexity

Conditions 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 10
nop 3
dl 0
loc 13
ccs 0
cts 9
cp 0
crap 12
rs 9.9
c 0
b 0
f 0
1
#!/usr/bin/env python2
2
from __future__ import print_function
3
4
import logging
5
6
7
import ssg_test_suite.oscap
8
from ssg_test_suite.rule import get_viable_profiles
9
10
logging.getLogger(__name__).addHandler(logging.NullHandler())
11
12
13
class ProfileChecker(ssg_test_suite.oscap.Checker):
14
    """
15
    Iterate over profiles in datastream and perform scanning of unaltered system
16
    using every profile according to input. Also perform remediation run.
17
    Return value not defined, textual output and generated reports is the result.
18
    """
19
    def _test_target(self, target):
20
        profiles = get_viable_profiles(
21
            target, self.datastream, self.benchmark_id)
22
        self.run_test_for_all_profiles(profiles)
23
24
    def _run_test(self, profile, test_data):
25
        self.executed_tests += 1
26
27
        runner_cls = ssg_test_suite.oscap.REMEDIATION_PROFILE_RUNNERS[self.remediate_using]
28
        runner = runner_cls(
29
            self.test_env, profile, self.datastream, self.benchmark_id)
30
31
        for stage in ("initial", "remediation", "final"):
32
            result = runner.run_stage(stage)
33
            if result:
34
                logging.info("Evaluation of the profile has passed: {0} ({1} stage).".format(profile, stage))
35
            else:
36
                logging.error("Evaluation of the profile has failed: {0} ({1} stage).".format(profile, stage))
37
38
39
def perform_profile_check(options):
40
    checker = ProfileChecker(options.test_env)
41
42
    checker.datastream = options.datastream
43
    checker.benchmark_id = options.benchmark_id
44
    checker.remediate_using = options.remediate_using
45
46
    checker.test_target(options.target)
47