[Patch for Review] iSCSI Name Validation using regex.
Chris Lumens
clumens at redhat.com
Mon Apr 27 19:01:26 UTC 2015
> The following patch is to make use of a regular expression to validate
> the user given iSCSI Initiator name in Anaconda, while selecting iSCSI
> disks during OS installation.
Thanks for taking a look at this!
> diff --git a/pyanaconda/regexes.py b/pyanaconda/regexes.py
> index b4e52a3..f153915 100644
> --- a/pyanaconda/regexes.py
> +++ b/pyanaconda/regexes.py
> @@ -135,3 +135,11 @@ REPO_NAME_VALID = re.compile(r'^[a-zA-Z0-9_.:-]+$')
>
> # Product Version string, just the starting numbers like 21 or 21.1
> VERSION_DIGITS = r'([\d.]+)'
> +
> +
> +#iSCSI Naming Standards: RFC 3720 and RFC 3721
> +ISCSI_IQN_NAMING_FORMAT = re.compile(r'^iqn\.\d{4}-\d{2}((?<!-)\.(?!-)[a-zA-Z0-9\-]+){1,63}(?<!-)(?<!\.)(:[^:]+)?')
^^^^^^^^
From your above description, it looks like the first dot is required.
Could you not just put it outside the parens, then?
I kind of get the feeling you might be trying to be a little too terse
here, when being more verbose would help us understand what is happening
here more at a glance. Specifically, I'd personally rather see fewer
lookaheads.
> @@ -303,7 +306,18 @@ class ISCSIDialog(GUIObject):
>
> stripped = text.strip()
> #iSCSI Naming Standards: RFC 3720 and RFC 3721
> - return "." in stripped
> + if stripped.startswith('iqn.'):
> + initiator_name_match = re.match(ISCSI_IQN_NAMING_FORMAT,stripped)
> + elif stripped.startswith('eui.'):
> + initiator_name_match = re.match(ISCSI_EUI_NAMING_FORMAT,stripped)
> + else:
> + return False
> +
> + if initiator_name_match and (len(initiator_name_match.group(0)) == len(stripped)):
> + return True
> + else:
> + return False
> +
Please use four spaces instead of tabs.
Would you mind adding some tests into tests/regex_tests/ for this, too?
It sounds like you've already come up with a lot of test cases during
development. I'd just like to see them added so we don't break this
code in the future.
- Chris
More information about the anaconda-patches
mailing list