Allow unicode in smoke test

Allow smoketest to handle unicode and add configuration with unicode strings

Change-Id: Ib3183f62502ad719163ff18c539b7b147b98cde5
This commit is contained in:
Ryan Brandt 2015-05-07 14:04:06 -06:00
parent 6b267c0040
commit 4ddb39a72b
4 changed files with 19 additions and 9 deletions

View File

@ -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:

View File

@ -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

View File

@ -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',

View File

@ -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'