def test_numa_topo_dict_with_usage(self): topo = hw.VirtNUMAHostTopology(cells=[ hw.VirtNUMATopologyCellUsage(1, set([1, 2]), 1024), hw.VirtNUMATopologyCellUsage(2, set([3, 4]), 1024) ]) topo_dict = { 'cells': [{ 'cpus': '1,2', 'cpu_usage': 0, 'mem': { 'total': 1024, 'used': 0 }, 'id': 1 }, { 'cpus': '3,4', 'cpu_usage': 0, 'mem': { 'total': 1024, 'used': 0 }, 'id': 2 }] } self._test_to_dict(topo, topo_dict) self._test_topo_from_dict(topo_dict, topo, with_usage=True)
def _fake_resources(self, values=None): resources = { 'memory_mb': 2048, 'memory_mb_used': 0, 'free_ram_mb': 2048, 'local_gb': 20, 'local_gb_used': 0, 'free_disk_gb': 20, 'vcpus': 2, 'vcpus_used': 0, 'numa_topology': hardware.VirtNUMAHostTopology(cells=[ hardware.VirtNUMATopologyCellUsage(1, [1, 2], 512), hardware.VirtNUMATopologyCellUsage(2, [3, 4], 512) ]).to_json() } if values: resources.update(values) return resources
def test_topo_usage_none(self): hosttopo = hw.VirtNUMAHostTopology([ hw.VirtNUMATopologyCellUsage(0, set([0, 1]), 512), hw.VirtNUMATopologyCellUsage(1, set([2, 3]), 512), ]) instance1 = hw.VirtNUMAInstanceTopology([ hw.VirtNUMATopologyCell(0, set([0, 1]), 256), hw.VirtNUMATopologyCell(2, set([2]), 256), ]) hostusage = hw.VirtNUMAHostTopology.usage_from_instances( None, [instance1]) self.assertIsNone(hostusage) hostusage = hw.VirtNUMAHostTopology.usage_from_instances( hosttopo, []) self.assertEqual(hostusage.cells[0].cpu_usage, 0) self.assertEqual(hostusage.cells[0].memory_usage, 0) self.assertEqual(hostusage.cells[1].cpu_usage, 0) self.assertEqual(hostusage.cells[1].memory_usage, 0) hostusage = hw.VirtNUMAHostTopology.usage_from_instances( hosttopo, None) self.assertEqual(hostusage.cells[0].cpu_usage, 0) self.assertEqual(hostusage.cells[0].memory_usage, 0) self.assertEqual(hostusage.cells[1].cpu_usage, 0) self.assertEqual(hostusage.cells[1].memory_usage, 0)
def setUp(self): super(NUMATopologyClaimsTest, self).setUp() self.host = hw.VirtNUMAHostTopology( cells=[ hw.VirtNUMATopologyCellUsage( 1, set([1, 2, 3, 4]), 2048, cpu_usage=1, memory_usage=512), hw.VirtNUMATopologyCellUsage( 2, set([5, 6]), 1024)]) self.limits = hw.VirtNUMALimitTopology( cells=[ hw.VirtNUMATopologyCellLimit( 1, set([1, 2, 3, 4]), 2048, cpu_limit=8, memory_limit=4096), hw.VirtNUMATopologyCellLimit( 2, set([5, 6]), 1024, cpu_limit=4, memory_limit=2048)]) self.large_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1, 2, 3, 4, 5, 6]), 8192), hw.VirtNUMATopologyCell(2, set([7, 8]), 4096)]) self.medium_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1, 2, 3, 4]), 1024), hw.VirtNUMATopologyCell(2, set([7, 8]), 2048)]) self.small_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1]), 256), hw.VirtNUMATopologyCell(2, set([5]), 1024)])
def test_json(self): expected = hw.VirtNUMAHostTopology(cells=[ hw.VirtNUMATopologyCellUsage(1, set([1, 2]), 1024), hw.VirtNUMATopologyCellUsage(2, set([3, 4]), 1024) ]) got = hw.VirtNUMAHostTopology.from_json(expected.to_json()) for exp_cell, got_cell in zip(expected.cells, got.cells): self.assertNUMACellMatches(exp_cell, got_cell)
def setUp(self): super(HelperMethodsTestCase, self).setUp() self.hosttopo = hw.VirtNUMAHostTopology([ hw.VirtNUMATopologyCellUsage(0, set([0, 1]), 512), hw.VirtNUMATopologyCellUsage(1, set([2, 3]), 512), ]) self.instancetopo = hw.VirtNUMAInstanceTopology([ hw.VirtNUMATopologyCell(0, set([0, 1]), 256), hw.VirtNUMATopologyCell(1, set([2]), 256), ]) self.context = context.RequestContext('fake-user', 'fake-project')
def test_host_usage_sparse(self): hosttopo = hw.VirtNUMAHostTopology([ hw.VirtNUMATopologyCellUsage(0, set([0, 1, 2, 3]), 1024), hw.VirtNUMATopologyCellUsage(5, set([4, 6]), 512), hw.VirtNUMATopologyCellUsage(6, set([5, 7]), 512), ]) instance1 = hw.VirtNUMAInstanceTopology([ hw.VirtNUMATopologyCell(0, set([0, 1, 2]), 256), hw.VirtNUMATopologyCell(6, set([4]), 256), ]) instance2 = hw.VirtNUMAInstanceTopology([ hw.VirtNUMATopologyCell(0, set([0, 1]), 256), hw.VirtNUMATopologyCell(5, set([5, 7]), 256), ]) hostusage = hw.VirtNUMAHostTopology.usage_from_instances( hosttopo, [instance1, instance2]) self.assertEqual(len(hosttopo), len(hostusage)) self.assertIsInstance(hostusage.cells[0], hw.VirtNUMATopologyCellUsage) self.assertEqual(hosttopo.cells[0].id, hostusage.cells[0].id) self.assertEqual(hosttopo.cells[0].cpuset, hostusage.cells[0].cpuset) self.assertEqual(hosttopo.cells[0].memory, hostusage.cells[0].memory) self.assertEqual(hostusage.cells[0].cpu_usage, 5) self.assertEqual(hostusage.cells[0].memory_usage, 512) self.assertIsInstance(hostusage.cells[1], hw.VirtNUMATopologyCellUsage) self.assertEqual(hosttopo.cells[1].id, hostusage.cells[1].id) self.assertEqual(hosttopo.cells[1].cpuset, hostusage.cells[1].cpuset) self.assertEqual(hosttopo.cells[1].memory, hostusage.cells[1].memory) self.assertEqual(hostusage.cells[1].cpu_usage, 2) self.assertEqual(hostusage.cells[1].memory_usage, 256) self.assertIsInstance(hostusage.cells[2], hw.VirtNUMATopologyCellUsage) self.assertEqual(hosttopo.cells[2].cpuset, hostusage.cells[2].cpuset) self.assertEqual(hosttopo.cells[2].memory, hostusage.cells[2].memory) self.assertEqual(hostusage.cells[2].cpu_usage, 1) self.assertEqual(hostusage.cells[2].memory_usage, 256)
def test_claim_not_enough_info(self): # No limits supplied self.assertIsNone( hw.VirtNUMAHostTopology.claim_test( self.host, [self.large_instance])) # Empty topology self.assertIsNone( hw.VirtNUMAHostTopology.claim_test( hw.VirtNUMAHostTopology(), [self.large_instance], limits=self.limits)) # No instances to claim self.assertIsNone( hw.VirtNUMAHostTopology.claim_test(self.host, [], self.limits))
def test_host_usage_culmulative_with_free(self): hosttopo = hw.VirtNUMAHostTopology([ hw.VirtNUMATopologyCellUsage(0, set([0, 1, 2, 3]), 1024, cpu_usage=2, memory_usage=512), hw.VirtNUMATopologyCellUsage(1, set([4, 6]), 512, cpu_usage=1, memory_usage=512), hw.VirtNUMATopologyCellUsage(2, set([5, 7]), 256), ]) instance1 = hw.VirtNUMAInstanceTopology([ hw.VirtNUMATopologyCell(0, set([0, 1, 2]), 512), hw.VirtNUMATopologyCell(1, set([3]), 256), hw.VirtNUMATopologyCell(2, set([4]), 256) ]) hostusage = hw.VirtNUMAHostTopology.usage_from_instances( hosttopo, [instance1]) self.assertIsInstance(hostusage.cells[0], hw.VirtNUMATopologyCellUsage) self.assertEqual(hostusage.cells[0].cpu_usage, 5) self.assertEqual(hostusage.cells[0].memory_usage, 1024) self.assertIsInstance(hostusage.cells[1], hw.VirtNUMATopologyCellUsage) self.assertEqual(hostusage.cells[1].cpu_usage, 2) self.assertEqual(hostusage.cells[1].memory_usage, 768) self.assertIsInstance(hostusage.cells[2], hw.VirtNUMATopologyCellUsage) self.assertEqual(hostusage.cells[2].cpu_usage, 1) self.assertEqual(hostusage.cells[2].memory_usage, 256) # Test freeing of resources hostusage = hw.VirtNUMAHostTopology.usage_from_instances(hostusage, [instance1], free=True) self.assertEqual(hostusage.cells[0].cpu_usage, 2) self.assertEqual(hostusage.cells[0].memory_usage, 512) self.assertEqual(hostusage.cells[1].cpu_usage, 1) self.assertEqual(hostusage.cells[1].memory_usage, 512) self.assertEqual(hostusage.cells[2].cpu_usage, 0) self.assertEqual(hostusage.cells[2].memory_usage, 0)
from nova import db from nova import exception from nova.objects import compute_node from nova.objects import hv_spec from nova.objects import service from nova.tests.unit.objects import test_objects from nova.virt import hardware NOW = timeutils.utcnow().replace(microsecond=0) fake_stats = {'num_foo': '10'} fake_stats_db_format = jsonutils.dumps(fake_stats) # host_ip is coerced from a string to an IPAddress # but needs to be converted to a string for the database format fake_host_ip = '127.0.0.1' fake_numa_topology = hardware.VirtNUMAHostTopology(cells=[ hardware.VirtNUMATopologyCellUsage(0, set([1, 2]), 512), hardware.VirtNUMATopologyCellUsage(1, set([3, 4]), 512) ]) fake_numa_topology_db_format = fake_numa_topology.to_json() fake_hv_spec = hv_spec.HVSpec(arch='foo', hv_type='bar', vm_mode='foobar') fake_supported_hv_specs = [fake_hv_spec] # for backward compatibility, each supported instance object # is stored as a list in the database fake_supported_hv_specs_db_format = jsonutils.dumps([fake_hv_spec.to_list()]) fake_compute_node = { 'created_at': NOW, 'updated_at': None, 'deleted_at': None, 'deleted': False, 'id': 123, 'service_id': 456, 'vcpus': 4,
# under the License. """ Fakes For Scheduler tests. """ import mox from nova.compute import vm_states from nova import db from nova.openstack.common import jsonutils from nova.scheduler import filter_scheduler from nova.scheduler import host_manager from nova.virt import hardware NUMA_TOPOLOGY = hardware.VirtNUMAHostTopology(cells=[ hardware.VirtNUMATopologyCellUsage(0, set([1, 2]), 512), hardware.VirtNUMATopologyCellUsage(1, set([3, 4]), 512) ]) COMPUTE_NODES = [ dict(id=1, local_gb=1024, memory_mb=1024, vcpus=1, disk_available_least=None, free_ram_mb=512, vcpus_used=1, free_disk_gb=512, local_gb_used=0, updated_at=None, service=dict(host='host1', disabled=False), hypervisor_hostname='node1',