From ac98e6cb1240cafa9c1d32d213ab6e6d7c0198eb Mon Sep 17 00:00:00 2001 From: Eva Balycheva Date: Sat, 28 Nov 2015 07:42:09 +0300 Subject: [PATCH] Fix zaqar-bench not working Currently zaqar-bench do not work with up-to-date Zaqar and python-zaqarclient. This happened because Zaqar server moved to version 1.1 and python-zaqarclient did not. And also because python-zaqarclient has changed it's default authentication backend to "keystone". This patch makes zaqar-bench instantiate each python-zaqarclient's Client object with Zaqar API version, "X-PROJECT-ID" and 'noauth' backend specified. Also to avoid huge code duplication it adds "helpers.py" file which provides a convenient method to get a new Client object. Change-Id: If0d905d3d373d145d5c46738d33685c47fe6d425 Closes-Bug: 1518815 --- zaqar/bench/conductor.py | 5 ++--- zaqar/bench/consumer.py | 4 ++-- zaqar/bench/helpers.py | 31 +++++++++++++++++++++++++++++++ zaqar/bench/observer.py | 4 ++-- zaqar/bench/producer.py | 4 ++-- 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 zaqar/bench/helpers.py diff --git a/zaqar/bench/conductor.py b/zaqar/bench/conductor.py index bfba5bec6..274c6b10c 100644 --- a/zaqar/bench/conductor.py +++ b/zaqar/bench/conductor.py @@ -17,10 +17,9 @@ from __future__ import print_function import json import multiprocessing as mp -from zaqarclient.queues import client - from zaqar.bench import config from zaqar.bench import consumer +from zaqar.bench import helpers from zaqar.bench import observer from zaqar.bench import producer @@ -39,7 +38,7 @@ def _print_verbose_stats(name, stats): def _reset_queues(): - cli = client.Client(CONF.server_url, 1.1) + cli = helpers.get_new_client() for i in range(CONF.num_queues): # TODO(kgriffs): DRY up name generation so it is done diff --git a/zaqar/bench/consumer.py b/zaqar/bench/consumer.py index 6e0162af3..bd2bb18a0 100644 --- a/zaqar/bench/consumer.py +++ b/zaqar/bench/consumer.py @@ -24,10 +24,10 @@ from gevent import monkey as curious_george curious_george.patch_all(thread=False, select=False) import gevent import marktime -from zaqarclient.queues import client from zaqarclient.transport import errors from zaqar.bench import config +from zaqar.bench import helpers CONF = config.conf @@ -95,7 +95,7 @@ def claim_delete(queues, stats, test_duration, ttl, grace, limit): def load_generator(stats, num_workers, num_queues, test_duration, url, ttl, grace, limit): - cli = client.Client(CONF.server_url) + cli = helpers.get_new_client() queues = [cli.queue(CONF.queue_prefix + '-' + str(i)) for i in range(num_queues)] diff --git a/zaqar/bench/helpers.py b/zaqar/bench/helpers.py new file mode 100644 index 000000000..a31499c23 --- /dev/null +++ b/zaqar/bench/helpers.py @@ -0,0 +1,31 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from zaqarclient.queues import client + +from zaqar.bench import config + +CONF = config.conf + +client_conf = { + 'auth_opts': { + 'backend': 'noauth', + 'options': { + 'os_project_id': 'my-lovely-benchmark', + }, + }, +} + + +def get_new_client(): + return client.Client(CONF.server_url, 1.1, conf=client_conf) diff --git a/zaqar/bench/observer.py b/zaqar/bench/observer.py index 44f595517..9a2e5f4e4 100644 --- a/zaqar/bench/observer.py +++ b/zaqar/bench/observer.py @@ -25,10 +25,10 @@ curious_george.patch_all(thread=False, select=False) import gevent import marktime from six.moves import urllib -from zaqarclient.queues import client from zaqarclient.transport import errors from zaqar.bench import config +from zaqar.bench import helpers CONF = config.conf @@ -99,7 +99,7 @@ def observer(queues, stats, test_duration, limit): def load_generator(stats, num_workers, num_queues, test_duration, limit): - cli = client.Client(CONF.server_url) + cli = helpers.get_new_client() queues = [cli.queue(CONF.queue_prefix + '-' + str(i)) for i in range(num_queues)] diff --git a/zaqar/bench/producer.py b/zaqar/bench/producer.py index 9c12e9bd3..8bcb94224 100644 --- a/zaqar/bench/producer.py +++ b/zaqar/bench/producer.py @@ -25,10 +25,10 @@ from gevent import monkey as curious_george curious_george.patch_all(thread=False, select=False) import gevent import marktime -from zaqarclient.queues import client from zaqarclient.transport import errors from zaqar.bench import config +from zaqar.bench import helpers CONF = config.conf @@ -104,7 +104,7 @@ def producer(queues, message_pool, stats, test_duration): # weight them, so can have some busy queues, some not.) def load_generator(stats, num_workers, num_queues, test_duration): - cli = client.Client(CONF.server_url) + cli = helpers.get_new_client() queues = [cli.queue(CONF.queue_prefix + '-' + str(i)) for i in range(num_queues)]