Skip to content
Snippets Groups Projects
Unverified Commit e75d7b3a authored by Andrea Franchini's avatar Andrea Franchini
Browse files

Refactor and fix test suite

parent 0b3e13b9
Branches
No related tags found
No related merge requests found
...@@ -134,9 +134,7 @@ else: ...@@ -134,9 +134,7 @@ else:
print("Failed to parse the DOMLR.", file=sys.stderr) print("Failed to parse the DOMLR.", file=sys.stderr)
exit(-1) exit(-1)
if (doml_ver == DOMLVersion.V2_2 if DOMLVersion.has_DOMLR_support(doml_ver):
or doml_ver == DOMLVersion.V2_2_1
or doml_ver == DOMLVersion.V2_3):
model = get_pyecore_model(doml_xmi, doml_ver) model = get_pyecore_model(doml_xmi, doml_ver)
func_reqs = model.functionalRequirements.items func_reqs = model.functionalRequirements.items
for req in func_reqs: for req in func_reqs:
......
...@@ -21,10 +21,13 @@ class DOMLVersion(Enum): ...@@ -21,10 +21,13 @@ class DOMLVersion(Enum):
"""Retrieve DOML version from string. """Retrieve DOML version from string.
Try to be less pedantic about versions Try to be less pedantic about versions
e.g.: 2.0 becomes V2_0""" e.g.: 2.0 becomes V2_0"""
doml_ver = v.replace(".", "_") doml_ver = v.replace(".", "_").replace("v", "V")
if doml_ver[0] != "V": if doml_ver[0] != "V":
doml_ver = "V" + doml_ver doml_ver = "V" + doml_ver
return DOMLVersion[doml_ver] return DOMLVersion[doml_ver]
def has_DOMLR_support(v: "DOMLVersion"):
return v != DOMLVersion.V2_0 and v != DOMLVersion.V2_1
Multiplicity = tuple[Literal["0", "1"], Literal["1", "*"]] Multiplicity = tuple[Literal["0", "1"], Literal["1", "*"]]
......
...@@ -82,11 +82,28 @@ def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> T ...@@ -82,11 +82,28 @@ def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> T
try: try:
dv = doml_versions.pop(0) dv = doml_versions.pop(0)
doml_version = dv doml_version = dv
return parse_xmi_model(raw_model, dv), dv parsed_xmi_model = parse_xmi_model(raw_model, dv)
# Try to extract the user-specified version from the DOML
try:
model_version = parsed_xmi_model.version
if model_version:
try:
dv = DOMLVersion.get(model_version)
return parse_xmi_model(raw_model, dv), dv
except:
MSG_ERR_INVALID_DOML_VERSION = f"DOML requires version \"{model_version}\", but could not parse it with that version. Is the version valid?"
logging.error(MSG_ERR_INVALID_DOML_VERSION)
raise RuntimeError(MSG_ERR_INVALID_DOML_VERSION)
except:
pass
# DOML version is not specified, proceed as usual
return parsed_xmi_model, dv
except Exception as e: except Exception as e:
logging.info(f"Couldn't parse with DOML {dv.value}. Trying another version...") logging.info(f"Couldn't parse with DOML {dv.value}. Trying another version...")
if len(doml_versions) == 0: if len(doml_versions) == 0:
raise e MSG_ERR_NO_DOML_VERSIONS = "No other compatible DOML versions found!"
logging.error(MSG_ERR_NO_DOML_VERSIONS)
raise RuntimeError(MSG_ERR_NO_DOML_VERSIONS)
else: else:
return get_model(raw_model, doml_version) return get_model(raw_model, doml_version)
...@@ -95,7 +112,7 @@ def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> T ...@@ -95,7 +112,7 @@ def parse_doml_model(raw_model: bytes, doml_version: Optional[DOMLVersion]) -> T
try: try:
model = parse_xmi_model(raw_model, doml_version) model = parse_xmi_model(raw_model, doml_version)
except: except:
raise Exception("Parsing of DOML failed. Perhaps you are using the wrong DOML version or IDE?") raise RuntimeError("Parsing of DOML failed. Perhaps you are using the wrong DOML version or IDE?")
logging.info(f"Model '{model.name}' parsed as DOML {doml_version.value}") logging.info(f"Model '{model.name}' parsed as DOML {doml_version.value}")
......
...@@ -37,9 +37,7 @@ def post(body, version=None): ...@@ -37,9 +37,7 @@ def post(body, version=None):
user_req_str_consts = [] user_req_str_consts = []
# Add support for Requirements in DOML # Add support for Requirements in DOML
if (dmc.doml_version == DOMLVersion.V2_2 if DOMLVersion.has_DOMLR_support(dmc.doml_version):
or dmc.doml_version == DOMLVersion.V2_2_1
or dmc.doml_version == DOMLVersion.V2_3):
domlr_parser = Parser(DOMLRTransformer) domlr_parser = Parser(DOMLRTransformer)
model = get_pyecore_model(doml_xmi, dmc.doml_version) model = get_pyecore_model(doml_xmi, dmc.doml_version)
func_reqs = model.functionalRequirements.items func_reqs = model.functionalRequirements.items
......
doml nginx_func_req doml nginx_func_req
version "v2.2"
application app { application app {
...@@ -121,29 +122,29 @@ optimization opt { ...@@ -121,29 +122,29 @@ optimization opt {
} }
functional_requirements { functional_requirements {
req_ext ``` req_ext ```
> "example requirement to test"
# Expr to parse # + "VM must have iface and iface is connected to network"
not ( # forall vm (
vm is class infrastructure.VirtualMachine # vm is class abstract.VirtualMachine
and # implies
vm is not class infrastructure.Storage # (
or # vm has abstract.ComputingNode.ifaces iface
vm is not class infrastructure.Storage # and
implies # iface has abstract.NetworkInterface.belongsTo net
vm is class infrastructure.Storage # )
) # )
iff # error: "TEST ERROR"
not exists iface, apple (
forall orange ( - "VM must have iface and iface is connected to network"
vm has association infrastructure.ComputingNode->ifaces iface vm is class abstract.VirtualMachine
or and
vm has association infrastructure.ComputingNode->ifaces iface not exists iface, net (
) vm has abstract.ComputingNode.ifaces iface
and and
vm has attribute infrastructure.ComputingNode->os Os1 iface has abstract.NetworkInterface.belongsTo net
)
--- )
"Virtual Machine {vm} has no iface" error: "TEST ERROR"
```;
} ```;}
<?xml version="1.0" encoding="ASCII"?> <?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_func_req" activeConfiguration="//@configurations.0" activeInfrastructure="//@concretizations.0"> <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_func_req" version="v2.2" activeConfiguration="//@configurations.0" activeInfrastructure="//@concretizations.0">
<application name="app"> <application name="app">
<components xsi:type="app:SoftwareComponent" name="nginx"> <components xsi:type="app:SoftwareComponent" name="nginx">
<annotations xsi:type="commons:SProperty" key="source_code" value="/usr/share/nginx/html/index.html"/> <annotations xsi:type="commons:SProperty" key="source_code" value="/usr/share/nginx/html/index.html"/>
...@@ -55,5 +55,5 @@ ...@@ -55,5 +55,5 @@
<configurations name="conf"> <configurations name="conf">
<deployments component="//@application/@components.0" node="//@infrastructure/@groups.0/@machineDefinition"/> <deployments component="//@application/@components.0" node="//@infrastructure/@groups.0/@machineDefinition"/>
</configurations> </configurations>
<functionalRequirements name="req_ext" description="```&#xA;&#xA; + &quot;VM must have iface and iface is connected to network&quot;&#xA; &#x9;forall vm (&#xA; &#x9;&#x9;vm is class abstract.VirtualMachine&#xA; &#x9;implies&#xA; (&#xA; &#x9;vm has abstract.ComputingNode.ifaces iface&#xA; &#x9;and&#xA; &#x9;iface has abstract.NetworkInterface.belongsTo net&#xA; )&#xA; )&#xA; error: &quot;TEST ERROR&quot;&#xA; &#xA; ```"/> <functionalRequirements name="req_ext" description="```&#xA;&#xA;# + &quot;VM must have iface and iface is connected to network&quot;&#xA;# &#x9;forall vm (&#xA;# &#x9;&#x9;vm is class abstract.VirtualMachine&#xA;# &#x9;implies&#xA;# (&#xA;# &#x9;vm has abstract.ComputingNode.ifaces iface&#xA;# &#x9;and&#xA;# &#x9;iface has abstract.NetworkInterface.belongsTo net&#xA;# )&#xA;# )&#xA;# error: &quot;TEST ERROR&quot;&#xA;&#xA;- &quot;VM must have iface and iface is connected to network&quot;&#xA;&#x9;vm is class abstract.VirtualMachine&#xA;&#x9;and&#xA;&#x9;not exists iface, net (&#xA; &#x9;vm has abstract.ComputingNode.ifaces iface&#xA; &#x9;and&#xA; &#x9;iface has abstract.NetworkInterface.belongsTo net&#xA; &#xA; )&#xA; error: &quot;TEST ERROR&quot;&#xA; &#xA; ```"/>
</commons:DOMLModel> </commons:DOMLModel>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment