AIM Policy Driver - Part 3 - Policy Rules

Policy Rule is mapped to an AIM Filter, and the Policy Classifier
is mapped to an AIM FilterEntry.

The older apic_mapping driver has been refactored slightly to create
a new library of functions called apic_mapping_lib that can be used both
from the apic_mapping driver as well as the new aim_mapping driver.

The rollback testing for the aim_driver has been enhanced by adding the
dummy_driver as second policy driver for testing, and having the dummy_driver
raise exception to trigger the rollback. This ensures that the entire code in
the aim_driver is executed before the exception, and hence the complete
rollback is tested.

This also fixes a bug in the _get_status_from_drivers() logic which resulted
in the driver extension attributes being dropped from the result that was
returned. This fix now allows validating the "apic:distinguished_names".

Change-Id: I7da7ecedd33a4c38623c944e366fbc01d216fdfa
This commit is contained in:
Sumit Naiksatam
2016-07-20 00:50:42 -07:00
parent 05c119d3a3
commit 8e463413f3
10 changed files with 680 additions and 199 deletions

View File

@@ -60,12 +60,23 @@ class APICNameMapper(object):
def mapper(name_type):
"""Wrapper to land all the common operations between mappers."""
def wrap(func):
def inner(inst, session, resource_id, resource_name=None):
def inner(inst, session, resource_id, resource_name=None,
prefix=None):
# REVISIT(Bob): Optional argument for reserving characters in
# the prefix?
saved_name = inst.db.get_apic_name(session,
resource_id,
name_type)
if saved_name:
result = saved_name[0]
# REVISIT(Sumit): Should this name mapper be aware of
# this prefixing logic, or should we instead prepend
# the prefix at the point from where this is being
# invoked. The latter approach has the disadvantage
# of having to replicate the logic in many places.
if prefix:
result = prefix + result
result = truncate(result, MAX_APIC_NAME_LENGTH)
return result
name = ''
try:
@@ -94,6 +105,9 @@ class APICNameMapper(object):
inst.db.add_apic_name(session, resource_id,
name_type, result)
if prefix:
result = prefix + result
result = truncate(result, MAX_APIC_NAME_LENGTH)
return result
return inner
return wrap
@@ -155,10 +169,9 @@ class APICNameMapper(object):
return policy_rule_set['name']
@mapper(NAME_TYPE_POLICY_RULE)
def policy_rule(self, context, policy_rule_id):
policy_rule = context._plugin.get_policy_rule(context._plugin_context,
policy_rule_id)
return policy_rule['name']
def policy_rule(self, context, policy_rule_id,
policy_rule_name=None):
return policy_rule_name
@mapper(NAME_TYPE_EXTERNAL_SEGMENT)
def external_segment(self, context, external_segment_id):