Skip to content

Commit 5dcf475

Browse files
author
David Noble
committed
Checkpoint
1 parent e973eb3 commit 5dcf475

File tree

2 files changed

+89
-16
lines changed

2 files changed

+89
-16
lines changed

setup.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import splunklib
2323
import tarfile
2424

25+
2526
def run_test_suite():
2627
try:
2728
import unittest2 as unittest
@@ -72,6 +73,7 @@ def finalize_options(self):
7273
def run(self):
7374
run_test_suite()
7475

76+
7577
class DistCommand(Command):
7678
"""setup.py command to create .spl files for modular input and search
7779
command examples"""
@@ -98,8 +100,8 @@ def run(self):
98100
# Create random_numbers.spl and github_forks.spl
99101

100102
app_names = ['random_numbers', 'github_forks']
101-
splunklib_dir = "splunklib"
102-
modinput_dir = os.path.join(splunklib_dir, "modularinput")
103+
splunklib_arcname = "splunklib"
104+
modinput_dir = os.path.join(splunklib_arcname, "modularinput")
103105

104106
for app in app_names:
105107
with closing(tarfile.open(os.path.join("build", app + ".spl"), "w")) as spl:
@@ -117,11 +119,11 @@ def run(self):
117119
arcname=os.path.join(app, "README", "inputs.conf.spec")
118120
)
119121

120-
splunklib_files = self.get_python_files(os.listdir(splunklib_dir))
122+
splunklib_files = self.get_python_files(os.listdir(splunklib_arcname))
121123
for file_name in splunklib_files:
122124
spl.add(
123-
os.path.join(splunklib_dir, file_name),
124-
arcname=os.path.join(app, "bin", splunklib_dir, file_name)
125+
os.path.join(splunklib_arcname, file_name),
126+
arcname=os.path.join(app, "bin", splunklib_arcname, file_name)
125127
)
126128

127129
modinput_files = self.get_python_files(os.listdir(modinput_dir))
@@ -137,14 +139,6 @@ def run(self):
137139

138140
sdk_dir = os.path.abspath('.')
139141

140-
tarball = os.path.join(sdk_dir, 'build', 'searchcommands_app.spl')
141-
142-
app_dir = os.path.join(sdk_dir, 'examples', 'searchcommands_app')
143-
arc_app_dir = 'searchcommands_app'
144-
145-
lib_dir = os.path.join(sdk_dir, 'splunklib', 'searchcommands')
146-
arc_app_lib_dir = os.path.join(arc_app_dir, 'bin', 'splunklib', 'searchcommands')
147-
148142
def exclude(path):
149143
# TODO: Replace with filter function because exclude is deprecated
150144
basename = os.path.basename(path)
@@ -153,10 +147,25 @@ def exclude(path):
153147
return True
154148
return False
155149

156-
with closing(tarfile.open(tarball, "w")) as spl:
157-
spl.add(app_dir, arcname=arc_app_dir, exclude=exclude)
158-
spl.add(lib_dir, arcname=arc_app_lib_dir, exclude=exclude)
150+
tarball = os.path.join(sdk_dir, 'build', 'searchcommands_app.spl')
151+
152+
splunklib_arcname = os.path.join(
153+
'searchcommands_app', 'bin', 'splunklib')
154+
155+
manifest = [
156+
(os.path.join(sdk_dir, 'examples', 'searchcommands_app'),
157+
'searchcommands_app'),
158+
(os.path.join(sdk_dir, 'splunklib', '__init__.py'),
159+
os.path.join(splunklib_arcname, '__init__.py')),
160+
(os.path.join(sdk_dir, 'splunklib', 'searchcommands'),
161+
os.path.join(splunklib_arcname, 'searchcommands'))
162+
]
163+
164+
with closing(tarfile.open(tarball, 'w')) as spl:
165+
for source, target in manifest:
166+
spl.add(source, arcname=target, exclude=exclude)
159167

168+
return
160169

161170
setup(
162171
author="Splunk, Inc.",

tests/test_search_commands.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2011-2013 Splunk, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
try:
18+
import unittest2 as unittest
19+
except ImportError:
20+
import unittest
21+
import testlib
22+
23+
24+
class SearchCommandsTestCase(testlib.SDKTestCase):
25+
def setUp(self):
26+
super(SearchCommandsTestCase, self).setUp()
27+
self.uncheckedRestartSplunk()
28+
29+
def test_lists_search_commands(self):
30+
version_major = self.service.splunk_version[0]
31+
if version_major < 5:
32+
print(
33+
'The splunklib.searchcommands module does not support Splunk '
34+
'%d. Skipping.'
35+
% version_major)
36+
return
37+
elif not self.app_collection_installed():
38+
print('Test requires sdk-app-collection. Skipping.')
39+
return
40+
else:
41+
# Install modular inputs to list, and restart so they'll show up
42+
self.install_app_from_collection("modular-inputs")
43+
self.uncheckedRestartSplunk()
44+
inputs = self.service.inputs
45+
if ('abcd','test2') not in inputs:
46+
inputs.create('abcd', 'test2', field1='boris')
47+
48+
input = inputs['abcd', 'test2']
49+
self.assertEqual(input.field1, 'boris')
50+
for m in self.service.modular_input_kinds:
51+
self.check_modular_input_kind(m)
52+
53+
def check_modular_input_kind(self, m):
54+
print m.name
55+
if m.name == 'test1':
56+
self.assertEqual('Test "Input" - 1', m['title'])
57+
self.assertEqual("xml", m['streaming_mode'])
58+
elif m.name == 'test2':
59+
self.assertEqual('test2', m['title'])
60+
self.assertEqual('simple', m['streaming_mode'])
61+
62+
63+
if __name__ == "__main__":
64+
unittest.main()

0 commit comments

Comments
 (0)