Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1c754af
Update config.yml
ryanfaircloth Aug 11, 2020
94b580f
Update config.yml
ryanfaircloth Aug 11, 2020
0b1f65d
Update config.yml
ryanfaircloth Aug 11, 2020
b4dd936
Update config.yml
ryanfaircloth Aug 11, 2020
bdd998b
Update config.yml
ryanfaircloth Aug 11, 2020
c87657c
Update config.yml
ryanfaircloth Aug 11, 2020
31ac22a
Update .python-version
ryanfaircloth Aug 11, 2020
98b0c7f
Update .python-version
ryanfaircloth Aug 11, 2020
56984f8
Delete .python-version
ryanfaircloth Aug 11, 2020
317e40f
Update config.yml
ryanfaircloth Aug 11, 2020
5e19843
Update config.yml
ryanfaircloth Aug 11, 2020
1eb3aae
Update config.yml
ryanfaircloth Aug 11, 2020
0bd9a97
wip
ryanfaircloth Aug 11, 2020
8a7380a
Update config.yml
ryanfaircloth Aug 11, 2020
1cae354
Update config.yml
ryanfaircloth Aug 11, 2020
4125359
Update config.yml
ryanfaircloth Aug 11, 2020
837f8fd
Update config.yml
ryanfaircloth Aug 11, 2020
5e093bd
Update config.yml
ryanfaircloth Aug 11, 2020
af7d098
Update config.yml
ryanfaircloth Aug 11, 2020
9a0f438
Update config.yml
ryanfaircloth Aug 11, 2020
b86a659
Update config.yml
ryanfaircloth Aug 11, 2020
c685ecc
Update config.yml
ryanfaircloth Aug 11, 2020
83b1a46
Update config.yml
ryanfaircloth Aug 11, 2020
906da97
Update config.yml
ryanfaircloth Aug 11, 2020
2000950
Update config.yml
ryanfaircloth Aug 11, 2020
5046ed4
Update config.yml
ryanfaircloth Aug 11, 2020
68f58d6
Update splunkenv.py
ryanfaircloth Aug 11, 2020
dd572d1
Update splunkenv.py
ryanfaircloth Aug 11, 2020
399edf1
matrix
ryanfaircloth Aug 11, 2020
5f881a1
Update config.yml
ryanfaircloth Aug 11, 2020
be5fa10
Update common.py
ryanfaircloth Aug 11, 2020
7d47883
Update .gitignore
ryanfaircloth Aug 11, 2020
7bdbb61
Update common.py
ryanfaircloth Aug 12, 2020
9a7221c
Install the library in the test app
ryanfaircloth Aug 12, 2020
1a56ec0
Update requirements.txt
ryanfaircloth Aug 12, 2020
c497d52
Update config.yml
ryanfaircloth Aug 12, 2020
5cdc88d
cleaup
ryanfaircloth Aug 12, 2020
f048c2e
Update config.yml
ryanfaircloth Aug 12, 2020
3b8964b
fix
ryanfaircloth Aug 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
executor: << parameters.os >>
steps:
- checkout
- python/load-cache
#- python/load-cache
- run:
name: install deps
command: |
Expand Down Expand Up @@ -50,6 +50,75 @@ jobs:
path: test-results
- store_artifacts:
path: htmlcov

test-splunk:
parameters:
os:
type: executor
splunk-version:
type: string
python-version:
type: string
executor: << parameters.os >>
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init
- run:
name: Install Splunk
command: |
pip install git+https://github.com/pixelb/crudini
export SPLUNK_PRODUCT=splunk
export SPLUNK_VERSION=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<<parameters.splunk-version>>" VERSION)
export SPLUNK_BUILD=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<<parameters.splunk-version>>" BUILD)
export SPLUNK_SLUG=$SPLUNK_VERSION-SPLUNK_BUILD
export SPLUNK_ARCH=x86_64
export SPLUNK_LINUX_FILENAME=splunk-${SPLUNK_VERSION}-${SPLUNK_BUILD}-Linux-${SPLUNK_ARCH}.tgz
export SPLUNK_BUILD_URL=https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME}
echo $SPLUNK_BUILD_URL
export SPLUNK_HOME=/opt/splunk
wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL}
sudo tar -C /opt -zxf /tmp/splunk.tgz
sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps
sudo cp -r solnlib $SPLUNK_HOME/etc/apps/solnlib_demo/bin/
sudo mkdir -p $SPLUNK_HOME/etc/apps/Splunk_TA_test/default/
sudo chown -R $USER:$USER /opt/splunk
ls $SPLUNK_HOME/etc/apps/solnlib_demo/bin/
echo [user_info] >$SPLUNK_HOME/etc/system/local/user-seed.conf
echo USERNAME=Admin >>$SPLUNK_HOME/etc/system/local/user-seed.conf
echo PASSWORD=Chang3d! >>$SPLUNK_HOME/etc/system/local/user-seed.conf
/opt/splunk/bin/splunk start --accept-license
#- python/load-cache
- run:
name: Install deps
command: |
pip install --upgrade pip
pip install --upgrade virtualenv
unset PYENV_ROOT
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
pyenv install << parameters.python-version >>
pyenv global << parameters.python-version >>
virtualenv .venv
pip install --upgrade virtualenv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .
mkdir test-results || true
- python/save-cache
- run:
command: |
source .venv/bin/activate
SPLUNK_HOME=/opt/splunk/ python -m pytest --junitxml=test-results/results.xml -v examples
name: Test
- store_test_results:
path: test-results
- store_artifacts:
path: test-results
- store_artifacts:
path: htmlcov

workflows:
main:
jobs:
Expand All @@ -58,3 +127,9 @@ workflows:
parameters:
os: [linux]
python-version: ["2.7.17", "3.7.4"]
- test-splunk:
matrix:
parameters:
os: [linux]
splunk-version: ["7.2", "7.3", "8.0"]
python-version: ["2.7.17", "3.7.4"]
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.coverage*
*.idea
*.DS_Store*
build
/build
dist
docs/_build
docs/solnlib
Expand All @@ -22,3 +22,6 @@ solnlib.egg-info/
venv/*
*.log
tools/solution_lib_release_env/*
.python-version
.venv
.vscode/settings.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/build/addonfactory_test_matrix_splunk"]
path = deps/build/addonfactory_test_matrix_splunk
url = git@github.com:splunk/addonfactory_test_matrix_splunk.git
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

1 change: 1 addition & 0 deletions deps/build/addonfactory_test_matrix_splunk
2 changes: 2 additions & 0 deletions examples/.pytest.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest-expect file v1
(3, 7, 7, 'final', 0)
33 changes: 17 additions & 16 deletions examples/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
import os
import os.path as op
Expand All @@ -18,18 +19,18 @@


def setup_environment():
print 'Setup solnlib demo environment...'
print 'Copying %s to %s' % (source_dir, target_dir)
print('Setup solnlib demo environment...')
print('Copying %s to %s' % (source_dir, target_dir))
shutil.copytree(source_dir, target_dir)
shutil.copytree(solnlib_lib_dir,
solnlib_lib_target_dir)
os.system(splunk_bin + ' start')


def teardown_environment():
print 'Teardown solnlib demo environment...'
print('Teardown solnlib demo environment...')
os.system(splunk_bin + ' stop')
print 'Removing %s' % target_dir
print('Removing %s' % target_dir)
if op.exists(target_dir):
shutil.rmtree(target_dir)

Expand All @@ -47,31 +48,31 @@ def run_test():
import test_hec_event_writer
import test_time_parser

print 'check splunk environment...'
print('check splunk environment...')
test_splunkenv.test_splunkenv()
print 'check splunk server info...'
print('check splunk server info...')
test_server_info.test_server_info()
print 'test kvstore...'
print('test kvstore...')
test_kvstore.test_kvstore()
print 'test metadata reader...'
print('test metadata reader...')
test_metadata.test_metadata_reader()
print 'test acl manager...'
print('test acl manager...')
test_acl.test_acl_manager()
print 'test credential manager...'
print('test credential manager...')
test_credentials.test_credential_manager()
print 'test conf manager...'
print('test conf manager...')
test_conf_manager.test_conf_manager()
print 'test user access...'
print('test user access...')
test_user_access.test_user_access()
print 'test hec config...'
print('test hec config...')
test_hec_config.test_hec_config()
print 'test hec eventwriter...'
print('test hec eventwriter...')
test_hec_event_writer.test_hec_event_writer()
print 'test time parser...'
print('test time parser...')
test_time_parser.test_time_parser()

if __name__ == '__main__':
teardown_environment()
setup_environment()
run_test()
print 'Run tests success.'
print('Run tests success.')
3 changes: 2 additions & 1 deletion examples/test_credentials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import range
import sys
import os.path as op
import pytest
Expand All @@ -19,7 +20,7 @@ def test_credential_manager():
cm.set_password('testuser1', 'password1')
assert cm.get_password('testuser1') == 'password1'

long_password = ''.join(['1111111111' for i in xrange(30)])
long_password = ''.join(['1111111111' for i in range(30)])
cm.set_password('testuser2', long_password)
assert cm.get_password('testuser2') == long_password

Expand Down
5 changes: 3 additions & 2 deletions examples/test_hec_event_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import range
import sys
import os.path as op

Expand All @@ -14,12 +15,12 @@ def test_hec_event_writer():

ew = hew.HECEventWriter("test", session_key)
m1 = {}
for i in xrange(100):
for i in range(100):
m1[i] = "test1 data %s" % i
e1 = ew.create_event(m1, index="main",
host="testing", sourcetype="hec")
m2 = {}
for i in xrange(100):
for i in range(100):
m2[i] = "test2 data %s" % i
e2 = ew.create_event(m2, index="main",
host="testing", sourcetype="hec")
Expand Down
3 changes: 2 additions & 1 deletion examples/test_kvstore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import range
import json
import os.path as op
import sys
Expand Down Expand Up @@ -27,7 +28,7 @@ def test_kvstore():
'user': 'string'}

last_ex = None
for i in xrange(3):
for i in range(3):
try:
kvstore.create('sessions', fields=fields)
break
Expand Down
19 changes: 10 additions & 9 deletions examples/test_server_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os.path as op
import sys

Expand All @@ -14,23 +15,23 @@ def test_server_info():

si = server_info.ServerInfo(session_key, scheme=context.scheme,
host=context.host, port=context.port)
print 'Local splunk server info'
print('Local splunk server info')

print ' -name: ', si.server_name
print(' -name: ', si.server_name)

print ' -version: ', si.version
print(' -version: ', si.version)

print ' -is a cluster captain: ', si.is_captain()
print(' -is a cluster captain: ', si.is_captain())

print ' -is a clound instance: ', si.is_cloud_instance()
print(' -is a clound instance: ', si.is_cloud_instance())

print ' -is a search head: ', si.is_search_head()
print(' -is a search head: ', si.is_search_head())

print ' -is a SHC member: ', si.is_shc_member()
print(' -is a SHC member: ', si.is_shc_member())

try:
shc_members = si.get_shc_members()
except server_info.ServerInfoException as e:
print e.message
print(e.message)
else:
print ' -SHC members are: ', shc_members
print(' -SHC members are: ', shc_members)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ setuptools-lint==0.4.1
pytest==2.9.1
pytest-cov==2.2.1
mock==2.0.0
requests==2.24.0
requests==2.24.0
future==0.18.2
pytest-expect
4 changes: 2 additions & 2 deletions solnlib/splunkenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def get_conf_stanzas(conf_name):
conf_name = conf_name[:-5]

# TODO: dynamically caculate SPLUNK_HOME
btool_cli = [op.join(os.environ['SPLUNK_HOME'], 'bin', 'btool'),
conf_name, 'list']
btool_cli = [op.join(os.environ['SPLUNK_HOME'], 'bin', 'splunk'),
'cmd', 'btool', conf_name, 'list']
p = subprocess.Popen(btool_cli,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, args, bufsize=0, executable=None,
preexec_fn=None, close_fds=False, shell=False,
cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0):
self._conf = args[1]
self._conf = args[3]

def communicate(self, input=None):
if self._conf == 'server':
Expand Down