]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Revert "Allows other users besides ubuntu"
authorZack Cerza <zack@redhat.com>
Fri, 10 Jul 2015 18:52:27 +0000 (12:52 -0600)
committerZack Cerza <zack@redhat.com>
Fri, 10 Jul 2015 18:52:27 +0000 (12:52 -0600)
This reverts commit 8ba655af8d78722b70a3615561e9bcfa9c5f8cc2.

This broke misc.canonicalize_hostname()

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/misc.py
teuthology/test/test_misc.py

index 5b6a8008d347042ebcc25a6fa78ad1ba450d83bb..bf6f709b3b35e53bd29cc4f10cf4e549e90a7dc0 100644 (file)
@@ -38,33 +38,41 @@ is_vm = lambda x: x.startswith('vpm') or x.startswith('ubuntu@vpm')
 is_arm = lambda x: x.startswith('tala') or x.startswith(
     'ubuntu@tala') or x.startswith('saya') or x.startswith('ubuntu@saya')
 
+hostname_expr_templ = '(?P<user>.*@)?(?P<shortname>.*)\.{lab_domain}'
 
-def canonicalize_hostname(hostname, user='ubuntu'):
-    userhost = hostname.split('@')
-
-    both_given = len(userhost) == 2
 
-    usr = userhost[0] if both_given else (user if user is not None else '')
-    hst = userhost[1] if both_given else userhost[0]
-    lab = config.lab_domain
+def canonicalize_hostname(hostname, user='ubuntu'):
+    hostname_expr = hostname_expr_templ.format(
+        lab_domain=config.lab_domain.replace('.', '\.'))
+    match = re.match(hostname_expr, hostname)
+    if match:
+        match_d = match.groupdict()
+        shortname = match_d['shortname']
+        if user is None:
+            user_ = user
+        else:
+            user_ = match_d.get('user') or user
+    else:
+        shortname = hostname.split('.')[0]
+        user_ = user
 
-    user_at = (usr + "@") if usr else ''
-    domain = hst if lab in hst else (hst + '.' + lab) if lab else hst
+    user_at = user_.strip('@') + '@' if user_ else ''
 
-    return user_at + domain
+    ret = '{user_at}{short}.{lab_domain}'.format(
+        user_at=user_at,
+        short=shortname,
+        lab_domain=config.lab_domain,
+    )
+    return ret
 
 
 def decanonicalize_hostname(hostname):
-    userhost = hostname.split('@')
-
-    both_given = len(userhost) == 2
-
-    host = userhost[1] if both_given else userhost[0]
-
-    if config.lab_domain:
-        return host.split('.')[0]
-    else:
-        return host
+    hostname_expr = hostname_expr_templ.format(
+        lab_domain=config.lab_domain.replace('.', '\.'))
+    match = re.match(hostname_expr, hostname)
+    if match:
+        hostname = match.groupdict()['shortname']
+    return hostname
 
 
 def config_file(string):
index 724994ea14d45cdad6eb4d40f24dd7812040832d..c3da5dbc10163334b7f06f784c89427eed8908e1 100644 (file)
@@ -94,35 +94,6 @@ class TestHostnames(object):
         assert result == 'box1'
 
 
-    def test_canonicalize_hostname_otheruser(self):
-        host_base = 'foo@box1'
-        result = misc.canonicalize_hostname(host_base)
-        assert result == 'foo@box1.front.sepia.ceph.com'
-
-    def test_canonicalize_hostname_nolab(self):
-        config.lab_domain = ''
-        host_base = 'foo@192.168.0.1'
-        result = misc.canonicalize_hostname(host_base)
-        assert result == 'foo@192.168.0.1'
-        host_base = 'foo@full.domain.org'
-        result = misc.canonicalize_hostname(host_base)
-        assert result == 'foo@full.domain.org'
-
-    def test_decanonicalize_hostname_nolab(self):
-        config.lab_domain = ''
-        host_base = 'foo@192.168.0.1'
-        result = misc.decanonicalize_hostname(host_base)
-        assert result == '192.168.0.1'
-        host_base = 'foo@full.domain.org'
-        result = misc.decanonicalize_hostname(host_base)
-        assert result == 'full.domain.org'
-
-    def test_canonicalize_hostname_repeateddomain(self):
-        config.lab_domain = 'ceph.com'
-        host_base = 'foo@bar.ceph.com'
-        result = misc.canonicalize_hostname(host_base)
-        assert result == 'foo@bar.ceph.com'
-
 class TestMergeConfigs(object):
     """ Tests merge_config and deep_merge in teuthology.misc """