Esempio n. 1
0
def test_webhook_mutate_pod_merge_fail(caplog):
    conf_file = os.path.join(util.cmk_root(), "tests", "data", "webhook",
                             "mutations.yaml")
    ar = get_admission_review()
    with patch('intel.webhook.merge', MagicMock(side_effect=YamlReaderError)):
        with pytest.raises(webhook.MutationError):
            webhook.mutate(ar, conf_file)
Esempio n. 2
0
def test_process_cpus_allowed_success(monkeypatch):
    fake_procfs = os.path.join(util.cmk_root(), "tests", "data", "procfs",
                               "ok")
    monkeypatch.setenv(proc.ENV_PROC_FS, fake_procfs)
    fake_pid = 1234
    fake_process = proc.Process(fake_pid)
    assert (fake_process.cpus_allowed() == [0, 1, 2, 3])
Esempio n. 3
0
def test_webhook_load_mutations_success():
    conf_file = os.path.join(util.cmk_root(), "tests", "data", "webhook",
                             "mutations.yaml")
    mutations = webhook.load_mutations(conf_file)
    assert type(mutations) is dict
    assert "perPod" in mutations
    assert "perContainer" in mutations
Esempio n. 4
0
def test_process_cpus_allowed_failure(monkeypatch):
    fake_procfs = os.path.join(util.cmk_root(), "tests", "data", "procfs",
                               "no_cpus_allowed_list")
    monkeypatch.setenv(proc.ENV_PROC_FS, fake_procfs)
    fake_pid = 1234
    fake_process = proc.Process(fake_pid)
    with pytest.raises(ValueError):
        fake_process.cpus_allowed()
def test_webhook_mutate_container_merge_fail(caplog):
    conf_file = os.path.join(util.cmk_root(), "tests", "data",
                             "webhook", MUTATIONS_YAML)
    ar = get_admission_review()
    with patch('intel.webhook.merge',
               MagicMock(side_effect=[None, YamlReaderError])):
        with pytest.raises(webhook.MutationError):
            webhook.mutate(ar, conf_file)
Esempio n. 6
0
def test_webhook_mutate_success():
    conf_file = os.path.join(util.cmk_root(), "tests", "data", "webhook",
                             "mutations.yaml")
    ar = get_admission_review()
    request_uid = ar["request"]["uid"]
    webhook.mutate(ar, conf_file)
    assert "response" in ar
    assert "request" not in ar
    assert ar["response"]["uid"] == request_uid
    assert ar["response"]["allowed"]
    assert type(ar["response"]["patch"]) is str
Esempio n. 7
0
def test_webhook_mutate_not_required(caplog):
    conf_file = os.path.join(util.cmk_root(), "tests", "data", "webhook",
                             "mutations.yaml")
    ar = get_admission_review()
    request_uid = ar["request"]["uid"]
    with patch('intel.webhook.is_mutation_required',
               MagicMock(return_value=False)):
        webhook.mutate(ar, conf_file)

    assert "response" in ar
    assert "request" not in ar
    assert ar["response"]["uid"] == request_uid
    assert ar["response"]["allowed"]
    assert "patch" not in ar["response"]

    log = "Mutation is not required. Skipping..."
    caplog_tuple = caplog.record_tuples
    assert caplog_tuple[-1][2] == log
def test_webhook_mutate_success_core_number_mismatch():
    conf_file = os.path.join(util.cmk_root(), "tests", "data", "webhook",
                             MUTATIONS_YAML)

    ar = get_admission_review()
    ar['request']['object']['spec'] = {
        "containers": [get_cmk_container3(),
                       get_cmk_container()]
    }

    request_uid = ar['request']['uid']
    webhook.mutate(ar, conf_file)

    assert "response" in ar
    assert "request" not in ar
    assert ar['response']['uid'] == request_uid
    assert ar['response']['allowed']
    assert "patch" in ar['response']

    patch = json.loads(base64.b64decode(ar['response']['patch']))
    containers = patch[1]['value']['containers']
    assert len(containers) == 2
    assert containers[0]['env'][1]['value'] == "1"
    assert containers[1]['env'][1]['value'] == "2"
Esempio n. 9
0
def test_cmk_root():
    result = util.cmk_root()
    assert os.path.isdir(os.path.join(result, "tests", "data"))
Esempio n. 10
0
def cmk():
    return os.path.join(util.cmk_root(), "cmk.py")
Esempio n. 11
0
def test_getpid_success(monkeypatch):
    fake_procfs = os.path.join(util.cmk_root(), "tests", "data", "procfs")
    monkeypatch.setenv(proc.ENV_PROC_FS, fake_procfs)
    assert (1234 == proc.getpid())
Esempio n. 12
0
def sst_cp_dir():
    return os.path.join(util.cmk_root(), "tests", "data", "sst", "cp", "{}",
                        "cpufreq", "energy_performance_preference")
Esempio n. 13
0
def sysfs_dir(name):
    return os.path.join(util.cmk_root(), "tests", "data", "sysfs", name)
Esempio n. 14
0
def conf_dir(name):
    return os.path.join(util.cmk_root(), "tests", "data", "config", name)