[AIM] Validation tool updates monitored resources

The validation tool now updates monitored resources. This is needed
because repair/migration may update these pre-existing resources, such
as by adding provided/consumed contracts. Since these start out as
copies of the existing resources (fixed for common Tenant), only the
required changes should be applied. An existing UT now clears
contracts on a pre-existing ExternalNetwork to test that these are
properly updated. Also, when creating common Tenant in AIM, set its
display name to an empty string instead of 'CommonTenant'.

Change-Id: Iaa8ca7e62aa89860d244a388167f3212cf79dc9c
This commit is contained in:
Robert Kukura 2018-10-24 08:18:01 -04:00
parent ffa9a29b43
commit 4bc66f1e8d
5 changed files with 24 additions and 19 deletions

View File

@ -2893,8 +2893,7 @@ class ApicMechanismDriver(api_plus.MechanismDriver,
def _ensure_common_tenant(self, aim_ctx): def _ensure_common_tenant(self, aim_ctx):
attrs = aim_resource.Tenant( attrs = aim_resource.Tenant(
name=COMMON_TENANT_NAME, monitored=True, name=COMMON_TENANT_NAME, monitored=True, display_name='')
display_name=aim_utils.sanitize_display_name('CommonTenant'))
tenant = self.aim.get(aim_ctx, attrs) tenant = self.aim.get(aim_ctx, attrs)
if not tenant: if not tenant:
LOG.info("Creating common tenant") LOG.info("Creating common tenant")
@ -4056,6 +4055,11 @@ class ApicMechanismDriver(api_plus.MechanismDriver,
mgr.register_aim_resource_class(aim_resource.VMMDomain) mgr.register_aim_resource_class(aim_resource.VMMDomain)
mgr.register_aim_resource_class(aim_resource.VRF) mgr.register_aim_resource_class(aim_resource.VRF)
# Copy common Tenant from actual to expected AIM store.
for tenant in mgr.aim_mgr.find(
mgr.actual_aim_ctx, aim_resource.Tenant, name=COMMON_TENANT_NAME):
mgr.aim_mgr.create(mgr.expected_aim_ctx, tenant)
# Copy AIM resources that are managed via aimctl from actual # Copy AIM resources that are managed via aimctl from actual
# to expected AIM stores. # to expected AIM stores.
for resource_class in [aim_infra.HostDomainMappingV2, for resource_class in [aim_infra.HostDomainMappingV2,

View File

@ -2450,9 +2450,8 @@ class AIMMappingDriver(nrd.CommonNeutronBase, aim_rpc.AIMMappingRPCMixin):
def _aim_tenant_name(self, session, tenant_id, aim_resource_class=None, def _aim_tenant_name(self, session, tenant_id, aim_resource_class=None,
gbp_resource=None, gbp_obj=None): gbp_resource=None, gbp_obj=None):
attrs = aim_resource.Tenant(name=md.COMMON_TENANT_NAME, attrs = aim_resource.Tenant(
display_name=aim_utils.sanitize_display_name( name=md.COMMON_TENANT_NAME, display_name='')
'CommonTenant'))
tenant = aim_mgr.get(aim_ctx, attrs) tenant = aim_mgr.get(aim_ctx, attrs)
if not tenant: if not tenant:
tenant = aim_mgr.create(aim_ctx, attrs) tenant = aim_mgr.create(aim_ctx, attrs)

View File

@ -234,16 +234,13 @@ class ValidationManager(object):
if not getattr(actual_resource, 'monitored', True): if not getattr(actual_resource, 'monitored', True):
self._handle_unexpected_aim_resource(actual_resource) self._handle_unexpected_aim_resource(actual_resource)
else: else:
# Some infra resources do not have the monitored # Update both monitored and unmonitored
# attribute, but are treated as if they are monitored. # resources. Monitored resources should have started out
if getattr(expected_resource, 'monitored', True): # as copies of actual resources, but may have had changes
# REVISIT: Make sure actual resource is monitored, but # made, such as additional contracts provided or consumed.
# ignore other differences. if not expected_resource.user_equal(actual_resource):
pass self._handle_incorrect_aim_resource(
else: expected_resource, actual_resource)
if not expected_resource.user_equal(actual_resource):
self._handle_incorrect_aim_resource(
expected_resource, actual_resource)
def _handle_unexpected_aim_resource(self, actual_resource): def _handle_unexpected_aim_resource(self, actual_resource):
if self.should_repair( if self.should_repair(

View File

@ -643,7 +643,7 @@ class TestAimMapping(ApicAimTestCase):
tenant_aname = vrf.tenant_name tenant_aname = vrf.tenant_name
vrf_tenant_dname = None vrf_tenant_dname = None
else: else:
vrf_tenant_dname = 'CommonTenant' vrf_tenant_dname = ''
elif scope: elif scope:
scope = self._actual_scopes.get(scope['id'], scope) scope = self._actual_scopes.get(scope['id'], scope)
vrf_aname = self.name_mapper.address_scope(None, scope['id']) vrf_aname = self.name_mapper.address_scope(None, scope['id'])
@ -667,7 +667,7 @@ class TestAimMapping(ApicAimTestCase):
vrf_aname = self.driver.apic_system_id + '_UnroutedVRF' vrf_aname = self.driver.apic_system_id + '_UnroutedVRF'
vrf_dname = 'CommonUnroutedVRF' vrf_dname = 'CommonUnroutedVRF'
vrf_tenant_aname = 'common' vrf_tenant_aname = 'common'
vrf_tenant_dname = 'CommonTenant' vrf_tenant_dname = ''
if net[SVI]: if net[SVI]:
ext_net = aim_resource.ExternalNetwork.from_dn( ext_net = aim_resource.ExternalNetwork.from_dn(
@ -933,7 +933,7 @@ class TestAimMapping(ApicAimTestCase):
# Check common Tenant. # Check common Tenant.
tenant = self._get_tenant('common') tenant = self._get_tenant('common')
self.assertEqual('common', tenant.name) self.assertEqual('common', tenant.name)
self.assertEqual('CommonTenant', tenant.display_name) self.assertEqual('', tenant.display_name)
self.assertEqual('', tenant.descr) self.assertEqual('', tenant.descr)
# Check unrouted VRF. # Check unrouted VRF.

View File

@ -490,13 +490,18 @@ class TestNeutronMapping(AimValidationTestCase):
net = self._test_external_network(vrf_name='v1') net = self._test_external_network(vrf_name='v1')
net_id = net['id'] net_id = net['id']
# Delete network extension data to test migration use case. # Delete network extension data and clear ExternalNetwork
# contracts to test migration use case.
(self.db_session.query(ext_db.NetworkExtensionDb). (self.db_session.query(ext_db.NetworkExtensionDb).
filter_by(network_id=net_id). filter_by(network_id=net_id).
delete()) delete())
(self.db_session.query(ext_db.NetworkExtensionCidrDb). (self.db_session.query(ext_db.NetworkExtensionCidrDb).
filter_by(network_id=net_id). filter_by(network_id=net_id).
delete()) delete())
self.aim_mgr.update(
self.aim_ctx, ext_net,
provided_contract_names=[],
consumed_contract_names=[])
# Test without DN for migration. # Test without DN for migration.
self._validate_unrepairable() self._validate_unrepairable()