From 6e41c34c318fd91997e886fdc1a4a2502ba293fc Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 1 Feb 2017 17:36:47 +0100 Subject: [PATCH] tools: make measure injector works without gnocchiclient Change-Id: I838b86ef92a44bb47e059a62ca40457008b96164 --- devstack/gate/post_test_hook.sh | 1 - tools/measures_injector.py | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/devstack/gate/post_test_hook.sh b/devstack/gate/post_test_hook.sh index 9cbb922f..948e60ca 100755 --- a/devstack/gate/post_test_hook.sh +++ b/devstack/gate/post_test_hook.sh @@ -46,7 +46,6 @@ curl -X GET ${GNOCCHI_SERVICE_URL}/v1/archive_policy -H "Content-Type: applicati sudo gnocchi-upgrade # Just ensure tools still works -gnocchi metric create sudo -E -H -u stack $GNOCCHI_DIR/tools/measures_injector.py --metrics 1 --batch-of-measures 2 --measures-per-batch 2 # NOTE(sileht): on swift job permissions are wrong, I don't known why diff --git a/tools/measures_injector.py b/tools/measures_injector.py index 01e6a385..ebaef520 100755 --- a/tools/measures_injector.py +++ b/tools/measures_injector.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import random +import uuid from concurrent import futures from oslo_config import cfg @@ -28,7 +29,9 @@ from gnocchi import utils def injector(): conf = cfg.ConfigOpts() conf.register_cli_opts([ - cfg.IntOpt("metrics"), + cfg.IntOpt("metrics", default=1, min=1), + cfg.StrOpt("archive-policy-name", default="low"), + cfg.StrOpt("creator", default="admin"), cfg.IntOpt("batch-of-measures", default=1000), cfg.IntOpt("measures-per-batch", default=10), ]) @@ -37,11 +40,12 @@ def injector(): index.connect() s = storage.get_driver(conf) - metrics = index.list_metrics() - if conf.metrics: - metrics = metrics[:conf.metrics] + def todo(): + metric = index.create_metric( + uuid.uuid4(), + creator=conf.creator, + archive_policy_name=conf.archive_policy_name) - def todo(metric): for _ in six.moves.range(conf.batch_of_measures): measures = [ storage.Measure( @@ -49,10 +53,9 @@ def injector(): for __ in six.moves.range(conf.measures_per_batch)] s.incoming.add_measures(metric, measures) - with futures.ThreadPoolExecutor(max_workers=len(metrics)) as executor: - # We use 'list' to iterate all threads here to raise the first - # exception now, not much choice - list(executor.map(todo, metrics)) + with futures.ThreadPoolExecutor(max_workers=conf.metrics) as executor: + for m in six.moves.range(conf.metrics): + executor.submit(todo) if __name__ == '__main__':