Merge "Add consistency and validation to required attribute"
This commit is contained in:
commit
fca4573fa9
@ -90,12 +90,12 @@ tosca.nodes.DBMS:
|
|||||||
derived_from: tosca.nodes.SoftwareComponent
|
derived_from: tosca.nodes.SoftwareComponent
|
||||||
properties:
|
properties:
|
||||||
port:
|
port:
|
||||||
required: no
|
required: false
|
||||||
type: integer
|
type: integer
|
||||||
description: >
|
description: >
|
||||||
The port the DBMS service will listen to for data and requests.
|
The port the DBMS service will listen to for data and requests.
|
||||||
root_password:
|
root_password:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: >
|
description: >
|
||||||
The root password for the DBMS service.
|
The root password for the DBMS service.
|
||||||
@ -108,17 +108,17 @@ tosca.nodes.Database:
|
|||||||
derived_from: tosca.nodes.Root
|
derived_from: tosca.nodes.Root
|
||||||
properties:
|
properties:
|
||||||
user:
|
user:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: >
|
description: >
|
||||||
User account name for DB administration
|
User account name for DB administration
|
||||||
name:
|
name:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: >
|
description: >
|
||||||
The name of the database.
|
The name of the database.
|
||||||
password:
|
password:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: >
|
description: >
|
||||||
The password for the DB user account
|
The password for the DB user account
|
||||||
@ -184,7 +184,7 @@ tosca.nodes.network.Network:
|
|||||||
properties:
|
properties:
|
||||||
ip_version:
|
ip_version:
|
||||||
type: integer
|
type: integer
|
||||||
required: no
|
required: false
|
||||||
default: 4
|
default: 4
|
||||||
constraints:
|
constraints:
|
||||||
- valid_values: [ 4, 6 ]
|
- valid_values: [ 4, 6 ]
|
||||||
@ -193,29 +193,29 @@ tosca.nodes.network.Network:
|
|||||||
or 6 for ipv6.
|
or 6 for ipv6.
|
||||||
cidr:
|
cidr:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
The cidr block of the requested network.
|
The cidr block of the requested network.
|
||||||
start_ip:
|
start_ip:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
The IP address to be used as the start of a pool of addresses within
|
The IP address to be used as the start of a pool of addresses within
|
||||||
the full IP range derived from the cidr block.
|
the full IP range derived from the cidr block.
|
||||||
end_ip:
|
end_ip:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
The IP address to be used as the end of a pool of addresses within
|
The IP address to be used as the end of a pool of addresses within
|
||||||
the full IP range derived from the cidr block.
|
the full IP range derived from the cidr block.
|
||||||
gateway_ip:
|
gateway_ip:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
The gateway IP address.
|
The gateway IP address.
|
||||||
network_name:
|
network_name:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
An identifier that represents an existing Network instance in the
|
An identifier that represents an existing Network instance in the
|
||||||
underlying cloud infrastructure or can be used as the name of the
|
underlying cloud infrastructure or can be used as the name of the
|
||||||
@ -226,7 +226,7 @@ tosca.nodes.network.Network:
|
|||||||
be created.
|
be created.
|
||||||
network_id:
|
network_id:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
An identifier that represents an existing Network instance in the
|
An identifier that represents an existing Network instance in the
|
||||||
underlying cloud infrastructure. This property is mutually exclusive
|
underlying cloud infrastructure. This property is mutually exclusive
|
||||||
@ -234,13 +234,13 @@ tosca.nodes.network.Network:
|
|||||||
or together with network_name to identify an existing network.
|
or together with network_name to identify an existing network.
|
||||||
segmentation_id:
|
segmentation_id:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
A segmentation identifier in the underlying cloud infrastructure.
|
A segmentation identifier in the underlying cloud infrastructure.
|
||||||
E.g. VLAN ID, GRE tunnel ID, etc..
|
E.g. VLAN ID, GRE tunnel ID, etc..
|
||||||
dhcp_enabled:
|
dhcp_enabled:
|
||||||
type: boolean
|
type: boolean
|
||||||
required: no
|
required: false
|
||||||
default: true
|
default: true
|
||||||
description: >
|
description: >
|
||||||
Indicates should DHCP service be enabled on the network or not.
|
Indicates should DHCP service be enabled on the network or not.
|
||||||
@ -257,12 +257,12 @@ tosca.nodes.network.Port:
|
|||||||
properties:
|
properties:
|
||||||
ip_address:
|
ip_address:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
Allow the user to set a static IP.
|
Allow the user to set a static IP.
|
||||||
order:
|
order:
|
||||||
type: integer
|
type: integer
|
||||||
required: no
|
required: false
|
||||||
default: 0
|
default: 0
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0
|
- greater_or_equal: 0
|
||||||
@ -270,7 +270,7 @@ tosca.nodes.network.Port:
|
|||||||
The order of the NIC on the compute instance (e.g. eth2).
|
The order of the NIC on the compute instance (e.g. eth2).
|
||||||
is_default:
|
is_default:
|
||||||
type: boolean
|
type: boolean
|
||||||
required: no
|
required: false
|
||||||
default: false
|
default: false
|
||||||
description: >
|
description: >
|
||||||
If is_default=true this port will be used for the default gateway
|
If is_default=true this port will be used for the default gateway
|
||||||
@ -278,13 +278,13 @@ tosca.nodes.network.Port:
|
|||||||
set as is_default=true.
|
set as is_default=true.
|
||||||
ip_range_start:
|
ip_range_start:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
Defines the starting IP of a range to be allocated for the compute
|
Defines the starting IP of a range to be allocated for the compute
|
||||||
instances that are associated with this Port.
|
instances that are associated with this Port.
|
||||||
ip_range_end:
|
ip_range_end:
|
||||||
type: string
|
type: string
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
Defines the ending IP of a range to be allocated for the compute
|
Defines the ending IP of a range to be allocated for the compute
|
||||||
instances that are associated with this Port.
|
instances that are associated with this Port.
|
||||||
@ -315,19 +315,19 @@ tosca.nodes.ObjectStorage:
|
|||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
required: yes
|
required: true
|
||||||
description: >
|
description: >
|
||||||
The logical name of the object store (or container).
|
The logical name of the object store (or container).
|
||||||
size:
|
size:
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
required: no
|
required: false
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0 GB
|
- greater_or_equal: 0 GB
|
||||||
description: >
|
description: >
|
||||||
The requested initial storage size.
|
The requested initial storage size.
|
||||||
maxsize:
|
maxsize:
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
required: no
|
required: false
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0 GB
|
- greater_or_equal: 0 GB
|
||||||
description: >
|
description: >
|
||||||
@ -406,22 +406,22 @@ tosca.capabilities.Container:
|
|||||||
derived_from: tosca.capabilities.Root
|
derived_from: tosca.capabilities.Root
|
||||||
properties:
|
properties:
|
||||||
num_cpus:
|
num_cpus:
|
||||||
required: no
|
required: false
|
||||||
type: integer
|
type: integer
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 1
|
- greater_or_equal: 1
|
||||||
cpu_frequency:
|
cpu_frequency:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.frequency
|
type: scalar-unit.frequency
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0.1 GHz
|
- greater_or_equal: 0.1 GHz
|
||||||
disk_size:
|
disk_size:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0 MB
|
- greater_or_equal: 0 MB
|
||||||
mem_size:
|
mem_size:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0 MB
|
- greater_or_equal: 0 MB
|
||||||
@ -499,7 +499,7 @@ tosca.capabilities.Scalable:
|
|||||||
properties:
|
properties:
|
||||||
min_instances:
|
min_instances:
|
||||||
type: integer
|
type: integer
|
||||||
required: yes
|
required: true
|
||||||
default: 1
|
default: 1
|
||||||
description: >
|
description: >
|
||||||
This property is used to indicate the minimum number of instances
|
This property is used to indicate the minimum number of instances
|
||||||
@ -507,7 +507,7 @@ tosca.capabilities.Scalable:
|
|||||||
a TOSCA orchestrator.
|
a TOSCA orchestrator.
|
||||||
max_instances:
|
max_instances:
|
||||||
type: integer
|
type: integer
|
||||||
required: yes
|
required: true
|
||||||
default: 1
|
default: 1
|
||||||
description: >
|
description: >
|
||||||
This property is used to indicate the maximum number of instances
|
This property is used to indicate the maximum number of instances
|
||||||
@ -515,7 +515,7 @@ tosca.capabilities.Scalable:
|
|||||||
a TOSCA orchestrator.
|
a TOSCA orchestrator.
|
||||||
default_instances:
|
default_instances:
|
||||||
type: integer
|
type: integer
|
||||||
required: no
|
required: false
|
||||||
description: >
|
description: >
|
||||||
An optional property that indicates the requested default number
|
An optional property that indicates the requested default number
|
||||||
of instances that should be the starting number of instances a
|
of instances that should be the starting number of instances a
|
||||||
|
@ -18,6 +18,8 @@ from toscaparser.utils.gettextutils import _
|
|||||||
class PropertyDef(object):
|
class PropertyDef(object):
|
||||||
'''TOSCA built-in Property type.'''
|
'''TOSCA built-in Property type.'''
|
||||||
|
|
||||||
|
VALID_REQUIRED_VALUES = ['true', 'false']
|
||||||
|
|
||||||
def __init__(self, name, value=None, schema=None):
|
def __init__(self, name, value=None, schema=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -31,6 +33,20 @@ class PropertyDef(object):
|
|||||||
ExceptionCollector.appendException(
|
ExceptionCollector.appendException(
|
||||||
InvalidSchemaError(message=msg))
|
InvalidSchemaError(message=msg))
|
||||||
|
|
||||||
|
if 'required' in self.schema:
|
||||||
|
required = self.schema['required']
|
||||||
|
if not isinstance(required, bool):
|
||||||
|
if required.lower() not in self.VALID_REQUIRED_VALUES:
|
||||||
|
valid_values = ', '.join(self.VALID_REQUIRED_VALUES)
|
||||||
|
msg = (_('Schema definition of "%(propname)s" has '
|
||||||
|
'"required" attribute with invalid value '
|
||||||
|
'"%(value1)s". The value must be one of '
|
||||||
|
'"%(value2)s".') % {"propname": self.name,
|
||||||
|
"value1": required,
|
||||||
|
"value2": valid_values})
|
||||||
|
ExceptionCollector.appendException(
|
||||||
|
InvalidSchemaError(message=msg))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def required(self):
|
def required(self):
|
||||||
if self.schema:
|
if self.schema:
|
||||||
|
@ -9,7 +9,7 @@ node_types:
|
|||||||
derived_from: tosca.nodes.WebApplication
|
derived_from: tosca.nodes.WebApplication
|
||||||
properties:
|
properties:
|
||||||
github_url:
|
github_url:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: location of the application on the github.
|
description: location of the application on the github.
|
||||||
default: https://github.com/sample.git
|
default: https://github.com/sample.git
|
||||||
|
@ -9,7 +9,7 @@ node_types:
|
|||||||
derived_from: tosca.nodes.WebApplication
|
derived_from: tosca.nodes.WebApplication
|
||||||
properties:
|
properties:
|
||||||
github_url:
|
github_url:
|
||||||
required: no
|
required: false
|
||||||
type: string
|
type: string
|
||||||
description: location of the application on the github.
|
description: location of the application on the github.
|
||||||
default: https://github.com/sample.git
|
default: https://github.com/sample.git
|
||||||
|
@ -234,3 +234,20 @@ class PropertyTest(TestCase):
|
|||||||
'prop', None, schema['properties']['prop'])
|
'prop', None, schema['properties']['prop'])
|
||||||
self.assertEqual(_('Schema definition of "prop" must have a "type" '
|
self.assertEqual(_('Schema definition of "prop" must have a "type" '
|
||||||
'attribute.'), str(error))
|
'attribute.'), str(error))
|
||||||
|
|
||||||
|
def test_invalid_required_value(self):
|
||||||
|
tpl_snippet = '''
|
||||||
|
properties:
|
||||||
|
prop:
|
||||||
|
type: tosca.mytesttype.Test
|
||||||
|
required: dunno
|
||||||
|
'''
|
||||||
|
schema = yamlparser.simple_parse(tpl_snippet)
|
||||||
|
error = self.assertRaises(exception.InvalidSchemaError, PropertyDef,
|
||||||
|
'prop', None, schema['properties']['prop'])
|
||||||
|
|
||||||
|
valid_values = ', '.join(PropertyDef.VALID_REQUIRED_VALUES)
|
||||||
|
expected_message = (_('Schema definition of "prop" has "required" '
|
||||||
|
'attribute with invalid value "dunno". The '
|
||||||
|
'value must be one of "%s".') % valid_values)
|
||||||
|
self.assertEqual(expected_message, str(error))
|
||||||
|
@ -288,17 +288,17 @@ class ScalarUnitNegativeTest(TestCase):
|
|||||||
derived_from: tosca.nodes.Root
|
derived_from: tosca.nodes.Root
|
||||||
properties:
|
properties:
|
||||||
cpu_frequency:
|
cpu_frequency:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.frequency
|
type: scalar-unit.frequency
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 0.1 GHz
|
- greater_or_equal: 0.1 GHz
|
||||||
disk_size:
|
disk_size:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
constraints:
|
constraints:
|
||||||
- greater_or_equal: 1 GB
|
- greater_or_equal: 1 GB
|
||||||
mem_size:
|
mem_size:
|
||||||
required: no
|
required: false
|
||||||
type: scalar-unit.size
|
type: scalar-unit.size
|
||||||
constraints:
|
constraints:
|
||||||
- in_range: [1 MiB, 1 GiB]
|
- in_range: [1 MiB, 1 GiB]
|
||||||
|
@ -353,7 +353,7 @@ class ToscaTemplateTest(TestCase):
|
|||||||
properties:
|
properties:
|
||||||
test:
|
test:
|
||||||
type: integer
|
type: integer
|
||||||
required: no
|
required: false
|
||||||
'''
|
'''
|
||||||
expected_capabilities = ['test_cap']
|
expected_capabilities = ['test_cap']
|
||||||
nodetemplates = (toscaparser.utils.yamlparser.
|
nodetemplates = (toscaparser.utils.yamlparser.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user