def setUp(self): super().setUp() self.neutron.list_extensions = self.list_extensions self.neutron_api = neutron.API() # TODO(sean-k-mooney): remove after # I275509eb0e0eb9eaf26fe607b7d9a67e1edc71f8 # has merged. self.useFixture(fixtures.MonkeyPatch( 'nova.virt.libvirt.driver.connector', fake_os_brick_connector)) self.start_compute( hostname='start_host', host_info=fakelibvirt.HostInfo( cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=2)) self.start_compute( hostname='end_host', host_info=fakelibvirt.HostInfo( cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=2)) self.ctxt = context.get_admin_context() # TODO(sean-k-mooney): remove this when it is part of ServersTestBase self.useFixture(fixtures.MonkeyPatch( 'nova.tests.unit.virt.libvirt.fakelibvirt.Domain.migrateToURI3', self._migrate_stub))
def __init__(self, context, instance, destination, block_migration, disk_over_commit, migration, compute_rpcapi, servicegroup_api, query_client, report_client, request_spec=None): super(LiveMigrationTask, self).__init__(context, instance) self.destination = destination self.block_migration = block_migration self.disk_over_commit = disk_over_commit self.migration = migration self.source = instance.host self.migrate_data = None self.limits = None self.compute_rpcapi = compute_rpcapi self.servicegroup_api = servicegroup_api self.query_client = query_client self.report_client = report_client self.request_spec = request_spec self._source_cn = None self._held_allocations = None self.network_api = neutron.API()
def _setup(self): self.controller = networks_v21.NetworkController( self.fake_network_api) self.neutron_ctrl = networks_v21.NetworkController( neutron.API()) self.req = fakes.HTTPRequest.blank('', project_id=fakes.FAKE_PROJECT_ID)
def test_get_aggregates_for_routed_subnet_none(self, mock_get_segment_ids): mock_get_segment_ids.return_value = None report_client = report.SchedulerReportClient() network_api = neutron.API() self.assertEqual( [], scheduler_utils.get_aggregates_for_routed_subnet( self.context, network_api, report_client, uuids.subnet1))
def get_metadata_by_address(address): ctxt = context.get_admin_context() fixed_ip = neutron.API().get_fixed_ip_by_address(ctxt, address) LOG.info('Fixed IP %(ip)s translates to instance UUID %(uuid)s', {'ip': address, 'uuid': fixed_ip['instance_uuid']}) return get_metadata_by_instance_id(fixed_ip['instance_uuid'], address, ctxt)
def test_get_aggregates_for_routed_subnet(self, mock_get_segment_ids): mock_get_segment_ids.return_value = uuids.segment1 report_client = report.SchedulerReportClient() network_api = neutron.API() agg_info = report.AggInfo(aggregates=[uuids.agg1], generation=1) with mock.patch.object(report_client, '_get_provider_aggregates', return_value=agg_info) as mock_get_aggs: res = scheduler_utils.get_aggregates_for_routed_subnet( self.context, network_api, report_client, uuids.subnet1) self.assertEqual([uuids.agg1], res) mock_get_segment_ids.assert_called_once_with( self.context, uuids.subnet1) mock_get_aggs.assert_called_once_with(self.context, uuids.segment1)
def test_instance_has_port_with_resource_request(self): network_api = mock.Mock(spec=network.API()) network_api.list_ports.return_value = { 'ports': [{ 'resource_request': mock.sentinel.request }] } res = common.instance_has_port_with_resource_request( mock.sentinel.uuid, network_api) self.assertTrue(res) network_api.list_ports.assert_called_once_with( test.MatchType(context.RequestContext), device_id=mock.sentinel.uuid, fields=['resource_request']) # assert that the neutron call uses an admin context ctxt = network_api.mock_calls[0][1][0] self.assertTrue(ctxt.is_admin) self.assertIsNone(ctxt.auth_token)
def _get_nwinfo_old_skool(): """Support for getting network info without objects.""" if (instance_ref.get('info_cache') and instance_ref['info_cache'].get('network_info') is not None): cached_info = instance_ref['info_cache']['network_info'] if isinstance(cached_info, network_model.NetworkInfo): return cached_info return network_model.NetworkInfo.hydrate(cached_info) try: return neutron.API().get_instance_nw_info(admin_context, instance_ref) except Exception: try: with excutils.save_and_reraise_exception(): LOG.exception('Failed to get nw_info', instance=instance_ref) except Exception: if ignore_missing_network_data: return raise
def test_get_aggregates_for_routed_network(self, mock_get_segment_ids): mock_get_segment_ids.return_value = [uuids.segment1, uuids.segment2] report_client = report.SchedulerReportClient() network_api = neutron.API() def fake_get_provider_aggregates(context, segment_id): agg = uuids.agg1 if segment_id == uuids.segment1 else uuids.agg2 agg_info = report.AggInfo(aggregates=[agg], generation=1) return agg_info with mock.patch.object(report_client, '_get_provider_aggregates', side_effect=fake_get_provider_aggregates) as mock_get_aggs: res = scheduler_utils.get_aggregates_for_routed_network( self.context, network_api, report_client, uuids.network1) self.assertEqual([uuids.agg1, uuids.agg2], res) mock_get_segment_ids.assert_called_once_with( self.context, uuids.network1) mock_get_aggs.assert_has_calls( [mock.call(self.context, uuids.segment1), mock.call(self.context, uuids.segment2)])
def test_get_aggregates_for_routed_subnet_fails(self, mock_get_segment_ids): mock_get_segment_ids.return_value = uuids.segment1 report_client = report.SchedulerReportClient() network_api = neutron.API() # We could fail on some placement issue... with mock.patch.object(report_client, '_get_provider_aggregates', return_value=None): self.assertRaises( exception.InvalidRoutedNetworkConfiguration, scheduler_utils.get_aggregates_for_routed_subnet, self.context, network_api, report_client, uuids.subnet1) # ... but we also want to fail if we can't find the related aggregate agg_info = report.AggInfo(aggregates=set(), generation=1) with mock.patch.object(report_client, '_get_provider_aggregates', return_value=agg_info): self.assertRaises( exception.InvalidRoutedNetworkConfiguration, scheduler_utils.get_aggregates_for_routed_subnet, self.context, network_api, report_client, uuids.subnet1)
def setUp(self): super().setUp() self.neutron.list_extensions = self.list_extensions self.neutron_api = neutron.API() self.useFixture(nova_fixtures.OSBrickFixture()) self.start_compute(hostname='start_host', host_info=fakelibvirt.HostInfo(cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=2)) self.start_compute(hostname='end_host', host_info=fakelibvirt.HostInfo(cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=2)) self.ctxt = context.get_admin_context() # TODO(sean-k-mooney): remove this when it is part of ServersTestBase self.useFixture( fixtures.MonkeyPatch( 'nova.tests.fixtures.libvirt.Domain.migrateToURI3', self._migrate_stub))
def remote_managed_ports_filter( context: nova_context.RequestContext, request_spec: 'objects.RequestSpec', ) -> bool: """Filter out hosts without remote managed port support (driver or hw). If a request spec contains VNIC_TYPE_REMOTE_MANAGED ports then a remote-managed port trait (COMPUTE_REMOTE_MANAGED_PORTS) is added to the request in order to pre-filter hosts that do not use compute drivers supporting remote managed ports and the ones that do not have the device pools providing remote-managed ports (actual device availability besides a pool presence check is done at the time of PciPassthroughFilter execution). """ if request_spec.requested_networks: network_api = neutron.API() for request_net in request_spec.requested_networks: if request_net.port_id and network_api.is_remote_managed_port( context, request_net.port_id): request_spec.root_required.add( os_traits.COMPUTE_REMOTE_MANAGED_PORTS) LOG.debug('remote_managed_ports_filter request filter added ' f'trait {os_traits.COMPUTE_REMOTE_MANAGED_PORTS}') return True
def __init__(self): super(InterfaceAttachmentController, self).__init__() self.compute_api = compute.API() self.network_api = neutron.API()
def __init__(self): super(MigrateServerController, self).__init__() self.compute_api = compute.API() self.network_api = neutron.API()
def routed_networks_filter( ctxt: nova_context.RequestContext, request_spec: 'objects.RequestSpec' ) -> bool: """Adds requested placement aggregates that match requested networks. This will modify request_spec to request hosts in aggregates that matches segment IDs related to requested networks. :param ctxt: The usual suspect for a context object. :param request_spec: a classic RequestSpec object containing the request. :returns: True if the filter was used or False if not. :raises: exception.InvalidRoutedNetworkConfiguration if something went wrong when trying to get the related segment aggregates. """ if not CONF.scheduler.query_placement_for_routed_network_aggregates: return False # NOTE(sbauza): On a create operation with no specific network request, we # allocate the network only after scheduling when the nova-compute service # calls Neutron. In this case, here we just want to accept any destination # as fine. # NOTE(sbauza): This could be also going from an old compute reschedule. if 'requested_networks' not in request_spec: return True # This object field is not nullable requested_networks = request_spec.requested_networks # NOTE(sbauza): This field could be not created yet. if ( 'requested_destination' not in request_spec or request_spec.requested_destination is None ): request_spec.requested_destination = objects.Destination() # Get the clients we need network_api = neutron.API() report_api = report.SchedulerReportClient() for requested_network in requested_networks: network_id = None # Check for a specifically requested network ID. if "port_id" in requested_network and requested_network.port_id: # We have to lookup the port to see which segment(s) to support. port = network_api.show_port(ctxt, requested_network.port_id)[ "port" ] if port['fixed_ips']: # The instance already exists with a related subnet. We need to # stick on this subnet. # NOTE(sbauza): In case of multiple IPs, we could have more # subnets than only one but given they would be for the same # port, just looking at the first subnet is needed. subnet_id = port['fixed_ips'][0]['subnet_id'] try: aggregates = utils.get_aggregates_for_routed_subnet( ctxt, network_api, report_api, subnet_id) except exception.InvalidRoutedNetworkConfiguration as e: raise exception.RequestFilterFailed( reason=_('Aggregates not found for the subnet %s' ) % subnet_id) from e else: # The port was just created without a subnet. network_id = port["network_id"] elif ( "network_id" in requested_network and requested_network.network_id ): network_id = requested_network.network_id if network_id: # As the user only requested a network or a port unbound to a # segment, we are free to choose any segment from the network. try: aggregates = utils.get_aggregates_for_routed_network( ctxt, network_api, report_api, network_id) except exception.InvalidRoutedNetworkConfiguration as e: raise exception.RequestFilterFailed( reason=_('Aggregates not found for the network %s' ) % network_id) from e if aggregates: LOG.debug( 'routed_networks_filter request filter added the following ' 'aggregates for network ID %s: %s', network_id, ', '.join(aggregates)) # NOTE(sbauza): All of the aggregates from this request will be # accepted, but they will have an AND relationship with any other # requested aggregate, like for another NIC request in this loop. request_spec.requested_destination.require_aggregates(aggregates) return True
def __init__(self): super(FloatingIPController, self).__init__() self.compute_api = compute.API() self.network_api = neutron.API()
def __init__(self): super(FloatingIPPoolsController, self).__init__() self.network_api = neutron.API()
def __init__(self): super(EvacuateController, self).__init__() self.compute_api = compute.API() self.host_api = compute.HostAPI() self.network_api = neutron.API()
def __init__(self, network_api=None): super(NetworkController, self).__init__() # TODO(stephenfin): 'network_api' is only being passed for use by tests self.network_api = network_api or neutron.API()
def __init__(self): super(ShelveController, self).__init__() self.compute_api = compute.API() self.network_api = neutron.API()
def __init__(self): super(TenantNetworkController, self).__init__() self.network_api = neutron.API() self._default_networks = []