Hi All, 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. I have tested it for cases which I could think of at this time. Requesting review/feedback and inclusion.
Thanks and Regards, Sujith Pandel
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@gmail.com --- pyanaconda/regexes.py | 8 ++++++++ pyanaconda/ui/gui/spokes/advstorage/iscsi.py | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-)
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}(?<!-)(?<!.)(:[^:]+)?') + +ISCSI_EUI_NAMING_FORMAT = re.compile(r'^eui.[a-fA-F0-9]{16}') + + diff --git a/pyanaconda/ui/gui/spokes/advstorage/iscsi.py b/pyanaconda/ui/gui/spokes/advstorage/iscsi.py index 22e11c3..764e81f 100644 --- a/pyanaconda/ui/gui/spokes/advstorage/iscsi.py +++ b/pyanaconda/ui/gui/spokes/advstorage/iscsi.py @@ -18,7 +18,7 @@ # # Red Hat Author(s): Chris Lumens clumens@redhat.com # - +import re from IPy import IP from collections import namedtuple from gi.repository import GLib @@ -29,6 +29,9 @@ from pyanaconda.ui.gui import GUIObject from pyanaconda.ui.gui.utils import escape_markup from pyanaconda.i18n import _ from pyanaconda import nm +from pyanaconda.regexes import ISCSI_IQN_NAMING_FORMAT +from pyanaconda.regexes import ISCSI_EUI_NAMING_FORMAT +
__all__ = ["ISCSIDialog"]
@@ -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 +
def on_discover_field_changed(self, *args): # Make up a credentials object so we can test if it's valid.
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
anaconda-patches@lists.fedorahosted.org