From b5bc853d667837b5ecff6c4c1a7ee01dd72741be Mon Sep 17 00:00:00 2001 From: Larry Hamel Date: Mon, 1 May 2017 11:14:24 -0700 Subject: [PATCH] gpperfmon: Add behave test for log_alert_history Signed-off-by: Marbin Tan Signed-off-by: C.J. Jameson --- .../test/behave/mgmt_utils/gpperfmon.feature | 10 ++++++++ .../behave/mgmt_utils/steps/mgmt_utils.py | 23 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gpMgmt/test/behave/mgmt_utils/gpperfmon.feature b/gpMgmt/test/behave/mgmt_utils/gpperfmon.feature index 8054508f20..d0bc7b2733 100644 --- a/gpMgmt/test/behave/mgmt_utils/gpperfmon.feature +++ b/gpMgmt/test/behave/mgmt_utils/gpperfmon.feature @@ -63,6 +63,16 @@ Feature: gpperfmon When the user truncates "system_history" tables in "gpperfmon" Then wait until the results from boolean sql "SELECT count(*) > 0 FROM system_history" is "true" + @gpperfmon_log_alert_history + Scenario: gpperfmon adds to log_alert_history table + Given gpperfmon is configured and running in qamode + When the user truncates "log_alert_history" tables in "gpperfmon" + And the user runs "psql non_existing_database" + Then psql should return a return code of 2 + When the latest gpperfmon gpdb-alert log is copied to a file with a fake (earlier) timestamp + Then wait until the results from boolean sql "SELECT count(*) > 0 FROM log_alert_history" is "true" + And the file with the fake timestamp no longer exists + @gpperfmon_segment_history Scenario: gpperfmon adds to segment_history table Given gpperfmon is configured and running in qamode diff --git a/gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py b/gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py index 6c8b452c92..11e9cba35f 100644 --- a/gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py +++ b/gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py @@ -12,7 +12,6 @@ import tarfile import thread import json import csv -import glob import subprocess import commands @@ -4875,3 +4874,25 @@ def impl(context): Then wait until the process "gpmmon" is up And wait until the process "gpsmon" is up ''') + + +@given('the latest gpperfmon gpdb-alert log is copied to a file with a fake (earlier) timestamp') +@when('the latest gpperfmon gpdb-alert log is copied to a file with a fake (earlier) timestamp') +def impl(context): + gpdb_alert_file_path_src = sorted(glob.glob(os.path.join(os.getenv("MASTER_DATA_DIRECTORY"), + "gpperfmon", + "logs", + "gpdb-alert*")))[-1] + # typical filename would be gpdb-alert-2017-04-26_155335.csv + # setting the timestamp to a string that starts with `-` (em-dash) + # will be sorted (based on ascii) before numeric timestamps + # without colliding with a real timestamp + dest = re.sub(r"_\d{6}\.csv$", "_-takeme.csv", gpdb_alert_file_path_src) + shutil.copy(gpdb_alert_file_path_src, dest) + context.fake_timestamp_file = dest + + +@then('the file with the fake timestamp no longer exists') +def impl(context): + if os.path.exists(context.fake_timestamp_file): + raise Exception("expected no file at: %s" % context.fake_timestamp_file) -- GitLab