From bc5547f43f0ec33be48ade6bb7d1e77e2a8984dd Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Tue, 29 Oct 2019 09:50:59 +0800 Subject: [PATCH 1/4] add an unit test for parsing the "/etc/os-release" of CentOS --- pkg/util/helpers_test.go | 6 ++++++ pkg/util/testdata/os-release-centos | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 pkg/util/testdata/os-release-centos diff --git a/pkg/util/helpers_test.go b/pkg/util/helpers_test.go index 32b3ff5e6..7e7d84d1f 100644 --- a/pkg/util/helpers_test.go +++ b/pkg/util/helpers_test.go @@ -161,6 +161,12 @@ func TestGetOSVersion(t *testing.T) { expectedOSVersion: "ubuntu 16.04.6 LTS (Xenial Xerus)", expectErr: false, }, + { + name: "centos", + fakeOSReleasePath: "testdata/os-release-centos", + expectedOSVersion: "centos 7 (Core)", + expectErr: false, + }, { name: "Unknown", fakeOSReleasePath: "testdata/os-release-unknown", diff --git a/pkg/util/testdata/os-release-centos b/pkg/util/testdata/os-release-centos new file mode 100644 index 000000000..21d782619 --- /dev/null +++ b/pkg/util/testdata/os-release-centos @@ -0,0 +1,15 @@ +NAME="CentOS Linux" +VERSION="7 (Core)" +ID="centos" +ID_LIKE="rhel fedora" +VERSION_ID="7" +PRETTY_NAME="CentOS Linux 7 (Core)" +ANSI_COLOR="0;31" +CPE_NAME="cpe:/o:centos:centos:7" +HOME_URL="https://www.centos.org/" +BUG_REPORT_URL="https://bugs.centos.org/" + +CENTOS_MANTISBT_PROJECT="CentOS-7" +CENTOS_MANTISBT_PROJECT_VERSION="7" +REDHAT_SUPPORT_PRODUCT="centos" +REDHAT_SUPPORT_PRODUCT_VERSION="7" \ No newline at end of file From a7496834bcd08ebc6c1d4a5a7641569f204d6bef Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Tue, 29 Oct 2019 10:02:44 +0800 Subject: [PATCH 2/4] add an unit test for parsing the "/etc/os-release" of CentOS --- pkg/util/testdata/os-release-centos | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/testdata/os-release-centos b/pkg/util/testdata/os-release-centos index 21d782619..c276e3ae5 100644 --- a/pkg/util/testdata/os-release-centos +++ b/pkg/util/testdata/os-release-centos @@ -12,4 +12,4 @@ BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" -REDHAT_SUPPORT_PRODUCT_VERSION="7" \ No newline at end of file +REDHAT_SUPPORT_PRODUCT_VERSION="7" From cd66c63f7ede4c9e7b7362a64361134f40eed4c8 Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Thu, 31 Oct 2019 17:11:15 +0800 Subject: [PATCH 3/4] When the state changes, it may be necessary to output customized messages --- pkg/custompluginmonitor/custom_plugin_monitor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index 8b9bf6d42..9c284b683 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -188,7 +188,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat if condition.Status == types.True && status != types.True { // Scenario 1: Condition status changes from True to False/Unknown newReason = defaultConditionReason - if newMessage == "" { + if result.Message == "" { newMessage = defaultConditionMessage } else { newMessage = result.Message @@ -200,7 +200,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat } else if condition.Status != status { // Scenario 3: Condition status changes from False to Unknown or vice versa newReason = defaultConditionReason - if newMessage == "" { + if result.Message == "" { newMessage = defaultConditionMessage } else { newMessage = result.Message From cf102274f7ae22adc448f81996c6c1fbe0536226 Mon Sep 17 00:00:00 2001 From: tongxin21 Date: Fri, 1 Nov 2019 09:28:57 +0800 Subject: [PATCH 4/4] recovery --- pkg/custompluginmonitor/custom_plugin_monitor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index 9c284b683..8b9bf6d42 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -188,7 +188,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat if condition.Status == types.True && status != types.True { // Scenario 1: Condition status changes from True to False/Unknown newReason = defaultConditionReason - if result.Message == "" { + if newMessage == "" { newMessage = defaultConditionMessage } else { newMessage = result.Message @@ -200,7 +200,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat } else if condition.Status != status { // Scenario 3: Condition status changes from False to Unknown or vice versa newReason = defaultConditionReason - if result.Message == "" { + if newMessage == "" { newMessage = defaultConditionMessage } else { newMessage = result.Message