diff options
-rw-r--r-- | api/resources/v1/env.py | 2 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | yardstick/benchmark/core/task.py | 68 | ||||
-rw-r--r-- | yardstick/common/httpClient.py | 24 |
4 files changed, 53 insertions, 43 deletions
diff --git a/api/resources/v1/env.py b/api/resources/v1/env.py index 47ea91643..04cc659c7 100644 --- a/api/resources/v1/env.py +++ b/api/resources/v1/env.py @@ -123,7 +123,7 @@ class V1Env(ApiResource): "isDefault": True, } try: - HttpClient().post(url, data) + HttpClient().post(url, data, timeout=10) except Exception: LOG.exception('Create datasources failed') raise diff --git a/requirements.txt b/requirements.txt index d5d079386..a16fce3ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ Jinja2==2.8.1 # BSD; OSI Approved BSD License MarkupSafe==0.23 # BSD; OSI Approved BSD License PyYAML==3.12 # MIT; OSI Approved MIT License SQLAlchemy==1.1.4 # MIT License; OSI Approved MIT License -ansible==2.2.2.0 # GPLv3; OSI Approved GNU General Public License v3 or later (GPLv3+) +ansible==2.3.2 # GPLv3; OSI Approved GNU General Public License v3 or later (GPLv3+) appdirs==1.4.3 # MIT; OSI Approved MIT License backport-ipaddress==0.1; python_version <= "2.7" # OSI Approved Python Software Foundation License chainmap==1.0.2 # Python Software Foundation License; OSI Approved Python Software Foundation License diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index 75703cf50..0b6e3230b 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -325,23 +325,30 @@ class Task(object): # pragma: no cover # TODO support get multi hosts/vms info context_cfg = {} - if "host" in scenario_cfg: - context_cfg['host'] = Context.get_server(scenario_cfg["host"]) + server_name = scenario_cfg.get('options', {}).get('server_name', {}) - if "target" in scenario_cfg: - if is_ip_addr(scenario_cfg["target"]): - context_cfg['target'] = {} - context_cfg['target']["ipaddr"] = scenario_cfg["target"] + def config_context_target(cfg): + target = cfg['target'] + if is_ip_addr(target): + context_cfg['target'] = {"ipaddr": target} else: - context_cfg['target'] = Context.get_server( - scenario_cfg["target"]) - if self._is_same_heat_context(scenario_cfg["host"], - scenario_cfg["target"]): - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["private_ip"] + context_cfg['target'] = Context.get_server(target) + if self._is_same_heat_context(cfg["host"], target): + context_cfg['target']["ipaddr"] = context_cfg['target']["private_ip"] else: - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["ip"] + context_cfg['target']["ipaddr"] = context_cfg['target']["ip"] + + host_name = server_name.get('host', scenario_cfg.get('host')) + if host_name: + context_cfg['host'] = Context.get_server(host_name) + + for item in [server_name, scenario_cfg]: + try: + config_context_target(item) + except KeyError: + pass + else: + break if "targets" in scenario_cfg: ip_list = [] @@ -669,25 +676,24 @@ def parse_task_args(src_name, args): def change_server_name(scenario, suffix): - try: - host = scenario['host'] - except KeyError: - pass - else: - try: - host['name'] += suffix - except TypeError: - scenario['host'] += suffix - try: - target = scenario['target'] - except KeyError: - pass - else: + def add_suffix(cfg, key): try: - target['name'] += suffix - except TypeError: - scenario['target'] += suffix + value = cfg[key] + except KeyError: + pass + else: + try: + value['name'] += suffix + except TypeError: + cfg[key] += suffix + + server_name = scenario.get('options', {}).get('server_name', {}) + + add_suffix(scenario, 'host') + add_suffix(scenario, 'target') + add_suffix(server_name, 'host') + add_suffix(server_name, 'target') try: key = 'targets' diff --git a/yardstick/common/httpClient.py b/yardstick/common/httpClient.py index 11c2d752d..54f7be670 100644 --- a/yardstick/common/httpClient.py +++ b/yardstick/common/httpClient.py @@ -9,6 +9,7 @@ from __future__ import absolute_import import logging +import time from oslo_serialization import jsonutils import requests @@ -18,18 +19,21 @@ logger = logging.getLogger(__name__) class HttpClient(object): - def post(self, url, data): + def post(self, url, data, timeout=0): data = jsonutils.dump_as_bytes(data) headers = {'Content-Type': 'application/json'} - try: - response = requests.post(url, data=data, headers=headers) - result = response.json() - logger.debug('The result is: %s', result) - - return result - except Exception as e: - logger.debug('Failed: %s', e) - raise + t_end = time.time() + timeout + while True: + try: + response = requests.post(url, data=data, headers=headers) + result = response.json() + logger.debug('The result is: %s', result) + return result + except Exception: + if time.time() > t_end: + logger.exception('') + raise + time.sleep(1) def get(self, url): response = requests.get(url) |