Support Python 3
Currently splunklib only suppports Python 2. This is quite a bit annoying for those of us that have made the jump to Python 3, especially as the spunk api is not easily handleable via standard Python XML tools.
I've looked at using modernize to move splunklib to a six world, but I can't get all tests to run with dockerized splunk. This makes it pretty frustrating to work with.
What tests are failing?
Had to recreate the docker image.. One thing the docs don't seem to mention, at least on mac, is that the admin port isn't bound by default so is unavailable. This bit me last time too and took a while to figure out. Anyway, some errors:
test_upload (test_examples.ExamplesTestCase) ... Traceback (most recent call last):
File "upload.py", line 81, in <module>
main(sys.argv[1:])
File "upload.py", line 78, in main
index.upload(fullpath, **kwargs_submit)
File "../splunklib/client.py", line 2094, in upload
self.service.post(path, name=filename, **kwargs)
File "../splunklib/binding.py", line 287, in wrapper
return request_fun(self, *args, **kwargs)
File "../splunklib/binding.py", line 69, in new_f
val = f(*args, **kwargs)
File "../splunklib/binding.py", line 738, in post
response = self.http.post(path, all_headers, **query)
File "../splunklib/binding.py", line 1201, in post
return self.request(url, message)
File "../splunklib/binding.py", line 1221, in request
raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 400 Bad Request -- unable to open file: path='/Users/andersh/Projects/splunk-sdk-python-clean/examples/upload.py' error='No such file or directory'
FAIL
This is weird because that file does in fact exist at that path. It it trying that path inside docker maybe?
test_countmatches_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp) ... FAIL
test_generatehello_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp) ... FAIL
test_pypygeneratetext_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp) ... FAIL
test_sum_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp) ... FAIL
...
test_analytics (test_examples.ExamplesTestCase) ... ERROR
test_async (test_examples.ExamplesTestCase) ... Traceback (most recent call last):
File "async/async.py", line 205, in <module>
main(sys.argv[1:])
File "async/async.py", line 143, in main
do_search(query)
File "async/async.py", line 94, in do_search
results = job.results()
File "async/../../splunklib/client.py", line 2757, in results
return self.get("results", **query_params).body
File "async/../../splunklib/client.py", line 989, in get
return super(Entity, self).get(path_segment, owner=owner, app=app, sharing=sharing, **query)
File "async/../../splunklib/client.py", line 746, in get
**query)
File "async/../../splunklib/binding.py", line 287, in wrapper
return request_fun(self, *args, **kwargs)
File "async/../../splunklib/binding.py", line 69, in new_f
val = f(*args, **kwargs)
File "async/../../splunklib/binding.py", line 665, in get
response = self.http.get(path, self._auth_headers, **query)
File "async/../../splunklib/binding.py", line 1160, in get
return self.request(url, { 'method': "GET", 'headers': headers })
File "async/../../splunklib/binding.py", line 1221, in request
raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 404 Not Found -- Unknown sid.
FAIL
...
test_build_dir_exists (test_examples.ExamplesTestCase) ... FAIL
...
test_upload [(like above) ...]
...
test_default (test_index.IndexTest) ... ERROR
...
test_disable_enable (test_index.IndexTest) ... ERROR
test_integrity (test_index.IndexTest) ... ERROR
test_prefresh (test_index.IndexTest) ... ERROR
test_submit (test_index.IndexTest) ... ERROR
test_submit_namespaced (test_index.IndexTest) ... ERROR
test_submit_via_attach (test_index.IndexTest) ... ERROR
test_submit_via_attach_using_token_header (test_index.IndexTest) ... ERROR
test_submit_via_attach_with_cookie_header (test_index.IndexTest) ... ERROR
test_submit_via_attach_with_multiple_cookie_headers (test_index.IndexTest) ... ERROR
test_submit_via_attached_socket (test_index.IndexTest) ... ERROR
test_upload (test_index.IndexTest) ... Test requires sdk-app-collection. Skipping.
ERROR
...
test_lists_modular_inputs (test_input.TestInput) ... Test requires sdk-app-collection. Skipping.
...
test_inputs_list_on_one_kind_with_search (test_input.TestRead) ... FAIL
...
test_enable_preview (test_job.TestJobWithDelayedDone) ... Test requires sdk-app-collection. Skipping.
ok
test_setpriority (test_job.TestJobWithDelayedDone) ... Test requires sdk-app-collection. Skipping.
...
What is "sdk-app-collection"? No mention of it on https://github.com/splunk/splunk-sdk-python README.
test_lists_modular_inputs (test_modular_input.ModularInputKindTestCase) ... Test requires sdk-app-collection. Skipping.
test_list_arguments (test_modular_input_kinds.ModularInputKindTestCase) ... Test requires sdk-app-collection. Skipping.
test_list_modular_inputs (test_modular_input_kinds.ModularInputKindTestCase) ... Test requires sdk-app-collection. Skipping.
test_update_raises_exception (test_modular_input_kinds.ModularInputKindTestCase) ... Test requires sdk-app-collection. Skipping.
The error log at the end:
======================================================================
ERROR: test_analytics (test_examples.ExamplesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_examples.py", line 322, in test_analytics
index.clean()
File "/Users/andersh/Projects/splunk-sdk-python-clean/splunklib/client.py", line 2032, in clean
(self.name, timeout)
OperationError: Cleaning index sdk-test took longer than 60 seconds; timing out.
======================================================================
ERROR: test_default (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_disable_enable (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_integrity (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_prefresh (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_namespaced (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_via_attach (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_via_attach_using_token_header (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_via_attach_with_cookie_header (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_via_attach_with_multiple_cookie_headers (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_submit_via_attached_socket (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
ERROR: test_upload (test_index.IndexTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_index.py", line 43, in tearDown
self.assertEventuallyTrue(lambda: self.index_name not in self.service.indexes)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/testlib.py", line 92, in assertEventuallyTrue
self.fail(timeout_message)
AssertionError: Operation timed out.
======================================================================
FAIL: test_countmatches_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/searchcommands/test_searchcommands_app.py", line 166, in test_countmatches_as_unit
self.assertEqual('', errors)
AssertionError: u'' != 'Traceback (most recent call last):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 76, in emit\n if self.shouldRollover(record):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 154, in shouldRollover\n self.stream = self._open()\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 945, in _open\n stream = codecs.open(self.baseFilename, self.mode, self.encoding)\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 896, in open\n file = __builtin__.open(filename, mode, buffering)\nIOError: [Errno 2] No such file or directory: \'/Users/andersh/Projects/splunk-sdk-python-clean/tests/var/log/splunk/searchcommands_app.log\'\nLogged from file search_command.py, line 278\n'
======================================================================
FAIL: test_generatehello_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/searchcommands/test_searchcommands_app.py", line 185, in test_generatehello_as_unit
self.assertEqual('', errors)
AssertionError: u'' != 'Traceback (most recent call last):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 76, in emit\n if self.shouldRollover(record):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 154, in shouldRollover\n self.stream = self._open()\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 945, in _open\n stream = codecs.open(self.baseFilename, self.mode, self.encoding)\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 896, in open\n file = __builtin__.open(filename, mode, buffering)\nIOError: [Errno 2] No such file or directory: \'/Users/andersh/Projects/splunk-sdk-python-clean/tests/var/log/splunk/searchcommands_app.log\'\nLogged from file search_command.py, line 278\n'
======================================================================
FAIL: test_pypygeneratetext_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/searchcommands/test_searchcommands_app.py", line 205, in test_pypygeneratetext_as_unit
self.assertEqual('', errors)
AssertionError: u'' != 'Traceback (most recent call last):\n File "/usr/local/Cellar/pypy/5.1.0/libexec/lib-python/2.7/logging/handlers.py", line 76, in emit\n if self.shouldRollover(record):\n File "/usr/local/Cellar/pypy/5.1.0/libexec/lib-python/2.7/logging/handlers.py", line 154, in shouldRollover\n self.stream = self._open()\n File "/usr/local/Cellar/pypy/5.1.0/libexec/lib-python/2.7/logging/__init__.py", line 956, in _open\n stream = codecs.open(self.baseFilename, self.mode, self.encoding)\n File "/usr/local/Cellar/pypy/5.1.0/libexec/lib-python/2.7/codecs.py", line 884, in open\n file = __builtin__.open(filename, mode, buffering)\nIOError: [Errno 2] No such file or directory: \'/Users/andersh/Projects/splunk-sdk-python-clean/tests/var/log/splunk/searchcommands_app.log\'\nLogged from file search_command.py, line 278\n'
======================================================================
FAIL: test_sum_as_unit (searchcommands.test_searchcommands_app.TestSearchCommandsApp)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/searchcommands/test_searchcommands_app.py", line 229, in test_sum_as_unit
self.assertEqual('', errors)
AssertionError: u'' != 'Traceback (most recent call last):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 76, in emit\n if self.shouldRollover(record):\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/handlers.py", line 154, in shouldRollover\n self.stream = self._open()\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 945, in _open\n stream = codecs.open(self.baseFilename, self.mode, self.encoding)\n File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 896, in open\n file = __builtin__.open(filename, mode, buffering)\nIOError: [Errno 2] No such file or directory: \'/Users/andersh/Projects/splunk-sdk-python-clean/tests/var/log/splunk/searchcommands_app.log\'\nLogged from file search_command.py, line 278\n'
======================================================================
FAIL: test_async (test_examples.ExamplesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_examples.py", line 73, in test_async
self.assertEquals(result, 0)
AssertionError: 1 != 0
======================================================================
FAIL: test_build_dir_exists (test_examples.ExamplesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_examples.py", line 85, in test_build_dir_exists
self.assertTrue(os.path.exists("../build"), 'Run setup.py build, then setup.py dist')
AssertionError: Run setup.py build, then setup.py dist
======================================================================
FAIL: test_upload (test_examples.ExamplesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_examples.py", line 244, in test_upload
"upload.py --index=sdk-tests %s" % file_to_upload)
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_examples.py", line 62, in check_commands
self.assertEquals(result, 0, '"{0}" run failed with result code {1}'.format(arg, result))
AssertionError: "upload.py --index=sdk-tests ./upload.py" run failed with result code 1
======================================================================
FAIL: test_inputs_list_on_one_kind_with_search (test_input.TestRead)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/andersh/Projects/splunk-sdk-python-clean/tests/test_input.py", line 158, in test_inputs_list_on_one_kind_with_search
self.assertEqual(expected, found)
AssertionError: Lists differ: ['$SPLUNK_HOME/etc/splunk.vers... != ['$SPLUNK_HOME/etc/splunk.vers...
Second list contains 6 additional elements.
First extra element 6:
'/host/containers/*/[a-f0-9]+-json.log$'
['$SPLUNK_HOME/etc/splunk.version',
'$SPLUNK_HOME/var/log/introspection',
'$SPLUNK_HOME/var/log/splunk',
'$SPLUNK_HOME/var/log/splunk/license_usage_summary.log',
'$SPLUNK_HOME/var/spool/splunk',
- '$SPLUNK_HOME/var/spool/splunk/...stash_new']
? ^
+ '$SPLUNK_HOME/var/spool/splunk/...stash_new',
? ^
+ '/host/containers/*/[a-f0-9]+-json.log$',
+ '/host/containers/*/config.v2.json$',
+ '/host/containers/*/hostconfig.json$',
+ '/host/containers/*/hostname$',
+ '/host/containers/*/hosts$',
+ '/host/containers/*/resolv.conf$']
----------------------------------------------------------------------
Ran 340 tests in 442.851s
FAILED (failures=8, errors=13)
Oh, and having to manually run splunk-sdk-python-clean/examples/searchcommands_app/setup.py build and not having that mentioned in the README for how to run the tests is also annoying.
Did any of this happen when you ran the tests using Python 2.7, or is that what you were trying originally?
Yes, that's a clean clone I did just then.
On 15 Mar 2017, at 07:15, Christopher Goes [email protected] wrote:
Did any of this happen when you ran the tests using Python 2.7, or is that what you were trying originally?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
How close are we? Some of us only write for Python3.x.
How is there still not Python 3 support in 2017? I can't remember the last thing I wrote in 2.x. Is there any official word on this from the Splunk team? Was just gearing up to build some internal tooling and the thought of having to develop and maintain a 2.x Splunk app is pretty disappointing.
Adding my +1.
The rest of the world seems able to move forward to Python 3, and I'm sure a lot of them had big, internal Python 2.x libraries as well.
So... is anything happening? Some feedback on how to even run the test suite under python 2 would be appreciated.
I would like to echo the disbelief that splunk does not have python3 support when python 2 is nearing the end of its maintenance phase, active development on it long since ended.
After posting a partial port on Dec 3, 2014 (see above), allow me to make a pitch for dask, a pure-python parallel data processing and analytic computation engine. Where splunk is failing some people, dask may be the solution; although the focus is really quite different, dask will work excellently for ETL problems and aggregations that people wish to express in python, and real-time, batch processing and queues are rapidly advancing. You would use that computation engine in combination with ordinary python ecosystem tools for visualisation (e.g., jupyter with bokeh). Just a thought!
I made an attempt to add Py3 support on a fork https://github.com/tltx/splunk-sdk-python/. There are still unicode handling problems, some tests fail and I have not tested it besides running the unit tests. I'm going to put it aside for now but if someone want to continue the work or test it, go ahead.
I fixed most of the issues I found so I think it's ready to be tested now.
Please upgrade quickly. Python 3.x is the future.
@MZamanMughal : python 3 is perhaps the present, certainly not the future - by the time this is done, we'll probably have python 4!
We're at three months since the last official response. Please advise. Anyone who has commented on this or the similar issues is a paying customer who would like to have this resolved.
I'm a paying customer and would really like to have this resolved ASAP. It's ridiculous that this has been ignored for several years. The Python community has made is quite easy to bridge the gap between 2.x and 3.x.
Elasticsearch offers excellent Python support for far less money.
@cudneys If you can try @tltx 's branch it would be nice. We are also a paying customer but we just can't wait for this as we're going to py3 very soon. His branch is what we'll use in production when we switch over and it handles our cases at least.
We really should deduct this development effort from their next invoice :P
We're actually gearing up to drastically reduce our Splunk use in production and moving the majority of our logging to ELK. A good portion of the reason is that we can't develop against it without significant effort or using unsupported SDK's. It's really a shame because it's a good product. Oh well, c'est la vie.