Passed
Push — master ( ea7c4a...d61422 )
by Matěj
01:18 queued 12s
created

ssg_test_suite.profile.perform_profile_check()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 2
rs 10
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