Skip to content

Commit 6214372

Browse files
committed
chore: changes after review
1 parent ae17291 commit 6214372

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

solnlib/splunkenv.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,12 @@ def msp(*args, **kwargs):
6363
"get_conf_key_value",
6464
"get_conf_stanza",
6565
"get_conf_stanzas",
66-
"_get_conf_stanzas_from_splunk_api",
6766
]
6867

6968
ETC_LEAF = "etc"
7069
APP_SYSTEM = "system"
7170
APP_HEC = "splunk_httpinput"
7271

73-
# See validateSearchHeadPooling() in src/libbundle/ConfSettings.cpp
74-
on_shared_storage = [
75-
os.path.join(ETC_LEAF, "apps"),
76-
os.path.join(ETC_LEAF, "users"),
77-
os.path.join("var", "run", "splunk", "dispatch"),
78-
os.path.join("var", "run", "splunk", "srtemp"),
79-
os.path.join("var", "run", "splunk", "rss"),
80-
os.path.join("var", "run", "splunk", "scheduler"),
81-
os.path.join("var", "run", "splunk", "lookup_tmp"),
82-
]
83-
8472

8573
class SessionKeyNotFound(Exception):
8674
pass
@@ -409,7 +397,11 @@ def _get_conf_stanzas_from_splunk_api(
409397
session_key = getattr(__main__, "___sessionKey")
410398

411399
if not session_key:
412-
raise SessionKeyNotFound()
400+
raise SessionKeyNotFound(
401+
"Session key is missing. If you are using 'splunkenv' module in your TA, please ensure you are "
402+
"providing session_key to it's functions. For more information "
403+
"please see: https://splunk.github.io/addonfactory-solutions-library-python/release_7_0_0/"
404+
)
413405

414406
server_response, server_content = simpleRequest(
415407
url,

tests/integration/test_splunkenv.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import pytest
1617

1718
import context
1819
import conftest
1920
import os
2021
import os.path as op
2122
import sys
2223
from solnlib import splunkenv
24+
from unittest import mock
2325

2426
sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__))))
2527

2628

27-
def test_splunkenv(monkeypatch):
29+
@mock.patch("solnlib.splunkenv.getSessionKey")
30+
def test_splunkenv(mock_get_session_key, monkeypatch):
2831
conftest.mock_splunk(monkeypatch)
32+
mock_get_session_key.return_value = None
2933

3034
assert "SPLUNK_HOME" in os.environ
3135

@@ -51,3 +55,13 @@ def test_splunkenv(monkeypatch):
5155

5256
uri = splunkenv.get_splunkd_uri(sk)
5357
assert uri == f"{scheme}://{host}:{port}"
58+
59+
exp_msg = (
60+
"Session key is missing. If you are using 'splunkenv' module in your TA, please ensure you are "
61+
"providing session_key to it's functions. For more information "
62+
"please see: https://splunk.github.io/addonfactory-solutions-library-python/release_7_0_0/"
63+
)
64+
65+
with pytest.raises(splunkenv.SessionKeyNotFound) as e:
66+
splunkenv.get_splunk_host_info()
67+
assert e.value.args[0] == exp_msg

0 commit comments

Comments
 (0)