diff --git a/docker-compose.yaml b/docker-compose.yaml index c2c1b74739367efc21a07f847a418bbf49f8d1f0..2bbf5c3aaebf132d4a7ccf5a80818e779532008c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,8 +3,8 @@ services: dmc: build: . ports: - - "8080:80" + - "8080:8080" environment: - UVICORN_PORT: 80 + UVICORN_PORT: 8080 UVICORN_HOST: "0.0.0.0" UVICORN_WORKERS: 2 diff --git a/mc_openapi/doml_mc/intermediate_model/metamodel.py b/mc_openapi/doml_mc/intermediate_model/metamodel.py index 6c5e520843f4c757ebe4f92b22d7a5540f811b64..a10a505687e64ce3ede5de1bd5a10501f464e7d3 100644 --- a/mc_openapi/doml_mc/intermediate_model/metamodel.py +++ b/mc_openapi/doml_mc/intermediate_model/metamodel.py @@ -13,7 +13,7 @@ class DOMLVersion(Enum): V1_0 = "v1.0" V2_0 = "v2.0" V2_1 = "v2.1" - V2_2 = "v2.1.1" + V2_2 = "v2.2" Multiplicity = tuple[Literal["0", "1"], Literal["1", "*"]] diff --git a/mc_openapi/doml_mc/xmi_parser/doml_model.py b/mc_openapi/doml_mc/xmi_parser/doml_model.py index 8aaf11b240e9b21e05aee2fbe78455ef74789822..288fb98d2e87dc3f0db114143e2e8cfa1b9c297e 100644 --- a/mc_openapi/doml_mc/xmi_parser/doml_model.py +++ b/mc_openapi/doml_mc/xmi_parser/doml_model.py @@ -66,10 +66,32 @@ def infer_domlx_version(raw_model: bytes) -> DOMLVersion: def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> Tuple[IntermediateModel, DOMLVersion]: + # if doml_version is None: + # doml_version = infer_domlx_version(raw_model) + + # Try every DOML version until one works! if doml_version is None: - doml_version = infer_domlx_version(raw_model) - model = parse_xmi_model(raw_model, doml_version) + doml_versions = [x for x in DOMLVersion] + print(doml_versions) + + def get_model(raw_model, doml_version): + try: + dv = doml_versions.pop(0) + doml_version = dv + return parse_xmi_model(raw_model, dv), dv + except Exception as e: + print(f"Couldn't parse with DOML {dv.value}. Trying another version...") + if len(doml_versions) == 0: + raise e + else: + return get_model(raw_model, doml_version) + + model, doml_version = get_model(raw_model, doml_version) + else: # if user specifies DOML version, respect that choice! + model = parse_xmi_model(raw_model, doml_version) + + print(f"Using DOML {doml_version.value}") elp = ELayerParser(MetaModels[doml_version], SpecialParsers[doml_version]) if model.application: diff --git a/tests/test_mc_openapi.py b/tests/test_mc_openapi.py index d96ac8938bb3fff770a35a40b8c5eca5b9c2f7b1..7ab1ae0ab3942a552d0dc5d79f6c792c5f2608b8 100644 --- a/tests/test_mc_openapi.py +++ b/tests/test_mc_openapi.py @@ -3,11 +3,6 @@ from mc_openapi.doml_mc.common_reqs import CommonRequirements from mc_openapi.doml_mc import DOMLVersion import requests - -def test_version(): - assert __version__ == '1.2.0' - - # V2_0 tests def test_post_nginx_sat_V2_0(): with open("tests/doml/v2.0/nginx-openstack_v2.0.domlx", "r") as f: @@ -74,3 +69,36 @@ def test_post_faas_unsat_V2_1(): assert r.status_code == requests.codes.ok assert payload["result"] is not None assert payload["result"] == "unsat" + +# V2_2 tests +def test_post_nginx_sat_V2_1(): + with open("tests/doml/v2.2/nginx-aws-ec2.domlx", "r") as f: + doml = f.read() + + r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) + payload = r.json() + assert r.status_code == requests.codes.ok + assert payload["result"] is not None + assert payload["result"] == "sat" + + +def test_post_faas_unsat_V2_2(): + with open("tests/doml/v2.2/faas.domlx", "r") as f: + doml = f.read() + + r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) + payload = r.json() + assert r.status_code == requests.codes.ok + assert payload["result"] is not None + assert payload["result"] == "sat" + + +def test_post_nginx_with_func_reqs_unsat_V2_2(): + with open("tests/doml/v2.2/nginx_func_req.domlx", "r") as f: + doml = f.read() + + r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) + payload = r.json() + assert r.status_code == requests.codes.ok + assert payload["result"] is not None + assert payload["result"] == "unsat" \ No newline at end of file