Replace ip_address attribute with public_address and private_address

Replace the attribute ip_address with public_address and
private_address where applicable. Current implementation is to
support private_address and public_address interchangeably until
TOSCA support for multiple (private and public) IP addresses is
implemented in the specification.

Change-Id: I020160d3e4f01bfc2214a2dbfa2cb4c1e3d49ce0
Closes-Bug: #1432085
This commit is contained in:
Vahid Hashemian 2015-03-17 15:31:58 -07:00
parent 01f85e17b8
commit 26cc4ecdbe
23 changed files with 100 additions and 51 deletions

View File

View 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)

View File

@ -165,6 +165,12 @@ class ToscaCompute(HotResource):
# Convert from a TOSCA attribute for a nodetemplate to a HOT
# attribute for the matching resource. Unless there is additional
# 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

View File

@ -13,8 +13,6 @@
from translator.hot.syntax.hot_output import HotOutput
TOSCA_TO_HOT_GET_ATTRS = {'ip_address': 'first_address'}
class TranslateOutputs():
'''Translate TOSCA Outputs to Heat Outputs.'''

View File

@ -49,9 +49,9 @@ node_templates:
snapshot_id: { get_input: storage_snapshot_id }
outputs:
public_ip:
description: Public IP address of the newly created compute instance.
value: { get_attribute: [my_server, ip_address] }
private_ip:
description: 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

@ -44,7 +44,7 @@ node_templates:
implementation: nodejs/config.sh
inputs:
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
mongo_dbms:
@ -59,7 +59,7 @@ node_templates:
configure:
implementation: mongodb/config.sh
inputs:
mongodb_ip: { get_attribute: [mongo_server, ip_address] }
mongodb_ip: { get_attribute: [mongo_server, private_address] }
start: mongodb/start.sh
mongo_server:
@ -78,8 +78,8 @@ node_templates:
outputs:
nodejs_url:
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:
description: URL for the mongodb server.
value: { get_attribute: [mongo_server, ip_address] }
value: { get_attribute: [mongo_server, private_address] }

View File

@ -72,6 +72,6 @@ node_templates:
snapshot_id: { get_input: storage_snapshot_id }
outputs:
public_ip:
description: Public IP address of the newly created compute instance.
value: { get_attribute: [my_server, ip_address] }
private_ip:
description: Private IP address of the newly created compute instance.
value: { get_attribute: [my_server, private_address] }

View File

@ -47,12 +47,12 @@ class ToscaBlockStorageTest(TestCase):
self.assertEqual(translated_value, expected_value)
outputs = output_dict['outputs']
self.assertIn('public_ip', outputs)
self.assertIn('private_ip', outputs)
self.assertEqual(
'Public IP address of the newly created compute instance.',
outputs['public_ip']['description'])
'Private IP address of the newly created compute instance.',
outputs['private_ip']['description'])
self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]},
outputs['public_ip']['value'])
outputs['private_ip']['value'])
self.assertIn('volume_id', outputs)
self.assertEqual('The volume id of the block storage instance.',
outputs['volume_id']['description'])

View File

@ -51,14 +51,10 @@ tosca.nodes.Compute:
- greater_or_equal: 0 MB
description: >
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:
ip_address:
private_address:
type: string
public_address:
type: string
capabilities:
host:

View File

@ -106,8 +106,8 @@ class GetAttribute(Function):
Examples:
* { get_attribute: [ server, ip_address ] }
* { get_attribute: [ HOST, ip_address ] }
* { get_attribute: [ server, private_address ] }
* { get_attribute: [ HOST, private_address ] }
"""
def validate(self):

View File

@ -105,4 +105,4 @@ node_templates:
outputs:
website_url:
description: IP address for Wordpress wiki.
value: { get_attribute: [server, ip_address] }
value: { get_attribute: [server, private_address] }

View File

@ -18,7 +18,7 @@ node_templates:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, ip_address ] }
ip_address: { get_attribute: [ HOST, private_address ] }
database:
type: tosca.nodes.Database
@ -29,4 +29,4 @@ node_templates:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, ip_address ] }
ip_address: { get_attribute: [ HOST, private_address ] }

View File

@ -13,4 +13,4 @@ node_templates:
configure:
implementation: configure.sh
inputs:
ip_address: { get_attribute: [ HOST, ip_address ] }
ip_address: { get_attribute: [ HOST, private_address ] }

View File

@ -11,4 +11,4 @@ node_templates:
outputs:
ip_address:
value: { get_attribute: [ HOST, ip_address ] }
value: { get_attribute: [ HOST, private_address ] }

View File

@ -22,4 +22,4 @@ node_templates:
outputs:
ip_address:
value: { get_attribute: [ unknown_node_template, ip_address ] }
value: { get_attribute: [ unknown_node_template, private_address ] }

View File

@ -29,4 +29,4 @@ node_templates:
outputs:
server_address:
description: IP address of server instance.
value: { get_attribute: [server, ip_address] }
value: { get_attribute: [server, private_address] }

View File

@ -27,4 +27,4 @@ node_templates:
outputs:
server_address:
description: IP address of server instance.
value: { get_property: [server, ip_address] }
value: { get_property: [server, private_address] }

View File

@ -29,4 +29,4 @@ node_template:
outputs:
server_address:
description: IP address of server instance.
value: { get_property: [server, ip_address] }
value: { get_property: [server, private_address] }

View File

@ -27,7 +27,7 @@ dsl_definitions:
pre_configure_source:
implementation: collectd/pre_configure_source.py
inputs:
host: { get_attribute: [ TARGET, ip_address ]}
host: { get_attribute: [ TARGET, private_address ]}
tosca.interfaces.relationship.Configure:
pre_configure_target:
implementation: collectd/pre_configure_target.py
@ -36,7 +36,7 @@ dsl_definitions:
pre_configure_source:
implementation: rsyslog/pre_configure_source.py
inputs:
host: { get_attribute: [ TARGET, ip_address ]}
host: { get_attribute: [ TARGET, private_address ]}
inputs:
my_cpus:
type: integer
@ -109,7 +109,7 @@ node_templates:
pre_configure_source:
implementation: pre_configure_source.py
inputs:
host: { get_attribute: [ TARGET, ip_address ] }
host: { get_attribute: [ TARGET, private_address ] }
port: { get_attribute: [ TARGET, port ] }
interfaces:
tosca.interfaces.node.lifecycle.Standard:
@ -199,19 +199,19 @@ node_templates:
outputs:
nodejs_url:
description: URL for the nodejs server.
value: { get_attribute: [ app_server, ip_address ] }
value: { get_attribute: [ app_server, private_address ] }
mongodb_url:
description: URL for the mongodb server.
value: { get_attribute: [ mongo_server, ip_address ] }
value: { get_attribute: [ mongo_server, private_address ] }
mongodb_port:
description: Port for the mongodb server.
value: { get_property: [ mongo_dbms, dbms_port ] }
elasticsearch_url:
description: URL for the elasticsearch server.
value: { get_attribute: [ elasticsearch_server, ip_address ] }
value: { get_attribute: [ elasticsearch_server, private_address ] }
logstash_url:
description: URL for the logstash server.
value: { get_attribute: [ logstash_server, ip_address ] }
value: { get_attribute: [ logstash_server, private_address ] }
kibana_url:
description: URL for the kibana server.
value: { get_attribute: [ kibana_server, ip_address ] }
value: { get_attribute: [ kibana_server, private_address ] }

View File

@ -108,4 +108,4 @@ node_templates:
outputs:
website_url:
description: URL for Wordpress wiki.
value: { get_attribute: [server, ip_address] }
value: { get_attribute: [server, private_address] }

View File

@ -112,7 +112,8 @@ class GetAttributeTest(TestCase):
x for x in tpl.outputs if x.name == 'website_url'][0]
self.assertIsInstance(website_url_output.value, functions.GetAttribute)
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):
expected_msg = 'Expected arguments: node-template-name, attribute-name'

View File

@ -99,13 +99,12 @@ class ToscaDefTest(TestCase):
def test_properties_def(self):
self.assertEqual(
['disk_size', 'ip_address', 'mem_size',
'num_cpus'],
['disk_size', 'mem_size', 'num_cpus'],
sorted(compute_type.get_properties_def().keys()))
def test_attributes_def(self):
self.assertEqual(
['ip_address'],
['private_address', 'public_address'],
sorted([p.name for p in compute_type.attributes_def]))
def test_requirements(self):

View File

@ -74,7 +74,7 @@ class ToscaTemplateValidationTest(TestCase):
outputs:
server_address:
description: IP address of server instance.
values: { get_property: [server, ip_address] }
values: { get_property: [server, private_address] }
'''
outputs = (translator.toscalib.utils.yamlparser.
simple_parse(tpl_snippet)['outputs'])
@ -92,7 +92,7 @@ class ToscaTemplateValidationTest(TestCase):
outputs:
server_address:
descriptions: IP address of server instance.
value: { get_property: [server, ip_address] }
value: { get_property: [server, private_address] }
'''
outputs = (translator.toscalib.utils.yamlparser.
simple_parse(tpl_snippet)['outputs'])