log = logging.getLogger(__name__)
+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
+
+
+def decanonicalize_hostname(hostname):
+ match = re.match(hostname_expr, hostname)
+ if match:
+ hostname = match.groupdict()['shortname']
+ return hostname
+
def lock_many(ctx, num, machinetype, user=None, description=None):
machinetypes = misc.get_multi_machine_types(machinetype)
return True
-def canonicalize_hostname(s):
- if re.match('ubuntu@.*\.front\.sepia\.ceph\.com', s) is None:
- s = 'ubuntu@' + s + '.front.sepia.ceph.com'
- return s
-
-
def main(ctx):
if ctx.verbose:
teuthology.log.setLevel(logging.DEBUG)
print "{cnt:12d} {up:3d}".format(cnt=total_count, up=total_up)
-def decanonicalize_hostname(s):
- if re.match('ubuntu@.*\.front\.sepia\.ceph\.com', s):
- s = s[len('ubuntu@'): -len('.front.sepia.ceph.com')]
- return s
-
-
def _get_downburst_exec():
"""
First check for downburst in the user's path.
host = 'ubuntu@box1.front.sepia.ceph.com'
result = lock.decanonicalize_hostname(host)
assert result == 'box1'
+
+ def test_canonicalize_hostname_nouser(self):
+ host_base = 'box1'
+ result = lock.canonicalize_hostname(host_base, user=None)
+ assert result == 'box1.front.sepia.ceph.com'
+
+ def test_decanonicalize_hostname_nouser(self):
+ host = 'box1.front.sepia.ceph.com'
+ result = lock.decanonicalize_hostname(host)
+ assert result == 'box1'