Merge "Update the 6th block storage example from the spec (1)"
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import os
|
||||
from translator.hot.tosca_translator import TOSCATranslator
|
||||
from translator.tests.base import TestCase
|
||||
from translator.toscalib.tosca_template import ToscaTemplate
|
||||
import translator.toscalib.utils.yamlparser
|
||||
|
||||
|
||||
class ToscaBlockStorageTest(TestCase):
|
||||
parsed_params = {'storage_snapshot_id': 'test_id',
|
||||
'storage_location': '/test', 'cpus': '1',
|
||||
'storage_size': '1'}
|
||||
|
||||
def test_translate_multi_storage(self):
|
||||
'''TOSCA template with multiple BlockStorage and Attachment.'''
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"../toscalib/tests/data/storage/"
|
||||
"tosca_multiple_blockstorage_with_attachment.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
translated_volume_attachment = []
|
||||
translate = TOSCATranslator(tosca, self.parsed_params)
|
||||
output = translate.translate()
|
||||
|
||||
expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid': {'get_resource': 'my_server'},
|
||||
'mountpoint':
|
||||
{'get_param': 'storage_location'},
|
||||
'volume_id': {'get_resource': 'my_storage'}}}
|
||||
|
||||
expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid':
|
||||
{'get_resource': 'my_server2'},
|
||||
'mountpoint':
|
||||
{'get_param': 'storage_location'},
|
||||
'volume_id': {'get_resource': 'my_storage2'}}}
|
||||
|
||||
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
|
||||
resources = output_dict.get('resources')
|
||||
translated_volume_attachment.append(resources.get('attachesto_1'))
|
||||
translated_volume_attachment.append(resources.get('attachesto_2'))
|
||||
self.assertIn(expected_resource_1, translated_volume_attachment)
|
||||
self.assertIn(expected_resource_2, translated_volume_attachment)
|
||||
@@ -193,6 +193,32 @@ class ToscaHotTranslationTest(TestCase):
|
||||
json.dumps(diff2, indent=4,
|
||||
separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_multiple_blockstorage_with_attachment(self):
|
||||
tosca_file = \
|
||||
'../toscalib/tests/data/storage/' \
|
||||
'tosca_multiple_blockstorage_with_attachment.yaml'
|
||||
hot_file1 = '../toscalib/tests/data/hot_output/storage/' \
|
||||
'hot_multiple_blockstorage_with_attachment_alt1.yaml'
|
||||
hot_file2 = '../toscalib/tests/data/hot_output/storage/' \
|
||||
'hot_multiple_blockstorage_with_attachment_alt2.yaml'
|
||||
params = {'cpus': 1,
|
||||
'storage_location': '/dev/vdc',
|
||||
'storage_size': 1,
|
||||
'storage_snapshot_id': 'ssid'}
|
||||
diff1 = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
|
||||
hot_file1,
|
||||
params)
|
||||
try:
|
||||
self.assertEqual({}, diff1, '<difference> : ' +
|
||||
json.dumps(diff1, indent=4,
|
||||
separators=(', ', ': ')))
|
||||
except Exception:
|
||||
diff2 = TranslationUtils.compare_tosca_translation_with_hot(
|
||||
tosca_file, hot_file2, params)
|
||||
self.assertEqual({}, diff2, '<difference> : ' +
|
||||
json.dumps(diff2, indent=4,
|
||||
separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_single_object_store(self):
|
||||
tosca_file = \
|
||||
'../toscalib/tests/data/storage/tosca_single_object_store.yaml'
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
heat_template_version: 2013-05-23
|
||||
|
||||
description: >
|
||||
TOSCA simple profile with 2 servers each with different attached block storage.
|
||||
|
||||
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.medium
|
||||
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
|
||||
|
||||
attachesto_1:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
instance_uuid:
|
||||
get_resource: my_server
|
||||
mountpoint:
|
||||
get_param: storage_location
|
||||
volume_id:
|
||||
get_resource: my_storage
|
||||
|
||||
my_server2:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
flavor: m1.medium
|
||||
image: fedora-amd64-heat-config
|
||||
key_name: userkey
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
depends_on:
|
||||
- my_storage2
|
||||
|
||||
my_storage2:
|
||||
type: OS::Cinder::Volume
|
||||
properties:
|
||||
size:
|
||||
get_param: storage_size
|
||||
snapshot_id:
|
||||
get_param: storage_snapshot_id
|
||||
|
||||
attachesto_2:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
instance_uuid:
|
||||
get_resource: my_server2
|
||||
mountpoint:
|
||||
get_param: storage_location
|
||||
volume_id:
|
||||
get_resource: my_storage2
|
||||
|
||||
outputs:
|
||||
server_ip_1:
|
||||
description: The private IP address of the applications first server.
|
||||
value:
|
||||
get_attr:
|
||||
- my_server
|
||||
- networks
|
||||
- private
|
||||
- 0
|
||||
server_ip_2:
|
||||
description: The private IP address of the applications second server.
|
||||
value:
|
||||
get_attr:
|
||||
- my_server2
|
||||
- networks
|
||||
- private
|
||||
- 0
|
||||
volume_id_1:
|
||||
description: The volume id of the first block storage instance.
|
||||
value:
|
||||
get_resource: my_storage
|
||||
volume_id_2:
|
||||
description: The volume id of the second block storage instance.
|
||||
value:
|
||||
get_resource: my_storage2
|
||||
@@ -0,0 +1,111 @@
|
||||
heat_template_version: 2013-05-23
|
||||
|
||||
description: >
|
||||
TOSCA simple profile with 2 servers each with different attached block storage.
|
||||
|
||||
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.medium
|
||||
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
|
||||
|
||||
attachesto_2:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
instance_uuid:
|
||||
get_resource: my_server
|
||||
mountpoint:
|
||||
get_param: storage_location
|
||||
volume_id:
|
||||
get_resource: my_storage
|
||||
|
||||
my_server2:
|
||||
type: OS::Nova::Server
|
||||
properties:
|
||||
flavor: m1.medium
|
||||
image: fedora-amd64-heat-config
|
||||
key_name: userkey
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
depends_on:
|
||||
- my_storage2
|
||||
|
||||
my_storage2:
|
||||
type: OS::Cinder::Volume
|
||||
properties:
|
||||
size:
|
||||
get_param: storage_size
|
||||
snapshot_id:
|
||||
get_param: storage_snapshot_id
|
||||
|
||||
attachesto_1:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
instance_uuid:
|
||||
get_resource: my_server2
|
||||
mountpoint:
|
||||
get_param: storage_location
|
||||
volume_id:
|
||||
get_resource: my_storage2
|
||||
|
||||
outputs:
|
||||
server_ip_1:
|
||||
description: The private IP address of the applications first server.
|
||||
value:
|
||||
get_attr:
|
||||
- my_server
|
||||
- networks
|
||||
- private
|
||||
- 0
|
||||
server_ip_2:
|
||||
description: The private IP address of the applications second server.
|
||||
value:
|
||||
get_attr:
|
||||
- my_server2
|
||||
- networks
|
||||
- private
|
||||
- 0
|
||||
volume_id_1:
|
||||
description: The volume id of the first block storage instance.
|
||||
value:
|
||||
get_resource: my_storage
|
||||
volume_id_2:
|
||||
description: The volume id of the second block storage instance.
|
||||
value:
|
||||
get_resource: my_storage2
|
||||
@@ -1,9 +1,7 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: >
|
||||
This use case demonstrates how two different TOSCA BlockStorage nodes can be
|
||||
attached to two different Compute nodes (i.e., servers) each using the
|
||||
normative AttachesTo relationship.
|
||||
TOSCA simple profile with 2 servers each with different attached block storage.
|
||||
|
||||
topology_template:
|
||||
inputs:
|
||||
@@ -14,14 +12,16 @@ topology_template:
|
||||
- valid_values: [ 1, 2, 4, 8 ]
|
||||
storage_size:
|
||||
type: integer
|
||||
default: 1 GB
|
||||
default: 1
|
||||
description: Size of the storage to be created.
|
||||
storage_snapshot_id:
|
||||
type: string
|
||||
description: Some identifier that represents an existing snapshot that should be used when creating the block storage.
|
||||
description: >
|
||||
Optional identifier for an existing snapshot to use when creating storage.
|
||||
storage_location:
|
||||
type: string
|
||||
description: The relative location (e.g., path on the file system), which provides the root location to address an attached node.
|
||||
description: >
|
||||
Block storage mount point (filesystem path).
|
||||
|
||||
node_templates:
|
||||
my_server:
|
||||
@@ -79,6 +79,15 @@ topology_template:
|
||||
snapshot_id: { get_input: storage_snapshot_id }
|
||||
|
||||
outputs:
|
||||
private_ip:
|
||||
description: Private IP address of the newly created compute instance.
|
||||
server_ip_1:
|
||||
description: The private IP address of the application's first server.
|
||||
value: { get_attribute: [my_server, private_address] }
|
||||
server_ip_2:
|
||||
description: The private IP address of the application's second server.
|
||||
value: { get_attribute: [my_server2, private_address] }
|
||||
volume_id_1:
|
||||
description: The volume id of the first block storage instance.
|
||||
value: { get_attribute: [my_storage, volume_id] }
|
||||
volume_id_2:
|
||||
description: The volume id of the second block storage instance.
|
||||
value: { get_attribute: [my_storage2, volume_id] }
|
||||
|
||||
Reference in New Issue
Block a user