Esempio n. 1
0
    def testMatchingDevices(self):
        device_manager.socket.gethostbyname = self._mock_gethostbyname
        config = notch_config.get_config_from_file(
            os.path.join(TESTDATA, 'simple_config.yaml'))
        # Fudge the path of the router.db files so that it matches the testdata.
        config['device_sources']['old_rancid_configs']['root'] = (
            os.path.join(TESTDATA, 'router_db'))

        dm = device_manager.DeviceManager(config)
        self.assertEqual(dm.serve_ready, False)
        dm.scan_providers()
        self.assertEqual(dm.serve_ready, True)

        all = dm.devices_matching(r'.*')
        for d in ('lr1.foo', 'xr1.foo', 'xr2.foo'):
            self.assert_(d in all, '%s not in %s' % (d, all))

        devs = dm.devices_matching(r'^$')
        self.assert_(not devs)

        devs = dm.devices_matching(r'lr.*')
        self.assert_('lr1.foo' in devs)
        
        devs = dm.devices_matching(r'xr.*')
        self.assert_('xr1.foo' in devs)
        self.assert_('xr2.foo' in devs)

        devs = dm.devices_matching(r'^..1\.foo$')
        self.assert_('lr1.foo' in devs)
        self.assert_('xr1.foo' in devs)
Esempio n. 2
0
 def testGetConfigFromFile(self):
     config = notch_config.get_config_from_file(
         os.path.join(TESTDATA, 'notch_config.yaml'))
     self.assert_(config['device_sources'])
     self.assertEqual(
         config['device_sources']['old_rancid_configs']['root'],
         'testdata/router_db/')
Esempio n. 3
0
 def testScanProviders(self):
     config = notch_config.get_config_from_file(
         os.path.join(TESTDATA, 'simple_config.yaml'))
     self.device_manager = device_manager.DeviceManager(config)
     self.assertEqual(self.device_manager.serve_ready, False)
     self.device_manager.scan_providers()
     self.assertEqual(self.device_manager.serve_ready, True)
     self.device_manager.scan_providers()
     self.assertEqual(self.device_manager.serve_ready, True)
Esempio n. 4
0
 def testNonExistantFile(self):
     self.assertEqual(
         notch_config.load_config_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')).loaded,
         False)
     self.assertEqual(
         notch_config.load_config_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')).config_file,
         None)
     self.assertEqual(
         notch_config.get_config_from_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')), {})
Esempio n. 5
0
 def testNonExistantFile(self):
     self.assertEqual(
         notch_config.load_config_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')).loaded,
         False)
     self.assertEqual(
         notch_config.load_config_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')).config_file,
         None)
     self.assertEqual(
         notch_config.get_config_from_file(
             os.path.join(TESTDATA, 'file_is_not_there.yaml')),
         {})
Esempio n. 6
0
 def testProvider(self):
     config = notch_config.get_config_from_file(
         os.path.join(TESTDATA, 'notch_config.yaml'))
     self.device_manager = device_manager.DeviceManager(config)
     self.assert_(self.device_manager.provider('old_rancid_configs'))
     self.assertEqual(
         self.device_manager.provider('old_rancid_configs').name,
         'router.db')
     # Unknown providers return None.
     self.assertEqual(None, self.device_manager.provider('unknown'))
     self.assertEqual(None, self.device_manager.provider(''))
     self.assertEqual(None, self.device_manager.provider(None))
     self.assertEqual(None, self.device_manager.provider(0))
Esempio n. 7
0
    def testDeviceManagerReadConfigValid1(self):
        config = notch_config.get_config_from_file(
            os.path.join(TESTDATA, 'notch_config.yaml'))
        self.device_manager = device_manager.DeviceManager(config)
        self.assertEqual(len(self.device_manager.providers), 1)
        self.assert_(self.device_manager.provider('old_rancid_configs'))

        self.assertEqual(
            self.device_manager.provider('old_rancid_configs').root,
            'testdata/router_db/')
        self.assertEqual(
            self.device_manager.provider('old_rancid_configs'
                                          ).ignore_down_devices, True)
Esempio n. 8
0
    def testDeviceInfo(self):
        device_manager.socket.gethostbyname = self._mock_gethostbyname
        config = notch_config.get_config_from_file(
            os.path.join(TESTDATA, 'simple_config.yaml'))
        # Fudge the path of the router.db files so that it matches the testdata.
        config['device_sources']['old_rancid_configs']['root'] = (
            os.path.join(TESTDATA, 'router_db'))

        dm = device_manager.DeviceManager(config)
        self.assertEqual(dm.serve_ready, False)
        dm.scan_providers()
        self.assertEqual(dm.serve_ready, True)
        xr2_foo = device_manager.DeviceInfo(
            device_name='xr2.foo',
            addresses=['10.0.0.2', '10.0.0.3'],
            device_type='juniper')
        self.assertEqual(dm.device_info('xr2.foo'), xr2_foo)
        self.assertEqual(dm.device_info('xr1.foo').addresses, ['10.0.0.1'])
        self.assertEqual(dm.device_info('lr1.foo').device_type, 'cisco')
Esempio n. 9
0
 def testGetConfigFromFile(self):
     config = notch_config.get_config_from_file(
         os.path.join(TESTDATA, 'notch_config.yaml'))
     self.assert_(config['device_sources'])
     self.assertEqual(config['device_sources']['old_rancid_configs']
                      ['root'], 'testdata/router_db/')