From 4ddb39a72b8c7e8eaa38053172bb538d37892787 Mon Sep 17 00:00:00 2001 From: Ryan Brandt Date: Thu, 7 May 2015 14:04:06 -0600 Subject: [PATCH] Allow unicode in smoke test Allow smoketest to handle unicode and add configuration with unicode strings Change-Id: Ib3183f62502ad719163ff18c539b7b147b98cde5 --- tests/cli_wrapper.py | 5 ++++- tests/smoke.py | 8 +++++--- tests/smoke_configs.py | 10 ++++++---- tests/utils.py | 5 ++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/cli_wrapper.py b/tests/cli_wrapper.py index b49a4dc..a5772ba 100644 --- a/tests/cli_wrapper.py +++ b/tests/cli_wrapper.py @@ -6,6 +6,7 @@ from __future__ import print_function import sys import subprocess import json +import os def find_obj_for_name(object_json, name): @@ -39,8 +40,10 @@ def run_mon_cli(args, useJson=True): if useJson: args.insert(0, '--json') args.insert(0, 'monasca') + env = os.environ.copy() + env['PYTHONIOENCODING'] = "utf-8" try: - stdout = subprocess.check_output(args) + stdout = subprocess.check_output(args, env=env) if useJson: return json.loads(stdout) else: diff --git a/tests/smoke.py b/tests/smoke.py index 6f81e68..14aa4bb 100755 --- a/tests/smoke.py +++ b/tests/smoke.py @@ -285,11 +285,13 @@ def smoke_test(): break if x >= 29: msg = 'No metrics received for statsd metric {}{} in {} seconds'.format( - statsd_metric_name, statsd_metric_dimensions, x) + statsd_metric_name, statsd_metric_dimensions, time.time() - start_time) return False, msg time.sleep(1) - print('Received {0} metrics for {1}{2} in {3} seconds'.format( - final_statsd_num_metrics-initial_statsd_num_metrics, statsd_metric_name, statsd_metric_dimensions, x)) + print('Received {0} metrics for {1}{2} in {3} seconds'.format(final_statsd_num_metrics - initial_statsd_num_metrics, + statsd_metric_name, + statsd_metric_dimensions, + time.time() - start_time)) msg = '' return True, msg diff --git a/tests/smoke_configs.py b/tests/smoke_configs.py index c561000..74f3915 100644 --- a/tests/smoke_configs.py +++ b/tests/smoke_configs.py @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + """configurations for smoke test""" import subprocess @@ -18,18 +20,18 @@ test_config = { 'system_vars': system_vars['default'], 'notification': { - 'name': 'Monasca Smoke Test', + 'name': u'Monasca Smoke Test Ā', 'addr': 'root@'+system_vars['default']['mail_host'], 'type': 'EMAIL'}, 'alarm': { - 'name': 'high cpu and load', + 'name': u'high cpu and load Ա', 'expression': 'max(cpu.system_perc) > 0 and ' + 'max(load.avg_1_min{hostname=' + system_vars['default']['metric_host'] + '}) > 0', - 'description': 'System CPU Utilization exceeds 1% and ' + - 'Load exceeds 3 per measurement period'}, + 'description': u'System CPU Utilization exceeds 1% and ' + + u'Load exceeds 3 per measurement period ἀ'}, 'metric': { 'name': 'load.avg_1_min', diff --git a/tests/utils.py b/tests/utils.py index b2b5ee4..a5f2341 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -135,8 +135,10 @@ def ensure_has_notification_engine(): def find_notifications(alarm_id, user): args = ['sudo', 'cat', '/var/mail/' + user] result = [] + env = os.environ.copy() + env['PYTHONIOENCODING'] = "utf-8" try: - stdout = subprocess.check_output(args) + stdout = subprocess.check_output(args, env=env) except subprocess.CalledProcessError as e: print(e, file=sys.stderr) sys.exit(1) @@ -144,6 +146,7 @@ def find_notifications(alarm_id, user): previous = '' for line in stdout.splitlines(): # Get the state; the alarm_id always follows the state message + line = unicode(line, "utf-8") if alarm_id in line: """ In the notification message the state verb is framed by 'transitioned to the ' and ' state'