Skip to content

Commit a5e44b7

Browse files
artemrysArtem Rys
authored andcommitted
chore: pre-commit autoupdate
1 parent 559c288 commit a5e44b7

File tree

7 files changed

+117
-57
lines changed

7 files changed

+117
-57
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ repos:
1919
hooks:
2020
- id: check-merge-conflict
2121
- repo: https://github.com/psf/black
22-
rev: 21.7b0
22+
rev: 21.8b0
2323
hooks:
2424
- id: black

pytest_splunk_addon/standard_lib/event_ingestors/ingestor_helper.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ def get_consolidated_events(cls, events):
4343
ingestor_dict = dict()
4444
for event in events:
4545
input_type = event.metadata.get("input_type")
46-
if input_type in ["modinput", "windows_input", "syslog_tcp", "syslog_udp", "uf_file_monitor"]:
46+
if input_type in [
47+
"modinput",
48+
"windows_input",
49+
"syslog_tcp",
50+
"syslog_udp",
51+
"uf_file_monitor",
52+
]:
4753
event.event = event.event.encode("utf-8").decode()
4854
else:
4955
event.event = event.event.encode("utf-8")
@@ -86,10 +92,15 @@ def ingest_events(
8692
if run_requirement_test != "None":
8793
requirement_events = RequirementEventIngestor(run_requirement_test)
8894
requirement_events_get = requirement_events.get_events()
89-
requirement_events_dict = cls.get_consolidated_events(requirement_events_get)
95+
requirement_events_dict = cls.get_consolidated_events(
96+
requirement_events_get
97+
)
9098
for input_type, events in requirement_events_dict.items():
9199
LOGGER.debug(
92-
"Received the following input type for HEC event: {}".format(input_type))
100+
"Received the following input type for HEC event: {}".format(
101+
input_type
102+
)
103+
)
93104
event_ingestor = cls.get_event_ingestor(input_type, ingest_meta_data)
94105
event_ingestor.ingest(events, thread_count)
95106
LOGGER.info("Ingestion Done")

pytest_splunk_addon/standard_lib/event_ingestors/requirement_event_ingester.py

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ def get_models(self, root):
7373
model_list.append(str(model.text))
7474
return model_list
7575

76-
#extract_params_transport
76+
# extract_params_transport
7777
def extract_params(self, event):
7878
host, source, source_type = "", "", ""
79-
for transport in event.iter('transport'):
80-
if transport.get('host'):
81-
host = transport.get('host')
82-
if transport.get('source'):
83-
source = transport.get('source')
84-
if transport.get('sourcetype'):
85-
source_type = transport.get('sourcetype')
79+
for transport in event.iter("transport"):
80+
if transport.get("host"):
81+
host = transport.get("host")
82+
if transport.get("source"):
83+
source = transport.get("source")
84+
if transport.get("sourcetype"):
85+
source_type = transport.get("sourcetype")
8686
return host, source, source_type
8787

8888
def get_events(self):
8989
req_file_path = self.requirement_file_path
9090
events = []
91-
host, source, sourcetype = "", "",""
91+
host, source, sourcetype = "", "", ""
9292
if os.path.isdir(req_file_path):
9393
for file1 in os.listdir(req_file_path):
9494
filename = os.path.join(req_file_path, file1)
@@ -101,28 +101,53 @@ def get_events(self):
101101
transport_type = self.extract_transport_tag(event_tag)
102102
if transport_type == "syslog":
103103
transport_type = "syslog_tcp"
104-
LOGGER.info("sending data using sc4s {}".format(filename))
105-
elif transport_type in ("modinput","Modinput", "Mod input","Modular Input", "Modular input", "modular input","modular_input", "Mod Input","hec_event"):
104+
LOGGER.info(
105+
"sending data using sc4s {}".format(filename)
106+
)
107+
elif transport_type in (
108+
"modinput",
109+
"Modinput",
110+
"Mod input",
111+
"Modular Input",
112+
"Modular input",
113+
"modular input",
114+
"modular_input",
115+
"Mod Input",
116+
"hec_event",
117+
):
106118
transport_type = "modinput"
107-
LOGGER.info("sending data via HEC {}".format(filename))
108-
host, source, sourcetype = self.extract_params(event_tag)
109-
LOGGER.info(f"sending data via HEC {host}, {source} {sourcetype}")
119+
LOGGER.info(
120+
"sending data via HEC {}".format(filename)
121+
)
122+
host, source, sourcetype = self.extract_params(
123+
event_tag
124+
)
125+
LOGGER.info(
126+
f"sending data via HEC {host}, {source} {sourcetype}"
127+
)
110128
elif transport_type == "dbx":
111129
transport_type = "modinput"
112130
elif transport_type == "windows_input":
113131
transport_type = "windows_input"
114132
else:
115133
transport_type = "default"
116134
unescaped_event = self.extract_raw_events(event_tag)
117-
escaped_ingest = self.escape_before_ingest(unescaped_event)
118-
metadata = {'input_type': transport_type,
119-
'index': 'main',
120-
"source": source,
121-
"host": host,
122-
"sourcetype": sourcetype,
123-
"timestamp_type": "event",
124-
}
125-
events.append(SampleEvent(escaped_ingest, metadata, "requirement_test"))
135+
escaped_ingest = self.escape_before_ingest(
136+
unescaped_event
137+
)
138+
metadata = {
139+
"input_type": transport_type,
140+
"index": "main",
141+
"source": source,
142+
"host": host,
143+
"sourcetype": sourcetype,
144+
"timestamp_type": "event",
145+
}
146+
events.append(
147+
SampleEvent(
148+
escaped_ingest, metadata, "requirement_test"
149+
)
150+
)
126151

127152
else:
128153
# if there is no model in event do not ingest that event

pytest_splunk_addon/standard_lib/requirement_tests/test_generator.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,28 @@ def generate_cim_req_params(self):
118118
stripped_event = self.strip_syslog_header(unescaped_event)
119119
unescaped_event = stripped_event
120120
if stripped_event is None:
121-
LOGGER.error("Syslog event do not match CEF, RFC_3164, RFC_5424 format")
121+
LOGGER.error(
122+
"Syslog event do not match CEF, RFC_3164, RFC_5424 format"
123+
)
122124
continue
123-
elif transport_type in ("modinput","Modinput", "Mod input","Modular Input", "Modular input", "modular input","modular_input", "Mod Input", "dbx", "windows_input","hec_event"):
125+
elif transport_type in (
126+
"modinput",
127+
"Modinput",
128+
"Mod input",
129+
"Modular Input",
130+
"Modular input",
131+
"modular input",
132+
"modular_input",
133+
"Mod Input",
134+
"dbx",
135+
"windows_input",
136+
"hec_event",
137+
):
124138
host, source, sourcetype = self.extract_params(event_tag)
125139
modinput_params = {
126140
"host": host,
127141
"source": source,
128-
"sourcetype": sourcetype
142+
"sourcetype": sourcetype,
129143
}
130144
else:
131145
# todo: non syslog/modinput events are skipped currently until we support it
@@ -152,7 +166,7 @@ def generate_cim_req_params(self):
152166
"model_list": list_model_dataset_subdataset,
153167
"escaped_event": escaped_event,
154168
"Key_value_dict": key_value_dict,
155-
"modinput_params": modinput_params,
169+
"modinput_params": modinput_params,
156170
"transport_type": transport_type,
157171
},
158172
id=f"{model_list}::{filename}::event_no::{event_no}::req_test_id::{req_test_id}",
@@ -220,13 +234,13 @@ def check_xml_format(self, file_name):
220234

221235
def extract_params(self, event):
222236
host, source, source_type = "", "", ""
223-
for transport in event.iter('transport'):
224-
if transport.get('host'):
225-
host = transport.get('host')
226-
if transport.get('source'):
227-
source = transport.get('source')
228-
if transport.get('sourcetype'):
229-
source_type = transport.get('sourcetype')
237+
for transport in event.iter("transport"):
238+
if transport.get("host"):
239+
host = transport.get("host")
240+
if transport.get("source"):
241+
source = transport.get("source")
242+
if transport.get("sourcetype"):
243+
source_type = transport.get("sourcetype")
230244
return host, source, source_type
231245

232246
def escape_char_event(self, event):
@@ -273,6 +287,6 @@ def escape_char_event(self, event):
273287
]
274288
event = event.replace("\\", "\\\\")
275289
for character in escape_splunk_chars:
276-
event = event.replace(character, '\\' + character)
290+
event = event.replace(character, "\\" + character)
277291
event = event.replace("*", " ")
278292
return event

pytest_splunk_addon/standard_lib/requirement_tests/test_templates.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,12 @@ def datamodel_check_test(self, keyValue_dict_SPL, requrement_file_model_list):
108108
) = self.compare_datamodel(requrement_file_model_list, datamodel_based_on_tag)
109109
return list_extra_datamodel_requirement_file, lis_extra_extracted_splunkside
110110

111-
112111
def remove_empty_keys(self, event):
113112
event = re.sub(
114-
r"(\s[a-zA-Z0-9_]*(\\=|\\:)(\\\"\\\"|\\'\\'|\\-))",
115-
'',
116-
str(event)
113+
r"(\s[a-zA-Z0-9_]*(\\=|\\:)(\\\"\\\"|\\'\\'|\\-))", "", str(event)
117114
)
118115
return event
119116

120-
121117
@pytest.mark.splunk_searchtime_requirements
122118
def test_requirement_params(
123119
self, splunk_searchtime_requirement_param, splunk_search_util
@@ -130,8 +126,15 @@ def test_requirement_params(
130126
# search = f" search source= pytest_splunk_addon:hec:raw sourcetype={sourcetype} {escaped_event} |fields * "
131127
# removed source and sourcetype as sc4s assigns it based on event
132128
if transport_type in (
133-
"modinput", "Modinput", "Mod input", "Modular Input", "Modular input", "modular input", "modular_input",
134-
"Mod Input"):
129+
"modinput",
130+
"Modinput",
131+
"Mod input",
132+
"Modular Input",
133+
"Modular input",
134+
"modular input",
135+
"modular_input",
136+
"Mod Input",
137+
):
135138
host = modinput_params["host"]
136139
source = modinput_params["source"]
137140
sourcetype = modinput_params["sourcetype"]
@@ -149,9 +152,7 @@ def test_requirement_params(
149152
search, interval=INTERVAL, retries=RETRIES
150153
)
151154

152-
assert ingestion_check, (
153-
f"ingestion failure \nsearch={search}\n"
154-
)
155+
assert ingestion_check, f"ingestion failure \nsearch={search}\n"
155156
self.logger.info(f"ingestion_check: {ingestion_check}")
156157
keyValue_dict_SPL = splunk_search_util.getFieldValuesDict(
157158
search, interval=INTERVAL, retries=RETRIES

tests/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,10 @@
754754
]
755755

756756
TA_REQUIREMENTS_MODINPUT_PASSED = [
757-
'*test_splunk_app_requirements_modinput.py::Test_App::test_events_with_untokenised_values PASSED*',
758-
'*test_splunk_app_requirements_modinput.py::Test_App::test_requirement_params* PASSED*',
757+
"*test_splunk_app_requirements_modinput.py::Test_App::test_events_with_untokenised_values PASSED*",
758+
"*test_splunk_app_requirements_modinput.py::Test_App::test_requirement_params* PASSED*",
759759
]
760760

761761
TA_REQUIREMENTS_MODINPUT_FAILED = [
762-
'*test_splunk_app_requirements_modinput.py::Test_App::test_requirement_params* FAILED*',
763-
]
762+
"*test_splunk_app_requirements_modinput.py::Test_App::test_requirement_params* FAILED*",
763+
]

tests/test_splunk_addon.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def setup_test_dir(testdir):
4242
)
4343

4444
shutil.copytree(
45-
os.path.join(testdir.request.config.invocation_dir, "tests/requirement_test_modinput"),
45+
os.path.join(
46+
testdir.request.config.invocation_dir, "tests/requirement_test_modinput"
47+
),
4648
os.path.join(testdir.tmpdir, "tests/requirement_test_modinput"),
4749
)
4850

@@ -556,7 +558,9 @@ def empty_method():
556558
)
557559

558560
shutil.copytree(
559-
os.path.join(testdir.request.fspath.dirname, "addons/TA_requirement_test_modinput"),
561+
os.path.join(
562+
testdir.request.fspath.dirname, "addons/TA_requirement_test_modinput"
563+
),
560564
os.path.join(testdir.tmpdir, "package"),
561565
)
562566

@@ -576,8 +580,13 @@ def empty_method():
576580
)
577581
logger.info(result.outlines)
578582
logger.info(len(constants.TA_REQUIREMENTS_MODINPUT_PASSED))
579-
result.stdout.fnmatch_lines_random(constants.TA_REQUIREMENTS_MODINPUT_PASSED + constants.TA_REQUIREMENTS_MODINPUT_FAILED)
580-
result.assert_outcomes(passed=len(constants.TA_REQUIREMENTS_MODINPUT_PASSED), failed=1)
583+
result.stdout.fnmatch_lines_random(
584+
constants.TA_REQUIREMENTS_MODINPUT_PASSED
585+
+ constants.TA_REQUIREMENTS_MODINPUT_FAILED
586+
)
587+
result.assert_outcomes(
588+
passed=len(constants.TA_REQUIREMENTS_MODINPUT_PASSED), failed=1
589+
)
581590

582591
# make sure that that we get a non '0' exit code for the testsuite as it contains failure
583592
assert result.ret != 0

0 commit comments

Comments
 (0)