pytest-splunk-addon 5.2.4__tar.gz → 5.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/PKG-INFO +5 -7
  2. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pyproject.toml +10 -23
  3. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/__init__.py +3 -3
  4. pytest_splunk_addon-5.2.6/pytest_splunk_addon/docker_class.py +162 -0
  5. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/plugin.py +2 -2
  6. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/splunk.py +78 -14
  7. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/CIM_Models/__init__.py +2 -2
  8. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/CIM_Models/datamodel_definition.py +2 -2
  9. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/__init__.py +2 -2
  10. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_basic.py +2 -2
  11. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/__init__.py +2 -2
  12. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/eventtype_parser.py +2 -2
  13. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/fields.py +2 -2
  14. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/props_parser.py +2 -2
  15. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/savedsearches_parser.py +2 -2
  16. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/tags_parser.py +2 -2
  17. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/addon_parser/transforms_parser.py +2 -2
  18. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/app_test_generator.py +2 -2
  19. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/__init__.py +2 -2
  20. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/base_report.py +2 -2
  21. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/base_table.py +2 -2
  22. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/cim_report_generator.py +2 -2
  23. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/markdown_report.py +2 -2
  24. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/markdown_table.py +2 -2
  25. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_compliance/plugin.py +2 -2
  26. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/__init__.py +2 -2
  27. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/base_schema.py +2 -2
  28. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/data_model.py +2 -2
  29. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/data_model_handler.py +2 -2
  30. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/data_set.py +2 -2
  31. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/field_test_adapter.py +2 -2
  32. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/field_test_helper.py +2 -2
  33. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/json_schema.py +2 -2
  34. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/test_generator.py +2 -2
  35. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/test_templates.py +2 -2
  36. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Intrusion_Detection.json +2 -2
  37. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Network_Resolution.json +2 -2
  38. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Network_Traffic.json +5 -5
  39. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/__init__.py +2 -2
  40. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/base_event_ingestor.py +2 -2
  41. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/file_monitor_ingestor.py +2 -2
  42. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/hec_event_ingestor.py +2 -2
  43. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/hec_metric_ingestor.py +2 -2
  44. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/hec_raw_ingestor.py +2 -2
  45. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/ingestor_helper.py +2 -2
  46. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/event_ingestors/sc4s_event_ingestor.py +2 -2
  47. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/__init__.py +2 -2
  48. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/field_bank.py +2 -2
  49. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/requirement_test_datamodel_tag_constants.py +2 -2
  50. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/sample_parser.py +4 -3
  51. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/test_generator.py +2 -2
  52. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/fields_tests/test_templates.py +2 -2
  53. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/index_tests/__init__.py +2 -2
  54. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/index_tests/key_fields.py +2 -2
  55. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/index_tests/test_generator.py +2 -2
  56. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/index_tests/test_templates.py +2 -2
  57. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/__init__.py +2 -2
  58. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/pytest_splunk_addon_data_parser.py +2 -2
  59. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/rule.py +2 -2
  60. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/sample_event.py +2 -2
  61. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/sample_generator.py +2 -2
  62. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/sample_stanza.py +2 -2
  63. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/sample_xdist_generator.py +2 -2
  64. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/time_parser.py +2 -2
  65. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/utilities/__init__.py +2 -2
  66. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/utilities/junit_parser.py +2 -2
  67. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/utilities/log_helper.py +2 -2
  68. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/utilities/sample_splitter.py +2 -2
  69. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/utilities/xml_event_parser.py +2 -2
  70. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/tools/cim_field_report.py +2 -2
  71. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/LICENSE +0 -0
  72. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/.ignore_splunk_internal_errors +0 -0
  73. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json +0 -0
  74. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/cim_tests/DatamodelSchema.json +0 -0
  75. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Alerts.json +0 -0
  76. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Authentication.json +0 -0
  77. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Certificates.json +0 -0
  78. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Change.json +0 -0
  79. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/DLP.json +0 -0
  80. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Email.json +0 -0
  81. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Endpoint.json +0 -0
  82. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Malware.json +0 -0
  83. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Network_Sessions.json +0 -0
  84. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Updates.json +0 -0
  85. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Vulnerabilities.json +0 -0
  86. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/data_models/Web.json +0 -0
  87. {pytest_splunk_addon-5.2.4 → pytest_splunk_addon-5.2.6}/pytest_splunk_addon/standard_lib/sample_generation/schema.xsd +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-splunk-addon
3
- Version: 5.2.4
3
+ Version: 5.2.6
4
4
  Summary: A Dynamic test tool for Splunk Apps and Add-ons
5
5
  License: Apache-2.0
6
6
  Author: Splunk
@@ -18,20 +18,18 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Topic :: Software Development :: Testing
21
- Provides-Extra: docker
22
- Requires-Dist: Faker (>=13.12,<19.0.0)
21
+ Requires-Dist: Faker (>=18.0.0,<19.0.0)
23
22
  Requires-Dist: addonfactory-splunk-conf-parser-lib
24
23
  Requires-Dist: defusedxml (>=0.7.1,<0.8.0)
25
24
  Requires-Dist: filelock (>=3.0,<4.0)
26
- Requires-Dist: jsonschema (>=4,<5)
25
+ Requires-Dist: jsonschema (>=v4.17.3,<5.0.0)
27
26
  Requires-Dist: junitparser (>=2.2.0,<3.0.0)
28
- Requires-Dist: lovely-pytest-docker (>=0,<1) ; extra == "docker"
29
27
  Requires-Dist: pytest (>5.4.0,<8)
30
28
  Requires-Dist: pytest-ordering (>=0.6,<0.7)
31
- Requires-Dist: pytest-xdist (>=2.3.0,<3.0.0)
29
+ Requires-Dist: pytest-xdist (>=3.5.0,<4.0.0)
32
30
  Requires-Dist: requests (>=2.31.0,<3.0.0)
33
31
  Requires-Dist: splunk-sdk (>=1.6)
34
32
  Requires-Dist: splunksplwrapper (>=1.1.1,<2.0.0)
35
33
  Requires-Dist: urllib3 (<2)
36
- Requires-Dist: xmlschema (>=1.11.3,<2.0.0)
34
+ Requires-Dist: xmlschema (>=2.5.1,<3.0.0)
37
35
  Requires-Dist: xmltodict (>=0.13.0,<0.14.0)
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,7 @@
16
16
 
17
17
  [tool.poetry]
18
18
  name = "pytest-splunk-addon"
19
- version = "5.2.4"
19
+ version = "5.2.6"
20
20
  description = "A Dynamic test tool for Splunk Apps and Add-ons"
21
21
  authors = ["Splunk <addonfactory@splunk.com>"]
22
22
  license = "APACHE-2.0"
@@ -36,37 +36,24 @@ python = "^3.7"
36
36
  pytest = ">5.4.0,<8"
37
37
  splunk-sdk = ">=1.6"
38
38
  requests = "^2.31.0"
39
- jsonschema = ">=4,<5"
40
- pytest-xdist = "^2.3.0"
39
+ jsonschema = "^v4.17.3"
40
+ pytest-xdist = "^3.5.0"
41
41
  filelock = "^3.0"
42
42
  pytest-ordering = "~0.6"
43
- lovely-pytest-docker = { version="^0", optional = true }
44
43
  junitparser = "^2.2.0"
45
44
  addonfactory-splunk-conf-parser-lib = "*"
46
45
  defusedxml = "^0.7.1"
47
- Faker = ">=13.12,<19.0.0"
46
+ Faker = "^18.0.0"
48
47
  xmltodict = "^0.13.0"
49
- xmlschema = "^1.11.3"
48
+ xmlschema = "^2.5.1"
50
49
  splunksplwrapper = "^1.1.1"
51
50
  urllib3 = "<2"
52
51
 
53
- [tool.poetry.extras]
54
- docker = ['lovely-pytest-docker']
55
-
56
52
  [tool.poetry.group.dev.dependencies]
57
- lovely-pytest-docker = "~0.3.0"
58
- pytest-cov = "^3.0.0"
53
+ pytest-cov = "^4"
59
54
  requests-mock = "^1.8.0"
60
- freezegun = "^1.2.1"
61
- pytz = "^2022.1"
62
-
63
- [tool.poetry.group.docs]
64
- optional = true
65
-
66
- [tool.poetry.group.docs.dependencies]
67
- jinja2 = "3.0.3"
68
- sphinx-rtd-theme = "1.1.1"
69
- sphinx-panels = "0.6.0"
55
+ freezegun = "^1.5.1"
56
+ pytz = "^2024.1"
70
57
 
71
58
  [tool.poetry.plugins]
72
59
  pytest11 = { plugin = "pytest_splunk_addon.plugin", "splunk" = "pytest_splunk_addon.splunk" }
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,4 +18,4 @@
18
18
 
19
19
  __author__ = """Splunk Inc."""
20
20
  __email__ = "addonfactory@splunk.com"
21
- __version__ = "5.2.4"
21
+ __version__ = "5.2.6"
@@ -0,0 +1,162 @@
1
+ import functools
2
+ import os
3
+ from urllib.request import urlopen
4
+
5
+ import pytest
6
+ import re
7
+ import subprocess
8
+ import time
9
+ import timeit
10
+
11
+ from requests import HTTPError
12
+
13
+
14
+ def check_url(docker_ip, public_port, path="/"):
15
+ """Check if a service is reachable.
16
+
17
+ Makes a simple GET request to path of the HTTP endpoint. Service is
18
+ available if returned status code is < 500.
19
+ """
20
+ url = "http://{}:{}{}".format(docker_ip, public_port, path)
21
+ try:
22
+ r = urlopen(url)
23
+ return r.code < 500
24
+ except HTTPError as e:
25
+ # If service returns e.g. a 404 it's ok
26
+ return e.code < 500
27
+ except Exception:
28
+ # Possible service not yet started
29
+ return False
30
+
31
+
32
+ def execute(command, success_codes=(0,)):
33
+ """Run a shell command."""
34
+ try:
35
+ output = subprocess.check_output(
36
+ command,
37
+ stderr=subprocess.STDOUT,
38
+ shell=False,
39
+ )
40
+ status = 0
41
+ except subprocess.CalledProcessError as error:
42
+ output = error.output or b""
43
+ status = error.returncode
44
+ command = error.cmd
45
+ output = output.decode("utf-8")
46
+ if status not in success_codes:
47
+ raise Exception('Command %r returned %d: """%s""".' % (command, status, output))
48
+ return output
49
+
50
+
51
+ class Services(object):
52
+ """A class which encapsulates services from docker compose definition.
53
+
54
+ This code is partly taken from
55
+ https://github.com/AndreLouisCaron/pytest-docker
56
+ """
57
+
58
+ def __init__(self, compose_files, docker_ip, project_name="pytest"):
59
+ self._docker_compose = DockerComposeExecutor(compose_files, project_name)
60
+ self._services = {}
61
+ self.docker_ip = docker_ip
62
+
63
+ def start(self, *services):
64
+ """Ensures that the given services are started via docker compose.
65
+
66
+ :param services: the names of the services as defined in compose file
67
+ """
68
+ self._docker_compose.execute("up", "--build", "-d", *services)
69
+
70
+ def stop(self, *services):
71
+ """Ensures that the given services are stopped via docker compose.
72
+
73
+ :param services: the names of the services as defined in compose file
74
+ """
75
+ self._docker_compose.execute("stop", *services)
76
+
77
+ def execute(self, service, *cmd):
78
+ """Execute a command inside a docker container.
79
+
80
+ :param service: the name of the service as defined in compose file
81
+ :param cmd: list of command parts to execute
82
+ """
83
+ return self._docker_compose.execute("exec", "-T", service, *cmd)
84
+
85
+ def wait_for_service(
86
+ self, service, private_port, check_server=check_url, timeout=30.0, pause=0.1
87
+ ):
88
+ """
89
+ Waits for the given service to response to a http GET.
90
+
91
+ :param service: the service name as defined in the docker compose file
92
+ :param private_port: the private port as defined in docker compose file
93
+ :param check_server: optional function to check if the server is ready
94
+ (default check method makes GET request to '/'
95
+ of HTTP endpoint)
96
+ :param timeout: maximum time to wait for the service in seconds
97
+ :param pause: time in seconds to wait between retries
98
+
99
+ :return: the public port of the service exposed to host system if any
100
+ """
101
+ public_port = self.port_for(service, private_port)
102
+ self.wait_until_responsive(
103
+ timeout=timeout,
104
+ pause=pause,
105
+ check=lambda: check_server(self.docker_ip, public_port),
106
+ )
107
+ return public_port
108
+
109
+ def shutdown(self):
110
+ self._docker_compose.execute("down", "-v")
111
+
112
+ def port_for(self, service, port):
113
+ """Get the effective bind port for a service."""
114
+
115
+ # Lookup in the cache.
116
+ cache = self._services.get(service, {}).get(port, None)
117
+ if cache is not None:
118
+ return cache
119
+
120
+ output = self._docker_compose.execute("port", service, str(port))
121
+ endpoint = output.strip()
122
+ if not endpoint:
123
+ raise ValueError('Could not detect port for "%s:%d".' % (service, port))
124
+
125
+ # Usually, the IP address here is 0.0.0.0, so we don't use it.
126
+ match = int(endpoint.split(":", 1)[1])
127
+
128
+ # Store it in cache in case we request it multiple times.
129
+ self._services.setdefault(service, {})[port] = match
130
+
131
+ return match
132
+
133
+ @staticmethod
134
+ def wait_until_responsive(check, timeout, pause, clock=timeit.default_timer):
135
+ """Wait until a service is responsive."""
136
+
137
+ ref = clock()
138
+ now = ref
139
+ while (now - ref) < timeout:
140
+ if check():
141
+ return
142
+ time.sleep(pause)
143
+ now = clock()
144
+
145
+ raise Exception("Timeout reached while waiting on service!")
146
+
147
+
148
+ class DockerComposeExecutor(object):
149
+ def __init__(self, compose_files, project_name):
150
+ self._compose_files = compose_files
151
+ self._project_name = project_name
152
+ self.project_directory = os.path.dirname(os.path.realpath(compose_files[0]))
153
+
154
+ def execute(self, *subcommand):
155
+ command = ["docker", "compose"]
156
+ for compose_file in self._compose_files:
157
+ command.append("-f")
158
+ command.append(compose_file)
159
+ command.append("-p")
160
+ command.append(self._project_name)
161
+ command += subcommand
162
+ return execute(command)
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,11 +21,13 @@ from time import sleep
21
21
  import json
22
22
  import pytest
23
23
  import requests
24
+ import re
24
25
  import splunklib.client as client
25
26
  from splunksplwrapper.manager.jobs import Jobs
26
27
  from splunksplwrapper.splunk.cloud import CloudSplunk
27
28
  from splunksplwrapper.SearchUtil import SearchUtil
28
29
  from .standard_lib.event_ingestors import IngestorHelper
30
+ from .docker_class import Services
29
31
  from .standard_lib.CIM_Models.datamodel_definition import datamodels
30
32
  import configparser
31
33
  from filelock import FileLock
@@ -323,6 +325,13 @@ def pytest_addoption(parser):
323
325
  help="Should execute test or not (True|False)",
324
326
  default="True",
325
327
  )
328
+ group.addoption(
329
+ "--keepalive",
330
+ "-K",
331
+ action="store_true",
332
+ default=False,
333
+ help="Keep docker containers alive",
334
+ )
326
335
 
327
336
 
328
337
  @pytest.fixture(scope="session")
@@ -741,18 +750,21 @@ def splunk_ingest_data(request, splunk_hec_uri, sc4s, uf, splunk_events_cleanup)
741
750
  }
742
751
  thread_count = int(request.config.getoption("thread_count"))
743
752
  store_events = request.config.getoption("store_events")
744
- IngestorHelper.ingest_events(
745
- ingest_meta_data,
746
- addon_path,
747
- config_path,
748
- thread_count,
749
- store_events,
750
- )
751
- sleep(50)
752
- if "PYTEST_XDIST_WORKER" in os.environ:
753
- with open(os.environ.get("PYTEST_XDIST_TESTRUNUID") + "_wait", "w+"):
754
- PYTEST_XDIST_TESTRUNUID = os.environ.get("PYTEST_XDIST_TESTRUNUID")
755
-
753
+ try:
754
+ IngestorHelper.ingest_events(
755
+ ingest_meta_data,
756
+ addon_path,
757
+ config_path,
758
+ thread_count,
759
+ store_events,
760
+ )
761
+ sleep(50)
762
+ except Exception as e:
763
+ raise e
764
+ finally:
765
+ if "PYTEST_XDIST_WORKER" in os.environ:
766
+ with open(os.environ.get("PYTEST_XDIST_TESTRUNUID") + "_wait", "w+"):
767
+ PYTEST_XDIST_TESTRUNUID = os.environ.get("PYTEST_XDIST_TESTRUNUID")
756
768
  else:
757
769
  while not os.path.exists(os.environ.get("PYTEST_XDIST_TESTRUNUID") + "_wait"):
758
770
  sleep(1)
@@ -830,6 +842,56 @@ def splunk_dm_recommended_fields():
830
842
  return update_recommended_fields
831
843
 
832
844
 
845
+ @pytest.fixture(scope="session")
846
+ def docker_ip():
847
+ """Determine IP address for TCP connections to Docker containers."""
848
+
849
+ # When talking to the Docker daemon via a UNIX socket, route all TCP
850
+ # traffic to docker containers via the TCP loopback interface.
851
+ docker_host = os.environ.get("DOCKER_HOST", "").strip()
852
+ if not docker_host:
853
+ return "127.0.0.1"
854
+
855
+ match = re.match("^tcp://(.+?):\d+$", docker_host)
856
+ if not match:
857
+ raise ValueError('Invalid value for DOCKER_HOST: "%s".' % (docker_host,))
858
+ return match.group(1)
859
+
860
+
861
+ @pytest.fixture(scope="session")
862
+ def docker_compose_files(pytestconfig):
863
+ """Get the docker-compose.yml absolute path.
864
+ Override this fixture in your tests if you need a custom location.
865
+ """
866
+ return [os.path.join(str(pytestconfig.rootdir), "tests", "docker-compose.yml")]
867
+
868
+
869
+ @pytest.fixture(scope="session")
870
+ def docker_services_project_name(pytestconfig):
871
+ """
872
+ Create unique project name for docker compose based on the pytestconfig root directory.
873
+ Characters prohibited by Docker compose project names are replaced with hyphens.
874
+ """
875
+ slug = re.sub(r"[^a-z0-9]+", "-", str(pytestconfig.rootdir).lower())
876
+ project_name = "pytest{}".format(slug)
877
+ return project_name
878
+
879
+
880
+ @pytest.fixture(scope="session")
881
+ def docker_services(
882
+ request, docker_compose_files, docker_ip, docker_services_project_name
883
+ ):
884
+ """Provide the docker services as a pytest fixture.
885
+
886
+ The services will be stopped after all tests are run.
887
+ """
888
+ keep_alive = request.config.getoption("--keepalive", False)
889
+ services = Services(docker_compose_files, docker_ip, docker_services_project_name)
890
+ yield services
891
+ if not keep_alive:
892
+ services.shutdown()
893
+
894
+
833
895
  def is_responsive_uf(uf):
834
896
  """
835
897
  Verify if the management port of Universal Forwarder is responsive or not
@@ -957,3 +1019,5 @@ def pytest_unconfigure(config):
957
1019
  os.remove(PYTEST_XDIST_TESTRUNUID + "_wait")
958
1020
  if os.path.exists(PYTEST_XDIST_TESTRUNUID + "_events"):
959
1021
  os.remove(PYTEST_XDIST_TESTRUNUID + "_events")
1022
+ if os.path.exists(PYTEST_XDIST_TESTRUNUID + "_events.lock"):
1023
+ os.remove(PYTEST_XDIST_TESTRUNUID + "_events.lock")
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,11 +1,11 @@
1
1
  #
2
- # Copyright 2021 Splunk Inc.
2
+ # Copyright 2024 Splunk Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
6
6
  # You may obtain a copy of the License at
7
7
  #
8
- # http://www.apache.org/licenses/LICENSE-2.0
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
9
  #
10
10
  # Unless required by applicable law or agreed to in writing, software
11
11
  # distributed under the License is distributed on an "AS IS" BASIS,