def _check_extra_specs(self, specs): if type(specs) is not dict: msg = _('Bad extra_specs provided') raise exc.HTTPBadRequest(explanation=msg) try: flavors.validate_extra_spec_keys(specs.keys()) except TypeError: msg = _("Fail to validate provided extra specs keys. " "Expected string") raise exc.HTTPBadRequest(explanation=msg) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message()) for key, value in six.iteritems(specs): try: utils.check_string_length(key, 'extra_specs key', min_length=1, max_length=255) # NOTE(dims): The following check was added for backwards # compatibility. if (isinstance(value, (int, long, float))): value = six.text_type(value) utils.check_string_length(value, 'extra_specs value', max_length=255) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message())
def _check_extra_specs(self, specs): if type(specs) is not dict: msg = _('Bad extra_specs provided') raise exc.HTTPBadRequest(explanation=msg) try: flavors.validate_extra_spec_keys(specs.keys()) except TypeError: msg = _("Fail to validate provided extra specs keys. " "Expected string") raise exc.HTTPBadRequest(explanation=msg) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message()) for key, value in specs.iteritems(): try: utils.check_string_length(key, 'extra_specs key', min_length=1, max_length=255) # NOTE(dims): The following check was added for backwards # compatibility. if (isinstance(value, (int, long, float))): value = six.text_type(value) utils.check_string_length(value, 'extra_specs value', max_length=255) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message())
def _check_extra_specs(self, specs): if type(specs) is not dict: msg = _('Bad extra_specs provided') raise exc.HTTPBadRequest(explanation=msg) try: flavors.validate_extra_spec_keys(specs.keys()) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message()) for key, value in specs.iteritems(): try: utils.check_string_length(key, 'extra_specs key', min_length=1, max_length=255) utils.check_string_length(value, 'extra_specs value', max_length=255) except exception.InvalidInput as error: raise exc.HTTPBadRequest(explanation=error.format_message())
def _check_key_names(self, keys): try: flavors.validate_extra_spec_keys(keys) except exception.InvalidInput as error: raise webob.exc.HTTPBadRequest(explanation=error.format_message())
def test_flavor_validate_extra_spec_keys(self): key_name_list = ['abc', 'ab c', 'a-b-c', 'a_b-c', 'a:bc'] flavors.validate_extra_spec_keys(key_name_list)
def test_flavor_validate_extra_spec_keys(self): key_name_list = ["abc", "ab c", "a-b-c", "a_b-c", "a:bc"] flavors.validate_extra_spec_keys(key_name_list)