4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from cmframework.apis import cmvalidator
20 from cmdatahandlers.api import validation
23 class VersionValidation(cmvalidator.CMValidator):
24 domain = 'cloud.version'
27 # Should be same as 'version' in release build
28 devel_version = [2, 0, 3]
31 # {1: 'This is the first change requiring new template version (1.1.0)',
32 # 2: 'This is the second change requiring new template version (1.2.0)',
33 # 3: 'This is the third change requiring new template version (1.3.0)'}
36 def get_subscription_info(self):
37 logging.debug('get_subscription info called')
38 return r'^cloud\.version$'
40 def validate_set(self, dict_key_value):
41 logging.debug('validate_set called with %s' % str(dict_key_value))
43 for key, value in dict_key_value.iteritems():
44 version = json.loads(value)
45 if key == self.domain:
46 self.validate_version(version)
48 raise validation.ValidationError('Unexpected configuration %s' % key)
50 def validate_delete(self, prop):
51 logging.debug('validate_delete called with %s' % str(prop))
52 raise validation.ValidationError('%s cannot be deleted' % self.domain)
54 def validate_version(self, version_str):
56 raise validation.ValidationError('Missing configuration template version')
57 if not isinstance(version_str, basestring):
58 raise validation.ValidationError('Version configuration should be a string')
59 data = version_str.split('.')
61 raise validation.ValidationError('Invalid version data syntax in configuration')
65 raise validation.ValidationError('Version data does not consist of numbers')
66 version.append(int(i))
67 if self.version != self.devel_version and version == self.devel_version:
68 msg = 'Accepting development version %s' % version_str
70 elif version[0] != self.version[0]:
71 reason = 'Major configuration template version mismatch (%s does not match with %s)' \
72 % (version_str, str(self.version))
73 raise validation.ValidationError(reason)
74 elif version[1] != self.version[1]:
75 reason = 'Configuration template version mismatch (%s does not match with %s)' \
76 % (version_str, str(self.version))
77 self.log_changes(version[1])
78 raise validation.ValidationError(reason)
79 elif version[2] != self.version[2]:
80 msg = 'Minor configuration template version mismatch, check the latest template changes'
83 def log_changes(self, version):
84 for key, log in self.change_log.iteritems():
86 logging.warning('Changes in template version %s.%s.0: %s' % (str(self.version[0]),