Beispiel #1
0
 def test_clear_device_id(self):
     neutron_wrapper = neutron.Neutron(mock.Mock())
     neutron_wrapper.api_client.update_port = mock.Mock()
     neutron_wrapper.clear_device_id(mock.Mock(id='PORT1'))
     neutron_wrapper.api_client.update_port.assert_called_once_with(
         'PORT1', {'port': {
             'device_id': ''
         }})
Beispiel #2
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

        neutron_wrapper = neutron.Neutron(conf)
        neutron_wrapper.purge_management_interface()
        self.assertEqual(driver.get_device_name.call_count, 1)
        self.assertEqual(driver.unplug.call_count, 1)
Beispiel #3
0
 def test_create(self, client_wrapper):
     mock_client = mock.Mock()
     mock_client.show_router.return_value = {'router': self.ROUTER}
     mock_client.list_ports.return_value = {
         'ports': [self.ROUTER['ports'][0]]
     }
     client_wrapper.return_value = mock_client
     neutron_wrapper = neutron.Neutron(self.conf)
     with mock.patch.object(neutron_wrapper, 'get_network_subnets') as gns:
         gns.return_value = self.SUBNETS
         port = neutron_wrapper.create_router_external_port(self.router)
         self.assertEqual(port.id, self.EXTERNAL_PORT_ID)
Beispiel #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}
        mock_client.list_ports.return_value = {'ports': []}

        client_wrapper.return_value = mock_client
        neutron_wrapper = neutron.Neutron(self.conf)
        with mock.patch.object(neutron_wrapper, 'get_network_subnets') as gns:
            gns.return_value = self.SUBNETS
            self.assertRaises(neutron.RouterGatewayMissing,
                              neutron_wrapper.create_router_external_port,
                              self.router)
Beispiel #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.list_ports.return_value = {'ports': [router['ports'][0]]}

        mock_client.show_router.return_value = {'router': router}
        client_wrapper.return_value = mock_client
        neutron_wrapper = neutron.Neutron(self.conf)
        with mock.patch.object(neutron_wrapper, 'get_network_subnets') as gns:
            gns.return_value = self.SUBNETS
            try:
                neutron_wrapper.create_router_external_port(self.router)
            except neutron.MissingIPAllocation as e:
                self.assertEqual(6, e.missing[0][0])
            else:
                self.fail('Should have seen MissingIPAllocation')
Beispiel #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.neutron = neutron_api.Neutron(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()
Beispiel #7
0
    def pre_populate_hook():
        """Fetch the existing routers from neutrom then and returns list back
        to populate to be distributed to workers.

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

        """
        nap_time = 1
        max_sleep = 15

        neutron_client = neutron.Neutron(cfg.CONF)

        while True:
            try:
                neutron_routers = neutron_client.get_routers(detailed=False)
                resources = []
                for router in neutron_routers:
                    resources.append(
                        event.Resource(driver=DRIVER_NAME,
                                       id=router.id,
                                       tenant_id=router.tenant_id))

                return resources
            except (q_exceptions.Unauthorized, q_exceptions.Forbidden) as err:
                LOG.warning(_LW('PrePopulateWorkers thread failed: %s'), err)
                return
            except Exception as err:
                LOG.warning(_LW('Could not fetch routers from neutron: %s'),
                            err)
                LOG.warning(_LW('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)
Beispiel #8
0
def main(argv=sys.argv[1:]):
    """Main Entry point into the akanda-rug

    This is the main entry point into the akanda-rug. On invocation of
    this method, logging, local network connectivity setup is performed.
    This information is obtained through the 'ak-config' file, passed as
    arguement to this method. Worker threads are spawned for handling
    various tasks that are associated with processing as well as
    responding to different Neutron events prior to starting a notification
    dispatch loop.

    :param argv: list of Command line arguments

    :returns: None

    :raises: None

    """
    # TODO(rama) Error Handling to be added as part of the docstring
    # description

    # 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'
    ak_cfg.parse_config(argv)
    log.setup(cfg.CONF, 'akanda-rug')
    cfg.CONF.log_opt_values(LOG, logging.INFO)

    neutron = neutron_api.Neutron(cfg.CONF)

    # TODO(mark): develop better way restore after machine reboot
    # neutron.purge_management_interface()

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

    # bring the external port
    if cfg.CONF.plug_external_port:
        neutron.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={'notification_queue': notification_queue},
        name='notification-listener',
    )
    notification_proc.start()

    mgt_ip_address = neutron_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()

    from akanda.rug.api import rug as rug_api
    rug_api_proc = multiprocessing.Process(target=rug_api.serve,
                                           args=(mgt_ip_address, ),
                                           name='rug-api')
    rug_api_proc.start()

    # Set up the notifications publisher
    Publisher = (notifications.Publisher if cfg.CONF.ceilometer.enabled else
                 notifications.NoopPublisher)
    publisher = Publisher(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, notifier=publisher)

    # Set up the scheduler that knows how to manage the routers and
    # dispatch messages.
    sched = scheduler.Scheduler(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:
        LOG.info(_LI('Stopping scheduler.'))
        sched.stop()
        LOG.info(_LI('Stopping notification publisher.'))
        publisher.stop()

        # Terminate the subprocesses
        for subproc in [notification_proc, metadata_proc, rug_api_proc]:
            LOG.info(_LI('Stopping %s.'), subproc.name)
            subproc.terminate()
Beispiel #9
0
 def test_neutron_router_status_update_error(self, client_wrapper):
     urs = client_wrapper.return_value.update_status
     urs.side_effect = RuntimeError('should be caught')
     conf = mock.Mock()
     neutron_wrapper = neutron.Neutron(conf)
     neutron_wrapper.update_router_status('router-id', 'new-status')