PTG update notification to service chain Node Drivers

Closed-bug: 1639319
Change-Id: I94f5ece9f28bbb17a926777a72dbc1d9174a8687
This commit is contained in:
Vikash082 2016-11-04 10:06:19 +05:30 committed by Ivar Lazzaro
parent 6d11dee1d6
commit 68c4dea751
8 changed files with 114 additions and 0 deletions

View File

@ -348,6 +348,15 @@ class ServiceChainPluginBase(service_base.ServicePluginBase):
"""
pass
def policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group,
instance_id):
""" Utility function.
Override this method to react to policy target group update
"""
pass
@abc.abstractmethod
@log.log
def get_servicechain_nodes(self, context, filters=None, fields=None):

View File

@ -165,6 +165,7 @@ class ChainMappingDriver(api.PolicyDriver, local_api.LocalAPI,
context, context.current['provided_policy_rule_sets'],
providing_ptg=context.current)
self._handle_prs_added(context)
self._handle_provider_updated(context)
@log.log
def update_policy_target_group_precommit(self, context):
@ -192,6 +193,7 @@ class ChainMappingDriver(api.PolicyDriver, local_api.LocalAPI,
context, curr['provided_policy_rule_sets'],
providing_ptg=context.current)
self._handle_prs_updated(context)
self._handle_provider_updated(context)
@log.log
def delete_policy_target_group_precommit(self, context):
@ -822,3 +824,20 @@ class ChainMappingDriver(api.PolicyDriver, local_api.LocalAPI,
"""
return (not group.get('proxied_group_id') and
group.get('enforce_service_chains', True) is True)
def _get_ptg_provided_chain_id(self, context, ptg):
try:
return [x.servicechain_instance_id for x in
self._get_ptg_servicechain_mapping(
context._plugin_context.session,
provider_ptg_ids=[ptg['id']])][0]
except IndexError:
return None
def _handle_provider_updated(self, context):
sci = self._get_ptg_provided_chain_id(context, context.current)
if sci:
chain_context = self._get_chain_admin_context(
context._plugin_context, instance_id=sci)
self._notify_ptg_updated(chain_context, context.original,
context.current, sci)

View File

@ -35,3 +35,8 @@ class ServiceChainNotificationsMixin(object):
if self._servicechain_plugin:
self._servicechain_plugin.update_chains_consumer_removed(
context, policy_target_group, instance_id)
def _notify_ptg_updated(self, context, old, current, instance_id):
if self._servicechain_plugin:
self._servicechain_plugin.policy_target_group_updated(
context, old, current, instance_id)

View File

@ -197,6 +197,19 @@ class NodeDriverBase(object):
"""
pass
@abc.abstractmethod
def policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group):
"""Update a Node Driver that a chain provider PTG was created or
changed
:param context: NodeDriverContext instance describing the service chain
and the specific node to be processed by this driver.
:param old_policy_target_group: PTG state before the update. None if
the group was created.
:param current_policy_target_group: Current PTG state.
"""
pass
@abc.abstractmethod
def notify_chain_parameters_updated(self, context):
"""Update a deployed Service Chain Node on GBP PRS updates

View File

@ -68,6 +68,11 @@ class NoopNodeDriver(driver_base.NodeDriverBase):
def notify_chain_parameters_updated(self, context):
pass
@log.log
def policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group):
pass
@property
def name(self):
return self._name

View File

@ -254,6 +254,11 @@ class HeatNodeDriver(driver_base.NodeDriverBase):
def notify_chain_parameters_updated(self, context):
self.update(context)
@log.log
def policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group):
pass
@property
def name(self):
return self._name

View File

@ -277,6 +277,17 @@ class NodeCompositionPlugin(servicechain_db.ServiceChainDbPlugin,
self._update_chains_consumer_modified(context, policy_target_group,
instance_id, 'added')
def policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group,
instance_id):
""" Utility function.
Override this method to react to policy target group update
"""
self._policy_target_group_updated(context,
old_policy_target_group,
current_policy_target_group,
instance_id)
def update_chains_consumer_removed(self, context, policy_target_group,
instance_id):
""" Auto scaling function.
@ -287,6 +298,23 @@ class NodeCompositionPlugin(servicechain_db.ServiceChainDbPlugin,
self._update_chains_consumer_modified(context, policy_target_group,
instance_id, 'removed')
def _policy_target_group_updated(self, context, old_policy_target_group,
current_policy_target_group,
instance_id):
updaters = self._get_scheduled_drivers(
context,
self.get_servicechain_instance(context, instance_id),
'update')
for update in updaters.values():
try:
update['driver'].policy_target_group_updated(
update['context'],
old_policy_target_group,
current_policy_target_group)
except exc.NodeDriverError as ex:
LOG.error(_("Node Update on policy target group modification "
"failed, %s"), ex.message)
def _update_chains_pt_modified(self, context, policy_target, instance_id,
action):
updaters = self._get_scheduled_drivers(

View File

@ -743,6 +743,36 @@ class NodeCompositionPluginTestCase(
self.assertFalse(add.called)
self.assertFalse(rem.called)
def test_node_drivers_notified_provider_updated(self):
upd = self.driver.policy_target_group_updated = mock.Mock()
prof = self._create_service_profile(
service_type='LOADBALANCER',
vendor=self.SERVICE_PROFILE_VENDOR)['service_profile']
node = self.create_servicechain_node(
service_profile_id=prof['id'],
config=self.DEFAULT_LB_CONFIG,
expected_res_status=201)['servicechain_node']
spec = self.create_servicechain_spec(
nodes=[node['id']],
expected_res_status=201)['servicechain_spec']
prs = self._create_redirect_prs(spec['id'])['policy_rule_set']
provider = self.create_policy_target_group(
provided_policy_rule_sets={prs['id']: ''})['policy_target_group']
# Verify notification issued for PTG consuming
upd.assert_called_with(mock.ANY, None, provider)
upd.reset_mock()
# Verify notification issued for PTG consuming
new_provider = self.update_policy_target_group(
provider['id'],
consumed_policy_rule_sets={prs['id']: ''})['policy_target_group']
upd.assert_called_with(mock.ANY, provider, new_provider)
upd.reset_mock()
class TestQuotasForServiceChain(test_base.ServiceChainPluginTestCase):