]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Fix canonicalize_hostname()
authorZack Cerza <zack.cerza@inktank.com>
Mon, 25 Aug 2014 19:50:38 +0000 (13:50 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Mon, 25 Aug 2014 19:50:52 +0000 (13:50 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/misc.py

index 6bddc86e36735d2dca446f727d24810e4d88d90e..2ffc0f4e1e2c8461525d64fb492106dbe75e4e84 100644 (file)
@@ -39,12 +39,20 @@ hostname_expr = '(?P<user>.*@)?(?P<shortname>.*)\.front\.sepia\.ceph\.com'
 
 def canonicalize_hostname(hostname, user='ubuntu'):
     match = re.match(hostname_expr, hostname)
-    if match is None:
-        user_at = user + '@' if user else ''
-        hostname = '{user_at}{short}.front.sepia.ceph.com'.format(
-            user_at=user_at,
-            short=hostname)
-    return hostname
+    if match:
+        match_d = match.groupdict()
+        shortname = match_d['shortname']
+        user_ = match_d.get('user') or user
+    else:
+        shortname = hostname.split('.')[0]
+        user_ = user
+
+    user_at = user_ + '@' if user_ else ''
+
+    ret = '{user_at}{short}.front.sepia.ceph.com'.format(
+        user_at=user_at,
+        short=shortname)
+    return ret
 
 
 def decanonicalize_hostname(hostname):