Assign floating IP to the vdu

Assign floating IP to the vdu using TOSCA template

Change-Id: I53a89397c1ef676f1a21bc1378c91aece65a3d91
Closes-Bug: 1537636
This commit is contained in:
Saju Madhavan 2017-03-04 21:59:59 +05:30
parent 58ae9d75ac
commit 52bdf321c4
6 changed files with 293 additions and 0 deletions

View File

@ -475,6 +475,61 @@ net-01 is as shown below.
| | | | | VL is to be attached |
+------------+----------+--------+-------------+-----------------------------+
Floating IP
-----------
Floating IP is used to access VDU from public network.
An example of assign floating ip to VDU
::
..
topology_template:
node_templates:
VDU1:
..
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
..
FIP1:
type: tosca.nodes.network.FloatingIP
properties:
floating_network: public
requirements:
- link:
node: CP1
:type:
tosca.nodes.network.FloatingIP
:properties:
+-------------------+----------+--------+-------------+-----------------------+
|Name | Required | Type | Constraints | Description |
+-------------------+----------+--------+-------------+-----------------------+
|floating_network | Yes | String | None | Name of public network|
+-------------------+----------+--------+-------------+-----------------------+
|floating_ip_address| No | String | None | Floating IP Address |
| | | | | from public network |
+------------+------+----------+--------+-------------+-----------------------+
:requirements:
+------+-------------------+--------------------+-------------------+
|Name |Capability |Relationship |Description |
+------+-------------------+--------------------+-------------------+
|link |tosca.capabilities |tosca.relationships |States the CP node |
| |.network.Linkable |.network.LinksTo |to connect to |
+------+-------------------+--------------------+-------------------+
Multiple nodes
--------------
Multiple node types can be defined in a VNFD.

View File

@ -0,0 +1,7 @@
---
features:
- |
Support to assign floating IP to VDU using TOSCA template.
We have to use the node type tosca.nodes.network.FloatingIP
For details please refer
https://docs.openstack.org/tacker/latest/contributor/vnfd_template_description.html#floating-ip

View File

@ -0,0 +1,45 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Example Floating IP - Allocate specified IP from floating network and attach to CP.
metadata:
template_name: sample-tosca-vnfd-test-fip-with-floating-ip-address
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
capabilities:
nfv_compute:
properties:
disk_size: 1 GB
mem_size: 512 MB
num_cpus: 1
properties:
image: cirros-0.3.5-x86_64-disk
mgmt_driver: noop
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker
FIP1:
type: tosca.nodes.network.FloatingIP
properties:
floating_network: public
floating_ip_address: 192.168.56.154
requirements:
- link:
node: CP1

View File

@ -0,0 +1,44 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Example Floating IP - Allocate one IP from floating network and attach to CP.
metadata:
template_name: sample-tosca-vnfd-test-fip-with-floating-network
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
capabilities:
nfv_compute:
properties:
disk_size: 1 GB
mem_size: 512 MB
num_cpus: 1
properties:
image: cirros-0.3.5-x86_64-disk
mgmt_driver: noop
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: net1
vendor: Tacker
FIP1:
type: tosca.nodes.network.FloatingIP
properties:
floating_network: public
requirements:
- link:
node: CP1

View File

@ -0,0 +1,44 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
description: Example Floating IP - Allocate one IP from floating network and attach to CP.
metadata:
template_name: sample-tosca-vnfd-test-fip-with-floating-network
topology_template:
node_templates:
VDU1:
type: tosca.nodes.nfv.VDU.Tacker
capabilities:
nfv_compute:
properties:
disk_size: 1 GB
mem_size: 512 MB
num_cpus: 1
properties:
image: cirros-0.3.5-x86_64-disk
mgmt_driver: noop
CP1:
type: tosca.nodes.nfv.CP.Tacker
properties:
management: true
requirements:
- virtualLink:
node: VL1
- virtualBinding:
node: VDU1
VL1:
type: tosca.nodes.nfv.VL
properties:
network_name: net_mgmt
vendor: Tacker
FIP1:
type: tosca.nodes.network.FloatingIP
properties:
floating_network: public
requirements:
- link:
node: CP1

View File

@ -0,0 +1,98 @@
# Copyright 2017 OpenStack Foundation
#
# 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 yaml
from tacker.tests import constants
from tacker.tests.functional import base
from tacker.tests.utils import read_file
class VnfTestToscaFloatingIp(base.BaseTackerTest):
def get_heat_stack_resource(self, stack_id, resource_name):
resource_types = self.h_client.resources
resource_details = resource_types.get(stack_id=stack_id,
resource_name=resource_name)
resource_dict = resource_details.to_dict()
return resource_dict
def connect_public_and_private_nw_with_router(self):
public_nw = 'public'
private_nw = 'net_mgmt'
private_nw_subnet = 'subnet_mgmt'
public_nw_id = None
private_nw_id = None
private_nw_subnet_id = None
neutronclient = self.neutronclient()
networks = neutronclient.list_networks()['networks']
for nw in networks:
if nw['name'] == public_nw:
public_nw_id = nw['id']
if nw['name'] == private_nw:
private_nw_id = nw['id']
if public_nw_id and private_nw_id:
break
self.assertIsNotNone(public_nw_id)
self.assertIsNotNone(private_nw_id)
subnets = neutronclient.list_subnets()['subnets']
for subnet in subnets:
if subnet['network_id'] == private_nw_id\
and subnet['name'] == private_nw_subnet:
private_nw_subnet_id = subnet['id']
break
self.assertIsNotNone(private_nw_subnet_id)
router_id = neutronclient.create_router(
{'router': {'name': 'fip_test_router'}})['router']['id']
self.assertIsNotNone(router_id)
self.addCleanup(self.neutronclient().delete_router, router_id)
rt_gw_id = neutronclient.add_gateway_router(
router_id, {'network_id': public_nw_id})['router']['id']
self.assertIsNotNone(rt_gw_id)
self.addCleanup(self.neutronclient().remove_gateway_router,
router_id)
rt_int = neutronclient.add_interface_router(
router_id, {'subnet_id': private_nw_subnet_id})['id']
self.assertIsNotNone(rt_int)
self.addCleanup(self.neutronclient().remove_interface_router,
router_id, {'subnet_id': private_nw_subnet_id})
def test_assign_floatingip_to_vdu(self):
vnfd_file = 'sample_tosca_assign_floatingip_to_vdu.yaml'
vnf_name = 'Assign Floating IP to VDU'
values_str = read_file(vnfd_file)
template = yaml.safe_load(values_str)
vnf_arg = {'vnf': {'vnfd_template': template, 'name': vnf_name}}
self.connect_public_and_private_nw_with_router()
vnf_instance = self.client.create_vnf(body=vnf_arg)
vnf_id = vnf_instance['vnf']['id']
self.addCleanup(self.wait_until_vnf_delete, vnf_id,
constants.VNF_CIRROS_DELETE_TIMEOUT)
self.addCleanup(self.client.delete_vnf, vnf_id)
self.wait_until_vnf_active(
vnf_id,
constants.VNF_CIRROS_CREATE_TIMEOUT,
constants.ACTIVE_SLEEP_TIME)
vnf_show_out = self.client.show_vnf(vnf_id)['vnf']
self.assertIsNotNone(vnf_show_out['mgmt_url'])
stack_id = vnf_show_out['instance_id']
fip_res = self.get_heat_stack_resource(stack_id, 'FIP1')
floating_ip_address = fip_res['attributes']['floating_ip_address']
self.assertIsNotNone(floating_ip_address)
fip_port_id = fip_res['attributes']['port_id']
port_res = self.get_heat_stack_resource(stack_id, 'CP1')
port_id = port_res['attributes']['id']
self.assertEqual(fip_port_id, port_id)