Merge "Replace ip_address attribute with public_address and private_address"
This commit is contained in:
commit
65af5cb78d
49
translator/hot/tests/test_translate_outputs.py
Normal file
49
translator/hot/tests/test_translate_outputs.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# 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.toscalib.tests.base import TestCase
|
||||||
|
from translator.toscalib.tosca_template import ToscaTemplate
|
||||||
|
import translator.toscalib.utils.yamlparser
|
||||||
|
|
||||||
|
|
||||||
|
class ToscaTemplateOutputTest(TestCase):
|
||||||
|
|
||||||
|
def test_translate_output(self):
|
||||||
|
tosca_tpl = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
"../../tests/data/tosca_elk.yaml")
|
||||||
|
tosca = ToscaTemplate(tosca_tpl)
|
||||||
|
translate = TOSCATranslator(tosca, [])
|
||||||
|
hot_translation = translate.translate()
|
||||||
|
|
||||||
|
expected_output = {'nodejs_url':
|
||||||
|
{'description': 'URL for the nodejs '
|
||||||
|
'server, http://<IP>:3000',
|
||||||
|
'value':
|
||||||
|
{'get_attr':
|
||||||
|
['app_server', 'networks', 'private', 0]}},
|
||||||
|
'mongodb_url':
|
||||||
|
{'description': 'URL for the mongodb server.',
|
||||||
|
'value':
|
||||||
|
{'get_attr':
|
||||||
|
['mongo_server', 'networks', 'private', 0]}}}
|
||||||
|
|
||||||
|
hot_translation_dict = \
|
||||||
|
translator.toscalib.utils.yamlparser.simple_parse(hot_translation)
|
||||||
|
|
||||||
|
outputs = hot_translation_dict.get('outputs')
|
||||||
|
for resource_name in outputs:
|
||||||
|
translated_value = outputs.get(resource_name)
|
||||||
|
expected_value = expected_output.get(resource_name)
|
||||||
|
self.assertEqual(translated_value, expected_value)
|
@ -169,6 +169,12 @@ class ToscaCompute(HotResource):
|
|||||||
# Convert from a TOSCA attribute for a nodetemplate to a HOT
|
# Convert from a TOSCA attribute for a nodetemplate to a HOT
|
||||||
# attribute for the matching resource. Unless there is additional
|
# attribute for the matching resource. Unless there is additional
|
||||||
# runtime support, this should be a one to one mapping.
|
# runtime support, this should be a one to one mapping.
|
||||||
if attribute == 'ip_address':
|
|
||||||
attr['get_attr'] = [self.name, 'networks', '"private"', 0]
|
# Note: We treat private and public IP addresses equally, but
|
||||||
|
# this will change in the future when TOSCA starts to support
|
||||||
|
# multiple private/public IP addresses.
|
||||||
|
if attribute == 'private_address' or \
|
||||||
|
attribute == 'public_address':
|
||||||
|
attr['get_attr'] = [self.name, 'networks', 'private', 0]
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
from translator.hot.syntax.hot_output import HotOutput
|
from translator.hot.syntax.hot_output import HotOutput
|
||||||
|
|
||||||
TOSCA_TO_HOT_GET_ATTRS = {'ip_address': 'first_address'}
|
|
||||||
|
|
||||||
|
|
||||||
class TranslateOutputs():
|
class TranslateOutputs():
|
||||||
'''Translate TOSCA Outputs to Heat Outputs.'''
|
'''Translate TOSCA Outputs to Heat Outputs.'''
|
||||||
|
@ -49,9 +49,9 @@ node_templates:
|
|||||||
snapshot_id: { get_input: storage_snapshot_id }
|
snapshot_id: { get_input: storage_snapshot_id }
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
public_ip:
|
private_ip:
|
||||||
description: Public IP address of the newly created compute instance.
|
description: Private IP address of the newly created compute instance.
|
||||||
value: { get_attribute: [my_server, ip_address] }
|
value: { get_attribute: [my_server, private_address] }
|
||||||
volume_id:
|
volume_id:
|
||||||
description: The volume id of the block storage instance.
|
description: The volume id of the block storage instance.
|
||||||
value: { get_attribute: [my_storage, volume_id] }
|
value: { get_attribute: [my_storage, volume_id] }
|
||||||
|
@ -44,7 +44,7 @@ node_templates:
|
|||||||
implementation: nodejs/config.sh
|
implementation: nodejs/config.sh
|
||||||
inputs:
|
inputs:
|
||||||
github_url: { get_property: [ SELF, github_url ] }
|
github_url: { get_property: [ SELF, github_url ] }
|
||||||
mongodb_ip: { get_attribute: [mongo_server, ip_address] }
|
mongodb_ip: { get_attribute: [mongo_server, private_address] }
|
||||||
start: nodejs/start.sh
|
start: nodejs/start.sh
|
||||||
|
|
||||||
mongo_dbms:
|
mongo_dbms:
|
||||||
@ -59,7 +59,7 @@ node_templates:
|
|||||||
configure:
|
configure:
|
||||||
implementation: mongodb/config.sh
|
implementation: mongodb/config.sh
|
||||||
inputs:
|
inputs:
|
||||||
mongodb_ip: { get_attribute: [mongo_server, ip_address] }
|
mongodb_ip: { get_attribute: [mongo_server, private_address] }
|
||||||
start: mongodb/start.sh
|
start: mongodb/start.sh
|
||||||
|
|
||||||
mongo_server:
|
mongo_server:
|
||||||
@ -78,8 +78,8 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
nodejs_url:
|
nodejs_url:
|
||||||
description: URL for the nodejs server, http://<IP>:3000
|
description: URL for the nodejs server, http://<IP>:3000
|
||||||
value: { get_attribute: [app_server, ip_address] }
|
value: { get_attribute: [app_server, private_address] }
|
||||||
mongodb_url:
|
mongodb_url:
|
||||||
description: URL for the mongodb server.
|
description: URL for the mongodb server.
|
||||||
value: { get_attribute: [mongo_server, ip_address] }
|
value: { get_attribute: [mongo_server, private_address] }
|
||||||
|
|
||||||
|
@ -72,6 +72,6 @@ node_templates:
|
|||||||
snapshot_id: { get_input: storage_snapshot_id }
|
snapshot_id: { get_input: storage_snapshot_id }
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
public_ip:
|
private_ip:
|
||||||
description: Public IP address of the newly created compute instance.
|
description: Private IP address of the newly created compute instance.
|
||||||
value: { get_attribute: [my_server, ip_address] }
|
value: { get_attribute: [my_server, private_address] }
|
||||||
|
@ -47,12 +47,12 @@ class ToscaBlockStorageTest(TestCase):
|
|||||||
self.assertEqual(translated_value, expected_value)
|
self.assertEqual(translated_value, expected_value)
|
||||||
|
|
||||||
outputs = output_dict['outputs']
|
outputs = output_dict['outputs']
|
||||||
self.assertIn('public_ip', outputs)
|
self.assertIn('private_ip', outputs)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'Public IP address of the newly created compute instance.',
|
'Private IP address of the newly created compute instance.',
|
||||||
outputs['public_ip']['description'])
|
outputs['private_ip']['description'])
|
||||||
self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]},
|
self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]},
|
||||||
outputs['public_ip']['value'])
|
outputs['private_ip']['value'])
|
||||||
self.assertIn('volume_id', outputs)
|
self.assertIn('volume_id', outputs)
|
||||||
self.assertEqual('The volume id of the block storage instance.',
|
self.assertEqual('The volume id of the block storage instance.',
|
||||||
outputs['volume_id']['description'])
|
outputs['volume_id']['description'])
|
||||||
|
@ -51,14 +51,10 @@ tosca.nodes.Compute:
|
|||||||
- greater_or_equal: 0 MB
|
- greater_or_equal: 0 MB
|
||||||
description: >
|
description: >
|
||||||
Size of memory, available to applications running on the Compute node.
|
Size of memory, available to applications running on the Compute node.
|
||||||
ip_address:
|
|
||||||
required: no
|
|
||||||
type: string
|
|
||||||
description: >
|
|
||||||
The primary IP address assigned by the cloud provider that applications
|
|
||||||
may use to access the Compute node.
|
|
||||||
attributes:
|
attributes:
|
||||||
ip_address:
|
private_address:
|
||||||
|
type: string
|
||||||
|
public_address:
|
||||||
type: string
|
type: string
|
||||||
capabilities:
|
capabilities:
|
||||||
host:
|
host:
|
||||||
|
@ -106,8 +106,8 @@ class GetAttribute(Function):
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
* { get_attribute: [ server, ip_address ] }
|
* { get_attribute: [ server, private_address ] }
|
||||||
* { get_attribute: [ HOST, ip_address ] }
|
* { get_attribute: [ HOST, private_address ] }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
@ -105,4 +105,4 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
website_url:
|
website_url:
|
||||||
description: IP address for Wordpress wiki.
|
description: IP address for Wordpress wiki.
|
||||||
value: { get_attribute: [server, ip_address] }
|
value: { get_attribute: [server, private_address] }
|
||||||
|
@ -18,7 +18,7 @@ node_templates:
|
|||||||
configure:
|
configure:
|
||||||
implementation: configure.sh
|
implementation: configure.sh
|
||||||
inputs:
|
inputs:
|
||||||
ip_address: { get_attribute: [ HOST, ip_address ] }
|
ip_address: { get_attribute: [ HOST, private_address ] }
|
||||||
|
|
||||||
database:
|
database:
|
||||||
type: tosca.nodes.Database
|
type: tosca.nodes.Database
|
||||||
@ -29,4 +29,4 @@ node_templates:
|
|||||||
configure:
|
configure:
|
||||||
implementation: configure.sh
|
implementation: configure.sh
|
||||||
inputs:
|
inputs:
|
||||||
ip_address: { get_attribute: [ HOST, ip_address ] }
|
ip_address: { get_attribute: [ HOST, private_address ] }
|
||||||
|
@ -13,4 +13,4 @@ node_templates:
|
|||||||
configure:
|
configure:
|
||||||
implementation: configure.sh
|
implementation: configure.sh
|
||||||
inputs:
|
inputs:
|
||||||
ip_address: { get_attribute: [ HOST, ip_address ] }
|
ip_address: { get_attribute: [ HOST, private_address ] }
|
||||||
|
@ -11,4 +11,4 @@ node_templates:
|
|||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
ip_address:
|
ip_address:
|
||||||
value: { get_attribute: [ HOST, ip_address ] }
|
value: { get_attribute: [ HOST, private_address ] }
|
||||||
|
@ -22,4 +22,4 @@ node_templates:
|
|||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
ip_address:
|
ip_address:
|
||||||
value: { get_attribute: [ unknown_node_template, ip_address ] }
|
value: { get_attribute: [ unknown_node_template, private_address ] }
|
||||||
|
@ -29,4 +29,4 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
server_address:
|
server_address:
|
||||||
description: IP address of server instance.
|
description: IP address of server instance.
|
||||||
value: { get_attribute: [server, ip_address] }
|
value: { get_attribute: [server, private_address] }
|
||||||
|
@ -27,4 +27,4 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
server_address:
|
server_address:
|
||||||
description: IP address of server instance.
|
description: IP address of server instance.
|
||||||
value: { get_property: [server, ip_address] }
|
value: { get_property: [server, private_address] }
|
||||||
|
@ -29,4 +29,4 @@ node_template:
|
|||||||
outputs:
|
outputs:
|
||||||
server_address:
|
server_address:
|
||||||
description: IP address of server instance.
|
description: IP address of server instance.
|
||||||
value: { get_property: [server, ip_address] }
|
value: { get_property: [server, private_address] }
|
||||||
|
@ -27,7 +27,7 @@ dsl_definitions:
|
|||||||
pre_configure_source:
|
pre_configure_source:
|
||||||
implementation: collectd/pre_configure_source.py
|
implementation: collectd/pre_configure_source.py
|
||||||
inputs:
|
inputs:
|
||||||
host: { get_attribute: [ TARGET, ip_address ]}
|
host: { get_attribute: [ TARGET, private_address ]}
|
||||||
tosca.interfaces.relationship.Configure:
|
tosca.interfaces.relationship.Configure:
|
||||||
pre_configure_target:
|
pre_configure_target:
|
||||||
implementation: collectd/pre_configure_target.py
|
implementation: collectd/pre_configure_target.py
|
||||||
@ -36,7 +36,7 @@ dsl_definitions:
|
|||||||
pre_configure_source:
|
pre_configure_source:
|
||||||
implementation: rsyslog/pre_configure_source.py
|
implementation: rsyslog/pre_configure_source.py
|
||||||
inputs:
|
inputs:
|
||||||
host: { get_attribute: [ TARGET, ip_address ]}
|
host: { get_attribute: [ TARGET, private_address ]}
|
||||||
inputs:
|
inputs:
|
||||||
my_cpus:
|
my_cpus:
|
||||||
type: integer
|
type: integer
|
||||||
@ -109,7 +109,7 @@ node_templates:
|
|||||||
pre_configure_source:
|
pre_configure_source:
|
||||||
implementation: pre_configure_source.py
|
implementation: pre_configure_source.py
|
||||||
inputs:
|
inputs:
|
||||||
host: { get_attribute: [ TARGET, ip_address ] }
|
host: { get_attribute: [ TARGET, private_address ] }
|
||||||
port: { get_attribute: [ TARGET, port ] }
|
port: { get_attribute: [ TARGET, port ] }
|
||||||
interfaces:
|
interfaces:
|
||||||
tosca.interfaces.node.lifecycle.Standard:
|
tosca.interfaces.node.lifecycle.Standard:
|
||||||
@ -199,19 +199,19 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
nodejs_url:
|
nodejs_url:
|
||||||
description: URL for the nodejs server.
|
description: URL for the nodejs server.
|
||||||
value: { get_attribute: [ app_server, ip_address ] }
|
value: { get_attribute: [ app_server, private_address ] }
|
||||||
mongodb_url:
|
mongodb_url:
|
||||||
description: URL for the mongodb server.
|
description: URL for the mongodb server.
|
||||||
value: { get_attribute: [ mongo_server, ip_address ] }
|
value: { get_attribute: [ mongo_server, private_address ] }
|
||||||
mongodb_port:
|
mongodb_port:
|
||||||
description: Port for the mongodb server.
|
description: Port for the mongodb server.
|
||||||
value: { get_property: [ mongo_dbms, dbms_port ] }
|
value: { get_property: [ mongo_dbms, dbms_port ] }
|
||||||
elasticsearch_url:
|
elasticsearch_url:
|
||||||
description: URL for the elasticsearch server.
|
description: URL for the elasticsearch server.
|
||||||
value: { get_attribute: [ elasticsearch_server, ip_address ] }
|
value: { get_attribute: [ elasticsearch_server, private_address ] }
|
||||||
logstash_url:
|
logstash_url:
|
||||||
description: URL for the logstash server.
|
description: URL for the logstash server.
|
||||||
value: { get_attribute: [ logstash_server, ip_address ] }
|
value: { get_attribute: [ logstash_server, private_address ] }
|
||||||
kibana_url:
|
kibana_url:
|
||||||
description: URL for the kibana server.
|
description: URL for the kibana server.
|
||||||
value: { get_attribute: [ kibana_server, ip_address ] }
|
value: { get_attribute: [ kibana_server, private_address ] }
|
||||||
|
@ -111,4 +111,4 @@ node_templates:
|
|||||||
outputs:
|
outputs:
|
||||||
website_url:
|
website_url:
|
||||||
description: URL for Wordpress wiki.
|
description: URL for Wordpress wiki.
|
||||||
value: { get_attribute: [server, ip_address] }
|
value: { get_attribute: [server, private_address] }
|
||||||
|
@ -112,7 +112,8 @@ class GetAttributeTest(TestCase):
|
|||||||
x for x in tpl.outputs if x.name == 'website_url'][0]
|
x for x in tpl.outputs if x.name == 'website_url'][0]
|
||||||
self.assertIsInstance(website_url_output.value, functions.GetAttribute)
|
self.assertIsInstance(website_url_output.value, functions.GetAttribute)
|
||||||
self.assertEqual('server', website_url_output.value.node_template_name)
|
self.assertEqual('server', website_url_output.value.node_template_name)
|
||||||
self.assertEqual('ip_address', website_url_output.value.attribute_name)
|
self.assertEqual('private_address',
|
||||||
|
website_url_output.value.attribute_name)
|
||||||
|
|
||||||
def test_get_attribute_invalid_args(self):
|
def test_get_attribute_invalid_args(self):
|
||||||
expected_msg = 'Expected arguments: node-template-name, attribute-name'
|
expected_msg = 'Expected arguments: node-template-name, attribute-name'
|
||||||
|
@ -99,13 +99,12 @@ class ToscaDefTest(TestCase):
|
|||||||
|
|
||||||
def test_properties_def(self):
|
def test_properties_def(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
['disk_size', 'ip_address', 'mem_size',
|
['disk_size', 'mem_size', 'num_cpus'],
|
||||||
'num_cpus'],
|
|
||||||
sorted(compute_type.get_properties_def().keys()))
|
sorted(compute_type.get_properties_def().keys()))
|
||||||
|
|
||||||
def test_attributes_def(self):
|
def test_attributes_def(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
['ip_address'],
|
['private_address', 'public_address'],
|
||||||
sorted([p.name for p in compute_type.attributes_def]))
|
sorted([p.name for p in compute_type.attributes_def]))
|
||||||
|
|
||||||
def test_requirements(self):
|
def test_requirements(self):
|
||||||
|
@ -74,7 +74,7 @@ class ToscaTemplateValidationTest(TestCase):
|
|||||||
outputs:
|
outputs:
|
||||||
server_address:
|
server_address:
|
||||||
description: IP address of server instance.
|
description: IP address of server instance.
|
||||||
values: { get_property: [server, ip_address] }
|
values: { get_property: [server, private_address] }
|
||||||
'''
|
'''
|
||||||
outputs = (translator.toscalib.utils.yamlparser.
|
outputs = (translator.toscalib.utils.yamlparser.
|
||||||
simple_parse(tpl_snippet)['outputs'])
|
simple_parse(tpl_snippet)['outputs'])
|
||||||
@ -92,7 +92,7 @@ class ToscaTemplateValidationTest(TestCase):
|
|||||||
outputs:
|
outputs:
|
||||||
server_address:
|
server_address:
|
||||||
descriptions: IP address of server instance.
|
descriptions: IP address of server instance.
|
||||||
value: { get_property: [server, ip_address] }
|
value: { get_property: [server, private_address] }
|
||||||
'''
|
'''
|
||||||
outputs = (translator.toscalib.utils.yamlparser.
|
outputs = (translator.toscalib.utils.yamlparser.
|
||||||
simple_parse(tpl_snippet)['outputs'])
|
simple_parse(tpl_snippet)['outputs'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user