Add networking-sfc port-chain resource plug-in

This patch adds below networking-sfc resource

OS::Neutron::PortChain

blueprint : sfc-heat

Change-Id: I2283e40ac4b562ff2d8780ea403a397073c2a82b
This commit is contained in:
mohankumar_n 2016-10-10 22:59:53 +05:30
parent f2182e12fa
commit 9180d7b07a
5 changed files with 327 additions and 0 deletions

View File

@ -166,6 +166,8 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
path = "/sfc/port_pair_groups" path = "/sfc/port_pair_groups"
elif resource == 'flow_classifier': elif resource == 'flow_classifier':
path = "/sfc/flow_classifiers" path = "/sfc/flow_classifiers"
elif resource == 'port_chain':
path = "/sfc/port_chains"
return path return path
def create_sfc_resource(self, resource, props): def create_sfc_resource(self, resource, props):

View File

@ -106,6 +106,16 @@ class PortPairConstraint(NeutronExtConstraint):
extension = 'sfc' extension = 'sfc'
class PortPairGroupConstraint(NeutronExtConstraint):
resource_name = 'port_pair_group'
extension = 'sfc'
class FlowClassifierConstraint(NeutronExtConstraint):
resource_name = 'flow_classifier'
extension = 'sfc'
class ProviderConstraint(constraints.BaseCustomConstraint): class ProviderConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.StackValidationFailed,) expected_exceptions = (exception.StackValidationFailed,)

View File

@ -0,0 +1,140 @@
# Copyright (c) 2016 Huawei Technologies India Pvt Ltd
# All Rights Reserved.
#
# 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.
from heat.common.i18n import _
from heat.engine import constraints
from heat.engine import properties
from heat.engine.resources.openstack.neutron import neutron
from heat.engine import support
from heat.engine import translation
class PortChain(neutron.NeutronResource):
"""A resource for neutron networking-sfc.
This resource used to define the service function path by arranging
networking-sfc port-pair-groups and set of flow classifiers, to specify
the classified traffic flows to enter the chain.
"""
support_status = support.SupportStatus(
version='8.0.0',
status=support.UNSUPPORTED)
required_service_extension = 'sfc'
PROPERTIES = (
NAME, DESCRIPTION, PORT_PAIR_GROUPS, FLOW_CLASSIFIERS,
CHAIN_PARAMETERS,
) = (
'name', 'description', 'port_pair_groups',
'flow_classifiers', 'chain_parameters',
)
properties_schema = {
NAME: properties.Schema(
properties.Schema.STRING,
_('Name of the Port Chain.'),
update_allowed=True
),
DESCRIPTION: properties.Schema(
properties.Schema.STRING,
_('Description for the Port Chain.'),
update_allowed=True
),
PORT_PAIR_GROUPS: properties.Schema(
properties.Schema.LIST,
_('A list of port pair groups to apply to the Port Chain.'),
update_allowed=True,
required=True,
schema=properties.Schema(
properties.Schema.STRING,
_('Port Pair Group ID or Name .'),
constraints=[
constraints.CustomConstraint('neutron.port_pair_group')
]
)
),
FLOW_CLASSIFIERS: properties.Schema(
properties.Schema.LIST,
_('A list of flow classifiers to apply to the Port Chain.'),
default=[],
update_allowed=True,
schema=properties.Schema(
properties.Schema.STRING,
_('Flow Classifier ID or Name .'),
constraints=[
constraints.CustomConstraint('neutron.flow_classifier')
]
)
),
CHAIN_PARAMETERS: properties.Schema(
properties.Schema.MAP,
_('Dictionary of chain parameters. Currently, only '
'correlation=mpls is supported by default.'),
default={"correlation": "mpls"}
),
}
def translation_rules(self, props):
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.PORT_PAIR_GROUPS],
client_plugin=self.client_plugin(),
finder='resolve_ext_resource',
entity='port_pair_group'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FLOW_CLASSIFIERS],
client_plugin=self.client_plugin(),
finder='resolve_ext_resource',
entity='flow_classifier'
),
]
def _show_resource(self):
return self.client_plugin().show_sfc_resource('port_chain',
self.resource_id)
def handle_create(self):
props = self.prepare_properties(self.properties,
self.physical_resource_name())
port_chain = self.client_plugin().create_sfc_resource(
'port_chain', props)
self.resource_id_set(port_chain['id'])
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
self.prepare_update_properties(prop_diff)
self.client_plugin().update_sfc_resource('port_chain',
prop_diff,
self.resource_id)
def handle_delete(self):
if self.resource_id is None:
return
with self.client_plugin().ignore_not_found:
self.client_plugin().delete_sfc_resource('port_chain',
self.resource_id)
def resource_mapping():
return {
'OS::Neutron::PortChain': PortChain,
}

View File

@ -0,0 +1,173 @@
#
# All Rights Reserved.
#
# 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 mock
from heat.engine.clients.os import neutron
from heat.engine.resources.openstack.neutron.sfc import port_chain
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
port_chain_template = {
'heat_template_version': '2015-04-30',
'resources': {
'test_resource': {
'type': 'OS::Neutron::PortChain',
'properties': {
'name': 'test_port_chain',
'description': 'port_chain_desc',
'port_pair_groups': ['port_pair_group_1'],
'flow_classifiers': ['flow_classifier1'],
'chain_parameters': {"correlation": 'mpls'}
}
}
}
}
RESOURCE_TYPE = 'OS::Neutron::PortChain'
class PortChainTest(common.HeatTestCase):
def setUp(self):
super(PortChainTest, self).setUp()
self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
return_value=True)
self.ctx = utils.dummy_context()
self.stack = stack.Stack(
self.ctx, 'test_stack',
template.Template(port_chain_template)
)
self.test_resource = self.stack['test_resource']
self.test_client_plugin = mock.MagicMock()
self.test_resource.client_plugin = mock.MagicMock(
return_value=self.test_client_plugin)
self.test_client = mock.MagicMock()
self.test_resource.client = mock.MagicMock(
return_value=self.test_client)
self.test_client_plugin.get_notification = mock.MagicMock(
return_value='sample_notification')
self.patchobject(self.test_client_plugin, 'resolve_ext_resource'
).return_value = ('port_pair_group_1')
self.patchobject(self.test_client_plugin, 'resolve_ext_resource'
).return_value = ('flow_classifier1')
def test_resource_mapping(self):
mapping = port_chain.resource_mapping()
self.assertEqual(port_chain.PortChain,
mapping['OS::Neutron::PortChain'])
def _get_mock_resource(self):
value = mock.MagicMock()
value.id = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
return value
def test_resource_handle_create(self):
mock_pc_create = self.test_client_plugin.create_sfc_resource
mock_resource = self._get_mock_resource()
mock_pc_create.return_value = mock_resource
# validate the properties
self.assertEqual(
'test_port_chain',
self.test_resource.properties.get(
port_chain.PortChain.NAME))
self.assertEqual(
'port_chain_desc',
self.test_resource.properties.get(
port_chain.PortChain.DESCRIPTION))
self.assertEqual(
['port_pair_group_1'],
self.test_resource.properties.get(
port_chain.PortChain.PORT_PAIR_GROUPS))
self.assertEqual(
['flow_classifier1'],
self.test_resource.properties.get(
port_chain.PortChain.FLOW_CLASSIFIERS))
self.assertEqual(
{"correlation": 'mpls'},
self.test_resource.properties.get(
port_chain.PortChain.CHAIN_PARAMETERS))
self.test_resource.data_set = mock.Mock()
self.test_resource.handle_create()
mock_pc_create.assert_called_once_with(
'port_chain',
{
'name': 'test_port_chain',
'description': 'port_chain_desc',
'port_pair_groups': ['port_pair_group_1'],
'flow_classifiers': ['flow_classifier1'],
'chain_parameters': {"correlation": 'mpls'}}
)
def delete_portchain(self):
mock_pc_delete = self.test_client_plugin.delete_sfc_resource
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_pc_delete.return_value = None
self.assertIsNone(self.test_resource.handle_delete())
mock_pc_delete.assert_called_once_with(
'port_chain', self.test_resource.resource_id)
def delete_portchain_resource_id_is_none(self):
self.test_resource.resource_id = None
self.assertIsNone(self.test_resource.handle_delete())
self.assertEqual(0, self.test_client_plugin.
delete_sfc_resource.call_count)
def test_resource_handle_delete_not_found(self):
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_pc_delete = self.test_client_plugin.delete_sfc_resource
mock_pc_delete.side_effect = self.test_client_plugin.NotFound
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_show_resource(self):
mock_pc_get = self.test_client_plugin.show_sfc_resource
mock_pc_get.return_value = None
self.assertEqual(None, self.test_resource._show_resource(),
'Failed to show resource')
def test_resource_handle_update(self):
mock_ppg_patch = self.test_client_plugin.update_sfc_resource
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
prop_diff = {
'name': 'name-updated',
'description': 'description-updated',
'port_pair_groups': ['port_pair_group_2'],
'flow_classifiers': ['flow_classifier2'],
}
self.test_resource.handle_update(json_snippet=None,
tmpl_diff=None,
prop_diff=prop_diff)
mock_ppg_patch.assert_called_once_with(
'port_chain',
{
'name': 'name-updated',
'description': 'description-updated',
'port_pair_groups': ['port_pair_group_2'],
'flow_classifiers': ['flow_classifier2'],
}, self.test_resource.resource_id)

View File

@ -117,6 +117,7 @@ heat.constraints =
mistral.workflow = heat.engine.clients.os.mistral:WorkflowConstraint mistral.workflow = heat.engine.clients.os.mistral:WorkflowConstraint
monasca.notification = heat.engine.clients.os.monasca:MonascaNotificationConstraint monasca.notification = heat.engine.clients.os.monasca:MonascaNotificationConstraint
neutron.address_scope = heat.engine.clients.os.neutron.neutron_constraints:AddressScopeConstraint neutron.address_scope = heat.engine.clients.os.neutron.neutron_constraints:AddressScopeConstraint
neutron.flow_classifier = heat.engine.clients.os.neutron.neutron_constraints:FlowClassifierConstraint
neutron.lbaas.listener = heat.engine.clients.os.neutron.lbaas_constraints:ListenerConstraint neutron.lbaas.listener = heat.engine.clients.os.neutron.lbaas_constraints:ListenerConstraint
neutron.lbaas.loadbalancer = heat.engine.clients.os.neutron.lbaas_constraints:LoadbalancerConstraint neutron.lbaas.loadbalancer = heat.engine.clients.os.neutron.lbaas_constraints:LoadbalancerConstraint
neutron.lbaas.pool = heat.engine.clients.os.neutron.lbaas_constraints:PoolConstraint neutron.lbaas.pool = heat.engine.clients.os.neutron.lbaas_constraints:PoolConstraint
@ -125,6 +126,7 @@ heat.constraints =
neutron.network = heat.engine.clients.os.neutron.neutron_constraints:NetworkConstraint neutron.network = heat.engine.clients.os.neutron.neutron_constraints:NetworkConstraint
neutron.port = heat.engine.clients.os.neutron.neutron_constraints:PortConstraint neutron.port = heat.engine.clients.os.neutron.neutron_constraints:PortConstraint
neutron.port_pair = heat.engine.clients.os.neutron.neutron_constraints:PortPairConstraint neutron.port_pair = heat.engine.clients.os.neutron.neutron_constraints:PortPairConstraint
neutron.port_pair_group = heat.engine.clients.os.neutron.neutron_constraints:PortPairGroupConstraint
neutron.qos_policy = heat.engine.clients.os.neutron.neutron_constraints:QoSPolicyConstraint neutron.qos_policy = heat.engine.clients.os.neutron.neutron_constraints:QoSPolicyConstraint
neutron.router = heat.engine.clients.os.neutron.neutron_constraints:RouterConstraint neutron.router = heat.engine.clients.os.neutron.neutron_constraints:RouterConstraint
neutron.security_group = heat.engine.clients.os.neutron.neutron_constraints:SecurityGroupConstraint neutron.security_group = heat.engine.clients.os.neutron.neutron_constraints:SecurityGroupConstraint