|
| 1 | +import pytest |
| 2 | +from lib.update_env import * |
| 3 | +from lib.splunk_api import * |
| 4 | +import string |
| 5 | +import random |
| 6 | +_tag = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) |
| 7 | + |
| 8 | + |
| 9 | +class TestSplunkNozzleLocal(): |
| 10 | + @pytest.fixture(scope='class', autouse=True) |
| 11 | + def setup_class(self, test_env, splunk_logger, nozzle_logger, test_setup): |
| 12 | + update_environment_variables(input_dict={'EVENTS': 'LogMessage', |
| 13 | + 'EXTRA_FIELDS': 'test_tag:{},test2.0:nozzle2.0'.format(_tag), |
| 14 | + 'ENABLE_EVENT_TRACING': False, |
| 15 | + 'ADD_APP_INFO': False} |
| 16 | + ) |
| 17 | + |
| 18 | + path = os.path.join(get_integration_folder(), "scripts") |
| 19 | + env_path = get_project_folder() |
| 20 | + time_interval = 20 |
| 21 | + cmd = "cd {0}; ./start_nozzle.sh {1} {2}".format(path, env_path, time_interval) |
| 22 | + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, |
| 23 | + stderr=subprocess.STDOUT) |
| 24 | + proc.communicate() |
| 25 | + |
| 26 | + @pytest.mark.Critical |
| 27 | + @pytest.mark.parametrize("query_input, is_result_empty", [ |
| 28 | + ("index={0} test_tag::{1} event_type=ValueMetric", True), |
| 29 | + ("index={0} test_tag::{1} event_type=CounterEvent", True), |
| 30 | + ("index={0} test_tag::{1} event_type=LogMessage", False), |
| 31 | + ("index={0} test_tag::{1} event_type=HttpStartStop", True), |
| 32 | + ("index={0} test_tag::{1} event_type=ContainerMetric", True) |
| 33 | + ]) |
| 34 | + def test_search_event_on_splunk_is_not_empty(self, query_input, is_result_empty, test_env, splunk_logger, nozzle_logger): |
| 35 | + self.splunk_api = SplunkApi(test_env, splunk_logger) |
| 36 | + search_results = self.splunk_api.check_events_from_splunk( |
| 37 | + query=query_input.format(test_env['splunk_index'], _tag), |
| 38 | + start_time="-10m@m") |
| 39 | + |
| 40 | + if is_result_empty: |
| 41 | + assert len(search_results) == 0, \ |
| 42 | + '\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results)) |
| 43 | + else: |
| 44 | + assert len(search_results) > 0, \ |
| 45 | + '\nNumber of events from Splunk should not be {}, however the result is {}'\ |
| 46 | + .format(0, len(search_results)) |
| 47 | + |
| 48 | + @pytest.mark.Critical |
| 49 | + @pytest.mark.parametrize("query_input, is_result_empty", [ |
| 50 | + ("index={0} test_tag::{1} test2.0::nozzle2.0", False), |
| 51 | + ("index={0} test_tag::{1} test::nozzle2.0", True), |
| 52 | + ("index={0} test_tag::{1} test2.0::nozzle", True) |
| 53 | + ]) |
| 54 | + def test_search_by_extra_fields(self, query_input, is_result_empty, test_env, splunk_logger): |
| 55 | + self.splunk_api = SplunkApi(test_env, splunk_logger) |
| 56 | + search_results = self.splunk_api.check_events_from_splunk( |
| 57 | + query=query_input.format(test_env['splunk_index'], _tag), |
| 58 | + start_time="-10m@m") |
| 59 | + |
| 60 | + if is_result_empty: |
| 61 | + assert len(search_results) == 0, \ |
| 62 | + '\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results)) |
| 63 | + else: |
| 64 | + assert len(search_results) > 0, \ |
| 65 | + '\nNumber of events from Splunk should not be {}, however the result is {}'\ |
| 66 | + .format(0, len(search_results)) |
| 67 | + |
| 68 | + @pytest.mark.Critical |
| 69 | + @pytest.mark.parametrize("query_input", [ |
| 70 | + "index={0} test_tag::{1} nozzle-event-counter>0", # nozzle-event-counter should not be searchable |
| 71 | + "index={0} test_tag::{1} subscription-id::splunk-ci", # subscription-id should not be searchable |
| 72 | + "index={0} test_tag::{1} uuid::*" # uuid should not be searchable |
| 73 | + ]) |
| 74 | + def test_enable_event_tracing_is_false(self, test_env, query_input, splunk_logger): |
| 75 | + self.splunk_api = SplunkApi(test_env, splunk_logger) |
| 76 | + search_results = self.splunk_api.check_events_from_splunk( |
| 77 | + query=query_input.format(test_env['splunk_index'], _tag), |
| 78 | + start_time="-10m@m") |
| 79 | + |
| 80 | + assert len(search_results) == 0, \ |
| 81 | + '\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results)) |
| 82 | + |
| 83 | + @pytest.mark.Critical |
| 84 | + @pytest.mark.parametrize("query_input", [ |
| 85 | + "index={0} test_tag::{1} cf_space_id=*", # when cf_space_id is false, cf_org_name is not searchable |
| 86 | + "index={0} test_tag::{1} cf_org_id=*", # cf_org_id add_app_info is false, cf_org_name is not searchable |
| 87 | + "index={0} test_tag::{1} cf_org_name=*", # when add_app_info is false, cf_org_name is not searchable |
| 88 | + "index={0} test_tag::{1} cf_space_name=*" # when add_app_info is false, cf_space_name is not searchable |
| 89 | + ]) |
| 90 | + def test_add_app_info_is_false(self, test_env, query_input, splunk_logger): |
| 91 | + self.splunk_api = SplunkApi(test_env, splunk_logger) |
| 92 | + search_results = self.splunk_api.check_events_from_splunk( |
| 93 | + query=query_input.format(test_env['splunk_index'], _tag), |
| 94 | + start_time="-10m@m") |
| 95 | + |
| 96 | + assert len(search_results) == 0, \ |
| 97 | + '\nNumber of events from Splunk should be {}, however the result is {}'.format(0, len(search_results)) |
0 commit comments