示例#1
0
    def testRelationPodDevice(self):
        podOne = createPod('testpodOne', self.session)
        deviceOne = Device('testDeviceOne', 'QFX5100-48S', 'admin', 'admin',
                           "spine", "", "", podOne)
        self.session.add(deviceOne)

        podTwo = createPod('testpodTwo', self.session)
        deviceTwo = Device('testDeviceOne', 'QFX5100-48S', 'admin', 'admin',
                           "spine", "", "", podTwo)
        self.session.add(deviceTwo)
        deviceThree = Device('testDeviceOne', 'QFX5100-48S', 'admin', 'admin',
                             "spine", "", "", podTwo)
        self.session.add(deviceThree)
        self.session.commit()

        self.assertEqual(2, self.session.query(Pod).count())
        pods = self.session.query(Pod).all()
        self.assertEqual(1, len(pods[0].devices))
        self.assertEqual(2, len(pods[1].devices))

        # check relation navigation from device to Pod
        devices = self.session.query(Device).all()
        self.assertIsNotNone(devices[0].pod)
        self.assertIsNotNone(devices[1].pod)
        self.assertEqual(podOne.id, devices[0].pod_id)
        self.assertEqual(podTwo.id, devices[1].pod_id)
示例#2
0
 def testLargeAsn(self):
     podOne = createPod('testpod', self.session)
     device = Device('testdevice', 'qfx-5100-48s-6q', 'admin', 'admin', "spine", "", "", podOne)
     device.asn = 4294967295
     self.session.add(device)
     self.session.commit()  
     fetched = self.session.query(Device).one()
     self.assertEqual(device, fetched)        
示例#3
0
 def testWriteConfigInFile(self):
     from jnpr.openclos.model import DeviceConfig
     self._conf['writeConfigInFile'] = True
     with self._dao.getReadWriteSession() as session:
         pod = createPod('pod1', session)
         device = Device('test_device', "",'admin', 'admin', 'spine', "", "", pod)
         device.config = DeviceConfig(device.id, "dummy config")
         configWriter = ConfigWriter(self._conf, pod, self._dao)
         configWriter.write(device)
         self.assertTrue(os.path.exists(os.path.join(configWriter.outputDir, device.id+'__test_device.conf')))
示例#4
0
    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)
示例#5
0
    def testConnectToDeviceValueError(self):
        flexmock(self._dao).should_receive('getObjectById').and_return(
            Device("test", "qfx5100-48s-6q", None, "abcd1234", "leaf", "",
                   "0.0.0.0", None))
        self.dataCollector.manualInit()

        with self.assertRaises(DeviceConnectFailed) as ve:
            self.dataCollector.connectToDevice()
示例#6
0
 def testWrite(self):
     pod = createPod('pod1', self.dao.Session())
     device = Device('test_device', "", 'admin', 'admin', 'spine', "", "",
                     pod)
     configWriter = ConfigWriter(self.conf, pod, self.dao)
     configWriter.write(device, "dummy config")
     self.assertTrue(
         os.path.exists(configWriter.outputDir + '/test_device.conf'))
示例#7
0
    def testConnectToDevice(self):
        flexmock(self._dao).should_receive('getObjectById').and_return(
            Device("test", "qfx5100-48s-6q", "root", "abcd1234", "leaf", "",
                   "192.168.48.182", None))

        dataCollector = DeviceDataCollectorNetconf('1234', {}, InMemoryDao)
        dataCollector._dao = self._dao
        dataCollector.manualInit()

        dataCollector.connectToDevice()
示例#8
0
    def testCollectLldpFromDevice(self):
        flexmock(self._dao).should_receive('getObjectById').and_return(
            Device("test", "qfx5100-96s-8q", "root", "abcd1234", "leaf", "",
                   "192.168.48.219", None))

        dataCollector = L2DataCollector('1234', self.__conf, InMemoryDao)
        dataCollector._dao = self._dao
        dataCollector.manualInit()

        dataCollector.connectToDevice()
        dataCollector.collectLldpFromDevice()
示例#9
0
    def testConnectToDeviceConnectError(self):
        flexmock(self._dao).should_receive('getObjectById').and_return(
            Device("test", "qfx5100-48s-6q", "root", "abcd1234", "leaf", "",
                   "0.0.0.0", None))
        self.dataCollector.manualInit()

        with self.assertRaises(DeviceConnectFailed) as de:
            self.dataCollector.connectToDevice()

        self.assertIsNotNone(de.exception.cause)
        self.assertTrue(issubclass(type(de.exception.cause), ConnectError))
示例#10
0
 def testOrm(self):
     podOne = createPod('testpod', self.session)
     device = Device('testdevice', 'qfx-5100-48s-6q', 'admin', 'admin', "spine", "", "", podOne, "provision", "VB1234567890")
     self.session.add(device)
     self.session.commit()  
     fetched = self.session.query(Device).one()
     self.assertEqual(device, fetched)
     
     #delete object
     self.session.delete(device)
     self.session.commit()
     self.assertEqual(0, self.session.query(Device).count())
示例#11
0
    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)
示例#12
0
    def testCreateRoutingOptionsStatic(self):
        self.createPodSpineLeaf()
        with self._dao.getReadSession() as session:
            pod = session.query(Pod).one()
            device = Device("test", "qfx5100-48s-6q", "user", "pwd", "leaf",
                            "mac", "mgmtIp", pod)
            device.pod.outOfBandGateway = '10.0.0.254'
            device.pod.outOfBandAddressList = '10.0.10.5/32, 10.0.20.5/32'

            configlet = self.l3ClosMediation._createRoutingOptionsStatic(
                session, device)
            self.assertEquals(1, configlet.count('static'))
            self.assertEquals(2, configlet.count('route'))
示例#13
0
    def testOrm(self):
        podOne = createPod('testpod', self.session)
        device = Device('testdevice', 'QFX5100-48S', 'admin', 'admin', "spine",
                        "", "", podOne)
        self.session.add(device)
        self.session.commit()
        fetched = self.session.query(Device).one()
        self.assertEqual(device, fetched)

        #delete object
        self.session.delete(device)
        self.session.commit()
        self.assertEqual(0, self.session.query(Device).count())
示例#14
0
 def testCreateAccessInterface(self):
     with self._dao.getReadSession() as session:
         from test_model import createPod
         pod = createPod('test', session)
         device = Device("test", "qfx5100-48s-6q", "user", "pwd", "leaf",
                         "mac", "mgmtIp", pod)
         configlet = self.l3ClosMediation._createAccessPortInterfaces(
             session, device)
         self.assertEquals(96, configlet.count('family ethernet-switching'))
         self.assertTrue('xe-0/0/0' in configlet)
         self.assertTrue('xe-0/0/47' in configlet)
         self.assertTrue('ge-0/0/0' in configlet)
         self.assertTrue('ge-0/0/47' in configlet)
示例#15
0
 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)
示例#16
0
    def testCreatePolicyOptionSpine(self):
        l3ClosMediation = L3ClosMediation(self.conf)
        device = Device("test", "QFX5100-24Q", "user", "pwd", "spine", "mac",
                        "mgmtIp", self.createPod(l3ClosMediation))
        device.pod.allocatedIrbBlock = '10.0.0.0/28'
        device.pod.allocatedLoopbackBlock = '11.0.0.0/28'
        configlet = l3ClosMediation.createPolicyOption(device)

        self.assertTrue('irb_in' not in configlet
                        and '10.0.0.0/28' in configlet)
        self.assertTrue('lo0_in' not in configlet
                        and '11.0.0.0/28' in configlet)
        self.assertTrue('lo0_out' not in configlet)
        self.assertTrue('irb_out' not in configlet)
示例#17
0
 def testCreateAccessInterfaceEx4300(self):
     self._conf['deviceFamily']['ex4300-48p'] = {
         "uplinkPorts": 'et-0/0/[48-51]',
         "downlinkPorts": 'ge-0/0/[0-47]'
     }
     self.l3ClosMediation = L3ClosMediation(self._conf, InMemoryDao)
     with self._dao.getReadSession() as session:
         from test_model import createPod
         pod = createPod('test', session)
         device = Device("test", "ex4300-48p", "user", "pwd", "leaf", "mac",
                         "mgmtIp", pod)
         configlet = self.l3ClosMediation._createAccessPortInterfaces(
             session, device)
         self.assertEquals(48, configlet.count('family ethernet-switching'))
         self.assertTrue('ge-0/0/0' in configlet)
         self.assertTrue('ge-0/0/47' in configlet)
示例#18
0
    def testStoreBgpLinks(self):
        device_id = None
        with self._dao.getReadWriteSession() as session:
            from test_model import createPod
            pod = createPod('pod1', session)
            session.add(pod)
            device = Device("leaf1", "qfx5100-48s-6q", "", "", "leaf",
                            "11:12:13:14:15:16", "1.2.3.4/24", pod)
            device_id = device.id
            session.add(device)

        with self._dao.getReadSession() as session:
            dataCollector = L3DataCollector(device_id, {}, InMemoryDao)
            dataCollector.manualInit()
            dataCollector._session = session

            bgpLinks = [{
                'device1': 'leaf1',
                'device1as1': 401,
                'device1Ip': '192.169.0.3+179',
                'device2': None,
                'device2as': 300,
                'device2Ip': '192.169.0.2+57574',
                'inputMsgCount': 16764,
                'outputMsgCount': 16811,
                'outQueueCount': 0,
                'linkState': 'Established',
                'active/receive/acceptCount': '3/3/3'
            }, {
                'device1': 'leaf1',
                'device1as1': 401,
                'device1Ip': '192.169.0.11+179',
                'device2': None,
                'device2as': 301,
                'device2Ip': '192.169.0.10+49383',
                'inputMsgCount': 16816,
                'outputMsgCount': 16810,
                'outQueueCount': 0,
                'linkState': 'Established',
                'active/receive/acceptCount': '2/2/2'
            }]
            dataCollector.persistBgpLinks(bgpLinks)

            bgpLinks = session.query(BgpLink).filter(
                BgpLink.device_id == device_id).all()
            self.assertEqual('192.169.0.3+179', bgpLinks[0].device1Ip)
            self.assertEqual('192.169.0.11+179', bgpLinks[1].device1Ip)
示例#19
0
    def testCreatePolicyOptionSpine(self):
        self.createPodSpineLeaf()
        with self._dao.getReadSession() as session:
            pod = session.query(Pod).one()
            device = Device("test", "qfx5100-24q-2p", "user", "pwd", "spine",
                            "mac", "mgmtIp", pod)
            device.pod.allocatedIrbBlock = '10.0.0.0/28'
            device.pod.allocatedLoopbackBlock = '11.0.0.0/28'
            configlet = self.l3ClosMediation._createPolicyOption(
                session, device)

        self.assertTrue('irb_in' not in configlet
                        and '10.0.0.0/28' in configlet)
        self.assertTrue('lo0_in' not in configlet
                        and '11.0.0.0/28' in configlet)
        self.assertTrue('lo0_out' not in configlet)
        self.assertTrue('irb_out' not in configlet)
示例#20
0
    def testCreateSnmpTrapAndEventLeafNoStagedZtp(self):
        self._conf['snmpTrap'] = {
            'openclos_trap_group': {
                'port': 20162,
                'target': '1.2.3.4'
            }
        }
        self.l3ClosMediation = L3ClosMediation(self._conf, InMemoryDao)
        self.createTrapGroupsInDb(self._dao)

        device = Device("test", "qfx5100-48s-6q", "user", "pwd", "leaf", "mac",
                        "mgmtIp", None)
        with self._dao.getReadSession() as session:
            configlet = self.l3ClosMediation._createSnmpTrapAndEvent(
                session, device)

        self.assertEqual('', configlet)
示例#21
0
    def testCreatePolicyOptionLeaf(self):
        l3ClosMediation = L3ClosMediation(self.conf)
        device = Device("test", "QFX5100-48S", "user", "pwd", "leaf", "mac",
                        "mgmtIp", self.createPod(l3ClosMediation))
        device.pod.allocatedIrbBlock = '10.0.0.0/28'
        device.pod.allocatedLoopbackBlock = '11.0.0.0/28'
        flexmock(l3ClosMediation.dao.Session).should_receive(
            'query.join.filter.filter.one').and_return(
                InterfaceLogical("test", device, '12.0.0.0/28'))

        configlet = l3ClosMediation.createPolicyOption(device)
        self.assertTrue('irb_in' not in configlet
                        and '10.0.0.0/28' in configlet)
        self.assertTrue('lo0_in' not in configlet
                        and '11.0.0.0/28' in configlet)
        self.assertTrue('lo0_out' not in configlet
                        and '12.0.0.0/28' in configlet)
        self.assertTrue('irb_out' not in configlet)
示例#22
0
    def testCreatePolicyOptionLeaf(self):
        self.createPodSpineLeaf()
        with self._dao.getReadSession() as session:
            pod = session.query(Pod).one()
            device = Device("test", "qfx5100-48s-6q", "user", "pwd", "leaf",
                            "mac", "mgmtIp", pod)
            device.pod.allocatedIrbBlock = '10.0.0.0/28'
            device.pod.allocatedLoopbackBlock = '11.0.0.0/28'
            mockSession = flexmock(session)
            mockSession.should_receive(
                'query.join.filter.filter.one').and_return(
                    InterfaceLogical("test", device, '12.0.0.0/28'))

            configlet = self.l3ClosMediation._createPolicyOption(
                session, device)
            self.assertTrue('irb_in' not in configlet
                            and '10.0.0.0/28' in configlet)
            self.assertTrue('lo0_in' not in configlet
                            and '11.0.0.0/28' in configlet)
            self.assertTrue('lo0_out' not in configlet
                            and '12.0.0.0/28' in configlet)
            self.assertTrue('irb_out' not in configlet)
示例#23
0
def createPodDevice(session, name, pod):
    device = Device(name, "", "", "", "spine", "11:12:13:14:15:16", "1.2.3.4", pod)
    session.add(device)
    session.commit()
    return device
示例#24
0
def createDevice(session, name):
    device = Device(name, "", "", "", "spine", "11:12:13:14:15:16", "1.2.3.4/24", createPod(name, session))
    session.add(device)
    session.commit()
    return device
示例#25
0
 def testConstructorPass(self):
     podOne = createPod('testpod', self.session)
     self.assertTrue(Device('testdevice', 'qfx-5100-48s-6q', 'admin', 'admin', "spine", "", "", podOne) is not None)