TOSCA: Do not import individual exception classes
Do not import individual exception classes. It is clean and recommended approach. Change-Id: I940ad0ccfa28f034183768c11d60ad95a7cf44a3
This commit is contained in:
parent
4b5805cb31
commit
fc70248653
@ -13,8 +13,7 @@
|
||||
import datetime
|
||||
import yaml
|
||||
|
||||
from translator.toscalib.common.exception import InvalidSchemaError
|
||||
from translator.toscalib.common.exception import ValidationError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.elements.constraints import Constraint
|
||||
from translator.toscalib.elements.constraints import Schema
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
@ -45,7 +44,7 @@ class ConstraintTest(TestCase):
|
||||
- description: Number of CPUs for the server.
|
||||
'''
|
||||
schema = yamlparser.simple_parse(tpl_snippet)
|
||||
error = self.assertRaises(InvalidSchemaError, Schema,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Schema,
|
||||
'cpus', schema['cpus'])
|
||||
self.assertEqual('Schema cpus must be a dict.', str(error))
|
||||
|
||||
@ -55,7 +54,7 @@ class ConstraintTest(TestCase):
|
||||
description: Number of CPUs for the server.
|
||||
'''
|
||||
schema = yamlparser.simple_parse(tpl_snippet)
|
||||
error = self.assertRaises(InvalidSchemaError, Schema,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Schema,
|
||||
'cpus', schema['cpus'])
|
||||
self.assertEqual('Schema cpus must have type.', str(error))
|
||||
|
||||
@ -70,7 +69,7 @@ class ConstraintTest(TestCase):
|
||||
|
||||
def test_invalid_constraint_type(self):
|
||||
schema = {'invalid_type': 2}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.INTEGER,
|
||||
schema)
|
||||
self.assertEqual('Invalid constraint type "invalid_type".',
|
||||
@ -78,7 +77,7 @@ class ConstraintTest(TestCase):
|
||||
|
||||
def test_invalid_prop_type(self):
|
||||
schema = {'length': 5}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.INTEGER,
|
||||
schema)
|
||||
self.assertEqual('Constraint type "length" is not valid for '
|
||||
@ -86,7 +85,7 @@ class ConstraintTest(TestCase):
|
||||
|
||||
def test_invalid_validvalues(self):
|
||||
schema = {'valid_values': 2}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.INTEGER,
|
||||
schema)
|
||||
self.assertEqual('valid_values must be a list.', str(error))
|
||||
@ -99,14 +98,15 @@ class ConstraintTest(TestCase):
|
||||
def test_validvalues_validate_fail(self):
|
||||
schema = {'valid_values': [2, 4, 6, 8]}
|
||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 5)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 5)
|
||||
self.assertEqual('prop: 5 is not an valid value "[2, 4, 6, 8]".',
|
||||
str(error))
|
||||
|
||||
def test_invalid_in_range(self):
|
||||
snippet = 'in_range: {2, 6}'
|
||||
schema = yaml.load(snippet)
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.INTEGER,
|
||||
schema)
|
||||
self.assertEqual('in_range must be a list.', str(error))
|
||||
@ -127,7 +127,8 @@ class ConstraintTest(TestCase):
|
||||
def test_in_range_validate_fail(self):
|
||||
schema = {'in_range': [2, 6]}
|
||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 8)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 8)
|
||||
self.assertEqual('prop: 8 is out of range (min:2, max:6).',
|
||||
str(error))
|
||||
|
||||
@ -139,7 +140,8 @@ class ConstraintTest(TestCase):
|
||||
def test_equal_validate_fail(self):
|
||||
schema = {'equal': 4}
|
||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 8)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 8)
|
||||
self.assertEqual('prop: 8 is not equal to "4".', str(error))
|
||||
|
||||
def test_greater_than_validate(self):
|
||||
@ -150,10 +152,12 @@ class ConstraintTest(TestCase):
|
||||
def test_greater_than_validate_fail(self):
|
||||
schema = {'greater_than': 4}
|
||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 3)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 3)
|
||||
self.assertEqual('prop: 3 must be greater than "4".', str(error))
|
||||
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 4)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 4)
|
||||
self.assertEqual('prop: 4 must be greater than "4".', str(error))
|
||||
|
||||
def test_greater_or_equal_validate(self):
|
||||
@ -165,11 +169,13 @@ class ConstraintTest(TestCase):
|
||||
def test_greater_or_equal_validate_fail(self):
|
||||
schema = {'greater_or_equal': 3.9}
|
||||
constraint = Constraint('prop', Schema.FLOAT, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 3.0)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 3.0)
|
||||
self.assertEqual('prop: 3.0 must be greater or equal to "3.9".',
|
||||
str(error))
|
||||
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 3.8)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 3.8)
|
||||
self.assertEqual('prop: 3.8 must be greater or equal to "3.9".',
|
||||
str(error))
|
||||
|
||||
@ -182,14 +188,14 @@ class ConstraintTest(TestCase):
|
||||
def test_less_than_validate_fail(self):
|
||||
schema = {'less_than': datetime.date(2014, 0o7, 25)}
|
||||
constraint = Constraint('prop', Schema.TIMESTAMP, schema)
|
||||
error = self.assertRaises(ValidationError,
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate,
|
||||
datetime.date(2014, 0o7, 25))
|
||||
self.assertEqual('prop: 2014-07-25 must be '
|
||||
'less than "2014-07-25".',
|
||||
str(error))
|
||||
|
||||
error = self.assertRaises(ValidationError,
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate,
|
||||
datetime.date(2014, 0o7, 27))
|
||||
self.assertEqual('prop: 2014-07-27 must be '
|
||||
@ -205,18 +211,19 @@ class ConstraintTest(TestCase):
|
||||
def test_less_or_equal_validate_fail(self):
|
||||
schema = {'less_or_equal': 4}
|
||||
constraint = Constraint('prop', Schema.INTEGER, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 5)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 5)
|
||||
self.assertEqual('prop: 5 must be less or equal to "4".', str(error))
|
||||
|
||||
def test_invalid_length(self):
|
||||
schema = {'length': 'four'}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.STRING,
|
||||
schema)
|
||||
self.assertEqual('length must be integer.', str(error))
|
||||
|
||||
schema = {'length': 4.5}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.STRING,
|
||||
schema)
|
||||
self.assertEqual('length must be integer.', str(error))
|
||||
@ -229,11 +236,12 @@ class ConstraintTest(TestCase):
|
||||
def test_length_validate_fail(self):
|
||||
schema = {'length': 4}
|
||||
constraint = Constraint('prop', Schema.STRING, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 'abc')
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 'abc')
|
||||
self.assertEqual('length of prop: abc must be equal to "4".',
|
||||
str(error))
|
||||
|
||||
error = self.assertRaises(ValidationError,
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate,
|
||||
'abcde')
|
||||
self.assertEqual('length of prop: abcde must be equal to "4".',
|
||||
@ -241,7 +249,7 @@ class ConstraintTest(TestCase):
|
||||
|
||||
def test_invalid_min_length(self):
|
||||
schema = {'min_length': 'four'}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.STRING,
|
||||
schema)
|
||||
self.assertEqual('min_length must be integer.', str(error))
|
||||
@ -255,13 +263,14 @@ class ConstraintTest(TestCase):
|
||||
def test_min_length_validate_fail(self):
|
||||
schema = {'min_length': 4}
|
||||
constraint = Constraint('prop', Schema.STRING, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 'abc')
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 'abc')
|
||||
self.assertEqual('length of prop: abc must be at least "4".',
|
||||
str(error))
|
||||
|
||||
def test_invalid_max_length(self):
|
||||
schema = {'max_length': 'four'}
|
||||
error = self.assertRaises(InvalidSchemaError, Constraint,
|
||||
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
|
||||
'prop', Schema.STRING,
|
||||
schema)
|
||||
self.assertEqual('max_length must be integer.', str(error))
|
||||
@ -275,7 +284,7 @@ class ConstraintTest(TestCase):
|
||||
def test_max_length_validate_fail(self):
|
||||
schema = {'max_length': 4}
|
||||
constraint = Constraint('prop', Schema.STRING, schema)
|
||||
error = self.assertRaises(ValidationError,
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate,
|
||||
'abcde')
|
||||
self.assertEqual('length of prop: abcde must be no greater than "4".',
|
||||
@ -289,6 +298,7 @@ class ConstraintTest(TestCase):
|
||||
def test_pattern_validate_fail(self):
|
||||
schema = {'pattern': '[0-9]*'}
|
||||
constraint = Constraint('prop', Schema.STRING, schema)
|
||||
error = self.assertRaises(ValidationError, constraint.validate, 'abc')
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
constraint.validate, 'abc')
|
||||
self.assertEqual('prop: "abc" does not match pattern "[0-9]*".',
|
||||
str(error))
|
||||
|
@ -13,10 +13,7 @@
|
||||
import os
|
||||
|
||||
from testtools.testcase import skip
|
||||
from translator.toscalib.common.exception import MissingRequiredFieldError
|
||||
from translator.toscalib.common.exception import TypeMismatchError
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib.common.exception import ValidationError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.dataentity import DataEntity
|
||||
from translator.toscalib.elements.datatype import DataType
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
@ -147,7 +144,7 @@ class DataTypeTest(TestCase):
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
error = self.assertRaises(TypeMismatchError, data.validate)
|
||||
error = self.assertRaises(exception.TypeMismatchError, data.validate)
|
||||
self.assertEqual('[\'Tom\', \'Jerry\'] must be of type: '
|
||||
'"tosca.my.datatypes.PeopleBase".', error.__str__())
|
||||
|
||||
@ -160,7 +157,7 @@ class DataTypeTest(TestCase):
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
error = self.assertRaises(UnknownFieldError, data.validate)
|
||||
error = self.assertRaises(exception.UnknownFieldError, data.validate)
|
||||
self.assertEqual('Data value of type tosca.my.datatypes.PeopleBase '
|
||||
'contain(s) unknown field: "nema", refer to the '
|
||||
'definition to verify valid values.',
|
||||
@ -184,7 +181,8 @@ class DataTypeTest(TestCase):
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
error = self.assertRaises(MissingRequiredFieldError, data.validate)
|
||||
error = self.assertRaises(exception.MissingRequiredFieldError,
|
||||
data.validate)
|
||||
self.assertEqual('Data value of type tosca.my.datatypes.PeopleBase '
|
||||
'is missing required field: "[\'name\']".',
|
||||
error.__str__())
|
||||
@ -210,7 +208,7 @@ class DataTypeTest(TestCase):
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
error = self.assertRaises(ValidationError, data.validate)
|
||||
error = self.assertRaises(exception.ValidationError, data.validate)
|
||||
self.assertEqual('length of name: M must be at least "2".',
|
||||
error.__str__())
|
||||
|
||||
@ -243,7 +241,7 @@ class DataTypeTest(TestCase):
|
||||
value = yamlparser.simple_parse(value_snippet)
|
||||
data = DataEntity('tosca.my.datatypes.People', value,
|
||||
DataTypeTest.custom_type_def)
|
||||
error = self.assertRaises(UnknownFieldError, data.validate)
|
||||
error = self.assertRaises(exception.UnknownFieldError, data.validate)
|
||||
self.assertEqual('Data value of type tosca.my.datatypes.ContactInfo '
|
||||
'contain(s) unknown field: "contact_pone", refer to '
|
||||
'the definition to verify valid values.',
|
||||
|
@ -10,9 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from translator.toscalib.common.exception import MissingRequiredFieldError
|
||||
from translator.toscalib.common.exception import TOSCAException
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
|
||||
|
||||
@ -20,22 +18,24 @@ class ExceptionTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
TOSCAException.set_fatal_format_exception(False)
|
||||
exception.TOSCAException.set_fatal_format_exception(False)
|
||||
|
||||
def test_message(self):
|
||||
ex = MissingRequiredFieldError(what='Template', required='type')
|
||||
ex = exception.MissingRequiredFieldError(what='Template',
|
||||
required='type')
|
||||
self.assertEqual('Template is missing required field: "type".',
|
||||
ex.__str__())
|
||||
|
||||
def test_set_flag(self):
|
||||
TOSCAException.set_fatal_format_exception('True')
|
||||
self.assertFalse(TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS)
|
||||
exception.TOSCAException.set_fatal_format_exception('True')
|
||||
self.assertFalse(
|
||||
exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS)
|
||||
|
||||
def test_format_error(self):
|
||||
ex = UnknownFieldError(what='Template')
|
||||
ex = exception.UnknownFieldError(what='Template')
|
||||
self.assertEqual('An unknown exception occurred.', ex.__str__(),)
|
||||
self.assertRaises(KeyError, self._formate_exception)
|
||||
|
||||
def _formate_exception(self):
|
||||
UnknownFieldError.set_fatal_format_exception(True)
|
||||
raise UnknownFieldError(what='Template')
|
||||
exception.UnknownFieldError.set_fatal_format_exception(True)
|
||||
raise exception.UnknownFieldError(what='Template')
|
||||
|
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from translator.toscalib.common.exception import InvalidTypeError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.properties import Property
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
from translator.toscalib.utils import yamlparser
|
||||
@ -28,7 +28,7 @@ class PropertyTest(TestCase):
|
||||
test_property_schema = {'type': 'Fish'}
|
||||
propertyInstance = Property('test_property', 'Hughes',
|
||||
test_property_schema)
|
||||
error = self.assertRaises(InvalidTypeError,
|
||||
error = self.assertRaises(exception.InvalidTypeError,
|
||||
propertyInstance.validate)
|
||||
self.assertEqual('Type "Fish" is not a valid type.', str(error))
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from translator.toscalib.common.exception import ValidationError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.elements.constraints import Constraint
|
||||
from translator.toscalib.nodetemplate import NodeTemplate
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
@ -184,11 +184,13 @@ class ScalarUnitNegativeTest(TestCase):
|
||||
nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def)
|
||||
for p in nodetemplate.properties:
|
||||
if p.name == 'disk_size':
|
||||
error = self.assertRaises(ValidationError, p.validate)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
p.validate)
|
||||
self.assertEqual('disk_size: 500 MB must be greater or '
|
||||
'equal to "1 GB".', error.__str__())
|
||||
if p.name == 'mem_size':
|
||||
error = self.assertRaises(ValidationError, p.validate)
|
||||
error = self.assertRaises(exception.ValidationError,
|
||||
p.validate)
|
||||
self.assertEqual('mem_size: 1 MB is out of range '
|
||||
'(min:1 MiB, '
|
||||
'max:1 GiB).', error.__str__())
|
||||
|
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from translator.toscalib.common.exception import InvalidTypeError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.elements.nodetype import NodeType
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
compute_type = NodeType('tosca.nodes.Compute')
|
||||
@ -20,7 +20,7 @@ component_type = NodeType('tosca.nodes.SoftwareComponent')
|
||||
class ToscaDefTest(TestCase):
|
||||
def test_type(self):
|
||||
self.assertEqual(compute_type.type, "tosca.nodes.Compute")
|
||||
self.assertRaises(InvalidTypeError, NodeType,
|
||||
self.assertRaises(exception.InvalidTypeError, NodeType,
|
||||
'tosca.nodes.Invalid')
|
||||
|
||||
def test_parent_type(self):
|
||||
|
@ -13,11 +13,7 @@
|
||||
import os
|
||||
import six
|
||||
|
||||
from translator.toscalib.common.exception import InvalidTemplateVersion
|
||||
from translator.toscalib.common.exception import InvalidTypeError
|
||||
from translator.toscalib.common.exception import MissingRequiredFieldError
|
||||
from translator.toscalib.common.exception import TypeMismatchError
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.nodetemplate import NodeTemplate
|
||||
from translator.toscalib.parameters import Input, Output
|
||||
from translator.toscalib.relationship_template import RelationshipTemplate
|
||||
@ -38,15 +34,16 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
tpl_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_tosca_top_level_error1.yaml")
|
||||
err = self.assertRaises(MissingRequiredFieldError, ToscaTemplate,
|
||||
tpl_path)
|
||||
err = self.assertRaises(exception.MissingRequiredFieldError,
|
||||
ToscaTemplate, tpl_path)
|
||||
self.assertEqual('Template is missing required field: '
|
||||
'"tosca_definitions_version".', err.__str__())
|
||||
|
||||
tpl_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_tosca_top_level_error2.yaml")
|
||||
err = self.assertRaises(UnknownFieldError, ToscaTemplate, tpl_path)
|
||||
err = self.assertRaises(exception.UnknownFieldError,
|
||||
ToscaTemplate, tpl_path)
|
||||
self.assertEqual('Template contain(s) unknown field: '
|
||||
'"node_template", refer to the definition '
|
||||
'to verify valid values.', err.__str__())
|
||||
@ -67,7 +64,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
try:
|
||||
input.validate()
|
||||
except Exception as err:
|
||||
self.assertTrue(isinstance(err, UnknownFieldError))
|
||||
self.assertTrue(isinstance(err, exception.UnknownFieldError))
|
||||
self.assertEqual('Input cpus contain(s) unknown field: '
|
||||
'"constraint", refer to the definition to '
|
||||
'verify valid values.', err.__str__())
|
||||
@ -86,7 +83,8 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
try:
|
||||
output.validate()
|
||||
except Exception as err:
|
||||
self.assertTrue(isinstance(err, MissingRequiredFieldError))
|
||||
self.assertTrue(
|
||||
isinstance(err, exception.MissingRequiredFieldError))
|
||||
self.assertEqual('Output server_address is missing required '
|
||||
'field: "value".', err.__str__())
|
||||
|
||||
@ -103,7 +101,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
try:
|
||||
output.validate()
|
||||
except Exception as err:
|
||||
self.assertTrue(isinstance(err, UnknownFieldError))
|
||||
self.assertTrue(isinstance(err, exception.UnknownFieldError))
|
||||
self.assertEqual('Output server_address contain(s) unknown '
|
||||
'field: "descriptions", refer to the definition '
|
||||
'to verify valid values.',
|
||||
@ -156,9 +154,10 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'''
|
||||
expectedmessage = ('Template server is missing '
|
||||
'required field: "type".')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
self._single_node_template_content_test(
|
||||
tpl_snippet,
|
||||
exception.MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
|
||||
tpl_snippet = '''
|
||||
node_templates:
|
||||
@ -183,7 +182,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'contain(s) unknown field: "requirement", '
|
||||
'refer to the definition to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def test_node_template_type(self):
|
||||
@ -208,7 +207,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
expectedmessage = ('Type "tosca.nodes.Databases" is not '
|
||||
'a valid type.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
InvalidTypeError,
|
||||
exception.InvalidTypeError,
|
||||
expectedmessage)
|
||||
|
||||
def test_node_template_requirements(self):
|
||||
@ -226,7 +225,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
expectedmessage = ('Requirements of template webserver '
|
||||
'must be of type: "list".')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
TypeMismatchError,
|
||||
exception.TypeMismatchError,
|
||||
expectedmessage)
|
||||
|
||||
tpl_snippet = '''
|
||||
@ -252,7 +251,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'contain(s) unknown field: "database_endpoint", '
|
||||
'refer to the definition to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def test_node_template_capabilities(self):
|
||||
@ -278,7 +277,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'contain(s) unknown field: "http_endpoint", '
|
||||
'refer to the definition to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def test_node_template_properties(self):
|
||||
@ -298,9 +297,10 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'''
|
||||
expectedmessage = ('Properties of template server is missing '
|
||||
'required field: "[\'os_type\']".')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
self._single_node_template_content_test(
|
||||
tpl_snippet,
|
||||
exception.MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
|
||||
tpl_snippet = '''
|
||||
node_templates:
|
||||
@ -322,7 +322,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'unknown field: "os_image", refer to the '
|
||||
'definition to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def test_node_template_interfaces(self):
|
||||
@ -351,7 +351,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'"tosca.interfaces.node.Lifecycles", '
|
||||
'refer to the definition to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
tpl_snippet = '''
|
||||
@ -378,7 +378,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'unknown field: "config", refer to the definition'
|
||||
' to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
tpl_snippet = '''
|
||||
@ -405,7 +405,7 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
'unknown field: "inputs", refer to the definition'
|
||||
' to verify valid values.')
|
||||
self._single_node_template_content_test(tpl_snippet,
|
||||
UnknownFieldError,
|
||||
exception.UnknownFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def test_relationship_template_properties(self):
|
||||
@ -419,9 +419,10 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
expectedmessage = ('Properties of template '
|
||||
'storage_attachto is missing required field: '
|
||||
'"[\'location\']".')
|
||||
self._single_rel_template_content_test(tpl_snippet,
|
||||
MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
self._single_rel_template_content_test(
|
||||
tpl_snippet,
|
||||
exception.MissingRequiredFieldError,
|
||||
expectedmessage)
|
||||
|
||||
def _single_rel_template_content_test(self, tpl_snippet, expectederror,
|
||||
expectedmessage):
|
||||
@ -436,8 +437,8 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_invalid_template_version.yaml")
|
||||
err = self.assertRaises(InvalidTemplateVersion, ToscaTemplate,
|
||||
tosca_tpl)
|
||||
err = self.assertRaises(exception.InvalidTemplateVersion,
|
||||
ToscaTemplate, tosca_tpl)
|
||||
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
|
||||
ex_err_msg = ('The template version "tosca_xyz" is invalid. '
|
||||
'The valid versions are: "%s"' % valid_versions)
|
||||
|
Loading…
x
Reference in New Issue
Block a user