def test_delete_invalid_cfg_with_multi_region_and_empty_routers_list(self):
        """
        This test verifies that the  cfg-syncer will delete invalid cfg
        if the neutron-db (routers dictionary list) happens to be empty.

        Since the neutron-db router_db_info is empty, all region 0000002
        running-config should be deleted.

        Expect 8 invalid configs found

        ['ip nat inside source static 10.2.0.5 172.16.0.126'
          ' vrf nrouter-3ea5f9-0000002 redundancy neutron-hsrp-1064-3000',
         'ip nat inside source list neutron_acl_0000002_2564 pool '
         'nrouter-3ea5f9-0000002_nat_pool vrf nrouter-3ea5f9-0000002 overload',
         'ip nat pool nrouter-3ea5f9-0000002_nat_pool '
          '172.16.0.124 172.16.0.124 netmask 255.255.0.0',
         'ip route vrf nrouter-3ea5f9-0000002 0.0.0.0 0.0.0.0'
          ' Port-channel10.3000 172.16.0.1',
         'ip access-list standard neutron_acl_0000002_2564',
         <IOSCfgLine # 83 'interface Port-channel10.2564'>,
         <IOSCfgLine # 96 'interface Port-channel10.3000'>,
         'nrouter-3ea5f9-0000002']
        """
        cfg.CONF.set_override('enable_multi_region', True, 'multi_region')
        cfg.CONF.set_override('region_id', '0000002', 'multi_region')
        cfg.CONF.set_override('other_region_ids', ['0000001'], 'multi_region')
        router_db_info = []
        self.config_syncer = asr1k_cfg_syncer.ConfigSyncer(router_db_info,
                                                      self.driver,
                                                      self.hosting_device_info)
        self.config_syncer.get_running_config = \
            mock.Mock(return_value=self._read_asr_running_cfg(
                                            'asr_basic_running_cfg.json'))
        invalid_cfg = self.config_syncer.delete_invalid_cfg()
        self.assertEqual(8, len(invalid_cfg))
    def test_delete_invalid_cfg_empty_routers_list(self):
        """
        expected invalid_cfg
        [u'ip nat inside source static 10.2.0.5 172.16.0.126 vrf'
          ' nrouter-3ea5f9 redundancy neutron-hsrp-1064-3000',
         u'ip nat inside source list neutron_acl_2564 pool'
          ' nrouter-3ea5f9_nat_pool vrf nrouter-3ea5f9 overload',
         u'ip nat pool nrouter-3ea5f9_nat_pool 172.16.0.124'
          ' 172.16.0.124 netmask 255.255.0.0',
         u'ip route vrf nrouter-3ea5f9 0.0.0.0 0.0.0.0'
          ' Port-channel10.3000 172.16.0.1',
         u'ip access-list standard neutron_acl_2564',
         <IOSCfgLine # 83 'interface Port-channel10.2564'>,
         <IOSCfgLine # 96 'interface Port-channel10.3000'>,
         u'nrouter-3ea5f9']
        """
        cfg.CONF.set_override('enable_multi_region', False, 'multi_region')

        router_db_info = []

        self.config_syncer = asr1k_cfg_syncer.ConfigSyncer(router_db_info,
                                                      self.driver,
                                                      self.hosting_device_info)
        self.config_syncer.get_running_config = \
            mock.Mock(return_value=self._read_asr_running_cfg(
                               'asr_basic_running_cfg_no_multi_region.json'))

        invalid_cfg = self.config_syncer.delete_invalid_cfg()
        self.assertEqual(8, len(invalid_cfg))
    def setUp(self):
        super(ASR1kCfgSyncer, self).setUp()

        self._read_neutron_db_data()
        self.hosting_device_info = \
            {'id': '00000000-0000-0000-0000-000000000003'}
        self.driver = mock.Mock()
        self.config_syncer = asr1k_cfg_syncer.ConfigSyncer(self.router_db_info,
                                                      self.driver,
                                                      self.hosting_device_info)
def main():

    conf = cfg.CONF

    common_config.init(sys.argv[1:])
    conf(project='neutron')

    host = conf.host
    devmgr_rpc = CiscoDevMgrRPC(cisco_constants.DEVICE_MANAGER_PLUGIN, host)
    plugin_rpc = CiscoRoutingPluginRPC(topics.L3PLUGIN, host)

    context = bc.ctxt.Context('', '')
    # TODO(create an admin context instead)

    hardware_router_type_id = plugin_rpc.get_hardware_router_type_id(context)
    print("Hardware router type ID: %s" % hardware_router_type_id)

    routers = plugin_rpc.get_all_hosted_routers(context)
    hosting_devs = devmgr_rpc.get_all_hosting_devices(context)

    print("ROUTERS: %s" % pprint.pformat(routers))

    for hd in hosting_devs['hosting_devices']:
        print("HOSTING DEVICE: %s, IP: %s\n-----------------" %
            (hd['id'], hd['management_ip_address']))

        if hd['template_id'] != hardware_router_type_id:
            continue

        conn = get_nc_conn(hd)

        cfg_cleaner = asr1k_cfg_syncer.ConfigSyncer(routers,
                                                    None,
                                                    hd,
                                                    test_mode=True)

        cfg_checker = asr1k_cfg_validator.ConfigValidator(routers,
                                                          hd,
                                                          conn)

        invalid_cfg = cfg_cleaner.delete_invalid_cfg(conn)
        missing_cfg = cfg_checker.process_routers_data(routers)

        print("Invalid Cfg: %s" % invalid_cfg)
        print("Missing Cfg: %s\n\n" % missing_cfg)

        conn.close_session()
Exemple #5
0
 def cleanup_invalid_cfg(self, hd, routers):
     cfg_syncer = asr1k_cfg_syncer.ConfigSyncer(routers, self, hd)
     cfg_syncer.delete_invalid_cfg()