Add missing storage examples from the spec

Add block storage examples 2 and 3 from the tosca yaml spec:
  Block Storage 2: Using a custom AttachesTo Relationship Type
  Block Storage 3: Using a Relationship Template of type AttachesTo

Until scalar-unit input type is supported use supported units and
add unit tests for their translation.

Also,
  - Fix a minor issue with volume attachment translation
  - Fix translating extended relationship property definition

Change-Id: I3f4ff1345e4a2cd734639fd801ea0d0b305bd475
Partial-Bug: #1474487
This commit is contained in:
Vahid Hashemian
2015-07-17 15:29:37 -07:00
parent 335f03ef98
commit 7d88184b7e
6 changed files with 305 additions and 9 deletions

View File

@@ -110,6 +110,37 @@ class ToscaHotTranslationTest(TestCase):
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_translate_blockstorage_with_custom_relationship_type(self):
tosca_file = \
'../toscalib/tests/data/storage/' \
'tosca_blockstorage_with_custom_relationship_type.yaml'
hot_file = '../toscalib/tests/data/hot_output/storage/' \
'hot_blockstorage_with_custom_relationship_type.yaml'
params = {'cpus': 1,
'storage_location': '/dev/vdc',
'storage_size': 1,
'storage_snapshot_id': 'ssid'}
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_file,
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_translate_blockstorage_with_relationship_template(self):
tosca_file = \
'../toscalib/tests/data/storage/' \
'tosca_blockstorage_with_relationship_template.yaml'
hot_file = '../toscalib/tests/data/hot_output/storage/' \
'hot_blockstorage_with_relationship_template.yaml'
params = {'cpus': 1,
'storage_location': '/dev/vdc',
'storage_size': 1}
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_file,
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_translate_blockstorage_with_attachment_notation1(self):
tosca_file = \
'../toscalib/tests/data/storage/' \

View File

@@ -110,11 +110,14 @@ class NodeTemplate(EntityTemplate):
self.relationship_tpl.append(tpl)
found_relationship_tpl = True
# create relationship template object.
rel_prfx = self.type_definition.RELATIONSHIP_PREFIX
if not found_relationship_tpl:
if isinstance(relationship, dict):
relationship = relationship.get('type')
rel_prfx = self.type_definition.RELATIONSHIP_PREFIX
if not relationship.startswith(rel_prfx):
if self.available_rel_types and \
relationship in self.available_rel_types.keys():
pass
elif not relationship.startswith(rel_prfx):
relationship = rel_prfx + relationship
for rtype in self.type_definition.relationship.keys():
if rtype.type == relationship:
@@ -125,13 +128,16 @@ class NodeTemplate(EntityTemplate):
if relationship in self.available_rel_types.keys():
rel_type_def = self.available_rel_types.\
get(relationship)
if 'derived_from' in rel_type_def \
and rtype.type == \
rel_type_def.get('derived_from'):
explicit_relation[rtype] = related_tpl
related_tpl.\
_add_relationship_template(req,
rtype.type)
if 'derived_from' in rel_type_def:
super_type = \
rel_type_def.get('derived_from')
if not super_type.startswith(rel_prfx):
super_type = rel_prfx + super_type
if rtype.type == super_type:
explicit_relation[rtype] = related_tpl
related_tpl.\
_add_relationship_template(
req, rtype.type)
return explicit_relation
def _add_relationship_template(self, requirement, rtype):

View File

@@ -0,0 +1,70 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with server and attached block storage using a custom
AttachesTo Relationship Type.
parameters:
cpus:
type: number
description: Number of CPUs for the server.
default: 1
constraints:
- allowed_values:
- 1
- 2
- 4
- 8
storage_location:
type: string
description: Block storage mount point (filesystem path).
default: /dev/vdc
storage_size:
type: number
description: Size of the storage to be created.
default: 1
storage_snapshot_id:
type: string
description: Optional identifier for an existing snapshot to use when creating storage.
default: ssid
resources:
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: fedora-amd64-heat-config
key_name: userkey
user_data_format: SOFTWARE_CONFIG
depends_on:
- my_storage
my_storage:
type: OS::Cinder::Volume
properties:
size:
get_param: storage_size
snapshot_id:
get_param: storage_snapshot_id
mycustomattachesto_1:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid:
get_resource: my_server
volume_id:
get_resource: my_storage
outputs:
private_ip:
description: The private IP address of the newly created compute instance.
value:
get_attr:
- my_server
- networks
- private
- 0
volume_id:
description: The volume id of the block storage instance.
value:
get_resource: my_storage

View File

@@ -0,0 +1,66 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with server and attached block storage using a named
Relationship Template for the storage attachment.
parameters:
cpus:
type: number
description: Number of CPUs for the server.
default: 1
constraints:
- allowed_values:
- 1
- 2
- 4
- 8
storage_location:
type: string
description: Block storage mount point (filesystem path).
default: /dev/vdc
storage_size:
type: number
description: Size of the storage to be created.
default: 1
resources:
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: fedora-amd64-heat-config
key_name: userkey
user_data_format: SOFTWARE_CONFIG
depends_on:
- my_storage
my_storage:
type: OS::Cinder::Volume
properties:
size:
get_param: storage_size
storage_attachment_1:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid:
get_resource: my_server
mountpoint:
get_input: storage_location
volume_id:
get_resource: my_storage
outputs:
private_ip:
description: The private IP address of the newly created compute instance.
value:
get_attr:
- my_server
- networks
- private
- 0
volume_id:
description: The volume id of the block storage instance.
value:
get_resource: my_storage

View File

@@ -0,0 +1,64 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with server and attached block storage using a custom AttachesTo Relationship Type.
relationship_types:
MyCustomAttachesTo:
derived_from: AttachesTo
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
storage_size:
type: integer
description: Size of the storage to be created.
default: 1
storage_snapshot_id:
type: string
description: >
Optional identifier for an existing snapshot to use when creating storage.
storage_location:
type: string
description: Block storage mount point (filesystem path).
node_templates:
my_server:
type: Compute
capabilities:
host:
properties:
disk_size: 10 GB
num_cpus: { get_input: cpus }
mem_size: 4 MB
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
requirements:
- local_storage:
node: my_storage
# Declare custom AttachesTo type using the 'relationship' keyword
relationship:
type: MyCustomAttachesTo
properties:
location: { get_input: storage_location }
my_storage:
type: BlockStorage
properties:
size: { get_input: storage_size }
snapshot_id: { get_input: storage_snapshot_id }
outputs:
private_ip:
description: The private IP address of the newly created compute instance.
value: { get_attribute: [my_server, private_address] }
volume_id:
description: The volume id of the block storage instance.
value: { get_attribute: [my_storage, volume_id] }

View File

@@ -0,0 +1,59 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with server and attached block storage using a named Relationship Template for the storage attachment.
topology_template:
inputs:
cpus:
type: integer
description: Number of CPUs for the server.
constraints:
- valid_values: [ 1, 2, 4, 8 ]
storage_size:
type: integer
description: Size of the storage to be created.
default: 1
storage_location:
type: string
description: Block storage mount point (filesystem path).
node_templates:
my_server:
type: Compute
capabilities:
host:
properties:
disk_size: 10 GB
num_cpus: { get_input: cpus }
mem_size: 4 MB
os:
properties:
architecture: x86_64
type: Linux
distribution: Fedora
version: 18.0
requirements:
- local_storage:
node: my_storage
# Declare template to use with 'relationship' keyword
relationship: storage_attachment
my_storage:
type: BlockStorage
properties:
size: { get_input: storage_size }
relationship_templates:
storage_attachment:
type: AttachesTo
properties:
location: { get_input: storage_location }
outputs:
private_ip:
description: The private IP address of the newly created compute instance.
value: { get_attribute: [my_server, private_address] }
volume_id:
description: The volume id of the block storage instance.
value: { get_attribute: [my_storage, volume_id] }