[PATCH v2] iSCSI Name Validation using regex.

Vratislav Podzimek vpodzime at redhat.com
Wed May 6 10:07:32 UTC 2015


On Tue, 2015-05-05 at 01:03 -0400, Sujith Pandel wrote:
> When adding iSCSI target disk during installation, the iSCSI Initiator name and the Target IP is validated to enable/disable the "Start Discovery" button on the page.
> Currently, the validation of iSCSI Initiator Name is based on the existence of dots only (".") and this can be more efficiently done by using a regular expression.
> 
> The conditions for iSCSI initiator name used in this regex are
> (https://tools.ietf.org/html/rfc3720#section-3.2.6.3.1 , https://tools.ietf.org/html/rfc3721#page-5 and http://standards.ieee.org/regauth/oui/tutorials/EUI64.html):
> 1. For iqn format:
>         a. Starts with string 'iqn.'
>         b. A date code specifying the year and month in which the organization registered the domain or sub-domain name used as the naming authority string. "yyyy-mm"
>         c. A dot (".")
>         d. The organizational naming authority string, which consists of a valid, reversed domain or subdomain name.
>         e. Optionally, a colon (":"), followed by a string of the assigning organization's choosing, which must make each assigned iSCSI name unique. With the exception of the colon prefix, the owner of the domain name can assign everything after the reversed domain name as desired.
> 
> 2. For eui format:
>         The format is "eui." followed by an EUI-64 identifier (16 ASCII-encoded hexadecimal digits).
> 
> Signed-off-by: Sujith Pandel <sujithpshankar at gmail.com>
> ---
> Changes since v1:
> - Rewrite the code changes in iscsi.py to use REGEX.match(string) instead of re.match(REGEX, string)
> - Simplify the code changes to fit into a single statement.
> - Add comments to new regexes in regexes.py
> - Remove the unneccessary import of re modules in iscsi.py and tests/regex_tests/iscsi_name_test.py
> 
>  pyanaconda/regexes.py                        | 19 +++++++
>  pyanaconda/ui/gui/spokes/advstorage/iscsi.py |  4 +-
>  tests/regex_tests/iscsi_name_test.py         | 77 ++++++++++++++++++++++++++++
>  3 files changed, 99 insertions(+), 1 deletion(-)
>  create mode 100644 tests/regex_tests/iscsi_name_test.py
> 
> diff --git a/pyanaconda/regexes.py b/pyanaconda/regexes.py
> index b4e52a3..e216aa7 100644
> --- a/pyanaconda/regexes.py
> +++ b/pyanaconda/regexes.py
> @@ -135,3 +135,22 @@ 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.]+)'
> +
> +
> +#Regexes to validate iSCSI Names according to RFC 3720 and RFC 3721
> +#The conditions for iSCSI name used in the following regexes are
> +#(https://tools.ietf.org/html/rfc3720#section-3.2.6.3.1 , https://tools.ietf.org/html/rfc3721#page-5 and http://standards.ieee.org/regauth/oui/tutorials/EUI64.html):
> +#1. For iqn format:
> +#	a. Starts with string 'iqn.'
> +#      b. A date code specifying the year and month in which the organization registered the domain or sub-domain name used as the naming authority string. "yyyy-mm"
> +#	c. A dot (".")
> +#	d. The organizational naming authority string, which consists of a valid, reversed domain or subdomain name.
> +#	e. Optionally, a colon (":"), followed by a string of the assigning organization's choosing, which must make each assigned iSCSI name unique. With the exception of the colon prefix, the owner of the domain name can assign everything after the reversed domain name as desired.
> +
> +#2. For eui format:
> +#	a. The format is "eui." followed by an EUI-64 identifier (16 ASCII-encoded hexadecimal digits).
> +ISCSI_IQN_NAME_REGEX = re.compile(r'^iqn\.\d{4}-\d{2}((?<!-)\.(?!-)[a-zA-Z0-9\-]+){1,63}(?<!-)(?<!\.)(:[^:]+)?$')
> +
> +ISCSI_EUI_NAME_REGEX = re.compile(r'^eui\.[a-fA-F0-9]{16}$')
I'd put the definitions of the regexes right before the particular
comments about their structure. But that's something I can do as part of
pushing this patch.

Looks good to me otherwise, ACK.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list