def test_list_combined_match():
    scenario_platforms = [
        "multi_platform_debian", "multi_platform_ubuntu",
        "Red Hat Enterprise Linux 6"
    ]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
Ejemplo n.º 2
0
    def _get_scenarios(self, rule_dir, scripts, scenarios_regex,
                       benchmark_cpes):
        """ Returns only valid scenario files, rest is ignored (is not meant
        to be executed directly.
        """

        if scenarios_regex is not None:
            scenarios_pattern = re.compile(scenarios_regex)

        scenarios = []
        for script in scripts:
            if scenarios_regex is not None:
                if scenarios_pattern.match(script) is None:
                    logging.debug("Skipping script %s - it did not match "
                                  "--scenarios regex" % script)
                    continue
            script_context = _get_script_context(script)
            if script_context is not None:
                script_params = self._parse_parameters(
                    os.path.join(rule_dir, script))
                script_params = self._modify_parameters(script_params)
                if common.matches_platform(script_params["platform"],
                                           benchmark_cpes):
                    scenarios += [
                        Scenario(script, script_context, script_params)
                    ]
                else:
                    logging.info(
                        "Script %s is not applicable on given platform" %
                        script)

        return scenarios
def test_list_combined_no_match():
    scenario_platforms = [
        "multi_platform_ubuntu", "multi_platform_fedora",
        "Red Hat Enterprise Linux 6", "openSUSE"
    ]
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
Ejemplo n.º 4
0
def test_list_combined_match_2():
    scenario_platforms = [
        "Debian 9", "multi_platform_ubuntu", "openSUSE",
        "Red Hat Enterprise Linux 8"
    ]
    benchmark_cpes = {"cpe:/o:debianproject:debian:9"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_multiple_multiple_bogus_benchmark_cpes_no_match():
    scenario_platforms = ["Fedora", "openSUSE"]
    benchmark_cpes = {
        "cpe:/o:abcdef:ghijklm:42"
        "cpe:/o:zzzzz:xxxx:77", "cpe:/o:redhat:enterprise_linux:7"
    }
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_simple_multiple_unrelated_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {
        "cpe:/o:redhat:enterprise_linux:7", "cpe:/o:redhat:enterprise_linux:6"
        "cpe:/o:scientificlinux:scientificlinux:6"
    }
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_simple_multiple_bogus_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {
        "cpe:/o:abcdef:ghijklm:42"
        "cpe:/o:zzzzz:xxxx:77", "cpe:/o:redhat:enterprise_linux:7"
    }
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_simple_multiple_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {
        "cpe:/o:redhat:enterprise_linux:7",
        "cpe:/o:redhat:enterprise_linux:7::client",
        "cpe:/o:redhat:enterprise_linux:7::computenode"
    }
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
Ejemplo n.º 9
0
 def matches_platform(self, benchmark_cpes):
     if self.context is None:
         return False
     if common.matches_platform(self.script_params["platform"],
                                benchmark_cpes):
         return True
     else:
         logging.warning("Script %s is not applicable on given platform" %
                         self.script)
         return False
Ejemplo n.º 10
0
def _get_scenarios(rule_dir, scripts, benchmark_cpes):
    """ Returns only valid scenario files, rest is ignored (is not meant
    to be executed directly.
    """

    scenarios = []
    for script in scripts:
        script_context = _get_script_context(script)
        if script_context is not None:
            script_params = _parse_parameters(os.path.join(rule_dir, script))
            if common.matches_platform(script_params["platform"],
                                       benchmark_cpes):
                scenarios += [Scenario(script, script_context, script_params)]
            else:
                logging.info("Script %s is not applicable on given platform" %
                             script)
    return scenarios
Ejemplo n.º 11
0
def _get_scenarios(rule_dir, scripts, scenarios_regex, benchmark_cpes):
    """ Returns only valid scenario files, rest is ignored (is not meant
    to be executed directly.
    """

    if scenarios_regex is not None:
        scenarios_pattern = re.compile(scenarios_regex)

    scenarios = []
    for script in scripts:
        if scenarios_regex is not None:
            if scenarios_pattern.match(script) is None:
                logging.debug("Skipping script %s - it did not match --scenarios regex" % script)
                continue
        script_context = _get_script_context(script)
        if script_context is not None:
            script_params = _parse_parameters(os.path.join(rule_dir, script))
            if common.matches_platform(script_params["platform"], benchmark_cpes):
                scenarios += [Scenario(script, script_context, script_params)]
            else:
                logging.info("Script %s is not applicable on given platform" % script)
    return scenarios
def test_multi_platform_no_match():
    scenario_platforms = ["multi_platform_fedora"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_multi_platform_all():
    scenario_platforms = ["multi_platform_all"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_wrong_multi_platform():
    scenario_platforms = ["multi_platform_fidorka"]
    benchmark_cpes = {"cpe:/o:fedoraproject:fedora:30"}
    with pytest.raises(ValueError):
        common.matches_platform(scenario_platforms, benchmark_cpes)
def test_multi_platform_all():
    scenario_platforms = ["multi_platform_all"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_simple_multiple_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7",
                      "cpe:/o:redhat:enterprise_linux:7::client",
                      "cpe:/o:redhat:enterprise_linux:7::computenode"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_combined_match():
    scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu",
                          "Red Hat Enterprise Linux 6"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_multi_platform_match_second():
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_multi_platform_match_second():
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_multi_platform_no_match():
    scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_list_multi_platform_match_first():
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_simple_no_match():
    scenario_platforms = [
        "Red Hat Enterprise Linux 7", "Red Hat Enterprise Linux 8"
    ]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_multi_platform_no_match():
    scenario_platforms = ["multi_platform_fedora"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_simple_match():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_typo():
    scenario_platforms = ["Rrd Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    with pytest.raises(ValueError):
        common.matches_platform(scenario_platforms, benchmark_cpes)
def test_list_multi_platform_match_first():
    scenario_platforms = ["multi_platform_rhel", "multi_platform_debian"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_simple_multiple_bogus_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
                      "cpe:/o:zzzzz:xxxx:77",
                      "cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_list_multi_platform_no_match():
    scenario_platforms = ["multi_platform_debian", "multi_platform_ubuntu"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_multiple_multiple_bogus_benchmark_cpes_no_match():
    scenario_platforms = ["Fedora", "openSUSE"]
    benchmark_cpes = {"cpe:/o:abcdef:ghijklm:42"
                      "cpe:/o:zzzzz:xxxx:77",
                      "cpe:/o:redhat:enterprise_linux:7"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_list_combined_no_match():
    scenario_platforms = ["multi_platform_ubuntu", "multi_platform_fedora",
                          "Red Hat Enterprise Linux 6", "openSUSE"]
    benchmark_cpes = {"cpe:/o:debianproject:debian:8"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == False
def test_typo():
    scenario_platforms = ["Rrd Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7"}
    with pytest.raises(ValueError):
        common.matches_platform(scenario_platforms, benchmark_cpes)
def test_simple_multiple_unrelated_benchmark_cpes():
    scenario_platforms = ["Red Hat Enterprise Linux 7"]
    benchmark_cpes = {"cpe:/o:redhat:enterprise_linux:7",
                      "cpe:/o:redhat:enterprise_linux:6"
                      "cpe:/o:scientificlinux:scientificlinux:6"}
    assert common.matches_platform(scenario_platforms, benchmark_cpes) == True
def test_wrong_multi_platform():
    scenario_platforms = ["multi_platform_fidorka"]
    benchmark_cpes = {"cpe:/o:fedoraproject:fedora:30"}
    with pytest.raises(ValueError):
        common.matches_platform(scenario_platforms, benchmark_cpes)