-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not print collection messages for compliance apiv2 options (#…
…4319) - RHINENG-14959 - When any compliance apiv2 options are specified, nothing will be collected, hence data collection relevant messages should not be printed to console. The rm_conf which includes the file/content redaction is also cleared for compliance apiv2 for this reason. Signed-off-by: Xiangce Liu <[email protected]> (cherry picked from commit 747e52d) (cherry picked from commit 06d2121)
- Loading branch information
Showing
2 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# -*- coding: UTF-8 -*- | ||
try: | ||
from unittest.mock import patch | ||
except Exception: | ||
from mock import patch | ||
|
||
from insights.client.client import collect | ||
from insights.client.config import InsightsConfig | ||
from insights.client.utilities import determine_hostname | ||
|
||
|
||
def patch_get_branch_info(): | ||
""" | ||
Sets a static response to get_branch_info method. | ||
""" | ||
|
||
def decorator(old_function): | ||
patcher = patch("insights.client.client.get_branch_info") | ||
return patcher(old_function) | ||
|
||
return decorator | ||
|
||
|
||
def patch_get_rm_conf(): | ||
""" | ||
Mocks InsightsUploadConf.get_rm_conf so it returns a fixed configuration. | ||
""" | ||
|
||
def decorator(old_function): | ||
patcher = patch("insights.client.client.InsightsUploadConf.get_rm_conf") | ||
return patcher(old_function) | ||
|
||
return decorator | ||
|
||
|
||
def patch_core_collector(): | ||
""" | ||
Replaces CoreCollector with a dummy mock. | ||
""" | ||
|
||
def decorator(old_function): | ||
patcher = patch("insights.client.client.CoreCollector") | ||
return patcher(old_function) | ||
|
||
return decorator | ||
|
||
|
||
@patch_core_collector() | ||
@patch_get_rm_conf() | ||
@patch_get_branch_info() | ||
@patch('insights.client.client.logger') | ||
def test_log_msgs_general(log, get_branch_info, get_rm_conf, core_collector): | ||
config = InsightsConfig() | ||
collect(config) | ||
get_branch_info.assert_called_once_with(config) | ||
get_rm_conf.assert_called_once_with() | ||
log.info.assert_called_once_with( | ||
'Starting to collect Insights data for %s' % determine_hostname(config.display_name) | ||
) | ||
|
||
|
||
@patch_core_collector() | ||
@patch_get_rm_conf() | ||
@patch_get_branch_info() | ||
@patch('insights.client.client.logger') | ||
def test_log_msgs_compliance(log, get_branch_info, get_rm_conf, core_collector): | ||
config = InsightsConfig(compliance=True) | ||
collect(config) | ||
get_branch_info.assert_called_once_with(config) | ||
get_rm_conf.assert_called_once_with() | ||
log.info.assert_called_once_with( | ||
'Starting to collect Insights data for %s' % determine_hostname(config.display_name) | ||
) | ||
|
||
|
||
@patch_core_collector() | ||
@patch_get_rm_conf() | ||
@patch_get_branch_info() | ||
@patch('insights.client.client.logger') | ||
def test_log_msgs_compliance_policies(log, get_branch_info, get_rm_conf, core_collector): | ||
config = InsightsConfig(compliance_policies=True) | ||
collect(config) | ||
get_branch_info.assert_called_once_with(config) | ||
get_rm_conf.assert_not_called() | ||
log.info.assert_not_called() | ||
|
||
|
||
@patch_core_collector() | ||
@patch_get_rm_conf() | ||
@patch_get_branch_info() | ||
@patch('insights.client.client.logger') | ||
def test_log_msgs_compliance_assign(log, get_branch_info, get_rm_conf, core_collector): | ||
config = InsightsConfig(compliance_assign=['abc']) | ||
collect(config) | ||
get_branch_info.assert_called_once_with(config) | ||
get_rm_conf.assert_not_called() | ||
log.info.assert_not_called() | ||
|
||
|
||
@patch_core_collector() | ||
@patch_get_rm_conf() | ||
@patch_get_branch_info() | ||
@patch('insights.client.client.logger') | ||
def test_log_msgs_compliance_unassign(log, get_branch_info, get_rm_conf, core_collector): | ||
config = InsightsConfig(compliance_unassign=['abc']) | ||
collect(config) | ||
get_branch_info.assert_called_once_with(config) | ||
get_rm_conf.assert_not_called() | ||
log.info.assert_not_called() |