Merge "Added mini-mon process checks to Smoke test - corrections from review comments"
This commit is contained in:
commit
f9646f8f7a
@ -30,10 +30,10 @@ import time
|
|||||||
import cli_wrapper
|
import cli_wrapper
|
||||||
import utils
|
import utils
|
||||||
import datetime
|
import datetime
|
||||||
|
import psutil
|
||||||
|
|
||||||
# export OS_AUTH_TOKEN=82510970543135
|
process_list = ('monasca-persister', 'monasca-notification', 'kafka', 'zookeeper.jar',
|
||||||
# export OS_NO_CLIENT_AUTH=1
|
'mon-api', 'influxdb', 'apache-storm', 'mysqld')
|
||||||
# export MONASCA_API_URL=http://192.168.10.4:8080/v2.0/
|
|
||||||
|
|
||||||
|
|
||||||
def get_metrics(name, dimensions, since):
|
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,' +
|
print('Notification Engine not installed on this VM,' +
|
||||||
' skipping Notifications test',
|
' skipping Notifications test',
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return True
|
return False
|
||||||
notifications = utils.find_notifications(alarm_id, "root")
|
|
||||||
|
notifications = utils.find_notifications(alarm_id,"root")
|
||||||
if len(notifications) != len(state_changes):
|
if len(notifications) != len(state_changes):
|
||||||
print('Expected %d notifications but only found %d' %
|
print('Expected %d notifications but only found %d' %
|
||||||
(len(state_changes), len(notifications)), file=sys.stderr)
|
(len(state_changes), len(notifications)), file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
for expected in state_changes:
|
for expected in state_changes:
|
||||||
actual = notifications[index]
|
actual = notifications[index]
|
||||||
@ -86,6 +88,7 @@ def check_notifications(alarm_id, state_changes):
|
|||||||
return False
|
return False
|
||||||
index = index + 1
|
index = index + 1
|
||||||
print('Received email notifications as expected')
|
print('Received email notifications as expected')
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -122,15 +125,7 @@ def wait_for_alarm_creation(alarm_definition_id):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def smoke_test(mail_host, metric_host):
|
||||||
if not utils.ensure_has_notification_engine():
|
|
||||||
return 1
|
|
||||||
|
|
||||||
mail_host = 'localhost'
|
|
||||||
metric_host = subprocess.check_output(['hostname', '-f']).strip()
|
|
||||||
|
|
||||||
utils.setup_cli()
|
|
||||||
|
|
||||||
notification_name = 'Monasca Smoke Test'
|
notification_name = 'Monasca Smoke Test'
|
||||||
notification_email_addr = 'root@' + mail_host
|
notification_email_addr = 'root@' + mail_host
|
||||||
alarm_definition_name = 'high cpu and load'
|
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')
|
hour_ago_str = hour_ago.strftime('%Y-%m-%dT%H:%M:%S')
|
||||||
initial_num_metrics = count_metrics(metric_name, metric_dimensions,
|
initial_num_metrics = count_metrics(metric_name, metric_dimensions,
|
||||||
hour_ago_str)
|
hour_ago_str)
|
||||||
|
|
||||||
if initial_num_metrics is None or initial_num_metrics == 0:
|
if initial_num_metrics is None or initial_num_metrics == 0:
|
||||||
print('No metric %s with dimensions %s received in last hour' %
|
print('No metric %s with dimensions %s received in last hour' %
|
||||||
(metric_name, metric_dimensions), file=sys.stderr)
|
(metric_name, metric_dimensions), file=sys.stderr)
|
||||||
return 1
|
return False
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
# Create Notification through CLI
|
# Create Notification through CLI
|
||||||
notification_id = cli_wrapper.create_notification(notification_name,
|
notification_id = cli_wrapper.create_notification(notification_name,
|
||||||
notification_email_addr)
|
notification_email_addr)
|
||||||
# Create Alarm through CLI
|
|
||||||
|
# Create Alarm through CLI
|
||||||
expression = 'max(cpu.system_perc) > 0 and ' + \
|
expression = 'max(cpu.system_perc) > 0 and ' + \
|
||||||
'max(cpu.load_avg_1_min{hostname=' + metric_host + '}) > 0'
|
'max(cpu.load_avg_1_min{hostname=' + metric_host + '}) > 0'
|
||||||
description = 'System CPU Utilization exceeds 1% and ' + \
|
description = 'System CPU Utilization exceeds 1% and ' + \
|
||||||
@ -166,23 +164,22 @@ def main():
|
|||||||
# Wait for an alarm to be created
|
# Wait for an alarm to be created
|
||||||
alarm_id = wait_for_alarm_creation(alarm_definition_id)
|
alarm_id = wait_for_alarm_creation(alarm_definition_id)
|
||||||
if alarm_id is None:
|
if alarm_id is None:
|
||||||
return 1
|
return False
|
||||||
|
|
||||||
# Ensure it is created in the right state
|
# Ensure it is created in the right state
|
||||||
initial_state = 'UNDETERMINED'
|
initial_state = 'UNDETERMINED'
|
||||||
if not utils.check_alarm_state(alarm_id, initial_state):
|
if not utils.check_alarm_state(alarm_id, initial_state):
|
||||||
return 1
|
return False
|
||||||
states = []
|
states = []
|
||||||
states.append(initial_state)
|
states.append(initial_state)
|
||||||
|
|
||||||
state = wait_for_alarm_state_change(alarm_id, initial_state)
|
state = wait_for_alarm_state_change(alarm_id, initial_state)
|
||||||
if state is None:
|
if state is None:
|
||||||
return 1
|
return False
|
||||||
|
|
||||||
if state != 'ALARM':
|
if state != 'ALARM':
|
||||||
print('Wrong final state, expected ALARM but was %s' % state,
|
print('Wrong final state, expected ALARM but was %s' % state,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return 1
|
return False
|
||||||
states.append(state)
|
states.append(state)
|
||||||
|
|
||||||
new_state = 'OK'
|
new_state = 'OK'
|
||||||
@ -196,12 +193,12 @@ def main():
|
|||||||
|
|
||||||
state = wait_for_alarm_state_change(alarm_id, new_state)
|
state = wait_for_alarm_state_change(alarm_id, new_state)
|
||||||
if state is None:
|
if state is None:
|
||||||
return 1
|
return False
|
||||||
|
|
||||||
if state != final_state:
|
if state != final_state:
|
||||||
print('Wrong final state, expected %s but was %s' %
|
print('Wrong final state, expected %s but was %s' %
|
||||||
(final_state, state), file=sys.stderr)
|
(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
|
# If the alarm changes state too fast, then there isn't time for the new
|
||||||
# metric to arrive. Unlikely, but it has been seen
|
# metric to arrive. Unlikely, but it has been seen
|
||||||
@ -213,14 +210,58 @@ def main():
|
|||||||
if final_num_metrics <= initial_num_metrics:
|
if final_num_metrics <= initial_num_metrics:
|
||||||
print('No new metrics received in %d seconds' % change_time,
|
print('No new metrics received in %d seconds' % change_time,
|
||||||
file=sys.stderr)
|
file=sys.stderr)
|
||||||
return 1
|
return False
|
||||||
print('Received %d metrics in %d seconds' %
|
print('Received %d metrics in %d seconds' %
|
||||||
((final_num_metrics - initial_num_metrics), change_time))
|
((final_num_metrics - initial_num_metrics), change_time))
|
||||||
if not utils.check_alarm_history(alarm_id, states):
|
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
|
# Notifications are only sent out for the changes, so omit the first state
|
||||||
if not check_notifications(alarm_id, states[1:]):
|
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 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user