def test_create_vrrp_port_error(self, client_wrapper): neutron_wrapper = neutron.Neutron(mock.Mock()) api_client = neutron_wrapper.api_client with mock.patch.object(api_client, 'create_port') as create_port: create_port.return_value.get.return_value = None self.assertRaises(ValueError, neutron_wrapper.create_vrrp_port, 'obj_id', 'the_net_id')
def pre_populate_hook(): """Fetch the existing LBs from neutron then and returns list back to populate to be distributed to workers. Wait for neutron to return the list of the existing LBs. Pause up to max_sleep seconds between each attempt and ignore neutron client exceptions. """ nap_time = 1 neutron_client = neutron.Neutron(cfg.CONF) while True: try: resources = [] for lb in neutron_client.get_loadbalancers(): resources.append( event.Resource(driver=LoadBalancer.RESOURCE_NAME, id=lb.id, tenant_id=lb.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 loadbalancers from neutron: %s'), err) LOG.warning(_LW('sleeping %s seconds before retrying'), nap_time) time.sleep(nap_time) nap_time = min(nap_time * 2, cfg.CONF.astara_appliance.max_sleep)
def _test_create_vrrp_port_success_hlpr(self, ext_enabled, client_wrapper): conf = mock.Mock() conf.neutron_port_security_extension_enabled = ext_enabled expected_port_data = { 'port': { 'name': 'ASTARA:VRRP:obj_id', 'admin_state_up': True, 'network_id': 'the_net_id', 'fixed_ips': [], 'security_groups': [] } } if ext_enabled: expected_port_data['port']['port_security_enabled'] = False neutron_wrapper = neutron.Neutron(conf) api_client = neutron_wrapper.api_client with mock.patch.object(api_client, 'create_port') as create_port: with mock.patch.object(neutron.Port, 'from_dict') as port_from_d: retval = neutron_wrapper.create_vrrp_port( 'obj_id', 'the_net_id') self.assertIs(retval, port_from_d.return_value) port_from_d.assert_called_once_with( create_port.return_value.get()) create_port.assert_called_once_with(expected_port_data)
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': '' }})
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)
def setUp(self): super(TestLocalServicePorts, self).setUp() self.config(management_network_id='fake_mgtnet_network_id') self.config(management_subnet_id='fake_mgtnet_subnet_id') self.config(management_prefix='172.16.77.0/24') self.config(management_prefix='fdca:3ba5:a17a:acda::/64') self.neutron_wrapper = neutron.Neutron(cfg.CONF) self.fake_interface_driver = mock.Mock(plug=mock.Mock(), init_l3=mock.Mock(), get_device_name=mock.Mock())
def test_delete_vrrp_ports_not_found(self, client_wrapper): conf = mock.Mock() neutron_wrapper = neutron.Neutron(conf) neutron_wrapper.api_client.list_ports = mock.Mock( return_value={'ports': []}) neutron_wrapper.api_client.delete_port = mock.Mock() neutron_wrapper.delete_vrrp_port(object_id='foo') neutron_wrapper.api_client.list_ports.assert_has_calls([ mock.call(name='ASTARA:VRRP:foo'), mock.call(name='AKANDA:VRRP:foo'), ]) self.assertFalse(neutron_wrapper.api_client.delete_port.called)
def test_delete_vrrp_ports(self, client_wrapper): conf = mock.Mock() neutron_wrapper = neutron.Neutron(conf) neutron_wrapper.api_client.list_ports = mock.Mock( return_value={'ports': [{ 'id': 'fake_port_id' }]}) neutron_wrapper.api_client.delete_port = mock.Mock() neutron_wrapper.delete_vrrp_port(object_id='foo') neutron_wrapper.api_client.list_ports.assert_called_with( name='ASTARA:VRRP:foo') neutron_wrapper.api_client.delete_port.assert_called_with( 'fake_port_id')
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 six.moves.range(workers) ] for t in threads: t.setDaemon(True) t.start()
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')
def main(argv=sys.argv[1:]): """Main Entry point into the astara-orchestrator This is the main entry point into the astara-orchestrator. 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, 'astara-orchestrator') 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 mgt_ip_address = neutron.ensure_local_service_port().split('/')[0] # 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() if CONF.coordination.enabled: coordinator_proc = multiprocessing.Process( target=coordination.start, kwargs={'notification_queue': notification_queue}, name='coordinator', ) coordinator_proc.start() else: coordinator_proc = None metadata_proc = multiprocessing.Process(target=metadata.serve, args=(mgt_ip_address, ), name='metadata-proxy') metadata_proc.start() from astara.api import rug as rug_api rug_api_proc = multiprocessing.Process(target=rug_api.serve, 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, management_address=mgt_ip_address, ) # 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, coordinator_proc, metadata_proc, rug_api_proc ]: if not subproc: continue LOG.info(_LI('Stopping %s.'), subproc.name) subproc.terminate()
def __init__(self, management_address=None): self.neutron = neutron.Neutron(cfg.CONF) self.nova_client = nova.Nova(cfg.CONF) self.management_address = management_address
def __init__(self): self.nova_client = nova.Nova(cfg.CONF) self.neutron_client = neutron.Neutron(cfg.CONF)