diff options
Diffstat (limited to 'src/test/resources/rule-driven-validator/rules')
9 files changed, 572 insertions, 0 deletions
diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/common_rules.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/common_rules.groovy new file mode 100644 index 0000000..70980fe --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/common_rules.groovy @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +rule { + name 'prov-status' + category 'INVALID_VALUE' + description 'prov-status value restricted to one of PREPROV, NVTPROV, PROV, CAPPED, DECOM, RETIRED' + errorText 'Invalid prov-status value. Must be PREPROV, NVTPROV, PROV, CAPPED, DECOM, or RETIRED' + severity 'CRITICAL' + attributes 'status' + validate '''switch (status) { + case "PREPROV": + case "NVTPROV": + case "PROV": + case "CAPPED": + case "DECOM": + case "RETIRED": + return true + default: return false + }''' +} + +// The following are used by both vce and newvce + +rule { + name 'vnf-name' + category 'INVALID_NAME' + description 'Invalid naming convention' + errorText 'Invalid name - attribute does not match xxxxxnnnvbc (where x = alphanumeric and n = numeric)' + severity 'MINOR' + attributes 'name' + validate 'name != null && name.matches("[a-z,0-9]{5}[0-9]{3}vbc")' +} + +rule { + name 'vnf-type' + category 'INVALID_VALUE' + description 'Invalid value' + errorText 'Invalid value - attribute must equal esx-vce' + severity 'MINOR' + attributes 'name' + validate 'name != null && name.matches("esx-vce")' +} + +rule { + name 'heat-stack-id equals first 11 bytes of vnf-name' + category 'INVALID_VALUE' + description 'The value of heat-stack-id must equal the first 11 bytes of vnf-name' + errorText 'Invalid value - the value of heat-stack-id must equal the first 11 bytes of vnf-name' + severity 'MINOR' + attributes 'heatstackid', 'vnfname' + validate '''def firstEleven = { str -> str ? str.take(11) : null } + heatstackid.equals(firstEleven(vnfname))''' +} diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/entity-complex.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/entity-complex.groovy new file mode 100644 index 0000000..48d2f26 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/entity-complex.groovy @@ -0,0 +1,146 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +entity { + type 'complex' + validation { + useRule { + name 'CLLI' + attributes 'physical-location-id' + } + useRule { + name 'not AAI default' + attributes 'street1' + } + useRule { + name 'not AAI default' + attributes 'city' + } + useRule { + name 'not AAI default' + attributes 'state' + } + useRule { + name 'not AAI default' + attributes 'postal-code' + } + useRule { + name 'not AAI default' + attributes 'region' + } + useRule { + name 'not AAI default' + attributes 'country' + } + useRule { + name 'critical not AAI default' + attributes 'physical-location-type' + } + useRule { + name 'length five or null' + attributes 'complex-name' + } + useRule {name 'complex is related to availability zone' } + useRule {name 'complex is related to 1 oam-network' } + useRule { + name 'if a customer is related to an oam-network then oam-network.network-name must match naming convention' + attributes 'relationship-list.relationship[*]' + } + } +} + +rule { + name 'CLLI' + category 'FIELD_LENGTH' + description 'Field must be 8 or 11 characters long' + errorText 'Invalid length - field must be 8 or 11 characters long' + severity 'CRITICAL' + attributes 'field' + validate 'field.size() == 8 || field.size() == 11' +} + +rule { + name 'not AAI default' + category 'FIELD_LENGTH' + description 'Invalid length - field must not be AAIDEFAULT or null' + errorText 'Invalid Value - must not be AAIDEFAULT or null' + severity 'MINOR' + attributes 'field' + validate 'field != null && field.size() > 0 && !field.equalsIgnoreCase("AAIDEFAULT")' +} + +rule { + name 'length five or null' + category 'FIELD_LENGTH' + description 'Field must be 5 characters long or null' + errorText 'Invalid Length - field must be 5 characters long or null' + severity 'MINOR' + attributes 'field' + validate 'field == null || field.size() == 5' +} + +rule { + name 'critical not AAI default' + category 'INVALID_VALUE' + description 'Field must not be AAIDEFAULT or null' + errorText 'Invalid Value - must not be AAIDEFAULT or null' + severity 'CRITICAL' + attributes 'field' + validate 'field != null && field.size() > 0 && !field.equalsIgnoreCase("AAIDEFAULT")' +} + +rule { + name 'complex is related to availability zone' + category 'MISSING_REL' + description 'Validates that a complex is related to an availability zone' + errorText 'Missing relationship - a complex must be related to an availability zone' + severity 'CRITICAL' + attributes 'relationship-list.relationship[*].related-to' + validate 'related-to != null && related-to.contains("availability-zone")' +} + +rule { + name 'complex is related to 1 oam-network' + category 'MISSING_REL' + description 'Validates that a complex is related to 1 oam-network (and not more than 1 oam-network)' + errorText 'Missing relationship - complex must be related to 1 oam-network' + severity 'MAJOR' + attributes 'relationship-list.relationship[*].related-to' + validate 'related-to != null && related-to.count("oam-network") == 1' +} + +rule { + name 'if a customer is related to an oam-network then oam-network.network-name must match naming convention' + category 'INVALID_NAME' + description 'validates that if a customer is related to an oam-network then oam-network.network-name must match naming convention' + errorText 'Invalid name - if a customer is related to an oam-network then network-name must start with VLAN' + severity 'MINOR' + attributes 'relationships' + validate ''' + def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName).getAsString() } + + relatedToOamNetwork = relationships.findAll { getStringProperty(it, "related-to") == "oam-network" } + + networkNameIsValid = relationships.findAll { getStringProperty(it, "related-to") == "oam-network" } + .collect { it."related-to-property".get(0) } + .findAll { getStringProperty(it, "property-key") == "oam-network.network-name" } + .find { getStringProperty(it, "property-value").startsWith("VLAN") } + + return !relatedToOamNetwork || networkNameIsValid + ''' +} diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/entity-newvce.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/entity-newvce.groovy new file mode 100644 index 0000000..dce812a --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/entity-newvce.groovy @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +entity { + type 'newvce' + validation { + useRule { + name 'prov-status' + attributes 'prov-status' + } + useRule { + name 'vnf-name' + attributes 'vnf-name' + } + useRule { + name 'vnf-type' + attributes 'vnf-type' + } + useRule { + name 'valid_ipv4_addr' + attributes 'ipv4-oam-address' + } + useRule { + name 'heat-stack-id equals first 11 bytes of vnf-name' + attributes 'heat-stack-id', 'vnf-name' + } + } +} diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/generic-vnf-rules.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/generic-vnf-rules.groovy new file mode 100644 index 0000000..d890c36 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/generic-vnf-rules.groovy @@ -0,0 +1,56 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +entity { + type 'generic-vnf' + validation { + useRule { + name 'prov-status' + attributes 'prov-status' + } + useRule { + name 'valid_ipv4_addr' + attributes 'ipv4-oam-address' + } + useRule { + name 'ipv4_addr_present' + attributes 'equipment-role', 'l-interfaces.l-interface[*].l3-interface-ipv4-address-list' + } + } +} + +rule { + name 'valid_ipv4_addr' + category 'INVALID_VALUE' + description 'Validate an IPv4 address' + errorText 'Invalid value - attribute is not a valid IPv4 address' + severity 'MINOR' + attributes 'ipaddr' + validate 'ipaddr != null && ipaddr.matches("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])")' +} + +// If generic-vnf.equipment-role="UCPE" and there is an l-interface - then there must be an IPV4 address related to the l-interface +rule { + name 'ipv4_addr_present' + category 'MISSING_REL' + description 'Validates that ICPE equipment has a related IPv4 address' + errorText 'UCPE l-interface missing the IPv4 relationship' + severity 'MINOR' + attributes 'equipment', 'ipv4' + validate 'equipment != "UCPE" || ipv4 != null' +} diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-all_others.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-all_others.groovy new file mode 100644 index 0000000..d922df9 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-all_others.groovy @@ -0,0 +1,118 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +rule { + name 'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)' + category 'MISSING_REL' + description 'Validates that a vserver is related to a vnf (vce or newvce or vpe or generic-vnf)' + errorText 'Missing relationship - a vserver must be related to a vnf (vce or newvce or vpe or generic-vnf)' + severity 'MINOR' + attributes 'related-to' + validate 'related-to != null && (related-to.contains("vce") || related-to.contains("newvce") || related-to.contains("vpe") || related-to.contains("generic-vnf"))' +} + +rule { + name 'vserver is related to 1 pserver' + category 'MISSING_REL' + description 'Validates that a vserver is related to 1 pserver (and not more than 1 pserver)' + errorText 'Missing relationship - vserver must be related to 1 pserver' + severity 'MINOR' + attributes 'relationship-list.relationship[*].related-to' + validate 'related-to == null || related-to.count("pserver") == 1' +} + +rule { + name 'vserver is related to 0 or 1 image' + category 'MISSING_REL' + description 'Validates that a vserver is either not related to an image or related to only 1 image' + errorText 'Missing relationship - vserver must be related to 0 or 1 image' + severity 'MINOR' + attributes 'relationship-list.relationship[*].related-to' + validate 'related-to == null || related-to.count("image") <= 1' +} + +rule { + name 'vserver is related to 0 or 1 flavor' + category 'MISSING_REL' + description 'Validates that a vserver is either not related to a flavor or related to only 1 flavor' + errorText 'Missing relationship - vserver must be related to 0 or 1 flavor' + severity 'MINOR' + attributes 'relationship-list.relationship[*].related-to' + validate 'related-to == null || related-to.count("flavor") <= 1' +} + +rule { + name 'vserver is related to vpe and vserver-name matches naming convention' + category 'INVALID_NAME' + description 'Validates that if a vserver is related to a vpe then vserver-name must contain me6' + errorText 'Invalid name - if vserver is related to vpe then vserver-name must contain me6' + severity 'MINOR' + attributes 'relationship-list.relationship[*].related-to', 'vserver-name' + validate '!related-to.contains("vpe") || vserver-name =~ "me6"' +} + +rule { + name 'vserver is related to vce and vserver-name matches naming convention' + category 'INVALID_NAME' + description 'Validates that if a vserver is related to a vce then vserver-name must match naming convention' + errorText 'Invalid name - if vserver is related to vce then vserver-name must match xxxxxxxxvbcnnceb (where x = alphanumeric and n = numeric)' + severity 'MINOR' + attributes 'relationship-list.relationship[*].related-to', 'vserver-name' + validate '!related-to.contains("vce") || vserver-name =~ "[a-z0-9]{8}vbc[0-9]{2}ceb"' +} + +rule { + name 'vserver is related to a TRINITY image and vserver-name matches naming convention' + category 'INVALID_NAME' + description 'Validates that if vserver is related to an image named TRINITY, then the vserver name matches naming convention' + errorText 'Invalid name - if vserver is related to an image named TRINITY, then the vserver name must match xxxxnnnnvmnnn (where x = character and n = number)' + severity 'MINOR' + attributes 'relationships', 'vservername' + validate ''' + def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() } + + relatedToTrinity = relationships.findAll { getStringProperty(it, "related-to") == "image" } + .findAll { it."related-to-property" != null } + .collect { it."related-to-property".get(0) } + .findAll { getStringProperty(it, "property-key") == "image.image-name" } + .find { getStringProperty(it, "property-value").startsWith("TRINITY") } + + // If (and only if) related to TRINITY then check the vserver name + return !relatedToTrinity || vservername != null && vservername ==~ "[a-z]{4}[0-9]{4}vm[0-9]{3}" + ''' +} + +rule { + name 'availability-zone must be related to a service-capability and service-capability.service-type matches naming convention' + category 'INVALID_NAME' + description 'Validates that an availability-zone is related to a service-capability and service-capability.service-type matches naming convention' + errorText 'Invalid name - availability-zone must be related to a service-capability and service-capability.service-type must be set to SDN-ETHERNET-INTERNET' + severity 'CRITICAL' + attributes 'relationships' + validate ''' + def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName)?.getAsString() } + + if (!relationships.find { getStringProperty(it, "related-to") == "service-capability" }) { return true } + + return relationships.findAll { getStringProperty(it, "related-to") == "service-capability" } + .findAll { it."related-to-property" != null } + .collect { it."relationship-data".get(0) } + .findAll { getStringProperty(it, "relationship-key") == "service-capability.service-type" } + .find { getStringProperty(it, "relationship-value") == "SDN-ETHERNET-INTERNET" } + ''' +} diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-related-generic-vnf.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-related-generic-vnf.groovy new file mode 100644 index 0000000..feeffa8 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-related-generic-vnf.groovy @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +rule { + name 'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention' + category 'INVALID_NAME' + description 'Validates that if vserver is related to an image named TRINITY, then the related generic-vnf name matches naming convention' + errorText 'Invalid name - if vserver is related to an image named TRINITY, then the related generic-vnf name must match xxxxnnnnv (where x = character and n = number)' + severity 'MINOR' + attributes 'relationships' + validate ''' + def getStringProperty = { jsonObject, propertyName -> jsonObject.get(propertyName).getAsString() } + + vnf_name = relationships.findAll { getStringProperty(it, "related-to") == "generic-vnf" } + .collect { it."related-to-property".get(0) } + .find { getStringProperty(it, "property-key") == "generic-vnf.vnf-name" } + .findResult { getStringProperty(it, "property-value") } + + relatedToTrinity = relationships.findAll { getStringProperty(it, "related-to") == "image" } + .collect { it."related-to-property".get(0) } + .findAll { getStringProperty(it, "property-key") == "image.image-name" } + .find { getStringProperty(it, "property-value").startsWith("TRINITY") } + + // If (and only if) related to TRINITY then check the generic-vnf name + return !relatedToTrinity || vnf_name?.matches("[a-z]{4}[0-9]{4}v") + ''' +}
\ No newline at end of file diff --git a/src/test/resources/rule-driven-validator/rules/aai-event/vserver-rules.groovy b/src/test/resources/rule-driven-validator/rules/aai-event/vserver-rules.groovy new file mode 100644 index 0000000..d379e17 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/aai-event/vserver-rules.groovy @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +entity { + type 'vserver' + validation { + useRule { + name 'prov-status' + attributes 'prov-status' + } + useRule {name 'vserver is related to 0 or 1 image' } + useRule {name 'vserver is related to 0 or 1 flavor' } + useRule {name 'vserver is related to 1 pserver' } + useRule {name 'vserver is related to vpe and vserver-name matches naming convention' } + useRule {name 'vserver is related to vce and vserver-name matches naming convention' } + useRule { + name 'vserver related to TRINITY image and generic-vnf.vnf-name matches naming convention' + attributes 'relationship-list.relationship[*]' + } + useRule { + name 'vserver is related to a TRINITY image and vserver-name matches naming convention' + attributes 'relationship-list.relationship[*]', 'vserver-name' + } + useRule { + name 'vserver is related to a vnf (vce or newvce or vpe or generic-vnf)' + attributes 'relationship-list.relationship[*].related-to' + } + } +} diff --git a/src/test/resources/rule-driven-validator/rules/gizmo-event/common_rules.groovy b/src/test/resources/rule-driven-validator/rules/gizmo-event/common_rules.groovy new file mode 100644 index 0000000..b30816e --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/gizmo-event/common_rules.groovy @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +rule { + name 'valid_ipv4_addr' + category 'INVALID_VALUE' + description 'Validate an IPv4 address' + errorText 'Invalid value - attribute is not a valid IPv4 address' + severity 'MINOR' + attributes 'ipaddr' + validate 'ipaddr != null && ipaddr.matches("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])")' +} diff --git a/src/test/resources/rule-driven-validator/rules/gizmo-event/pserver-rules.groovy b/src/test/resources/rule-driven-validator/rules/gizmo-event/pserver-rules.groovy new file mode 100644 index 0000000..79b3cc2 --- /dev/null +++ b/src/test/resources/rule-driven-validator/rules/gizmo-event/pserver-rules.groovy @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START=================================================== + * Copyright (c) 2018 Amdocs + * ============================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END===================================================== + */ + +entity { + type 'pserver' + validation { + useRule { + name 'valid_ipv4_addr' + attributes 'vertex.properties.ipv4-oam-address' + } + } +} |