def _get_ppg_device_cluster(self, session, ppg, tenant): tenant_aid = tenant ppg_aid = self.name_mapper.port_pair_group(session, ppg['id']) ppg_aname = aim_utils.sanitize_display_name(ppg['name']) return aim_sg.DeviceCluster(tenant_name=tenant_aid, name=ppg_aid, display_name=ppg_aname, managed=False)
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)
def test_host_data_migration(self): self.mgr.create(self.ctx, infra.HostLink( host_name='h1', interface_name='eth0', path='h1/path/VPC')) self.mgr.create(self.ctx, infra.HostLink( host_name='h1', interface_name='eth1', path='h1/path/2')) self.mgr.create(self.ctx, infra.HostLink( host_name='h1', interface_name='eth2', path='h1/path/VPC')) self.mgr.create(self.ctx, infra.HostLink( host_name='h2', interface_name='eth2', path='h2/path')) epg1 = self.mgr.create(self.ctx, resource.EndpointGroup( tenant_name='t1', app_profile_name='ap', name='epg1', static_paths=[{'path': 'h1/path/2', 'encap': '100'}, {'path': 'h2/path', 'encap': '100'}, {'path': 'not_known', 'encap': '100'}])) epg2 = self.mgr.create(self.ctx, resource.EndpointGroup( tenant_name='t1', app_profile_name='ap', name='epg2', static_paths=[{'path': 'h1/path/2', 'encap': '100'}, {'path': 'h1/path/VPC', 'encap': '100'}])) dc = self.mgr.create(self.ctx, service_graph.DeviceCluster( tenant_name='t2', name='dc', devices=[{'path': 'h1/path/2', 'name': '1'}, {'path': 'h2/path', 'name': '2'}])) cdi1 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface( tenant_name='t2', device_cluster_name='dc', device_name='1', name='dc', path='h1/path/VPC')) cdi2 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface( tenant_name='t2', device_cluster_name='dc', device_name='2', name='dc', path='h2/path')) l3out_iface1 = self.mgr.create( self.ctx, resource.L3OutInterface( tenant_name='t2', l3out_name='dc', node_profile_name='1', interface_profile_name='dc1', interface_path='h1/path/VPC')) l3out_iface2 = self.mgr.create( self.ctx, resource.L3OutInterface( tenant_name='t2', l3out_name='dc', node_profile_name='1', interface_profile_name='dc2', interface_path='h2/path')) add_host_column.migrate(self.ctx.db_session) epg1 = self.mgr.get(self.ctx, epg1) self.assertEqual( utils.deep_sort( [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'}, {'path': 'h2/path', 'encap': '100', 'host': 'h2'}, {'path': 'not_known', 'encap': '100'}]), utils.deep_sort(epg1.static_paths)) epg2 = self.mgr.get(self.ctx, epg2) self.assertEqual( utils.deep_sort( [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'}, {'path': 'h1/path/VPC', 'encap': '100', 'host': 'h1'}]), utils.deep_sort(epg2.static_paths)) dc = self.mgr.get(self.ctx, dc) self.assertEqual( utils.deep_sort( [{'path': 'h1/path/2', 'name': '1', 'host': 'h1'}, {'path': 'h2/path', 'name': '2', 'host': 'h2'}]), utils.deep_sort(dc.devices)) cdi1 = self.mgr.get(self.ctx, cdi1) self.assertEqual('h1', cdi1.host) cdi2 = self.mgr.get(self.ctx, cdi2) self.assertEqual('h2', cdi2.host) l3out_iface1 = self.mgr.get(self.ctx, l3out_iface1) self.assertEqual('h1', l3out_iface1.host) l3out_iface2 = self.mgr.get(self.ctx, l3out_iface2) self.assertEqual('h2', l3out_iface2.host)