Merge "Added mini-mon process checks to Smoke test - corrections from review comments"

This commit is contained in:
Jenkins 2014-10-06 22:29:36 +00:00 committed by Gerrit Code Review
commit f9646f8f7a

View File

@ -30,10 +30,10 @@ import time
import cli_wrapper
import utils
import datetime
import psutil
# export OS_AUTH_TOKEN=82510970543135
# export OS_NO_CLIENT_AUTH=1
# export MONASCA_API_URL=http://192.168.10.4:8080/v2.0/
process_list = ('monasca-persister', 'monasca-notification', 'kafka', 'zookeeper.jar',
'mon-api', 'influxdb', 'apache-storm', 'mysqld')
def get_metrics(name, dimensions, since):
@ -71,12 +71,14 @@ def check_notifications(alarm_id, state_changes):
print('Notification Engine not installed on this VM,' +
' skipping Notifications test',
file=sys.stderr)
return True
notifications = utils.find_notifications(alarm_id, "root")
return False
notifications = utils.find_notifications(alarm_id,"root")
if len(notifications) != len(state_changes):
print('Expected %d notifications but only found %d' %
(len(state_changes), len(notifications)), file=sys.stderr)
return False
index = 0
for expected in state_changes:
actual = notifications[index]
@ -86,6 +88,7 @@ def check_notifications(alarm_id, state_changes):
return False
index = index + 1
print('Received email notifications as expected')
return True
@ -122,15 +125,7 @@ def wait_for_alarm_creation(alarm_definition_id):
return None
def main():
if not utils.ensure_has_notification_engine():
return 1
mail_host = 'localhost'
metric_host = subprocess.check_output(['hostname', '-f']).strip()
utils.setup_cli()
def smoke_test(mail_host, metric_host):
notification_name = 'Monasca Smoke Test'
notification_email_addr = 'root@' + mail_host
alarm_definition_name = 'high cpu and load'
@ -143,16 +138,19 @@ def main():
hour_ago_str = hour_ago.strftime('%Y-%m-%dT%H:%M:%S')
initial_num_metrics = count_metrics(metric_name, metric_dimensions,
hour_ago_str)
if initial_num_metrics is None or initial_num_metrics == 0:
print('No metric %s with dimensions %s received in last hour' %
(metric_name, metric_dimensions), file=sys.stderr)
return 1
return False
start_time = time.time()
# Create Notification through CLI
notification_id = cli_wrapper.create_notification(notification_name,
notification_email_addr)
# Create Alarm through CLI
# Create Alarm through CLI
expression = 'max(cpu.system_perc) > 0 and ' + \
'max(cpu.load_avg_1_min{hostname=' + metric_host + '}) > 0'
description = 'System CPU Utilization exceeds 1% and ' + \
@ -166,23 +164,22 @@ def main():
# Wait for an alarm to be created
alarm_id = wait_for_alarm_creation(alarm_definition_id)
if alarm_id is None:
return 1
return False
# Ensure it is created in the right state
initial_state = 'UNDETERMINED'
if not utils.check_alarm_state(alarm_id, initial_state):
return 1
return False
states = []
states.append(initial_state)
state = wait_for_alarm_state_change(alarm_id, initial_state)
if state is None:
return 1
return False
if state != 'ALARM':
print('Wrong final state, expected ALARM but was %s' % state,
file=sys.stderr)
return 1
return False
states.append(state)
new_state = 'OK'
@ -196,12 +193,12 @@ def main():
state = wait_for_alarm_state_change(alarm_id, new_state)
if state is None:
return 1
return False
if state != final_state:
print('Wrong final state, expected %s but was %s' %
(final_state, state), file=sys.stderr)
return 1
return False
# If the alarm changes state too fast, then there isn't time for the new
# metric to arrive. Unlikely, but it has been seen
@ -213,14 +210,58 @@ def main():
if final_num_metrics <= initial_num_metrics:
print('No new metrics received in %d seconds' % change_time,
file=sys.stderr)
return 1
return False
print('Received %d metrics in %d seconds' %
((final_num_metrics - initial_num_metrics), change_time))
if not utils.check_alarm_history(alarm_id, states):
return 1
return False
# Notifications are only sent out for the changes, so omit the first state
if not check_notifications(alarm_id, states[1:]):
return False
return True
def find_processes():
"""Find_process is meant to validate that all the required processes
are running before starting the smoke test """
process_missing = []
for process in process_list: # process_list is a global defined at top of module
process_found_flag = False
for item in psutil.process_iter():
for cmd in item.cmdline():
if process in cmd:
process_found_flag = True
break
if not process_found_flag:
process_missing.append(process)
if len(process_missing) > 0: # if processes were not found
print ('Process = %s Not Found' % process_missing)
return False
else:
print ('All Mini-Mon Processes Found')
return True
def main():
# May be able to delete this test because the find_process check should validate the notification engine present.
if not utils.ensure_has_notification_engine():
return 1
utils.setup_cli()
mail_host = 'localhost'
metric_host = subprocess.check_output(['hostname', '-f']).strip()
if find_processes():
if not smoke_test(mail_host, metric_host):
return 1
else:
return 1
return 0