1515
1616import pytest
1717
18+ from splunklib .binding import HTTPError
1819from tests .ai_testlib import AITestCase
1920
2021
2122class TestAgenticApp (AITestCase ):
2223 def test_agetic_app (self ) -> None :
2324 pytest .importorskip ("langchain_openai" )
24- self .skip_splunk_10_2 ()
25+ self .requires_splunk_10_2 ()
2526
2627 resp = self .service .post (
2728 "agentic_app/agent-name" ,
@@ -32,7 +33,7 @@ def test_agetic_app(self) -> None:
3233
3334 def test_agentic_app_with_tools_weather (self ) -> None :
3435 pytest .importorskip ("langchain_openai" )
35- self .skip_splunk_10_2 ()
36+ self .requires_splunk_10_2 ()
3637
3738 resp = self .service .post (
3839 "agentic_app_with_local_tools/weather" ,
@@ -43,7 +44,7 @@ def test_agentic_app_with_tools_weather(self) -> None:
4344
4445 def test_agentic_app_with_tools_agent_name (self ) -> None :
4546 pytest .importorskip ("langchain_openai" )
46- self .skip_splunk_10_2 ()
47+ self .requires_splunk_10_2 ()
4748
4849 resp = self .service .post (
4950 "agentic_app_with_local_tools/agent-name" ,
@@ -52,10 +53,60 @@ def test_agentic_app_with_tools_agent_name(self) -> None:
5253 assert resp .status == 200
5354 assert "stefan" in str (resp .body )
5455
55- # TODO: Would be nice to test remote tool execution, such test would need to install the
56- # MCP Server App and define a custom tool (tools.conf). For now we only test remote tools ececution
57- # with a mock mcp server, outside of Splunk environment, see ../integration/ai/test_agent_mcp_tools.py.
56+ # To execute this test locally, download the Splunk MCP Server App tarball from
57+ # https://splunkbase.splunk.com/app/7931 and place it in a file named
58+ # splunk-mcp-server.tgz at the root of this repo (i.e. ../../splunk-mcp-server.tgz).
59+ #
60+ # Note: that the downloaded file could have a: .spl, .tar, .tar.gz or .tgz extension,
61+ # if it is not .tgz, then you must change it to .tgz.
62+ #
63+ # Our CI does this automatically.
64+ def test_agentic_app_with_remote_tools (self ) -> None :
65+ pytest .importorskip ("langchain_openai" )
66+ self .requires_splunk_10_2 ()
67+
68+ INDEX_NAME = "needle-index"
69+
70+ # Delete the index if already exists.
71+ for index in self .service .indexes : # pyright: ignore[reportUnknownVariableType]
72+ if index .name == INDEX_NAME :
73+ index .delete ()
74+
75+ # Skip test in case the instance does not have a /splunk-mcp-server.tgz file.
76+ # We do so, not to require app download for local development of the SDK.
77+ # Note that: our CI always has this file available.
78+ #
79+ # We check that through a separate endpoint call, since we want to have tests
80+ # that don't assume that our CI splunk instance is a docker container.
81+ try :
82+ resp = self .service .get ("agentic_app/has_mcp_app_file" )
83+ assert resp .status == 200
84+ except HTTPError as e :
85+ if e .status == 404 :
86+ self .skipTest ("Splunk MCP Server App file not found on Splunk instance" )
87+ raise
88+
89+ # AITestCase already removes the Splunk MCP Server App in case it is already
90+ # installed, so here we will always end up installing it, thus having a fresh
91+ # version of the app.
92+
93+ # Install the Splunk MCP Server App.
94+ app = self .service .apps .create (name = "/splunk-mcp-server.tgz" , filename = True ) # pyright: ignore[reportUnknownVariableType]
95+
96+ index = self .service .indexes .create (name = INDEX_NAME ) # pyright: ignore[reportUnknownVariableType]
97+
98+ resp = self .service .post (
99+ "agentic_app/indexes" ,
100+ body = self .test_llm_settings .model_dump_json (),
101+ )
102+
103+ assert resp .status == 200
104+ assert INDEX_NAME in str (resp .body ) # pyright: ignore[reportUnknownArgumentType]
105+
106+ index .delete ()
107+ app .delete ()
108+ self .restart_splunk () # app removal requires a restart
58109
59- def skip_splunk_10_2 (self ) -> None :
110+ def requires_splunk_10_2 (self ) -> None :
60111 if self .service .splunk_version [0 ] < 10 or self .service .splunk_version [1 ] < 2 :
61112 self .skipTest ("Python 3.13 not available on splunk < 10.2" )
0 commit comments