def verify_image_name(name, checksum, expected): img_meta = image_meta.ImageMeta(name=name, checksum=checksum) self.assertEqual(expected, ssp._get_image_name(img_meta)) self.assertTrue(len(expected) <= const.MaxLen.FILENAME_DEFAULT)
def _validate_numa_node(flavor): NUMA_NODES_KEY = 'hw:numa_nodes' NUMA_NODE_PREFIX = 'hw:numa_node.' specs = flavor.extra_specs try: hw_numa_nodes = int(specs.get(NUMA_NODES_KEY, 1)) except ValueError: msg = _('hw:numa_nodes value must be an integer') raise webob.exc.HTTPBadRequest(explanation=msg) if hw_numa_nodes < 1: msg = _('hw:numa_nodes value must be greater than 0') raise webob.exc.HTTPBadRequest(explanation=msg) for key in specs: if key.startswith(NUMA_NODE_PREFIX): # NUMA pinning not allowed when CPU policy is shared if (specs.get(CPU_POLICY_KEY) == fields.CPUAllocationPolicy.SHARED): msg = _('hw:numa_node not permitted when cpu policy ' 'is set to shared') raise webob.exc.HTTPConflict(explanation=msg) suffix = key.split(NUMA_NODE_PREFIX, 1)[1] try: vnode = int(suffix) except ValueError: msg = _('virtual numa node number must be an integer') raise webob.exc.HTTPBadRequest(explanation=msg) if vnode < 0: msg = _('virtual numa node number must be greater than or ' 'equal to 0') raise webob.exc.HTTPBadRequest(explanation=msg) try: pnode = int(specs[key]) except ValueError: msg = _('%s must be an integer') % key raise webob.exc.HTTPBadRequest(explanation=msg) if pnode < 0: msg = _('%s must be greater than or equal to 0') % key raise webob.exc.HTTPBadRequest(explanation=msg) if pnode >= MAX_HOST_NUMA_NODES: msg = (_('%(K)s value %(P)d is not valid. It must ' 'be an integer from 0 to %(N)d') % {'K': key, 'P': pnode, 'N': MAX_HOST_NUMA_NODES - 1 }) raise webob.exc.HTTPBadRequest(explanation=msg) if vnode >= hw_numa_nodes: msg = _('all hw:numa_node keys must use vnode id less than' ' the specified hw:numa_nodes value (%s)') \ % hw_numa_nodes raise webob.exc.HTTPBadRequest(explanation=msg) # CPU scaling doesn't currently support multiple guest NUMA nodes if hw_numa_nodes > 1 and CPU_SCALING_KEY in specs: msg = _('CPU scaling not supported for instances with' ' multiple NUMA nodes.') raise webob.exc.HTTPConflict(explanation=msg) # CGTS-3716 Asymmetric NUMA topology protection # Do common error check from numa_get_constraints with a clearer error if hw_numa_nodes > 0 and specs.get('hw:numa_cpus.0') is None: if (flavor.vcpus % hw_numa_nodes) > 0: msg = _('flavor vcpus not evenly divisible by' ' the specified hw:numa_nodes value (%s)') \ % hw_numa_nodes raise webob.exc.HTTPConflict(explanation=msg) if (flavor.memory_mb % hw_numa_nodes) > 0: msg = _('flavor memory not evenly divisible by' ' the specified hw:numa_nodes value (%s) so' ' per NUMA-node values must be explicitly specified') \ % hw_numa_nodes raise webob.exc.HTTPConflict(explanation=msg) # Catchall test try: # Check if this modified flavor would be valid assuming # no image metadata. hardware.numa_get_constraints(flavor, image_meta.ImageMeta( properties=image_meta.ImageMetaProps())) except Exception as error: msg = _('%s') % error.message raise webob.exc.HTTPConflict(explanation=msg)