From aed56e2b2787549127949bb2474b97d49981433f Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 12 Feb 2016 16:21:37 -0500 Subject: [PATCH] Reorder name normalization for DNS Having the truncation step as the last one meant we could truncate to a trailing hyphen. This could potential cause a failure for an invalid name. This commit reorders the normalization to put the truncation as the first step which should avoid that problem. Change-Id: I2219f6c73d882efc787127f02fda937f3e3b44eb Closes-Bug: #1545153 --- nova/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/utils.py b/nova/utils.py index b869c35f2..14488cab9 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -802,6 +802,7 @@ def sanitize_hostname(hostname, default_name=None): if six.PY3: hostname = hostname.decode('latin-1') + hostname = truncate_hostname(hostname) hostname = re.sub('[ _]', '-', hostname) hostname = re.sub('[^\w.-]+', '', hostname) hostname = hostname.lower() @@ -810,8 +811,7 @@ def sanitize_hostname(hostname, default_name=None): # empty hostname if hostname == "" and default_name is not None: return truncate_hostname(default_name) - - return truncate_hostname(hostname) + return hostname @contextlib.contextmanager