test_aci.py 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
"""Tests for the ACI Manifest module."""
import nrm
import nrm.aci
import pytest
import json


@pytest.fixture
def manifest_base_data():
    data = '''{
    "acKind": "ImageManifest",
    "acVersion": "0.6.0",
    "name": "test",
14 15 16 17 18 19 20 21 22 23
    "app": {
        "isolators": [
            {
                "name": "argo/container",
                "value": {
                    "cpus": "1",
                    "mems": "1"
                }
            }
        ]
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        }
}'''
    return json.loads(data)


def test_manifest_disabled_perfwrapper(manifest_base_data):
    """Ensure we can check if a feature is disabled."""
    manifest = nrm.aci.ImageManifest()
    isolator_text = '''{
    "name": "argo/perfwrapper",
    "value": {
        "enabled": "0"
    }
}'''
    isolator = json.loads(isolator_text)
    data = manifest_base_data
40
    data["app"]["isolators"].append(isolator)
41 42 43 44 45 46 47 48 49 50 51 52 53
    assert manifest.load_dict(data)
    assert not manifest.is_feature_enabled("perfwrapper")


def test_enabled_feature(manifest_base_data):
    """Ensure we can check if a feature is enabled without enabled in it."""
    manifest = nrm.aci.ImageManifest()
    isolator_text = '''{
    "name": "argo/perfwrapper",
    "value": {}
}'''
    isolator = json.loads(isolator_text)
    data = manifest_base_data
54
    data["app"]["isolators"].append(isolator)
55 56
    assert manifest.load_dict(data)
    assert manifest.is_feature_enabled("perfwrapper")
57 58 59 60 61 62 63


def test_missing_disabled(manifest_base_data):
    """Ensure that a missing feature doesn't appear enabled."""
    manifest = nrm.aci.ImageManifest()
    assert manifest.load_dict(manifest_base_data)
    assert not manifest.is_feature_enabled("perfwrapper")