diff --git a/mc_openapi/doml_mc/example_faas.ipynb b/mc_openapi/doml_mc/example_faas.ipynb index 4b530caa921be372c3dd19b804746436e35515ef..642003e845d962002106eaf3b16ba442ca60c5d3 100644 --- a/mc_openapi/doml_mc/example_faas.ipynb +++ b/mc_openapi/doml_mc/example_faas.ipynb @@ -50,7 +50,7 @@ "source": [ "from mc_openapi.doml_mc.xmi_parser.doml_model import parse_doml_model\n", "from mc_openapi.doml_mc import DOMLVersion\n", - "doml_document_path = \"../../tests/doml/faas.domlx\"\n", + "doml_document_path = \"../../tests/doml/v2.0/faas.domlx\"\n", "with open(doml_document_path, \"rb\") as xmif:\n", " doc = xmif.read()\n", "\n", diff --git a/mc_openapi/doml_mc/example_nginx.ipynb b/mc_openapi/doml_mc/example_nginx.ipynb index 005aa44431eff504ad298f1d513793a4ac1d0fff..48fbd363bc85a58249393c5575ba6d2abcb05899 100644 --- a/mc_openapi/doml_mc/example_nginx.ipynb +++ b/mc_openapi/doml_mc/example_nginx.ipynb @@ -50,8 +50,8 @@ "source": [ "from mc_openapi.doml_mc.xmi_parser.doml_model import parse_doml_model\n", "from mc_openapi.doml_mc import DOMLVersion\n", - "doml_document_path = \"../../tests/doml/nginx-openstack_v2.0.domlx\"\n", - "# doml_document_path = \"../../tests/doml/nginx-openstack_v2.0_wrong_vm_iface.domlx\"\n", + "doml_document_path = \"../../tests/doml/v2.0/nginx-openstack_v2.0.domlx\"\n", + "# doml_document_path = \"../../tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.domlx\"\n", "with open(doml_document_path, \"rb\") as xmif:\n", " doc = xmif.read()\n", "\n", diff --git a/mc_openapi/doml_mc/test.ipynb b/mc_openapi/doml_mc/test.ipynb index 3fa1544b30d001c7ef3e2d8973ba5906c339cd3e..9d72011c35730dd45f39f1b5d4d1f587a59d67ae 100644 --- a/mc_openapi/doml_mc/test.ipynb +++ b/mc_openapi/doml_mc/test.ipynb @@ -8,9 +8,9 @@ "source": [ "import mc_openapi.doml_mc as mc\n", "\n", - "doml_document_path = \"../../tests/doml/nginx-openstack_v2.0.domlx\"\n", - "# doml_document_path = \"../../tests/doml/nginx-openstack_v2.0_wrong_vm_iface.domlx\"\n", - "# doml_document_path = \"../../tests/doml/faas.domlx\"\n", + "doml_document_path = \"../../tests/doml/v2.0/nginx-openstack_v2.0.domlx\"\n", + "# doml_document_path = \"../../tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.domlx\"\n", + "# doml_document_path = \"../../tests/doml/v2.0/faas.domlx\"\n", "with open(doml_document_path, \"rb\") as xmif:\n", " doc = xmif.read()\n", "\n", diff --git a/tests/doml/faas.domlx b/tests/doml/v2.0/faas.domlx similarity index 100% rename from tests/doml/faas.domlx rename to tests/doml/v2.0/faas.domlx diff --git a/tests/doml/nginx-openstack_v2.0.domlx b/tests/doml/v2.0/nginx-openstack_v2.0.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_SoftwareComponents_deployed.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_concrete_map_something.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_concrete_map_something.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_concrete_map_something.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_concrete_map_something.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_concrete_map_something.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_concrete_map_something.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_concrete_map_something.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_concrete_map_something.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_all_infrastructure_elements_deployed.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_iface_uniq.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_iface_uniq.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_iface_uniq.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_iface_uniq.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_iface_uniq.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_iface_uniq.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_iface_uniq.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_iface_uniq.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_software_package_iface_net.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_software_package_iface_net.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_software_package_iface_net.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_software_package_iface_net.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_software_package_iface_net.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_software_package_iface_net.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_software_package_iface_net.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_software_package_iface_net.domlx diff --git a/tests/doml/nginx-openstack_v2.0_wrong_vm_iface.doml b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.doml similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_vm_iface.doml rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.doml diff --git a/tests/doml/nginx-openstack_v2.0_wrong_vm_iface.domlx b/tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.domlx similarity index 100% rename from tests/doml/nginx-openstack_v2.0_wrong_vm_iface.domlx rename to tests/doml/v2.0/nginx-openstack_v2.0_wrong_vm_iface.domlx diff --git a/tests/doml/v2.1/faas.domlx b/tests/doml/v2.1/faas.domlx new file mode 100644 index 0000000000000000000000000000000000000000..51dc9826cba0430f1fa4cb1da3ba4cc94b9515fc --- /dev/null +++ b/tests/doml/v2.1/faas.domlx @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="ASCII"?> +<commons:DOMLModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:app="http://www.piacere-project.eu/doml/application" xmlns:commons="http://www.piacere-project.eu/doml/commons" xmlns:infra="http://www.piacere-project.eu/doml/infrastructure" name="faas_app" activeConfiguration="//@configurations.0" activeInfrastructure="//@concretizations.0" version="v2.1"> + <application name="ImageResizeApp"> + <components xsi:type="app:SoftwareComponent" name="image_resize" consumedInterfaces="//@application/@components.1/@exposedInterfaces.0 //@application/@components.1/@exposedInterfaces.1 //@application/@components.2/@exposedInterfaces.1"> + <annotations xsi:type="commons:SProperty" key="source_code" value="path/lambda/function/image_resize.py"/> + <exposedInterfaces name="handle_image"/> + </components> + <components xsi:type="app:SaaS" name="s1"> + <exposedInterfaces name="storage_interface"/> + <exposedInterfaces name="bucket_in"/> + </components> + <components xsi:type="app:SaaS" name="s2"> + <exposedInterfaces name="storage_interface"/> + <exposedInterfaces name="bucket_out"/> + </components> + <components xsi:type="app:SoftwareComponent" name="notification" consumedInterfaces="//@application/@components.0/@exposedInterfaces.0 //@application/@components.1/@exposedInterfaces.1"/> + <components xsi:type="app:SoftwareComponent" name="web" consumedInterfaces="//@application/@components.1/@exposedInterfaces.0 //@application/@components.2/@exposedInterfaces.1"> + <annotations xsi:type="commons:SProperty" key="source_code" value="path/web_app"/> + </components> + </application> + <infrastructure name="infra"> + <nodes xsi:type="infra:VirtualMachine" name="vm1" credentials="//@infrastructure/@credentials.0" generatedFrom="//@infrastructure/@generators.0"> + <ifaces name="i1" endPoint="10.0.0.1" belongsTo="//@infrastructure/@networks.0" associated="//@infrastructure/@securityGroups.0"/> + <location region="eu-central-1"/> + </nodes> + <nodes xsi:type="infra:Container" name="c" generatedFrom="//@infrastructure/@generators.1"> + <configs host="//@infrastructure/@nodes.0"/> + </nodes> + <generators xsi:type="infra:VMImage" name="v_img" uri="ami-xxxxxxxxxxxxxxxxx" kind="IMAGE" generatedVMs="//@infrastructure/@nodes.0"/> + <generators xsi:type="infra:ContainerImage" name="c_img" uri="web-app:0.1.0" kind="IMAGE" generatedContainers="//@infrastructure/@nodes.1"/> + <storages name="st1"/> + <storages name="st2"/> + <faas name="f"/> + <credentials xsi:type="infra:KeyPair" name="ssh_key" user="ec2-user" keyfile="/tmp/ssh_key_file" algorithm="RSA" bits="4096"/> + <securityGroups name="sg" ifaces="//@infrastructure/@nodes.0/@ifaces.0"> + <rules name="icmp" protocol="icmp" fromPort="-1" toPort="-1"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="http" kind="INGRESS" protocol="tcp" fromPort="80" toPort="80"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="https" kind="INGRESS" protocol="tcp" fromPort="443" toPort="443"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="ssh" kind="INGRESS" protocol="tcp" fromPort="22" toPort="22"> + <cidr>0.0.0.0/0</cidr> + </rules> + </securityGroups> + <networks name="vpc" protocol="tcp/ip" addressRange="/24" connectedIfaces="//@infrastructure/@nodes.0/@ifaces.0"> + <subnets name="vpc_subnet" protocol="tcp/ip" addressRange="/24"/> + </networks> + </infrastructure> + <concretizations name="con_infra"> + <providers name="aws"> + <vms name="concrete_vm" maps="//@infrastructure/@nodes.0"> + <annotations xsi:type="commons:SProperty" key="instance_type" value="t2.micro"/> + <annotations xsi:type="commons:SProperty" key="ssh_key_name" value="demo-key"/> + <annotations xsi:type="commons:SProperty" key="ec2_role_name" value="demo-ec2-role"/> + </vms> + <networks name="concrete_net" maps="//@infrastructure/@networks.0"/> + <storages name="s3_bucket_in" maps="//@infrastructure/@storages.0"> + <annotations xsi:type="commons:SProperty" key="bucket_name" value="bucket_in"/> + </storages> + <storages name="s3_bucket_out" maps="//@infrastructure/@storages.1"> + <annotations xsi:type="commons:SProperty" key="bucket_name" value="bucket_out"/> + </storages> + <faas name="concrete_f" maps="//@infrastructure/@faas.0"> + <annotations xsi:type="commons:SProperty" key="lambda_role_name" value="DemoLambdaRole"/> + <annotations xsi:type="commons:SProperty" key="lambda_runtime" value="python3.8"/> + <annotations xsi:type="commons:SProperty" key="lambda_handler" value="image_resize.lambda_handler"/> + <annotations xsi:type="commons:IProperty" key="lambda_timeout" value="5"/> + <annotations xsi:type="commons:IProperty" key="lambda_memory" value="128"/> + </faas> + </providers> + </concretizations> + <configurations name="config1"> + <deployments component="//@application/@components.0" node="//@infrastructure/@faas.0"/> + <deployments component="//@application/@components.4" node="//@infrastructure/@nodes.1"/> + <deployments component="//@application/@components.1" node="//@infrastructure/@storages.0"/> + <deployments component="//@application/@components.2" node="//@infrastructure/@storages.1"/> + </configurations> +</commons:DOMLModel> diff --git a/tests/doml/v2.1/nginx-aws-ec2.domlx b/tests/doml/v2.1/nginx-aws-ec2.domlx new file mode 100644 index 0000000000000000000000000000000000000000..9bf39801a9f851526e967b6cf9936898f6c844f3 --- /dev/null +++ b/tests/doml/v2.1/nginx-aws-ec2.domlx @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="ASCII"?> +<commons:DOMLModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:app="http://www.piacere-project.eu/doml/application" xmlns:commons="http://www.piacere-project.eu/doml/commons" xmlns:infra="http://www.piacere-project.eu/doml/infrastructure" xmlns:optimization="http://www.piacere-project.eu/doml/optimization" name="nginx_aws_ec2" activeConfiguration="//@configurations.0" activeInfrastructure="//@concretizations.0" version="v2.1"> + <application name="app"> + <components xsi:type="app:SoftwareComponent" name="nginx"> + <annotations xsi:type="commons:SProperty" key="source_code" value="/usr/share/nginx/html/index.html"/> + </components> + </application> + <infrastructure name="infra"> + <generators xsi:type="infra:VMImage" name="vm_img" uri="ami-xxxxxxxxxxxxxxxxx" kind="IMAGE" generatedVMs="//@infrastructure/@groups.0/@machineDefinition"/> + <credentials xsi:type="infra:KeyPair" name="ssh_key" user="ec2-user" keyfile="/tmp/ssh_key_file" algorithm="RSA" bits="4096"/> + <groups xsi:type="infra:AutoScalingGroup" name="ag"> + <machineDefinition name="vm1" credentials="//@infrastructure/@credentials.0" generatedFrom="//@infrastructure/@generators.0"> + <ifaces name="i1" endPoint="10.0.0.1" belongsTo="//@infrastructure/@networks.0" associated="//@infrastructure/@securityGroups.0"/> + <location region="eu-central-1"/> + </machineDefinition> + </groups> + <securityGroups name="sg" ifaces="//@infrastructure/@groups.0/@machineDefinition/@ifaces.0"> + <rules name="icmp" protocol="icmp" fromPort="-1" toPort="-1"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="http" kind="INGRESS" protocol="tcp" fromPort="80" toPort="80"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="https" kind="INGRESS" protocol="tcp" fromPort="443" toPort="443"> + <cidr>0.0.0.0/0</cidr> + </rules> + <rules name="ssh" kind="INGRESS" protocol="tcp" fromPort="22" toPort="22"> + <cidr>0.0.0.0/0</cidr> + </rules> + </securityGroups> + <networks name="vpc" protocol="tcp/ip" addressRange="/24" connectedIfaces="//@infrastructure/@groups.0/@machineDefinition/@ifaces.0"> + <subnets name="vpc_subnet" protocol="tcp/ip" addressRange="/24"/> + </networks> + </infrastructure> + <concretizations name="con_infra"> + <providers name="aws"> + <vms name="ec2_vm" maps="//@infrastructure/@groups.0/@machineDefinition"> + <annotations xsi:type="commons:SProperty" key="vm_name" value="nginx-host"/> + <annotations xsi:type="commons:SProperty" key="instance_type" value="t2.micro"/> + <annotations xsi:type="commons:SProperty" key="ssh_key_name" value="demo-key"/> + <annotations xsi:type="commons:SProperty" key="ec2_role_name" value="demo-ec2-role"/> + </vms> + <vmImages name="concrete_vm_image" maps="//@infrastructure/@generators.0"/> + <networks name="concrete_net" maps="//@infrastructure/@networks.0"> + <annotations xsi:type="commons:SProperty" key="vm_name" value="nginx-host"/> + </networks> + </providers> + </concretizations> + <optimization name="opt"> + <objectives xsi:type="optimization:MeasurableObjective" kind="min" property="cost"/> + <objectives xsi:type="optimization:MeasurableObjective" kind="max" property="availability"/> + <nonfunctionalRequirements xsi:type="commons:RangedRequirement" name="req1" description="Cost <= 70.0" property="cost" max="70.0"/> + <nonfunctionalRequirements xsi:type="commons:RangedRequirement" name="req2" description="Availability >= 66.5%" property="availability" min="66.5"/> + </optimization> + <configurations name="config"> + <deployments component="//@application/@components.0" node="//@infrastructure/@groups.0/@machineDefinition"/> + </configurations> +</commons:DOMLModel> diff --git a/tests/test_mc_openapi.py b/tests/test_mc_openapi.py index ebd0b83cb1fec5ba7c639e7e7a94f5d257ac7cc2..d96ac8938bb3fff770a35a40b8c5eca5b9c2f7b1 100644 --- a/tests/test_mc_openapi.py +++ b/tests/test_mc_openapi.py @@ -8,8 +8,9 @@ def test_version(): assert __version__ == '1.2.0' -def test_post_nginx_sat(): - with open("tests/doml/nginx-openstack_v2.0.domlx", "r") as f: +# V2_0 tests +def test_post_nginx_sat_V2_0(): + with open("tests/doml/v2.0/nginx-openstack_v2.0.domlx", "r") as f: doml = f.read() r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) @@ -19,8 +20,8 @@ def test_post_nginx_sat(): assert payload["result"] == "sat" -def test_post_faas_sat(): - with open("tests/doml/faas.domlx", "r") as f: +def test_post_faas_unsat_V2_0(): + with open("tests/doml/v2.0/faas.domlx", "r") as f: doml = f.read() r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) @@ -41,7 +42,7 @@ def test_post_common_reqs_V2_0(): ] for req, err_desc in zip(CommonRequirements[DOMLVersion.V2_0].get_all_requirements(), check_strings): - with open(f"tests/doml/nginx-openstack_v2.0_wrong_{req.assert_name}.domlx", "r") as f: + with open(f"tests/doml/v2.0/nginx-openstack_v2.0_wrong_{req.assert_name}.domlx", "r") as f: doml = f.read() r = requests.post("http://0.0.0.0:8080/modelcheck", data=doml) @@ -50,3 +51,26 @@ def test_post_common_reqs_V2_0(): assert payload["result"] is not None assert payload["result"] == "unsat" assert err_desc in payload["description"] + + +# V2_1 tests +def test_post_nginx_sat_V2_1(): + with open("tests/doml/v2.1/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_1(): + with open("tests/doml/v2.1/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"] == "unsat"