Merge "Update network examples to the spec (1)"

This commit is contained in:
Jenkins
2015-07-24 19:30:02 +00:00
committed by Gerrit Code Review
8 changed files with 198 additions and 387 deletions

View File

@@ -1,255 +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 json
import os
from translator.common.utils import CompareUtils
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 ToscaNetworkTest(TestCase):
parsed_params = {'network_name': 'net1'}
def test_translate_single_network_single_server(self):
'''TOSCA template with single Network and single Compute.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../toscalib/tests/data/network/"
"tosca_one_server_one_network.yaml")
tosca = ToscaTemplate(tosca_tpl)
translate = TOSCATranslator(tosca, self.parsed_params)
output = translate.translate()
expected_resource_1 = {'type': 'OS::Neutron::Net',
'properties':
{'name': {'get_param': 'network_name'}
}}
expected_resource_2 = {'type': 'OS::Neutron::Subnet',
'properties':
{'cidr': '192.168.0.0/24',
'ip_version': 4,
'allocation_pools': [{'start': '192.168.0.50',
'end': '192.168.0.200'}],
'gateway_ip': '192.168.0.1',
'network': {'get_resource': 'my_network'}
}}
expected_resource_3 = {'type': 'OS::Neutron::Port',
'properties':
{'network': {'get_resource': 'my_network'}
}}
expected_resource_4 = [{'port': {'get_resource': 'my_port'}}]
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
resources = output_dict.get('resources')
self.assertIn('my_network', resources.keys())
self.assertIn('my_network_subnet', resources.keys())
self.assertIn('my_port', resources.keys())
self.assertIn('my_server', resources.keys())
self.assertEqual(resources.get('my_network'), expected_resource_1)
self.assertEqual(resources.get('my_network_subnet'),
expected_resource_2)
diff = CompareUtils.diff_dicts(resources.get('my_port'),
expected_resource_3)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
self.assertIn('properties', resources.get('my_server'))
self.assertIn('networks', resources.get('my_server').get('properties'))
translated_resource = resources.get('my_server').\
get('properties').get('networks')
self.assertEqual(translated_resource, expected_resource_4)
def test_translate_single_network_two_computes(self):
'''TOSCA template with single Network and two Computes.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../toscalib/tests/data/network/"
"tosca_two_servers_one_network.yaml")
tosca = ToscaTemplate(tosca_tpl)
translate = TOSCATranslator(tosca, self.parsed_params)
output = translate.translate()
expected_resource_1 = {'type': 'OS::Neutron::Net',
'properties':
{'name': {'get_param': 'network_name'}
}}
expected_resource_2 = {'type': 'OS::Neutron::Subnet',
'properties':
{'cidr': {'get_param': 'network_cidr'},
'ip_version': 4,
'network': {'get_resource': 'my_network'},
'allocation_pools': [{'start':
{'get_param':
'network_start_ip'},
'end':
{'get_param':
'network_end_ip'
}}
]
}}
expected_resource_3 = {'type': 'OS::Neutron::Port',
'properties':
{'network': {'get_resource': 'my_network'}
}}
expected_resource_4 = {'type': 'OS::Neutron::Port',
'properties':
{'network': {'get_resource': 'my_network'}
}}
expected_resource_5 = [{'port': {'get_resource': 'my_port'}}]
expected_resource_6 = [{'port': {'get_resource': 'my_port2'}}]
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
resources = output_dict.get('resources')
self.assertIn('my_network', resources.keys())
self.assertIn('my_network_subnet', resources.keys())
self.assertIn('my_port', resources.keys())
self.assertIn('my_port2', resources.keys())
self.assertIn('my_server', resources.keys())
self.assertIn('my_server2', resources.keys())
self.assertEqual(resources.get('my_network'), expected_resource_1)
self.assertEqual(resources.get('my_network_subnet'),
expected_resource_2)
diff = CompareUtils.diff_dicts(resources.get('my_port'),
expected_resource_3)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
diff = CompareUtils.diff_dicts(resources.get('my_port2'),
expected_resource_4)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
self.assertIn('properties', resources.get('my_server'))
self.assertIn('networks', resources.get('my_server').get('properties'))
translated_resource = resources.get('my_server').\
get('properties').get('networks')
self.assertEqual(translated_resource, expected_resource_5)
self.assertIn('properties', resources.get('my_server2'))
self.assertIn('networks', resources.get('my_server2').
get('properties'))
translated_resource = resources.get('my_server2').\
get('properties').get('networks')
self.assertEqual(translated_resource, expected_resource_6)
def test_translate_server_existing_network(self):
'''TOSCA template with 1 server attached to existing network.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../toscalib/tests/data/network/"
"tosca_server_on_existing_network.yaml")
tosca = ToscaTemplate(tosca_tpl)
translate = TOSCATranslator(tosca, self.parsed_params)
output = translate.translate()
expected_resource_1 = {'type': 'OS::Neutron::Port',
'properties':
{'network': {'get_param': 'network_name'}
}}
expected_resource_2 = [{'port': {'get_resource': 'my_port'}}]
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
resources = output_dict.get('resources')
self.assertItemsEqual(resources.keys(), ['my_server', 'my_port'])
self.assertEqual(resources.get('my_port'), expected_resource_1)
self.assertIn('properties', resources.get('my_server'))
self.assertIn('networks', resources.get('my_server').get('properties'))
translated_resource = resources.get('my_server').\
get('properties').get('networks')
self.assertEqual(translated_resource, expected_resource_2)
def test_translate_three_networks_single_server(self):
'''TOSCA template with three Networks and single Compute.'''
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../toscalib/tests/data/network/"
"tosca_one_server_three_networks.yaml")
tosca = ToscaTemplate(tosca_tpl)
translate = TOSCATranslator(tosca, self.parsed_params)
output = translate.translate()
output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
resources = output_dict.get('resources')
for net_num in range(1, 4):
net_name = 'my_network%d' % (net_num)
subnet_name = '%s_subnet' % (net_name)
port_name = 'my_port%d' % (net_num)
expected_resource_net = {'type': 'OS::Neutron::Net',
'properties':
{'name': 'net%d' % (net_num)}}
expected_resource_subnet = {'type': 'OS::Neutron::Subnet',
'properties':
{'cidr': '192.168.%d.0/24' % (net_num),
'ip_version': 4,
'network': {'get_resource': net_name}}
}
expected_resource_port = {'type': 'OS::Neutron::Port',
'properties':
{'network': {'get_resource': net_name}}}
self.assertIn(net_name, resources.keys())
self.assertIn(subnet_name, resources.keys())
self.assertIn(port_name, resources.keys())
self.assertEqual(resources.get(net_name), expected_resource_net)
self.assertEqual(resources.get(subnet_name),
expected_resource_subnet)
diff = CompareUtils.diff_dicts(resources.get(port_name),
expected_resource_port)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4,
separators=(', ', ': ')))
self.assertIn('properties', resources.get('my_server'))
self.assertIn('networks', resources.get('my_server').get('properties'))
translated_resource = resources.get('my_server').\
get('properties').get('networks')
expected_srv_networks = [{'port': {'get_resource': 'my_port1'}},
{'port': {'get_resource': 'my_port2'}},
{'port': {'get_resource': 'my_port3'}}]
self.assertEqual(translated_resource, expected_srv_networks)

View File

@@ -230,3 +230,54 @@ class ToscaHotTranslationTest(TestCase):
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
def test_hot_translate_one_server_one_network(self):
tosca_file = \
'../toscalib/tests/data/network/tosca_one_server_one_network.yaml'
hot_file = '../toscalib/tests/data/hot_output/network/' \
'hot_one_server_one_network.yaml'
params = {'network_name': 'private_net'}
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_server_on_existing_network(self):
tosca_file = '../toscalib/tests/data/network/' \
'tosca_server_on_existing_network.yaml'
hot_file = '../toscalib/tests/data/hot_output/network/' \
'hot_server_on_existing_network.yaml'
params = {'network_name': 'private_net'}
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_two_servers_one_network(self):
tosca_file = \
'../toscalib/tests/data/network/tosca_two_servers_one_network.yaml'
hot_file = '../toscalib/tests/data/hot_output/network/' \
'hot_two_servers_one_network.yaml'
params = {'network_name': 'my_private_net',
'network_cidr': '10.0.0.0/24',
'network_start_ip': '10.0.0.100',
'network_end_ip': '10.0.0.150'}
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_one_server_three_networks(self):
tosca_file = '../toscalib/tests/data/network/' \
'tosca_one_server_three_networks.yaml'
hot_file = '../toscalib/tests/data/hot_output/network/' \
'hot_one_server_three_networks.yaml'
params = {}
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_file,
params)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))

View File

@@ -1,21 +1,33 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with 1 network and 1 attached server
TOSCA simple profile with 1 server bound to a new network
outputs: {}
parameters:
network_name:
default: net1
description: Network name
type: string
description: Network name
default: private_net
resources:
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port }
user_data_format: SOFTWARE_CONFIG
my_network:
type: OS::Neutron::Net
properties:
name:
get_param: network_name
type: OS::Neutron::Net
my_network_subnet:
type: OS::Neutron::Subnet
properties:
allocation_pools:
- end: 192.168.0.200
@@ -23,21 +35,11 @@ resources:
cidr: 192.168.0.0/24
gateway_ip: 192.168.0.1
ip_version: 4
network: { get_resource: my_network}
type: OS::Neutron::Subnet
my_port:
depends_on:
- my_network
properties:
network: { get_resource: my_network}
type: OS::Neutron::Port
my_server:
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port}
user_data_format: SOFTWARE_CONFIG
type: OS::Nova::Server
network: { get_resource: my_network }
my_port:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network }
outputs: {}

View File

@@ -1,60 +1,13 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with 3 networks and 1 attached server
TOSCA simple profile with 1 server bound to 3 networks
outputs: {}
parameters: {}
resources:
my_network1:
properties:
name: net1
type: OS::Neutron::Net
my_network1_subnet:
properties:
cidr: 192.168.1.0/24
ip_version: 4
network: { get_resource: my_network1 }
type: OS::Neutron::Subnet
my_network2:
properties:
name: net2
type: OS::Neutron::Net
my_network2_subnet:
properties:
cidr: 192.168.2.0/24
ip_version: 4
network: { get_resource: my_network2 }
type: OS::Neutron::Subnet
my_network3:
properties:
name: net3
type: OS::Neutron::Net
my_network3_subnet:
properties:
cidr: 192.168.3.0/24
ip_version: 4
network: { get_resource: my_network3 }
type: OS::Neutron::Subnet
my_port1:
depends_on:
- my_network1
properties:
network: { get_resource: my_network1 }
type: OS::Neutron::Port
my_port2:
depends_on:
- my_network2
properties:
network: { get_resource: my_network2 }
type: OS::Neutron::Port
my_port3:
depends_on:
- my_network3
properties:
network: { get_resource: my_network3 }
type: OS::Neutron::Port
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
@@ -64,5 +17,56 @@ resources:
- port: { get_resource: my_port2 }
- port: { get_resource: my_port3 }
user_data_format: SOFTWARE_CONFIG
type: OS::Nova::Server
my_network1:
type: OS::Neutron::Net
properties:
name: net1
my_network2:
type: OS::Neutron::Net
properties:
name: net2
my_network3:
type: OS::Neutron::Net
properties:
name: net3
my_network1_subnet:
type: OS::Neutron::Subnet
properties:
cidr: 192.168.1.0/24
ip_version: 4
network: { get_resource: my_network1 }
my_network2_subnet:
type: OS::Neutron::Subnet
properties:
cidr: 192.168.2.0/24
ip_version: 4
network: { get_resource: my_network2 }
my_network3_subnet:
type: OS::Neutron::Subnet
properties:
cidr: 192.168.3.0/24
ip_version: 4
network: { get_resource: my_network3 }
my_port1:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network1 }
my_port2:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network2 }
my_port3:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network3 }
outputs: {}

View File

@@ -1,27 +1,28 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with 1 server attached to existing network
TOSCA simple profile with 1 server bound to an existing network
outputs: {}
parameters:
network_name:
default: net1
description: Network name
type: string
description: Network name
default: private_net
resources:
my_port:
properties:
network: {get_param: network_name}
type: OS::Neutron::Port
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port:
Ref: my_port
- port: { get_resource: my_port }
user_data_format: SOFTWARE_CONFIG
type: OS::Nova::Server
my_port:
type: OS::Neutron::Port
properties:
network: {get_param: network_name}
outputs: {}

View File

@@ -1,33 +1,55 @@
heat_template_version: 2013-05-23
description: >
TOSCA simple profile with 1 network and 2 attached servers
TOSCA simple profile with 2 servers bound to the 1 network
outputs: {}
parameters:
network_cidr:
default: 10.0.0.0/24
description: CIDR for the network
type: string
network_end_ip:
default: 10.0.0.150
description: End IP for the allocation pool
type: string
network_name:
default: net1
type: string
description: Network name
default: my_private_net
network_cidr:
type: string
description: CIDR for the network
default: 10.0.0.0/24
network_start_ip:
default: 10.0.0.100
description: Start IP for the allocation pool
type: string
description: Start IP for the allocation pool
default: 10.0.0.100
network_end_ip:
type: string
description: End IP for the allocation pool
default: 10.0.0.150
resources:
my_server:
type: OS::Nova::Server
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port }
user_data_format: SOFTWARE_CONFIG
my_server2:
type: OS::Nova::Server
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port2 }
user_data_format: SOFTWARE_CONFIG
my_network:
type: OS::Neutron::Net
properties:
name:
get_param: network_name
type: OS::Neutron::Net
my_network_subnet:
type: OS::Neutron::Subnet
properties:
allocation_pools:
- end:
@@ -37,36 +59,16 @@ resources:
cidr:
get_param: network_cidr
ip_version: 4
network: { get_resource: my_network}
type: OS::Neutron::Subnet
my_port:
depends_on:
- my_network
properties:
network: { get_resource: my_network}
type: OS::Neutron::Port
my_port2:
depends_on:
- my_network
properties:
network: { get_resource: my_network}
type: OS::Neutron::Port
my_server:
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port}
user_data_format: SOFTWARE_CONFIG
type: OS::Nova::Server
my_server2:
properties:
flavor: m1.small
image: cirros-0.3.2-x86_64-uec
key_name: userkey
networks:
- port: { get_resource: my_port2}
user_data_format: SOFTWARE_CONFIG
type: OS::Nova::Server
network: { get_resource: my_network }
my_port:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network }
my_port2:
type: OS::Neutron::Port
properties:
network: { get_resource: my_network }
outputs: {}

View File

@@ -1,9 +1,10 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with 3 networks and 1 attached server
TOSCA simple profile with 1 server bound to 3 networks
topology_template:
node_templates:
my_server:
type: tosca.nodes.Compute

View File

@@ -1,9 +1,10 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
TOSCA simple profile with 1 network and 2 attached servers
TOSCA simple profile with 2 servers bound to the 1 network
topology_template:
inputs:
network_name:
type: string
@@ -36,6 +37,7 @@ topology_template:
type: Linux
distribution: CirrOS
version: 0.3.2
my_server2:
type: tosca.nodes.Compute
capabilities:
@@ -50,6 +52,7 @@ topology_template:
type: Linux
distribution: CirrOS
version: 0.3.2
my_network:
type: tosca.nodes.network.Network
properties:
@@ -58,6 +61,7 @@ topology_template:
network_name: { get_input: network_name }
start_ip: { get_input: network_start_ip }
end_ip: { get_input: network_end_ip }
my_port:
type: tosca.nodes.network.Port
requirements:
@@ -65,6 +69,7 @@ topology_template:
node: my_server
- link:
node: my_network
my_port2:
type: tosca.nodes.network.Port
requirements: