def verify_fcp_list_in_hex_format(fcp_list): """Verify each FCP in the list is in Hex format :param fcp_list: (list) a list object contains FCPs. """ if not isinstance(fcp_list, list): errmsg = ('fcp_list ({}) is not a list object.' '').format(fcp_list) raise exception.SDKInvalidInputFormat(msg=errmsg) # Verify each FCP should be a 4-digit hex for fcp in fcp_list: if not (len(fcp) == 4 and all(char in string.hexdigits for char in fcp)): errmsg = ('FCP list {} contains non-hex value.' '').format(fcp_list) raise exception.SDKInvalidInputFormat(msg=errmsg)
def get_definition_info(self, userid, **kwargs): check_command = ["nic_coupled"] direct_info = self._smutclient.get_user_direct(userid) info = {} info['user_direct'] = direct_info for k, v in kwargs.items(): if k in check_command: if (k == 'nic_coupled'): info['nic_coupled'] = False nstr = "NICDEF %s TYPE QDIO LAN SYSTEM" % v for inf in direct_info: if nstr in inf: info['nic_coupled'] = True break else: raise exception.SDKInvalidInputFormat( msg=("invalid check option for user direct: %s") % k) return info
def wrap_func(*args, **kwargs): if args[0]._skip_input_check: # skip input check return function(*args, **kwargs) # drop class object self inputs = args[1:] if (len(inputs) > len(types)): msg = ("Too many parameters provided: %(specified)d specified," "%(expected)d expected." % {'specified': len(inputs), 'expected': len(types)}) LOG.info(msg) raise exception.SDKInvalidInputNumber(function.__name__, len(types), len(inputs)) argtypes = tuple(map(type, inputs)) match_types = types[0:len(argtypes)] invalid_type = False invalid_userid_idx = -1 for idx in range(len(argtypes)): _mtypes = match_types[idx] if not isinstance(_mtypes, tuple): _mtypes = (_mtypes,) argtype = argtypes[idx] if constants._TUSERID in _mtypes: userid_type = True for _tmtype in _mtypes: if ((argtype == _tmtype) and (_tmtype != constants._TUSERID)): userid_type = False if (userid_type and (not valid_userid(inputs[idx]))): invalid_userid_idx = idx break elif argtype not in _mtypes: invalid_type = True break if invalid_userid_idx != -1: msg = ("Invalid string value found at the #%d parameter, " "length should be less or equal to 8 and should not be " "null or contain spaces." % (invalid_userid_idx + 1)) LOG.info(msg) raise exception.SDKInvalidInputFormat(msg=msg) if invalid_type: msg = ("Invalid input types: %(argtypes)s; " "Expected types: %(types)s" % {'argtypes': str(argtypes), 'types': str(types)}) LOG.info(msg) raise exception.SDKInvalidInputTypes(function.__name__, str(types), str(argtypes)) valid_keys = validkeys.get('valid_keys') if valid_keys: for k in kwargs.keys(): if k not in valid_keys: msg = ("Invalid keyword: %(key)s; " "Expected keywords are: %(keys)s" % {'key': k, 'keys': str(valid_keys)}) LOG.info(msg) raise exception.SDKInvalidInputFormat(msg=msg) return function(*args, **kwargs)