Allow unicode in smoke test
Allow smoketest to handle unicode and add configuration with unicode strings Change-Id: Ib3183f62502ad719163ff18c539b7b147b98cde5
This commit is contained in:
parent
6b267c0040
commit
4ddb39a72b
@ -6,6 +6,7 @@ from __future__ import print_function
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def find_obj_for_name(object_json, name):
|
def find_obj_for_name(object_json, name):
|
||||||
@ -39,8 +40,10 @@ def run_mon_cli(args, useJson=True):
|
|||||||
if useJson:
|
if useJson:
|
||||||
args.insert(0, '--json')
|
args.insert(0, '--json')
|
||||||
args.insert(0, 'monasca')
|
args.insert(0, 'monasca')
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['PYTHONIOENCODING'] = "utf-8"
|
||||||
try:
|
try:
|
||||||
stdout = subprocess.check_output(args)
|
stdout = subprocess.check_output(args, env=env)
|
||||||
if useJson:
|
if useJson:
|
||||||
return json.loads(stdout)
|
return json.loads(stdout)
|
||||||
else:
|
else:
|
||||||
|
@ -285,11 +285,13 @@ def smoke_test():
|
|||||||
break
|
break
|
||||||
if x >= 29:
|
if x >= 29:
|
||||||
msg = 'No metrics received for statsd metric {}{} in {} seconds'.format(
|
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
|
return False, msg
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print('Received {0} metrics for {1}{2} in {3} seconds'.format(
|
print('Received {0} metrics for {1}{2} in {3} seconds'.format(final_statsd_num_metrics - initial_statsd_num_metrics,
|
||||||
final_statsd_num_metrics-initial_statsd_num_metrics, statsd_metric_name, statsd_metric_dimensions, x))
|
statsd_metric_name,
|
||||||
|
statsd_metric_dimensions,
|
||||||
|
time.time() - start_time))
|
||||||
|
|
||||||
msg = ''
|
msg = ''
|
||||||
return True, msg
|
return True, msg
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
"""configurations for smoke test"""
|
"""configurations for smoke test"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -18,18 +20,18 @@ test_config = {
|
|||||||
'system_vars': system_vars['default'],
|
'system_vars': system_vars['default'],
|
||||||
|
|
||||||
'notification': {
|
'notification': {
|
||||||
'name': 'Monasca Smoke Test',
|
'name': u'Monasca Smoke Test Ā',
|
||||||
'addr': 'root@'+system_vars['default']['mail_host'],
|
'addr': 'root@'+system_vars['default']['mail_host'],
|
||||||
'type': 'EMAIL'},
|
'type': 'EMAIL'},
|
||||||
|
|
||||||
'alarm': {
|
'alarm': {
|
||||||
'name': 'high cpu and load',
|
'name': u'high cpu and load Ա',
|
||||||
'expression': 'max(cpu.system_perc) > 0 and ' +
|
'expression': 'max(cpu.system_perc) > 0 and ' +
|
||||||
'max(load.avg_1_min{hostname=' +
|
'max(load.avg_1_min{hostname=' +
|
||||||
system_vars['default']['metric_host'] +
|
system_vars['default']['metric_host'] +
|
||||||
'}) > 0',
|
'}) > 0',
|
||||||
'description': 'System CPU Utilization exceeds 1% and ' +
|
'description': u'System CPU Utilization exceeds 1% and ' +
|
||||||
'Load exceeds 3 per measurement period'},
|
u'Load exceeds 3 per measurement period ἀ'},
|
||||||
|
|
||||||
'metric': {
|
'metric': {
|
||||||
'name': 'load.avg_1_min',
|
'name': 'load.avg_1_min',
|
||||||
|
@ -135,8 +135,10 @@ def ensure_has_notification_engine():
|
|||||||
def find_notifications(alarm_id, user):
|
def find_notifications(alarm_id, user):
|
||||||
args = ['sudo', 'cat', '/var/mail/' + user]
|
args = ['sudo', 'cat', '/var/mail/' + user]
|
||||||
result = []
|
result = []
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['PYTHONIOENCODING'] = "utf-8"
|
||||||
try:
|
try:
|
||||||
stdout = subprocess.check_output(args)
|
stdout = subprocess.check_output(args, env=env)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -144,6 +146,7 @@ def find_notifications(alarm_id, user):
|
|||||||
previous = ''
|
previous = ''
|
||||||
for line in stdout.splitlines():
|
for line in stdout.splitlines():
|
||||||
# Get the state; the alarm_id always follows the state message
|
# Get the state; the alarm_id always follows the state message
|
||||||
|
line = unicode(line, "utf-8")
|
||||||
if alarm_id in line:
|
if alarm_id in line:
|
||||||
""" In the notification message the state verb is framed by
|
""" In the notification message the state verb is framed by
|
||||||
'transitioned to the ' and ' state'
|
'transitioned to the ' and ' state'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user