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

ssg_test_suite.profile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 47
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ProfileChecker._test_target() 0 4 1
A ProfileChecker._run_test() 0 13 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A perform_profile_check() 0 8 1
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