def pin(instance): nt = numa.NUMATopology() computenodelist = objects.compute_node.ComputeNodeList() ctx = context.get_admin_context() topology_db_object = computenodelist.get_by_hypervisor( ctx, instance.node)[0].numa_topology host_topology = build_new_host_topology(instance.host, instance.uuid) LOG.debug("Host Topology: {}".format(host_topology.cells)) instance_topology = instance.numa_topology old_topology = instance_topology.obj_clone() LOG.debug("Old Instance Topology for {}: {}".format( instance.uuid, old_topology)) LOG.debug("Old Instance Pinning {}: {}".format(instance.uuid, old_topology.cells)) pinned = fit_to_host(host_topology, instance_topology) LOG.debug("New Instance Topology for {}: {}".format(instance.uuid, pinned)) LOG.debug("New Instance Pinning {}: {}".format( instance.uuid, instance.numa_topology.cells)) """ # Test that saves don't overwrite with an empty mapping for cell in instance.numa_topology.cells: cell['cpu_pinning_raw'] = {} """ cells_are_populated = [ cell.cpu_pinning_raw != {} for cell in instance.numa_topology.cells ] if reduce(lambda l, r: l or r, cells_are_populated): LOG.debug("Saving new pinning for {}".format(instance.uuid)) instance.save() else: LOG.warn("Pinning for {} failed".format(instance.uuid)) return {'old': old_topology, 'new': pinned}
def test_build_and_run_instance_limits_juno_compat( self, is_neutron, get_by_host_and_nodename): host_topology = objects_numa.NUMATopology(cells=[ objects_numa.NUMACell(id=0, cpuset=set([1, 2]), memory=512, cpu_usage=2, memory_usage=256, pinned_cpus=set([1])), objects_numa.NUMACell(id=1, cpuset=set([3, 4]), memory=512, cpu_usage=1, memory_usage=128, pinned_cpus=set([])) ]) limits = objects_numa.NUMATopologyLimits(cpu_allocation_ratio=16, ram_allocation_ratio=2) cnode = objects_compute_node.ComputeNode( numa_topology=jsonutils.dumps(host_topology.obj_to_primitive())) get_by_host_and_nodename.return_value = cnode legacy_limits = jsonutils.dumps(limits.to_dict_legacy(host_topology)) self.flags(compute='juno', group='upgrade_levels') netreqs = objects_network_request.NetworkRequestList(objects=[ objects_network_request.NetworkRequest( network_id="fake_network_id", address="10.0.0.1", port_id="fake_port_id") ]) self._test_compute_api('build_and_run_instance', 'cast', instance=self.fake_instance_obj, host='host', image='image', request_spec={'request': 'spec'}, filter_properties=[], admin_password='******', injected_files=None, requested_networks=netreqs, security_groups=None, block_device_mapping=None, node='node', limits={'numa_topology': limits}, legacy_limits={'numa_topology': legacy_limits}, version='3.33')