Merge "Update the first block storage example to the spec (1)"
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
from testtools.testcase import skip
|
||||
from translator.hot.tosca_translator import TOSCATranslator
|
||||
from translator.tests.base import TestCase
|
||||
from translator.toscalib.tosca_template import ToscaTemplate
|
||||
@@ -23,113 +22,6 @@ class ToscaBlockStorageTest(TestCase):
|
||||
'storage_location': '/test', 'cpus': '1',
|
||||
'storage_size': '1'}
|
||||
|
||||
def test_translate_single_storage(self):
|
||||
'''TOSCA template with single BlockStorage and Attachment.'''
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"../toscalib/tests/data/storage/"
|
||||
"tosca_blockstorage_with_attachment.yaml")
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
translate = TOSCATranslator(tosca, self.parsed_params)
|
||||
output = translate.translate()
|
||||
|
||||
expected_resouce = {'attachesto_1':
|
||||
{'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid': {'get_resource': 'my_server'},
|
||||
'mountpoint': {'get_param': 'storage_location'},
|
||||
'volume_id': {'get_resource': 'my_storage'}}}}
|
||||
|
||||
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
|
||||
resources = output_dict.get('resources')
|
||||
translated_value = resources.get('attachesto_1')
|
||||
expected_value = expected_resouce.get('attachesto_1')
|
||||
self.assertEqual(translated_value, expected_value)
|
||||
|
||||
outputs = output_dict['outputs']
|
||||
self.assertIn('private_ip', outputs)
|
||||
self.assertEqual(
|
||||
'Private IP address of the newly created compute instance.',
|
||||
outputs['private_ip']['description'])
|
||||
self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]},
|
||||
outputs['private_ip']['value'])
|
||||
self.assertIn('volume_id', outputs)
|
||||
self.assertEqual('The volume id of the block storage instance.',
|
||||
outputs['volume_id']['description'])
|
||||
self.assertEqual({'get_resource': 'my_storage'},
|
||||
outputs['volume_id']['value'])
|
||||
|
||||
def test_translate_storage_notation1(self):
|
||||
'''TOSCA template with single BlockStorage and Attachment.'''
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"../toscalib/tests/data/storage/"
|
||||
"tosca_blockstorage_with_attachment_notation1.yaml")
|
||||
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
translate = TOSCATranslator(tosca, self.parsed_params)
|
||||
output = translate.translate()
|
||||
|
||||
expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid':
|
||||
{'get_resource': 'my_web_app_tier_1'},
|
||||
'mountpoint': '/default_location',
|
||||
'volume_id': {'get_resource': 'my_storage'}}}
|
||||
expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid':
|
||||
{'get_resource': 'my_web_app_tier_2'},
|
||||
'mountpoint': '/some_other_data_location',
|
||||
'volume_id': {'get_resource': 'my_storage'}}}
|
||||
|
||||
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
|
||||
resources = output_dict.get('resources')
|
||||
self.assertIn('myattachesto_1', resources.keys())
|
||||
self.assertIn('myattachesto_2', resources.keys())
|
||||
self.assertIn(expected_resource_1, resources.values())
|
||||
self.assertIn(expected_resource_2, resources.values())
|
||||
|
||||
@skip("will fix in the next patch")
|
||||
def test_translate_storage_notation2(self):
|
||||
'''TOSCA template with single BlockStorage and Attachment.'''
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"../toscalib/tests/data/storage/"
|
||||
"tosca_blockstorage_with_attachment_notation2.yaml")
|
||||
|
||||
tosca = ToscaTemplate(tosca_tpl)
|
||||
translate = TOSCATranslator(tosca, self.parsed_params)
|
||||
output = translate.translate()
|
||||
|
||||
expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid':
|
||||
{'get_resource': 'my_web_app_tier_1'},
|
||||
'mountpoint': '/my_data_location',
|
||||
'volume_id': {'get_resource': 'my_storage'}}}
|
||||
expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
|
||||
'properties':
|
||||
{'instance_uuid':
|
||||
{'get_resource': 'my_web_app_tier_2'},
|
||||
'mountpoint': '/some_other_data_location',
|
||||
'volume_id': {'get_resource': 'my_storage'}}}
|
||||
|
||||
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
|
||||
|
||||
resources = output_dict.get('resources')
|
||||
# Resource name suffix depends on nodetemplates order in dict, which is
|
||||
# not certain. So we have two possibilities of resources name.
|
||||
if resources.get('storage_attachesto_1_1'):
|
||||
self.assertIn('storage_attachesto_1_1', resources.keys())
|
||||
self.assertIn('storage_attachesto_2_2', resources.keys())
|
||||
else:
|
||||
self.assertIn('storage_attachesto_1_2', resources.keys())
|
||||
self.assertIn('storage_attachesto_2_1', resources.keys())
|
||||
|
||||
self.assertIn(expected_resource_1, resources.values())
|
||||
self.assertIn(expected_resource_2, resources.values())
|
||||
|
||||
def test_translate_multi_storage(self):
|
||||
'''TOSCA template with multiple BlockStorage and Attachment.'''
|
||||
tosca_tpl = os.path.join(
|
||||
|
||||
@@ -94,6 +94,22 @@ class ToscaHotTranslationTest(TestCase):
|
||||
self.assertEqual({}, diff, '<difference> : ' +
|
||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||
|
||||
def test_hot_translate_blockstorage_with_attachment(self):
|
||||
tosca_file = \
|
||||
'../toscalib/tests/data/storage/' \
|
||||
'tosca_blockstorage_with_attachment.yaml'
|
||||
hot_file = '../toscalib/tests/data/hot_output/storage/' \
|
||||
'hot_blockstorage_with_attachment.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_attachment_notation1(self):
|
||||
tosca_file = \
|
||||
'../toscalib/tests/data/storage/' \
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
heat_template_version: 2013-05-23
|
||||
|
||||
description: >
|
||||
TOSCA simple profile with server and attached block storage using the normative
|
||||
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
|
||||
|
||||
attachesto_1:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
instance_uuid:
|
||||
get_resource: my_server
|
||||
mountpoint:
|
||||
get_param: 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
|
||||
@@ -1,10 +1,10 @@
|
||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||
|
||||
description: >
|
||||
Demonstrates how to attach a TOSCA BlockStorage node to a Compute node using
|
||||
the normative AttachesTo relationship.
|
||||
TOSCA simple profile with server and attached block storage using the normative AttachesTo Relationship Type.
|
||||
|
||||
topology_template:
|
||||
|
||||
inputs:
|
||||
cpus:
|
||||
type: integer
|
||||
@@ -13,48 +13,48 @@ topology_template:
|
||||
- valid_values: [ 1, 2, 4, 8 ]
|
||||
storage_size:
|
||||
type: integer
|
||||
default: 1 GB
|
||||
description: Size of the storage to be created.
|
||||
default: 1 GB
|
||||
storage_snapshot_id:
|
||||
type: string
|
||||
description: >
|
||||
Some identifier that represents an existing snapshot that should be used when creating the block storage.
|
||||
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:
|
||||
type: tosca.nodes.Compute
|
||||
type: Compute
|
||||
capabilities:
|
||||
host:
|
||||
properties:
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096 MB
|
||||
mem_size: 4096 kB
|
||||
os:
|
||||
properties:
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: Fedora
|
||||
type: linux
|
||||
distribution: fedora
|
||||
version: 18.0
|
||||
requirements:
|
||||
- local_storage:
|
||||
node: my_storage
|
||||
relationship:
|
||||
type: AttachesTo
|
||||
type: AttachesTo
|
||||
properties:
|
||||
location: { get_input: storage_location }
|
||||
|
||||
my_storage:
|
||||
type: tosca.nodes.BlockStorage
|
||||
type: BlockStorage
|
||||
properties:
|
||||
size: { get_input: storage_size }
|
||||
snapshot_id: { get_input: storage_snapshot_id }
|
||||
|
||||
outputs:
|
||||
private_ip:
|
||||
description: Private IP address of the newly created compute instance.
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user