Esempio n. 1
0
 def setupRestWithTwoDevices(self):
     from test_model import createDevice
     restServer = RestServer(self.conf)
     session = restServer.dao.Session()
     device1 = createDevice(session, "test1")
     device2 = createDevice(session, "test2")
     restServer.initRest()
     return TestApp(restServer.app)
Esempio n. 2
0
    def testGenerateSingleDhcpConf(self):
        from jnpr.openclos.l3Clos import util
        flexmock(util, isPlatformUbuntu = True)

        createDevice(self.session, 'dev1')
        createDevice(self.session, 'dev2')

        dhcpConf = self.ztpServer.generateSingleDhcpConf()
        self.assertFalse('{{' in dhcpConf)
        self.assertFalse('}}' in dhcpConf)
        self.assertEquals(3, dhcpConf.count('host-name')) # 1 global + 2 device
    def testGenerateSingleDhcpConf(self):
        from jnpr.openclos.l3Clos import util
        flexmock(util, isPlatformUbuntu=True)

        createDevice(self.session, 'dev1')
        createDevice(self.session, 'dev2')

        dhcpConf = self.ztpServer.generateSingleDhcpConf()
        self.assertFalse('{{' in dhcpConf)
        self.assertFalse('}}' in dhcpConf)
        self.assertEquals(3,
                          dhcpConf.count('host-name'))  # 1 global + 2 device
Esempio n. 4
0
    def testUpdateDeviceL2StatusWithException(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

            dataCollector.updateDeviceL2Status(None, error = DeviceRpcFailed("", cause=ValueError("test error")))
            self.assertEqual("error", leaf.l2Status)
            self.assertEqual("test error", leaf.l2StatusReason)
Esempio n. 5
0
    def testUpdateDeviceL2StatusWithErrorMessage(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

            dataCollector.updateDeviceL2Status("error", "test reason")
            self.assertEqual("error", leaf.l2Status)
            self.assertEqual("test reason", leaf.l2StatusReason)
Esempio n. 6
0
    def testUpdateDeviceL2StatusProcessing(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

            dataCollector.updateDeviceL2Status("processing")
            self.assertEqual(leaf.l2Status, "processing")
            self.assertIsNone(leaf.l2StatusReason)
Esempio n. 7
0
    def testUpdateDeviceL2StatusWithErrorMessage(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

            dataCollector.updateDeviceL2Status("error", "test reason")
            self.assertEqual("error", leaf.l2Status)
            self.assertEqual("test reason", leaf.l2StatusReason)
Esempio n. 8
0
    def testUpdateDeviceL2StatusProcessing(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

            dataCollector.updateDeviceL2Status("processing")
            self.assertEqual(leaf.l2Status, "processing")
            self.assertIsNone(leaf.l2StatusReason)
Esempio n. 9
0
 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))
Esempio n. 10
0
    def testUpdateDeviceL2StatusWithException(self):
        from test_model import createDevice
        with self._dao.getReadSession() as session:
            leaf = createDevice(session, 'leaf')
            dataCollector = L3DataCollector(leaf.id, {}, InMemoryDao)
            dataCollector.manualInit()
            dataCollector._session = session

            dataCollector.updateDeviceL3Status(
                None,
                error=DeviceRpcFailed("", cause=ValueError("test error")))
            self.assertEqual("error", leaf.l3Status)
            self.assertEqual("test error", leaf.l3StatusReason)
Esempio n. 11
0
    def testCascadeDeletePodDevice(self):
        from test_model import createDevice

        with self.__dao.getReadWriteSession() as session:
            device = createDevice(session, "test")

            self.assertEqual(1, len(self.__dao.getAll(session, Pod)))
            self.assertEqual(1, len(self.__dao.getAll(session, Device)))
            
            self.__dao.deleteObject(session, device.pod)
        
        with self.__dao.getReadSession() as session:
            self.assertEqual(0, len(self.__dao.getAll(session, Pod)))
            self.assertEqual(0, len(self.__dao.getAll(session, Device)))
Esempio n. 12
0
    def testCascadeDeletePodDevice(self):
        from test_model import createDevice
        #self.conf['debugSql'] = True
        dao = Dao(self.conf)
        session = dao.Session()
        device = createDevice(session, "test")

        self.assertEqual(1, len(dao.getAll(Pod)))
        self.assertEqual(1, len(dao.getAll(Device)))
        
        dao.deleteObject(device.pod)
        
        self.assertEqual(0, len(dao.getAll(Pod)))
        self.assertEqual(0, len(dao.getAll(Device)))
Esempio n. 13
0
    def testCascadeDeletePodDevice(self):
        from test_model import createDevice
        #self.conf['debugSql'] = True
        dao = Dao(self.conf)
        session = dao.Session()
        device = createDevice(session, "test")

        self.assertEqual(1, len(dao.getAll(Pod)))
        self.assertEqual(1, len(dao.getAll(Device)))

        dao.deleteObject(device.pod)

        self.assertEqual(0, len(dao.getAll(Pod)))
        self.assertEqual(0, len(dao.getAll(Device)))
Esempio n. 14
0
    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'])
Esempio n. 15
0
    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')))
Esempio n. 16
0
    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'])
Esempio n. 17
0
    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')))
Esempio n. 18
0
    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')))
Esempio n. 19
0
 def setupRestWithTwoDevices(self, session):
     from test_model import createDevice
     self.device1 = createDevice(session, "test1")
     self.device2 = createDevice(session, "test2")
Esempio n. 20
0
 def setupRestWithTwoDevices(self, session):
     from test_model import createDevice
     self.device1 = createDevice(session, "test1")
     self.device2 = createDevice(session, "test2")