def testGetConnectedInterconnectIFDsFilterFakeOnes(self): from test_model import createDevice with self.__dao.getReadWriteSession() as session: device = createDevice(session, "test") fakeSession = flexmock(session) fakeSession.should_receive('query.filter.filter.filter.order_by.all').\ and_return([InterfaceDefinition("et-0/1/0", None, 'uplink'), InterfaceDefinition("et-0/1/1", None, 'uplink'), InterfaceDefinition("uplink-2", None, 'uplink'), InterfaceDefinition("uplink-3", None, 'uplink')]) filteredIfds = self.__dao.getConnectedInterconnectIFDsFilterFakeOnes(fakeSession, device) self.assertEqual(2, len(filteredIfds))
def testcreateLinksInGraph(self): testLinksInTopology = pydot.Dot(graph_type='graph') pod = createPod('pod1', self.dao.Session()) cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao) deviceOne = Device('spine01', "", 'admin', 'admin', 'spine', "", "", pod) deviceOne.id = 'spine01' IF1 = InterfaceDefinition('IF1', deviceOne, 'downlink') IF1.id = 'IF1' deviceTwo = Device('leaf01', "", 'admin', 'admin', 'leaf', "", "", pod) deviceTwo.id = 'leaf01' IF21 = InterfaceDefinition('IF1', deviceTwo, 'uplink') IF21.id = 'IF21' IF1.peer = IF21 IF21.peer = IF1 linkLabel = {deviceOne.id + ':' + IF1.id: deviceTwo.id + ':' + IF21.id} cablingPlanWriter.createLinksInGraph(linkLabel, testLinksInTopology, 'red') path = cablingPlanWriter.outputDir + '/testLinklabel.dot' testLinksInTopology.write_raw(path) data = open(path, 'r').read() #check generated label for links self.assertTrue('spine01:IF1 -- leaf01:IF21 [color=red];' in data)
def testQueryOrderBy(self): deviceOne = createDevice(self.session, 'testdevice') IFDs = [ InterfaceDefinition('et-0/0/0', deviceOne, 9000), InterfaceDefinition('et-0/0/1', deviceOne, 9000), InterfaceDefinition('et-0/0/2', deviceOne, 9000), InterfaceDefinition('et-0/0/3', deviceOne, 9000), InterfaceDefinition('et-0/0/10', deviceOne, 9000), InterfaceDefinition('et-0/0/11', deviceOne, 9000), InterfaceDefinition('et-0/0/12', deviceOne, 9000), InterfaceDefinition('et-0/0/13', deviceOne, 9000) ] self.session.add_all(IFDs) self.session.commit() fetchedIfds = self.session.query(InterfaceDefinition).order_by( InterfaceDefinition.name_order_num).all() self.assertEqual('et-0/0/0', fetchedIfds[0].name) self.assertEqual('et-0/0/1', fetchedIfds[1].name) self.assertEqual('et-0/0/2', fetchedIfds[2].name) self.assertEqual('et-0/0/3', fetchedIfds[3].name) self.assertEqual('et-0/0/10', fetchedIfds[4].name) self.assertEqual('et-0/0/11', fetchedIfds[5].name) self.assertEqual('et-0/0/12', fetchedIfds[6].name) self.assertEqual('et-0/0/13', fetchedIfds[7].name)
def testGetAllocatedConnectedUplinkIfds(self): from test_model import createDevice with self._dao.getReadSession() as session: leaf = createDevice(session, 'leaf') dataCollector = L2DataCollector(leaf.id, {}, InMemoryDao) dataCollector.manualInit() dataCollector._session = session flexmock(session).should_receive('query.filter.filter.filter.order_by.all').\ and_return([InterfaceDefinition("et-0/0/48", None, 'uplink'), InterfaceDefinition("et-0/0/49", None, 'uplink'), InterfaceDefinition("et-0/0/50", None, 'uplink')]) ifds = dataCollector.getAllocatedConnectedUplinkIfds() self.assertIsNotNone(ifds['et-0/0/48']) self.assertTrue(isinstance(ifds['et-0/0/48'], InterfaceDefinition)) self.assertIsNotNone(ifds['et-0/0/49']) self.assertIsNotNone(ifds['et-0/0/50'])
def testCreateObjects(self): from test_model import createDevice with self.__dao.getReadWriteSession() as session: device = createDevice(session, "test") ifd1 = InterfaceDefinition('ifd1', device, 'downlink') ifd2 = InterfaceDefinition('ifd2', device, 'downlink') ifd3 = InterfaceDefinition('ifd3', device, 'downlink') ifd4 = InterfaceDefinition('ifd4', device, 'downlink') self.__dao.createObjects(session, [ifd1, ifd2, ifd3, ifd4]) with self.__dao.getReadSession() as session: self.assertEqual(4, len(self.__dao.getAll(session, InterfaceDefinition))) self.assertEqual(1, len(self.__dao.getObjectsByName(session, InterfaceDefinition, 'ifd1'))) self.assertEqual(1, len(self.__dao.getObjectsByName(session, InterfaceDefinition, 'ifd2')))
def testCreateObjects(self): from test_model import createDevice #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() device = createDevice(session, "test") ifd1 = InterfaceDefinition('ifd1', device, 'downlink') ifd2 = InterfaceDefinition('ifd2', device, 'downlink') ifd3 = InterfaceDefinition('ifd1', device, 'downlink') ifd4 = InterfaceDefinition('ifd2', device, 'downlink') dao.createObjects([ifd1, ifd2, ifd3, ifd4]) self.assertEqual(4, len(dao.getAll(InterfaceDefinition))) self.assertEqual( 2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd1'))) self.assertEqual( 2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd2')))
def testOrm(self): deviceOne = createDevice(self.session, 'testdevice') IFD = InterfaceDefinition('et-0/0/0', deviceOne, 'uplink') self.session.add(IFD) self.session.commit() fetched = self.session.query(InterfaceDefinition).one() self.assertEqual(IFD, fetched) self.assertEqual("physical", fetched.type) #delete object self.session.delete(IFD) self.session.commit() self.assertEqual(0, self.session.query(InterfaceDefinition).count())
def createTwoSpineTwoLeafPlugNPlay(self, session): from test_model import createPod pod = createPod('pod1', session) from test_model import createPodDevice spine1 = createPodDevice(session, 'spine1', pod) spine2 = createPodDevice(session, 'spine2', pod) leaf1 = createPodDevice(session, 'leaf1', pod) leaf1.role = 'leaf' leaf1.family = 'qfx5100-48s-6q' leaf2 = createPodDevice(session, 'leaf2', pod) leaf2.role = 'leaf' leaf2.family = 'unknown' IFDs = [ InterfaceDefinition('et-0/0/0', spine1, 'downlink'), InterfaceDefinition('et-0/0/1', spine1, 'downlink'), InterfaceDefinition('et-0/0/0', spine2, 'downlink'), InterfaceDefinition('et-0/0/1', spine2, 'downlink'), InterfaceDefinition('et-0/0/48', leaf1, 'uplink'), InterfaceDefinition('et-0/0/49', leaf1, 'uplink'), InterfaceDefinition('uplink-1', leaf2, 'uplink'), InterfaceDefinition('uplink-2', leaf2, 'uplink') ] session.add_all(IFDs) IFLs = self.createIfls(session, IFDs) IFDs[4].peer = IFDs[0] IFDs[0].peer = IFDs[4] IFDs[5].peer = IFDs[2] IFDs[2].peer = IFDs[5] IFDs[6].peer = IFDs[1] IFDs[1].peer = IFDs[6] IFDs[7].peer = IFDs[3] IFDs[3].peer = IFDs[7] return {'ifds': IFDs, 'ifls': IFLs}
def testcreateLinksInGraph(self): testLinksInTopology = pydot.Dot(graph_type='graph') pod = createPod('pod1', self.dao.Session()) cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao) deviceOne = Device('spine01',"", 'admin', 'admin', 'spine', "", "", pod) deviceOne.id = 'spine01' IF1 = InterfaceDefinition('IF1', deviceOne, 'downlink') IF1.id = 'IF1' deviceTwo = Device('leaf01',"", 'admin', 'admin', 'leaf', "", "", pod) deviceTwo.id = 'leaf01' IF21 = InterfaceDefinition('IF1', deviceTwo, 'uplink') IF21.id = 'IF21' IF1.peer = IF21 IF21.peer = IF1 linkLabel = {deviceOne.id + ':' + IF1.id : deviceTwo.id + ':' + IF21.id} cablingPlanWriter.createLinksInGraph(linkLabel, testLinksInTopology, 'red') path = cablingPlanWriter.outputDir + '/testLinklabel.dot' testLinksInTopology.write_raw(path) data = open(path, 'r').read() #check generated label for links self.assertTrue('spine01:IF1 -- leaf01:IF21 [color=red];' in data)
def testcreateDOTFile(self): # create pod # create device #create interface session = self.dao.Session() pod = createPod('pod1', session) cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao) deviceOne = Device('spine01', "", 'admin', 'admin', 'spine', "", "", pod) session.add(deviceOne) IF1 = InterfaceDefinition('IF1', deviceOne, 'downlink') session.add(IF1) IF2 = InterfaceDefinition('IF2', deviceOne, 'downlink') session.add(IF2) deviceTwo = Device('leaf01', "", 'admin', 'admin', 'leaf', "", "", pod) session.add(deviceTwo) IF21 = InterfaceDefinition('IF1', deviceTwo, 'uplink') session.add(IF21) IF22 = InterfaceDefinition('IF2', deviceTwo, 'uplink') session.add(IF22) IF23 = InterfaceDefinition('IF3', deviceTwo, 'downlink') session.add(IF23) IF24 = InterfaceDefinition('IF3', deviceTwo, 'downlink') session.add(IF24) deviceThree = Device('Access01', "", 'admin', 'admin', 'leaf', "", "", pod) session.add(deviceThree) IF31 = InterfaceDefinition('IF1', deviceThree, 'uplink') session.add(IF31) IF32 = InterfaceDefinition('IF2', deviceThree, 'uplink') session.add(IF32) IF1.peer = IF21 IF2.peer = IF22 IF21.peer = IF1 IF22.peer = IF2 IF23.peer = IF31 IF31.peer = IF23 IF24.peer = IF32 IF32.peer = IF24 session.commit() devices = session.query(Device).all() #check the DOT file is generated cablingPlanWriter.writeDOT() data = open(cablingPlanWriter.outputDir + '/cablingPlan.dot', 'r').read() #check generated label for links self.assertTrue('splines=polyline;' in data)
def testConstructorPass(self): deviceOne = createDevice(self.session, 'testdevice') self.assertTrue(InterfaceDefinition('et-0/0/0', deviceOne, 'downlink') is not None) self.assertTrue(InterfaceDefinition('et-0/0/1', deviceOne, 'uplink', 9000) is not None)
def testcreateDOTFile(self): # create pod # create device #create interface session = self.dao.Session() pod = createPod('pod1', session) cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao) deviceOne = Device('spine01',"", 'admin', 'admin', 'spine', "", "", pod) session.add(deviceOne) IF1 = InterfaceDefinition('IF1', deviceOne, 'downlink') session.add(IF1) IF2 = InterfaceDefinition('IF2', deviceOne, 'downlink') session.add(IF2) deviceTwo = Device('leaf01',"", 'admin', 'admin', 'leaf', "", "", pod) session.add(deviceTwo) IF21 = InterfaceDefinition('IF1', deviceTwo, 'uplink') session.add(IF21) IF22 = InterfaceDefinition('IF2', deviceTwo, 'uplink') session.add(IF22) IF23 = InterfaceDefinition('IF3', deviceTwo, 'downlink') session.add(IF23) IF24 = InterfaceDefinition('IF3', deviceTwo, 'downlink') session.add(IF24) deviceThree = Device('Access01', "",'admin', 'admin', 'leaf', "", "", pod) session.add(deviceThree) IF31 = InterfaceDefinition('IF1', deviceThree, 'uplink') session.add(IF31) IF32 = InterfaceDefinition('IF2', deviceThree, 'uplink') session.add(IF32) IF1.peer = IF21 IF2.peer = IF22 IF21.peer = IF1 IF22.peer = IF2 IF23.peer = IF31 IF31.peer = IF23 IF24.peer = IF32 IF32.peer = IF24 session.commit() devices = session.query(Device).all() #check the DOT file is generated cablingPlanWriter.writeDOT() data = open(cablingPlanWriter.outputDir + '/cablingPlan.dot', 'r').read() #check generated label for links self.assertTrue('splines=polyline;' in data)
def createSixSpineOneLeafqfx5100_48sPlugNPlay(self, session): from test_model import createPod pod = createPod('pod1', session) from test_model import createPodDevice spine1 = createPodDevice(session, 'spine1', pod) spine2 = createPodDevice(session, 'spine2', pod) spine3 = createPodDevice(session, 'spine3', pod) spine4 = createPodDevice(session, 'spine4', pod) spine5 = createPodDevice(session, 'spine5', pod) spine6 = createPodDevice(session, 'spine6', pod) leaf1 = createPodDevice(session, 'leaf1', pod) leaf1.role = 'leaf' leaf1.family = 'qfx5100-48s-6q' IFDs = [ InterfaceDefinition('et-0/0/0', spine1, 'downlink'), InterfaceDefinition('et-0/0/0', spine2, 'downlink'), InterfaceDefinition('et-0/0/0', spine3, 'downlink'), InterfaceDefinition('et-0/0/0', spine4, 'downlink'), InterfaceDefinition('et-0/0/0', spine5, 'downlink'), InterfaceDefinition('et-0/0/0', spine6, 'downlink'), InterfaceDefinition('et-0/0/48', leaf1, 'uplink'), InterfaceDefinition('et-0/0/49', leaf1, 'uplink'), InterfaceDefinition('et-0/0/50', leaf1, 'uplink'), InterfaceDefinition('et-0/0/51', leaf1, 'uplink'), InterfaceDefinition('et-0/0/52', leaf1, 'uplink'), InterfaceDefinition('et-0/0/53', leaf1, 'uplink') ] session.add_all(IFDs) IFLs = self.createIfls(session, IFDs) IFDs[6].peer = IFDs[0] IFDs[0].peer = IFDs[6] IFDs[7].peer = IFDs[1] IFDs[1].peer = IFDs[7] IFDs[8].peer = IFDs[2] IFDs[2].peer = IFDs[8] IFDs[9].peer = IFDs[3] IFDs[3].peer = IFDs[9] IFDs[10].peer = IFDs[4] IFDs[4].peer = IFDs[10] IFDs[11].peer = IFDs[5] IFDs[5].peer = IFDs[11] return {'ifds': IFDs, 'ifls': IFLs}
def createTwoSpineTwoLeafWithDummyUplinksForEx4300(self, session): from test_model import createPod pod = createPod('pod1', session) from test_model import createPodDevice spine1 = createPodDevice(session, 'spine1', pod) spine2 = createPodDevice(session, 'spine2', pod) spine3 = createPodDevice(session, 'spine3', pod) leaf1 = createPodDevice(session, 'leaf1', pod) leaf1.role = 'leaf' leaf1.family = 'qfx5100-48s-6q' leaf2 = createPodDevice(session, 'leaf2', pod) leaf2.role = 'leaf' leaf2.family = 'qfx5100-48s-6q' IFDs = [ InterfaceDefinition('et-0/0/0', spine1, 'downlink'), InterfaceDefinition('et-0/0/1', spine1, 'downlink'), InterfaceDefinition('et-0/0/0', spine2, 'downlink'), InterfaceDefinition('et-0/0/1', spine2, 'downlink'), InterfaceDefinition('et-0/0/0', spine3, 'downlink'), InterfaceDefinition('et-0/0/1', spine3, 'downlink'), InterfaceDefinition('et-0/0/48', leaf1, 'uplink'), InterfaceDefinition('et-0/0/49', leaf1, 'uplink'), InterfaceDefinition('et-0/0/50', leaf2, 'uplink'), InterfaceDefinition('et-0/0/48', leaf2, 'uplink'), InterfaceDefinition('et-0/0/49', leaf2, 'uplink'), InterfaceDefinition('dummy', leaf2, 'uplink') ] session.add_all(IFDs) IFDs[6].peer = IFDs[0] IFDs[0].peer = IFDs[6] IFDs[7].peer = IFDs[2] IFDs[2].peer = IFDs[7] IFDs[8].peer = IFDs[4] IFDs[4].peer = IFDs[8] IFDs[9].peer = IFDs[1] IFDs[1].peer = IFDs[9] IFDs[10].peer = IFDs[3] IFDs[3].peer = IFDs[10] IFDs[11].peer = IFDs[5] IFDs[5].peer = IFDs[11] return IFDs