Esempio n. 1
0
 def test_clear_device_id(self):
     quantum_wrapper = quantum.Quantum(mock.Mock())
     quantum_wrapper.api_client.update_port = mock.Mock()
     quantum_wrapper.clear_device_id(mock.Mock(id='PORT1'))
     quantum_wrapper.api_client.update_port.assert_called_once_with(
         'PORT1', {'port': {
             'device_id': ''
         }})
Esempio n. 2
0
 def test_create(self, client_wrapper):
     mock_client = mock.Mock()
     mock_client.show_router.return_value = {'router': self.ROUTER}
     client_wrapper.return_value = mock_client
     quantum_wrapper = quantum.Quantum(self.conf)
     with mock.patch.object(quantum_wrapper, 'get_network_subnets') as gns:
         gns.return_value = self.SUBNETS
         port = quantum_wrapper.create_router_external_port(self.router)
         self.assertEqual(port.id, self.EXTERNAL_PORT_ID)
Esempio n. 3
0
    def test_purge_management_interface(self, import_utils, ak_wrapper, cfg):
        conf = mock.Mock()
        driver = mock.Mock()
        import_utils.import_object.return_value = driver

        quantum_wrapper = quantum.Quantum(conf)
        quantum_wrapper.purge_management_interface()
        driver.get_device_name.assert_called_once()
        driver.unplug.assert_called_once()
Esempio n. 4
0
 def test_create_missing_gateway_port(self, client_wrapper):
     self.conf.retry_delay = 0
     mock_client = mock.Mock()
     router = copy.deepcopy(self.ROUTER)
     router['ports'] = []
     mock_client.show_router.return_value = {'router': router}
     client_wrapper.return_value = mock_client
     quantum_wrapper = quantum.Quantum(self.conf)
     with mock.patch.object(quantum_wrapper, 'get_network_subnets') as gns:
         gns.return_value = self.SUBNETS
         self.assertRaises(quantum.RouterGatewayMissing,
                           quantum_wrapper.create_router_external_port,
                           self.router)
Esempio n. 5
0
    def test_missing_v6(self, client_wrapper):
        mock_client = mock.Mock()

        router = copy.deepcopy(self.ROUTER)
        del router['ports'][0]['fixed_ips'][1]

        mock_client.show_router.return_value = {'router': router}
        client_wrapper.return_value = mock_client
        quantum_wrapper = quantum.Quantum(self.conf)
        with mock.patch.object(quantum_wrapper, 'get_network_subnets') as gns:
            gns.return_value = self.SUBNETS
            try:
                quantum_wrapper.create_router_external_port(self.router)
            except quantum.MissingIPAllocation as e:
                self.assertEqual(6, e.missing[0][0])
            else:
                self.fail('Should have seen MissingIPAllocation')
Esempio n. 6
0
    def __init__(self, conf, db, workers):
        self.db = db
        self.conn = sqlite3.connect(self.db)
        self.conn.row_factory = RouterRow.from_cursor
        self.nova = nova_api.Nova(conf)
        self.quantum = quantum_api.Quantum(conf)
        self.nova_queue = Queue.Queue()
        self.save_queue = Queue.Queue()

        # Create X threads to perform Nova calls and put results into a queue
        threads = [
            threading.Thread(
                name='fetcher-t%02d' % i,
                target=self.fetch_router_metadata,
            ) for i in xrange(workers)
        ]
        for t in threads:
            t.setDaemon(True)
            t.start()
Esempio n. 7
0
def _pre_populate_workers(scheduler):
    """Fetch the existing routers from quantum.

    Wait for quantum to return the list of the existing routers.
    Pause up to max_sleep seconds between each attempt and ignore
    quantum client exceptions.


    """
    nap_time = 1
    max_sleep = 15

    quantum_client = quantum.Quantum(cfg.CONF)

    while True:
        try:
            quantum_routers = quantum_client.get_routers(detailed=False)
            break
        except (q_exceptions.Unauthorized, q_exceptions.Forbidden) as err:
            LOG.warning('PrePopulateWorkers thread failed: %s', err)
            return
        except Exception as err:
            LOG.warning('%s: %s' %
                        ('Could not fetch routers from quantum', err))
            LOG.warning('sleeping %s seconds before retrying' % nap_time)
            time.sleep(nap_time)
            # FIXME(rods): should we get max_sleep from the config file?
            nap_time = min(nap_time * 2, max_sleep)

    LOG.debug('Start pre-populating the workers with %d fetched routers',
              len(quantum_routers))

    for router in quantum_routers:
        message = event.Event(tenant_id=router.tenant_id,
                              router_id=router.id,
                              crud=event.POLL,
                              body={})
        scheduler.handle_message(router.tenant_id, message)
Esempio n. 8
0
 def test_neutron_router_status_update_error(self, client_wrapper):
     urs = client_wrapper.return_value.update_router_status
     urs.side_effect = RuntimeError('should be caught')
     conf = mock.Mock()
     quantum_wrapper = quantum.Quantum(conf)
     quantum_wrapper.update_router_status('router-id', 'new-status')
Esempio n. 9
0
def main(argv=sys.argv[1:]):
    # Change the process and thread name so the logs are cleaner.
    p = multiprocessing.current_process()
    p.name = 'pmain'
    t = threading.current_thread()
    t.name = 'tmain'

    register_and_load_opts()
    cfg.CONF(argv, project='akanda-rug')

    log.setup('akanda-rug')
    cfg.CONF.log_opt_values(LOG, logging.INFO)

    # Purge the mgt tap interface on startup
    quantum = quantum_api.Quantum(cfg.CONF)
    # TODO(mark): develop better way restore after machine reboot
    # quantum.purge_management_interface()

    # bring the mgt tap interface up
    quantum.ensure_local_service_port()

    # bring the external port
    if cfg.CONF.plug_external_port:
        quantum.ensure_local_external_port()

    # Set up the queue to move messages between the eventlet-based
    # listening process and the scheduler.
    notification_queue = multiprocessing.Queue()

    # Ignore signals that might interrupt processing.
    daemon.ignore_signals()

    # If we see a SIGINT, stop processing.
    def _stop_processing(*args):
        notification_queue.put((None, None))

    signal.signal(signal.SIGINT, _stop_processing)

    # Listen for notifications.
    notification_proc = multiprocessing.Process(
        target=notifications.listen,
        kwargs={
            'host_id': cfg.CONF.host,
            'amqp_url': cfg.CONF.amqp_url,
            'notifications_exchange_name':
            cfg.CONF.incoming_notifications_exchange,
            'rpc_exchange_name': cfg.CONF.rpc_exchange,
            'notification_queue': notification_queue
        },
        name='notification-listener',
    )
    notification_proc.start()

    mgt_ip_address = quantum_api.get_local_service_ip(cfg.CONF).split('/')[0]
    metadata_proc = multiprocessing.Process(target=metadata.serve,
                                            args=(mgt_ip_address, ),
                                            name='metadata-proxy')
    metadata_proc.start()

    # Set up the notifications publisher
    Publisher = (notifications.Publisher if cfg.CONF.ceilometer.enabled else
                 notifications.NoopPublisher)
    publisher = Publisher(
        cfg.CONF.amqp_url,
        exchange_name=cfg.CONF.outgoing_notifications_exchange,
        topic=cfg.CONF.ceilometer.topic,
    )

    # Set up a factory to make Workers that know how many threads to
    # run.
    worker_factory = functools.partial(
        worker.Worker,
        num_threads=cfg.CONF.num_worker_threads,
        notifier=publisher,
        ignore_directory=cfg.CONF.ignored_router_directory,
        queue_warning_threshold=cfg.CONF.queue_warning_threshold,
        reboot_error_threshold=cfg.CONF.reboot_error_threshold,
    )

    # Set up the scheduler that knows how to manage the routers and
    # dispatch messages.
    sched = scheduler.Scheduler(
        num_workers=cfg.CONF.num_worker_processes,
        worker_factory=worker_factory,
    )

    # Prepopulate the workers with existing routers on startup
    populate.pre_populate_workers(sched)

    # Set up the periodic health check
    health.start_inspector(cfg.CONF.health_check_period, sched)

    # Block the main process, copying messages from the notification
    # listener to the scheduler
    try:
        shuffle_notifications(notification_queue, sched)
    finally:
        # Terminate the scheduler and its workers
        LOG.info('stopping processing')
        sched.stop()
        # Terminate the listening process
        LOG.debug('stopping %s', notification_proc.name)
        notification_proc.terminate()
        LOG.debug('stopping %s', metadata_proc.name)
        metadata_proc.terminate()
        LOG.info('exiting')
Esempio n. 10
0
 def __init__(self):
     self.neutron = quantum.Quantum(cfg.CONF)
     self.nova_client = nova.Nova(cfg.CONF)