From d2d6852444ed6a0e7aa5d2017723b5c1256f8138 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Fri, 6 Feb 2015 15:43:34 -0600 Subject: [PATCH] Adds a machine_type property to orchestra.remote.Remote Signed-off-by: Andrew Schoen --- teuthology/lockstatus.py | 5 +++++ teuthology/orchestra/remote.py | 9 +++++++++ teuthology/task/tests/test_locking.py | 6 +----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/teuthology/lockstatus.py b/teuthology/lockstatus.py index 4000b32ce..109b11345 100644 --- a/teuthology/lockstatus.py +++ b/teuthology/lockstatus.py @@ -1,8 +1,11 @@ import requests import os +import logging from .config import config from .misc import canonicalize_hostname +log = logging.getLogger(__name__) + def get_status(name): name = canonicalize_hostname(name, user=None) @@ -11,4 +14,6 @@ def get_status(name): success = response.ok if success: return response.json() + log.warning( + "Failed to query lock server for status of {name}".format(name=name)) return None diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index 15ef022e0..10c5a2f50 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -81,6 +81,15 @@ class Remote(object): self._hostname = proc.stdout.getvalue().strip() return self._hostname + @property + def machine_type(self): + if not getattr(self, '_machine_type', None): + remote_info = ls.get_status(self.hostname) + if not remote_info: + return None + self._machine_type = remote_info.get("machine_type", None) + return self._machine_type + @property def shortname(self): if self._shortname is None: diff --git a/teuthology/task/tests/test_locking.py b/teuthology/task/tests/test_locking.py index aa395e71a..23d7cf172 100644 --- a/teuthology/task/tests/test_locking.py +++ b/teuthology/task/tests/test_locking.py @@ -1,5 +1,4 @@ import pytest -import re class TestLocking(object): @@ -21,7 +20,4 @@ class TestLocking(object): def test_correct_machine_type(self, ctx, config): machine_type = ctx.machine_type for remote in ctx.cluster.remotes.iterkeys(): - # gotta be a better way to get machine_type - # if not, should we move this to Remote? - remote_type = re.sub("[0-9]", "", remote.shortname) - assert remote_type in machine_type + assert remote.machine_type in machine_type -- 2.47.3