def _get_ppg_service_redirect_policy(self, session, ppg, direction, tenant): if direction == INGRESS: prfx = PBR_INGR_PREFIX elif direction == EGRESS: prfx = PBR_EGR_PREFIX dc = self._get_ppg_device_cluster(session, ppg, tenant) pbr_id = self.name_mapper.port_pair_group(session, ppg['id'], prefix=prfx) return aim_sg.ServiceRedirectPolicy(tenant_name=dc.tenant_name, name=pbr_id)
def _delete_port_pair_group_mapping(self, plugin_context, ppg, tenant): # Just delete cascade the DeviceCluster and PBR policies session = plugin_context.session aim_ctx = aim_context.AimContext(session) dc = self._get_ppg_device_cluster(session, ppg, tenant) self.aim.delete(aim_ctx, dc, cascade=True) for prefix in [PBR_INGR_PREFIX, PBR_EGR_PREFIX]: pbr_id = self.name_mapper.port_pair_group(session, ppg['id'], prefix=prefix) self.aim.delete(aim_ctx, aim_sg.ServiceRedirectPolicy( tenant_name=dc.tenant_name, name=pbr_id), cascade=True)
def test_push_resources_service_graph(self): aim_mgr = aim_manager.AimManager() aim_mgr.create(self.ctx, resource.Tenant(name='t1')) def create_delete_object(aim_obj, aci_obj, aci_faults): # create object and faults to_create = [aci_obj] to_create.extend(aci_faults) self.universe.push_resources(self.ctx, {'create': to_create, 'delete': []}) self.assertIsNotNone(aim_mgr.get(self.ctx, aim_obj)) status = aim_mgr.get_status(self.ctx, aim_obj) self.assertEqual(len(aci_faults), len(status.faults)) self.assertEqual(sorted([f['faultInst']['attributes']['code'] for f in aci_faults]), sorted([f.fault_code for f in status.faults])) # delete filter faults self.universe.push_resources(self.ctx, {'create': [], 'delete': status.faults}) status = aim_mgr.get_status(self.ctx, aim_obj) self.assertEqual(0, len(status.faults)) # Objects with alt_resource dc1_aci = {'vnsLDevVip': {'attributes': {'dn': 'uni/tn-t1/lDevVip-cl2'}}} dc1_fault_objs = [ self._get_example_aci_fault( dn='uni/tn-t1/lDevVip-cl2/fault-F1110', code='F1110'), self._get_example_aci_fault( dn='uni/tn-t1/lDevVip-cl2/lIf-interface/fault-F1111', code='F1111'), self._get_example_aci_fault( dn='uni/tn-t1/lDevVip-cl2/cDev-n2/cIf-[interface]/fault-F1112', code='F1112')] dc1 = aim_service_graph.DeviceCluster(tenant_name='t1', name='cl2') create_delete_object(dc1, dc1_aci, dc1_fault_objs) sg1_aci = {'vnsAbsGraph': {'attributes': {'dn': 'uni/tn-t1/AbsGraph-gr2'}}} sg1_fault_objs = [ self._get_example_aci_fault( dn='uni/tn-t1/AbsGraph-gr2/fault-F1110', code='F1110'), self._get_example_aci_fault( dn='uni/tn-t1/AbsGraph-gr2/AbsConnection-C1/fault-F1111', code='F1111'), self._get_example_aci_fault( dn='uni/tn-t1/AbsGraph-gr2/AbsNode-N1/fault-F1112', code='F1112')] sg1 = aim_service_graph.ServiceGraph(tenant_name='t1', name='gr2') srp1_aci = {'vnsSvcRedirectPol': {'attributes': {'dn': 'uni/tn-t1/svcCont/svcRedirectPol-r2'}}} srp1_fault_objs = [ self._get_example_aci_fault( dn='uni/tn-t1/svcCont/svcRedirectPol-r2/fault-F1111', code='F1111'), self._get_example_aci_fault( dn=('uni/tn-t1/svcCont/svcRedirectPol-r2/' 'RedirectDest_ip-[10.6.1.1]/fault-F1112'), code='F1112')] srp1 = aim_service_graph.ServiceRedirectPolicy(tenant_name='t1', name='r2') dcc1_aci = {'vnsLDevCtx': {'attributes': {'dn': 'uni/tn-t1/ldevCtx-c-c1-g-g1-n-N1'}}} dcc1_fault_objs = [ self._get_example_aci_fault( dn='uni/tn-t1/ldevCtx-c-c1-g-g1-n-N1/fault-F1111', code='F1111'), self._get_example_aci_fault( dn=('uni/tn-t1/ldevCtx-c-c1-g-g1-n-N1/lIfCtx-c-consumer/' 'fault-F1112'), code='F1112')] dcc1 = aim_service_graph.DeviceClusterContext(tenant_name='t1', contract_name='c1', service_graph_name='g1', node_name='N1') create_delete_object(dc1, dc1_aci, dc1_fault_objs) create_delete_object(sg1, sg1_aci, sg1_fault_objs) create_delete_object(srp1, srp1_aci, srp1_fault_objs) create_delete_object(dcc1, dcc1_aci, dcc1_fault_objs)
def test_get_aim_resources(self, tree_type=tree_manager.CONFIG_TREE): tree_mgr = tree_manager.HashTreeManager() aim_mgr = aim_manager.AimManager() t1 = resource.Tenant(name='t1') t2 = resource.Tenant(name='t2') t1_fault = aim_status.AciFault( fault_code='101', external_identifier='uni/tn-t1/fault-101', description='failure101') t2_fault = aim_status.AciFault( fault_code='102', external_identifier='uni/tn-t2/fault-102', description='failure102') # Create Resources on a couple of tenants bd1 = resource.BridgeDomain( tenant_name='t1', name='bd1', display_name='somestuff', vrf_name='vrf') bd1_fault = aim_status.AciFault( fault_code='901', external_identifier='uni/tn-t1/BD-bd1/fault-901', description='failure901') bd1_fault2 = aim_status.AciFault( fault_code='902', external_identifier='uni/tn-t1/BD-bd1/fault-902', description='failure902') bd2 = resource.BridgeDomain( tenant_name='t2', name='bd1', display_name='somestuff', vrf_name='vrf2') dc1 = aim_service_graph.DeviceCluster( tenant_name='t1', name='clus1', devices=[{'name': '1'}]) dc1_fault = aim_status.AciFault( fault_code='901', external_identifier='uni/tn-t1/lDevVip-clus1/fault-901', description='failure901') sg1 = aim_service_graph.ServiceGraph( tenant_name='t1', name='gr1', linear_chain_nodes=[{'name': 'N1', 'device_cluster_name': 'cl1'}]) sg1_fault = aim_status.AciFault( fault_code='901', external_identifier='uni/tn-t1/AbsGraph-gr1/fault-901', description='failure901') srp1 = aim_service_graph.ServiceRedirectPolicy( tenant_name='t1', name='srp1', destinations=[{'ip': '1.1.1.1', 'mac': 'aa:bb:cc:dd:ee:ff'}]) srp1_fault = aim_status.AciFault( fault_code='901', external_identifier=('uni/tn-t1/svcCont/svcRedirectPol-srp1' '/fault-901'), description='failure901') dc_ctx1 = aim_service_graph.DeviceClusterContext( tenant_name='t1', contract_name='contract1', service_graph_name='graph1', node_name='N1', device_cluster_name='cluster1', device_cluster_tenant_name='common', bridge_domain_name='svc_bd', service_redirect_policy_name='srp1') dc_ctx1_fault = aim_status.AciFault( fault_code='901', external_identifier=('uni/tn-t1/ldevCtx-c-contract1-' 'g-graph1-n-N1/fault-901'), description='failure901') if tree_type == tree_manager.MONITORED_TREE: bd1.monitored = True bd2.monitored = True t1.monitored = True t2.monitored = True dc1.monitored = True sg1.monitored = True srp1.monitored = True dc_ctx1.monitored = True aim_mgr.create(self.ctx, t1) aim_mgr.create(self.ctx, t2) aim_mgr.create(self.ctx, bd1) aim_mgr.set_fault(self.ctx, t1, t1_fault) aim_mgr.set_fault(self.ctx, t2, t2_fault) aim_mgr.set_fault(self.ctx, bd1, bd1_fault) aim_mgr.set_fault(self.ctx, bd1, bd1_fault2) aim_mgr.create(self.ctx, bd2) aim_mgr.set_resource_sync_synced(self.ctx, t1) aim_mgr.set_resource_sync_synced(self.ctx, t2) aim_mgr.set_resource_sync_synced(self.ctx, bd2) aim_mgr.set_resource_sync_synced(self.ctx, bd1) aim_mgr.create(self.ctx, dc1) aim_mgr.create(self.ctx, sg1) aim_mgr.create(self.ctx, srp1) aim_mgr.create(self.ctx, dc_ctx1) aim_mgr.set_fault(self.ctx, dc1, dc1_fault) aim_mgr.set_fault(self.ctx, sg1, sg1_fault) aim_mgr.set_fault(self.ctx, srp1, srp1_fault) aim_mgr.set_fault(self.ctx, dc_ctx1, dc_ctx1_fault) aim_mgr.set_resource_sync_synced(self.ctx, dc1) aim_mgr.set_resource_sync_synced(self.ctx, sg1) aim_mgr.set_resource_sync_synced(self.ctx, srp1) aim_mgr.set_resource_sync_synced(self.ctx, dc_ctx1) # Two trees exist trees = tree_mgr.find(self.ctx, tree=tree_type) self.assertEqual(2, len(trees)) # Calculate the different with empty trees to retrieve missing keys diff_tn_1 = trees[0].diff(tree.StructuredHashTree()) diff_tn_2 = trees[1].diff(tree.StructuredHashTree()) self.universe.get_relevant_state_for_read = mock.Mock( return_value=[{'tn-t1': trees[0], 'tn-t2': trees[1]}]) result = self.universe.get_resources(diff_tn_1.get('add', []) + diff_tn_1.get('remove', []) + diff_tn_2.get('add', []) + diff_tn_2.get('remove', [])) converted = converter.AciToAimModelConverter().convert( converter.AimToAciModelConverter().convert( [bd1, bd2, dc1, sg1, srp1, dc_ctx1, t1, t2])) if tree_type == tree_manager.MONITORED_TREE: for x in converted: x.monitored = True if tree_type in [tree_manager.CONFIG_TREE, tree_manager.MONITORED_TREE]: self.assertEqual(len(converted), len(result)) for item in converted: self.assertTrue(item in result) elif tree_type == tree_manager.OPERATIONAL_TREE: self.assertEqual(8, len(result)) self.assertTrue(bd1_fault in result) self.assertTrue(bd1_fault2 in result) self.assertTrue(dc1_fault in result) self.assertTrue(sg1_fault in result) self.assertTrue(srp1_fault in result) self.assertTrue(dc_ctx1_fault in result)