summaryrefslogtreecommitdiffstats
path: root/src/test/resources/rule-driven-validator/rules/aai-event/rule-vserver-all_others.groovy
blob: d922df96aa731a66a2b038a117e3e27f83522ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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" }
	              '''
}