]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Abstract the lab domain (e.g. front.sepia.ceph.com)
authorZack Cerza <zack.cerza@inktank.com>
Thu, 30 Oct 2014 17:19:53 +0000 (11:19 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Mon, 3 Nov 2014 20:42:35 +0000 (13:42 -0700)
This should make usage in other labs easier.

Signed-off-by: Zack Cerza <zack@cerza.org>
teuthology/config.py
teuthology/misc.py
teuthology/test/test_misc.py

index 604d19711139397ea53a8a4222ee951b9a76e59d..5626fad4213ee0c962eef2c2aa54a057c8d4b9e6 100644 (file)
@@ -109,6 +109,7 @@ class TeuthologyConfig(YamlConfig):
         'archive_base': '/var/lib/teuthworker/archive',
         'automated_scheduling': False,
         'ceph_git_base_url': 'https://github.com/ceph/',
+        'lab_domain': 'front.sepia.ceph.com',
         'lock_server': 'http://paddles.front.sepia.ceph.com/',
         'max_job_time': 259200,  # 3 days
         'results_server': 'http://paddles.front.sepia.ceph.com/',
index 080e47e381200d82dd08dae4143f71acbfc2596d..ae849da82c5bc253421c46127439947506eb0262 100644 (file)
@@ -36,10 +36,12 @@ 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 = '(?P<user>.*@)?(?P<shortname>.*)\.front\.sepia\.ceph\.com'
+hostname_expr_templ = '(?P<user>.*@)?(?P<shortname>.*)\.{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()
@@ -54,13 +56,17 @@ def canonicalize_hostname(hostname, user='ubuntu'):
 
     user_at = user_.strip('@') + '@' if user_ else ''
 
-    ret = '{user_at}{short}.front.sepia.ceph.com'.format(
+    ret = '{user_at}{short}.{lab_domain}'.format(
         user_at=user_at,
-        short=shortname)
+        short=shortname,
+        lab_domain=config.lab_domain,
+    )
     return ret
 
 
 def decanonicalize_hostname(hostname):
+    hostname_expr = hostname_expr_templ.format(
+        lab_domain=config.lab_domain.replace('.', '\.'))
     match = re.match(hostname_expr, hostname)
     if match:
         hostname = match.groupdict()['shortname']
index e3e8c680d86a7c38a8efd7181d352cb541f2d182..1876c96ba5ea4e07224ea211251cb3d3863ea5ed 100644 (file)
@@ -53,6 +53,11 @@ def test_get_http_log_path():
 
 
 class TestHostnames(object):
+    def setup(self):
+        self.old_lab_domain = config.lab_domain
+
+    def teardown(self):
+        config.lab_domain = self.old_lab_domain
 
     def test_canonicalize_hostname(self):
         host_base = 'box1'
@@ -73,3 +78,15 @@ class TestHostnames(object):
         host = 'box1.front.sepia.ceph.com'
         result = misc.decanonicalize_hostname(host)
         assert result == 'box1'
+
+    def test_canonicalize_hostname_otherlab(self):
+        config.lab_domain = 'example.com'
+        host_base = 'box1'
+        result = misc.canonicalize_hostname(host_base)
+        assert result == 'ubuntu@box1.example.com'
+
+    def test_decanonicalize_hostname(self):
+        config.lab_domain = 'example.com'
+        host = 'ubuntu@box1.example.com'
+        result = misc.decanonicalize_hostname(host)
+        assert result == 'box1'