From 90acc26c997198e1b7da7fde3c2fc54f58127d93 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 18 Feb 2020 17:50:11 -0500 Subject: [PATCH 1/2] change library --- .vscode/settings.json | 3 +++ pytest_splunk_addon/plugin.py | 29 ++++++++++++++++++----------- requirements.txt | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..84c8f8358 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "venv/bin/python3" +} \ No newline at end of file diff --git a/pytest_splunk_addon/plugin.py b/pytest_splunk_addon/plugin.py index 359748b3a..2ac24d9db 100644 --- a/pytest_splunk_addon/plugin.py +++ b/pytest_splunk_addon/plugin.py @@ -77,19 +77,19 @@ def is_responsive(url): def is_responsive_splunk(splunk): try: - cs = CloudSplunk(splunkd_host=splunk['host'], - splunkd_port=splunk['port'], - username=splunk['username'], - password=splunk['password'] - ) - - conn = cs.create_logged_in_connector() - jobs = Jobs(conn) + client.connect(username=splunk['username'], password=splunk['password'], host=splunk['host'], + port=splunk['port']) return True except Exception: return False +@pytest.fixture(scope="session") +def docker_compose_file(pytestconfig): + """Get an absolute path to the `docker-compose.yml` file. Override this + fixture in your tests if you need a custom location.""" + return os.path.join(str(pytestconfig.invocation_dir), "tests", "docker-compose.yml") + @pytest.fixture(scope="session") def splunk(request): if request.config.getoption('splunk_type') == 'external': @@ -106,11 +106,12 @@ def splunk(request): @pytest.fixture(scope="session") -def splunk_docker(request, docker_services, docker_ip): +def splunk_docker(request, docker_services): + docker_services.start('splunk') port = docker_services.port_for("splunk", 8089) splunk = { - 'host': docker_ip, + 'host': docker_services.docker_ip, 'port': port, 'username': request.config.getoption('splunk_user'), 'password': request.config.getoption('splunk_password'), @@ -124,13 +125,19 @@ def splunk_docker(request, docker_services, docker_ip): @pytest.fixture(scope="session") -def splunk_external(request): +def splunk_external(request, docker_services): splunk = { 'host': request.config.getoption('splunk_host'), 'port': request.config.getoption('splunk_port'), 'username': request.config.getoption('splunk_user'), 'password': request.config.getoption('splunk_password'), } + + + docker_services.wait_until_responsive( + timeout=180.0, pause=1.0, check=lambda: is_responsive_splunk(splunk) + ) + return splunk diff --git a/requirements.txt b/requirements.txt index c0e069f45..172d19ac0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ httplib2 https://download.splunk.com/misc/appinspect/splunk-appinspect-latest.tar.gz pytest-dependency flaky -pytest-docker +lovely-pytest-docker requests From 77bd0544efac0ccc1703319c11b044ae7837c1c4 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 18 Feb 2020 18:48:44 -0500 Subject: [PATCH 2/2] updates --- .idea/markdown-navigator-enh.xml | 29 +++++++++++++++++ .idea/markdown-navigator.xml | 55 ++++++++++++++++++++++++++++++++ .idea/vcs.xml | 1 - .vscode/settings.json | 3 +- pytest_splunk_addon/plugin.py | 16 ++++++---- 5 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 .idea/markdown-navigator-enh.xml create mode 100644 .idea/markdown-navigator.xml diff --git a/.idea/markdown-navigator-enh.xml b/.idea/markdown-navigator-enh.xml new file mode 100644 index 000000000..12fb99d1b --- /dev/null +++ b/.idea/markdown-navigator-enh.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 000000000..4463382e6 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 5491342a2..94a25f7f4 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 84c8f8358..76083eb0a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "python.pythonPath": "venv/bin/python3" + "python.pythonPath": "venv/bin/python3", + "python.formatting.provider": "black" } \ No newline at end of file diff --git a/pytest_splunk_addon/plugin.py b/pytest_splunk_addon/plugin.py index 2ac24d9db..aa58611cf 100644 --- a/pytest_splunk_addon/plugin.py +++ b/pytest_splunk_addon/plugin.py @@ -10,6 +10,10 @@ from .helmut.splunk.cloud import CloudSplunk from .helmut_lib.SearchUtil import SearchUtil +import pytest +import requests +import splunklib.client as client + logger = logging.getLogger() @@ -89,14 +93,17 @@ def docker_compose_file(pytestconfig): fixture in your tests if you need a custom location.""" return os.path.join(str(pytestconfig.invocation_dir), "tests", "docker-compose.yml") - + @pytest.fixture(scope="session") def splunk(request): if request.config.getoption('splunk_type') == 'external': request.fixturenames.append('splunk_external') splunk = request.getfixturevalue("splunk_external") elif request.config.getoption('splunk_type') == 'docker': - os.environ['splunk_version'] = request.config.getoption('splunk_version') + os.environ['SPLUNK_PASSWORD'] = request.config.getoption( + 'splunk_password') + # os.environ['SPLUNK_HEC_TOKEN'] = request.config.getoption( + # 'splunk_hec_token') request.fixturenames.append('splunk_docker') splunk = request.getfixturevalue("splunk_docker") else: @@ -133,11 +140,6 @@ def splunk_external(request, docker_services): 'password': request.config.getoption('splunk_password'), } - - docker_services.wait_until_responsive( - timeout=180.0, pause=1.0, check=lambda: is_responsive_splunk(splunk) - ) - return splunk