def output_metrics(alarm_id, expected_state, metrics): print('Generating metrics, waiting for state change to %s' % expected_state) hostnames = ['AA', 'BB', 'CC'] for x in range(0, 90): for metric in metrics: metric_name = metric[0] dimensions = metric[1] args = ['metric-create', '--dimensions'] hostname = hostnames[x % len(hostnames)] args.append(dimensions + ',' + 'hostname=' + hostname) args.append(metric_name) args.append('42') cli_wrapper.run_mon_cli(args, useJson=False) state = cli_wrapper.get_alarm_state(alarm_id) if state == expected_state: break time.sleep(1) if state != expected_state: print('Did not change to state %s instead was %s in %d seconds' % (expected_state, state, x), file=sys.stderr) return False print('Changed to state %s in %d seconds' % (state, x)) return True
def check_alarm_state(alarm_id, expected): state = cli_wrapper.get_alarm_state(alarm_id) if state != expected: print('Wrong initial alarm state, expected %s but is %s' % (expected, state)) return False return True
def check_alarm_state(alarm_id, expected): state = cli_wrapper.get_alarm_state(alarm_id) if state != expected: print('Wrong initial alarm state, expected %s but is %s' % (expected, state)) return False return True
def wait_for_alarm_state_change(alarm_id, old_state): # Wait for it to change state print('Waiting for alarm to change state from {}'.format(old_state)) for x in range(0, 250): time.sleep(1) state = cli_wrapper.get_alarm_state(alarm_id) if state != old_state: print('Alarm state changed to {} in {} seconds'.format(state, x)) return state print('State never changed from {} in {} seconds'.format(old_state, x), file=sys.stderr) return None
def wait_for_alarm_state_change(alarm_id, old_state): # Wait for it to change state print('Waiting for alarm to change state from {}'.format(old_state)) for x in range(0, 250): time.sleep(1) state = cli_wrapper.get_alarm_state(alarm_id) if state != old_state: print('Alarm state changed to {} in {} seconds'.format(state, x)) return state print('State never changed from {} in {} seconds'.format(old_state, x), file=sys.stderr) return None