Skip to content

Commit

Permalink
Merge pull request #4441 from matejak/enable_all_profile
Browse files Browse the repository at this point in the history
Enable the (all) virtual profile in the rule-based test suite.
  • Loading branch information
jan-cerny committed Jun 25, 2019
2 parents 8f0a2a5 + 791b8c3 commit 40597c4
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,35 @@
from ssg_test_suite.log import LogHelper
import data


ALL_PROFILE_ID = "(all)"

logging.getLogger(__name__).addHandler(logging.NullHandler())


Scenario = collections.namedtuple(
"Scenario", ["script", "context", "script_params"])



def get_viable_profiles(selected_profiles, datastream, benchmark):
"""Read datastream, and return set intersection of profiles of given
benchmark and those provided in `selected_profiles` parameter.
"""

valid_profiles = []
all_profiles = xml_operations.get_all_profiles_in_benchmark(
all_profiles_elements = xml_operations.get_all_profiles_in_benchmark(
datastream, benchmark, logging)
for ds_profile_element in all_profiles:
ds_profile = ds_profile_element.attrib['id']
all_profiles = [el.attrib["id"] for el in all_profiles_elements]
all_profiles.append(ALL_PROFILE_ID)

for ds_profile in all_profiles:
if 'ALL' in selected_profiles:
valid_profiles += [ds_profile]
continue
for sel_profile in selected_profiles:
if ds_profile.endswith(sel_profile):
valid_profiles += [ds_profile]

if not valid_profiles:
logging.error('No profile ends with "{0}"'
.format(", ".join(selected_profiles)))
Expand Down Expand Up @@ -71,7 +76,7 @@ def _apply_script(rule_dir, domain_ip, script):

def _get_script_context(script):
"""Return context of the script."""
result = re.search('.*\.([^.]*)\.[^.]*$', script)
result = re.search(r'.*\.([^.]*)\.[^.]*$', script)
if result is None:
return None
return result.group(1)
Expand Down Expand Up @@ -203,7 +208,7 @@ def _parse_parameters(self, script):
with open(script, 'r') as script_file:
script_content = script_file.read()
for parameter in params:
found = re.search(r'^# {0} = ([ ,_\.\-\w]*)$'.format(parameter),
found = re.search(r'^# {0} = ([ ,_\.\-\w\(\)]*)$'.format(parameter),
script_content,
re.MULTILINE)
if found is None:
Expand Down Expand Up @@ -234,6 +239,12 @@ def _get_scenarios(self, rule_dir, scripts, scenarios_regex, benchmark_cpes):
scenarios += [Scenario(script, script_context, script_params)]
else:
logging.info("Script %s is not applicable on given platform" % script)

if not script_params["profiles"]:
script_params["profiles"].append(ALL_PROFILE_ID)
logging.debug(
"Added the {0} profile to the list of available profiles for {1}"
.format(ALL_PROFILE_ID, script))
return scenarios

def _check_rule(self, rule, remote_dir, state):
Expand Down

0 comments on commit 40597c4

Please sign in to comment.