From: Zack Cerza Date: Thu, 30 Oct 2014 17:19:53 +0000 (-0600) Subject: Abstract the lab domain (e.g. front.sepia.ceph.com) X-Git-Tag: 1.1.0~1088 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a087c6c3b3d8dea1cf33d87778aec7d7cd070757;p=teuthology.git Abstract the lab domain (e.g. front.sepia.ceph.com) This should make usage in other labs easier. Signed-off-by: Zack Cerza --- diff --git a/teuthology/config.py b/teuthology/config.py index 604d19711..5626fad42 100644 --- a/teuthology/config.py +++ b/teuthology/config.py @@ -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/', diff --git a/teuthology/misc.py b/teuthology/misc.py index 080e47e38..ae849da82 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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.*@)?(?P.*)\.front\.sepia\.ceph\.com' +hostname_expr_templ = '(?P.*@)?(?P.*)\.{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'] diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index e3e8c680d..1876c96ba 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -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'