def test_numa_topology_filter_pass_set_limit(self):
        self.flags(cpu_allocation_ratio=21)
        self.flags(ram_allocation_ratio=1.3)

        instance_topology = hardware.VirtNUMAInstanceTopology(cells=[
            hardware.VirtNUMATopologyCellInstance(0, set([1]), 512),
            hardware.VirtNUMATopologyCellInstance(1, set([3]), 512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = (
            objects.InstanceNUMATopology.obj_from_topology(instance_topology))
        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1',
                                   {'numa_topology': fakes.NUMA_TOPOLOGY})
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
        limits_topology = hardware.VirtNUMALimitTopology.from_json(
            host.limits['numa_topology'])
        self.assertEqual(limits_topology.cells[0].cpu_limit, 42)
        self.assertEqual(limits_topology.cells[1].cpu_limit, 42)
        self.assertEqual(limits_topology.cells[0].memory_limit, 665)
        self.assertEqual(limits_topology.cells[1].memory_limit, 665)
Esempio n. 2
0
 def topology_from_obj(self):
     cells = []
     for objcell in self.cells:
         cell = hardware.VirtNUMATopologyCellInstance(
             objcell.id, objcell.cpuset, objcell.memory, objcell.pagesize)
         cells.append(cell)
     return hardware.VirtNUMAInstanceTopology(cells=cells)
    def test_numa_topology_filter_numa_instance_no_numa_host_fail(self):
        instance_topology = hardware.VirtNUMAInstanceTopology(cells=[
            hardware.VirtNUMATopologyCellInstance(0, set([1]), 512),
            hardware.VirtNUMATopologyCellInstance(1, set([3]), 512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = (
            objects.InstanceNUMATopology.obj_from_topology(instance_topology))

        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {})
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
    def test_numa_topology_filter_fail_memory(self):
        self.flags(ram_allocation_ratio=1)

        instance_topology = hardware.VirtNUMAInstanceTopology(cells=[
            hardware.VirtNUMATopologyCellInstance(0, set([1]), 1024),
            hardware.VirtNUMATopologyCellInstance(1, set([3]), 512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = (
            objects.InstanceNUMATopology.obj_from_topology(instance_topology))
        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1',
                                   {'numa_topology': fakes.NUMA_TOPOLOGY})
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Esempio n. 5
0
 def test_numa_topology_passes(self, mock_get):
     huge_instance = hardware.VirtNUMAInstanceTopology(
             cells=[hardware.VirtNUMATopologyCellInstance(
                 1, set([1, 2, 3, 4, 5]), 2048)])
     limit_topo = hardware.VirtNUMALimitTopology(
             cells=[hardware.VirtNUMATopologyCellLimit(
                         1, [1, 2], 512, cpu_limit=5, memory_limit=4096),
                    hardware.VirtNUMATopologyCellLimit(
                         1, [3, 4], 512, cpu_limit=5, memory_limit=4096)])
     self._claim(limits={'numa_topology': limit_topo.to_json()},
                 numa_topology=huge_instance)
Esempio n. 6
0
 def test_numa_topology_fails(self, mock_get):
     huge_instance = hardware.VirtNUMAInstanceTopology(
             cells=[hardware.VirtNUMATopologyCellInstance(
                 1, set([1, 2, 3, 4, 5]), 2048)])
     limit_topo = hardware.VirtNUMALimitTopology(
             cells=[hardware.VirtNUMATopologyCellLimit(
                         1, [1, 2], 512, cpu_limit=2, memory_limit=512),
                    hardware.VirtNUMATopologyCellLimit(
                         1, [3, 4], 512, cpu_limit=2, memory_limit=512)])
     self.assertRaises(exception.ComputeResourcesUnavailable,
                       self._claim,
                       limits={'numa_topology': limit_topo.to_json()},
                       numa_topology=huge_instance)
Esempio n. 7
0
 def test_numa_topology_no_limit(self, mock_get):
     huge_instance = hardware.VirtNUMAInstanceTopology(
             cells=[hardware.VirtNUMATopologyCellInstance(
                 1, set([1, 2, 3, 4, 5]), 2048)])
     self._claim(numa_topology=huge_instance)
Esempio n. 8
0
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import uuid

import mock

from nova import exception
from nova import objects
from nova.tests.unit.objects import test_objects
from nova.virt import hardware

fake_instance_uuid = str(uuid.uuid4())
fake_numa_topology = hardware.VirtNUMAInstanceTopology(cells=[
    hardware.VirtNUMATopologyCellInstance(0, set([1, 2]), 512, 2048),
    hardware.VirtNUMATopologyCellInstance(1, set([3, 4]), 512, 2048)
])

fake_obj_numa_topology = objects.InstanceNUMATopology.obj_from_topology(
    fake_numa_topology)
fake_obj_numa_topology.instance_uuid = fake_instance_uuid

fake_db_topology = {
    'created_at': None,
    'updated_at': None,
    'deleted_at': None,
    'deleted': 0,
    'id': 1,
    'instance_uuid': fake_instance_uuid,
    'numa_topology': fake_obj_numa_topology._to_json()
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import uuid

import mock

from nova import exception
from nova import objects
from nova.tests.unit.objects import test_objects
from nova.virt import hardware

fake_numa_topology = hardware.VirtNUMAInstanceTopology(cells=[
    hardware.VirtNUMATopologyCellInstance(0, set([1, 2]), 512,
                                          hardware.VirtPageSize(2048)),
    hardware.VirtNUMATopologyCellInstance(1, set([3, 4]), 512,
                                          hardware.VirtPageSize(2048))
])

fake_db_topology = {
    'created_at': None,
    'updated_at': None,
    'deleted_at': None,
    'deleted': 0,
    'id': 1,
    'instance_uuid': str(uuid.uuid4()),
    'numa_topology': fake_numa_topology.to_json()
}