From 1c754af2e134650d0a0b241256520204f59dd26f Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:15:05 -0400 Subject: [PATCH 01/39] Update config.yml --- .circleci/config.yml | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 90d04601..33c60c44 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,6 +50,59 @@ jobs: path: test-results - store_artifacts: path: htmlcov + + test-splunk: + parameters: + os: + type: executor + splunk: + type: string + executor: << parameters.os >> + steps: + - checkout + - 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: + name: setup Splunk + command: | + SPLUNK_VERSION = 8.0.5 + SPLUNK_BUILD = a1a6394cc5ae + SPLUNK_SLUG = $SPLUNK_VERSION-SPLUNK_BUILD + SPLUNK_ARCH = x86_64 + SPLUNK_LINUX_FILENAME = splunk-${SPLUNK_VERSION}-${SPLUNK_BUILD}-Linux-${SPLUNK_ARCH}.tgz + SPLUNK_LINUX_BUILD_URL = https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME} + wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} + tar -C /opt/splunk --strip 1 -zxf /tmp/splunk.tgz + ls /opt/splunk/bin + - run: + command: | + source .venv/bin/activate + python -m pytest --junitxml=test-results/results.xml --cov=solnlib --cov-report=html examples + name: Test + - store_test_results: + path: test-results + - store_artifacts: + path: test-results + - store_artifacts: + path: htmlcov + workflows: main: jobs: @@ -58,3 +111,8 @@ workflows: parameters: os: [linux] python-version: ["2.7.17", "3.7.4"] + - test-splunk: + matrix: + parameters: + os: [linux] + python-version: ["8.0.5"] From 94b580f5328233328c026498aa68c5e66c1fd6bf Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:17:00 -0400 Subject: [PATCH 02/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 33c60c44..9930e0e7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -115,4 +115,4 @@ workflows: matrix: parameters: os: [linux] - python-version: ["8.0.5"] + splunk-version: ["8.0.5"] From 0b1f65dfc9bf04002d47ade4d1b5bb0f08f2c8e8 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:17:45 -0400 Subject: [PATCH 03/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9930e0e7..d4517143 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,7 +55,7 @@ jobs: parameters: os: type: executor - splunk: + splunk-version: type: string executor: << parameters.os >> steps: From b4dd9361601e7a698d7c68beadf7ef0f0e819944 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:18:34 -0400 Subject: [PATCH 04/39] Update config.yml --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d4517143..52b82290 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,6 +57,8 @@ jobs: type: executor splunk-version: type: string + python-version: + type: string executor: << parameters.os >> steps: - checkout @@ -116,3 +118,4 @@ workflows: parameters: os: [linux] splunk-version: ["8.0.5"] + python-version: ["2.7.17", "3.7.4"] From bdd998b055f506dbe18deb4a42dff44c61791d06 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:19:39 -0400 Subject: [PATCH 05/39] Update config.yml --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 52b82290..9473511e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,6 +90,7 @@ jobs: SPLUNK_ARCH = x86_64 SPLUNK_LINUX_FILENAME = splunk-${SPLUNK_VERSION}-${SPLUNK_BUILD}-Linux-${SPLUNK_ARCH}.tgz SPLUNK_LINUX_BUILD_URL = https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME} + SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} tar -C /opt/splunk --strip 1 -zxf /tmp/splunk.tgz ls /opt/splunk/bin From c87657ce401b9ef0534505d7b9007befc7225d30 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:22:47 -0400 Subject: [PATCH 06/39] Update config.yml --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9473511e..1b987cf4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,7 +20,7 @@ jobs: executor: << parameters.os >> steps: - checkout - - python/load-cache + #- python/load-cache - run: name: install deps command: | @@ -62,7 +62,7 @@ jobs: executor: << parameters.os >> steps: - checkout - - python/load-cache + #- python/load-cache - run: name: install deps command: | From 31ac22a68b394c7113dfa1a026b17d3ece0a24d4 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 14:24:58 -0400 Subject: [PATCH 07/39] Update .python-version --- .python-version | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.python-version b/.python-version index a6164926..96d0210f 100644 --- a/.python-version +++ b/.python-version @@ -1 +1,3 @@ +2.7.17 2.7.18 +3.7.4 From 98b0c7f7015620f722e85ecf128255a97ff1b615 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:02:23 -0400 Subject: [PATCH 08/39] Update .python-version --- .python-version | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.python-version b/.python-version index 96d0210f..addd93e5 100644 --- a/.python-version +++ b/.python-version @@ -1,3 +1 @@ -2.7.17 -2.7.18 -3.7.4 +2.7.17 \ No newline at end of file From 56984f8a9521c946af1d015bc5f0158a31ddc1b0 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:04:59 -0400 Subject: [PATCH 09/39] Delete .python-version --- .python-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .python-version diff --git a/.python-version b/.python-version deleted file mode 100644 index addd93e5..00000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -2.7.17 \ No newline at end of file From 317e40f8790f452fa96adde31cee18676d85b4d1 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:10:00 -0400 Subject: [PATCH 10/39] Update config.yml --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1b987cf4..004d6d61 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,13 +84,13 @@ jobs: - run: name: setup Splunk command: | - SPLUNK_VERSION = 8.0.5 - SPLUNK_BUILD = a1a6394cc5ae - SPLUNK_SLUG = $SPLUNK_VERSION-SPLUNK_BUILD - SPLUNK_ARCH = x86_64 - SPLUNK_LINUX_FILENAME = splunk-${SPLUNK_VERSION}-${SPLUNK_BUILD}-Linux-${SPLUNK_ARCH}.tgz - SPLUNK_LINUX_BUILD_URL = https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME} - SPLUNK_HOME=/opt/splunk + export SPLUNK_VERSION=8.0.5 + export SPLUNK_BUILD=a1a6394cc5ae + 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_LINUX_BUILD_URL=https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME} + export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} tar -C /opt/splunk --strip 1 -zxf /tmp/splunk.tgz ls /opt/splunk/bin From 5e19843dfe6cc63143a8637ca6cd1402d1d21464 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:16:10 -0400 Subject: [PATCH 11/39] Update config.yml --- .circleci/config.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 004d6d61..1e79d68d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: - checkout #- python/load-cache - run: - name: install deps + name: Install deps command: | pip install --upgrade pip pip install --upgrade virtualenv @@ -82,14 +82,16 @@ jobs: mkdir test-results || true - python/save-cache - run: - name: setup Splunk + name: Install Splunk command: | + export SPLUNK_PRODUCT=splunk export SPLUNK_VERSION=8.0.5 export SPLUNK_BUILD=a1a6394cc5ae 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_LINUX_BUILD_URL=https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME} + 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} tar -C /opt/splunk --strip 1 -zxf /tmp/splunk.tgz From 1eb3aae2ab04f03f2172b1534f0e9dcebf565dc0 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:21:10 -0400 Subject: [PATCH 12/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1e79d68d..20bf47ed 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,7 @@ jobs: echo $SPLUNK_BUILD_URL export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} - tar -C /opt/splunk --strip 1 -zxf /tmp/splunk.tgz + tar -C /opt -zxf /tmp/splunk.tgz ls /opt/splunk/bin - run: command: | From 0bd9a97fd01090a8dda68ee22b4314c7c22b973a Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:26:00 -0400 Subject: [PATCH 13/39] wip --- .circleci/config.yml | 2 +- .gitignore | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 20bf47ed..c399c14c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,7 @@ jobs: echo $SPLUNK_BUILD_URL export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} - tar -C /opt -zxf /tmp/splunk.tgz + sudo tar -C /opt -zxf /tmp/splunk.tgz ls /opt/splunk/bin - run: command: | diff --git a/.gitignore b/.gitignore index 5f48a64d..bc80f9a6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ solnlib.egg-info/ venv/* *.log tools/solution_lib_release_env/* +.python-version \ No newline at end of file From 8a7380a3b7a66c60495d50f3437e3313c7e414f2 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:32:54 -0400 Subject: [PATCH 14/39] Update config.yml --- .circleci/config.yml | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c399c14c..ecae2a05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,10 +62,27 @@ jobs: executor: << parameters.os >> steps: - checkout + - run: + name: Install Splunk + command: | + export SPLUNK_PRODUCT=splunk + export SPLUNK_VERSION=8.0.5 + export SPLUNK_BUILD=a1a6394cc5ae + 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 + ls $SPLUNK_HOME/etc/apps #- python/load-cache - run: name: Install deps command: | + export SPLUNK_HOME=/opt/splunk pip install --upgrade pip pip install --upgrade virtualenv unset PYENV_ROOT @@ -81,21 +98,6 @@ jobs: pip install -e . mkdir test-results || true - python/save-cache - - run: - name: Install Splunk - command: | - export SPLUNK_PRODUCT=splunk - export SPLUNK_VERSION=8.0.5 - export SPLUNK_BUILD=a1a6394cc5ae - 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 - ls /opt/splunk/bin - run: command: | source .venv/bin/activate From 1cae354b40e5f32b020a7dddd0dcfaf6ccf73d92 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:33:49 -0400 Subject: [PATCH 15/39] Update config.yml --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ecae2a05..b43956c3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,9 @@ jobs: export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} sudo tar -C /opt -zxf /tmp/splunk.tgz + sudo chown $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps + ls $SPLUNK_HOME/etc/apps #- python/load-cache - run: From 4125359c4c34ad4b631a021ab7a33713e9f2135e Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:33:56 -0400 Subject: [PATCH 16/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b43956c3..43000f68 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,7 @@ jobs: export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} sudo tar -C /opt -zxf /tmp/splunk.tgz - sudo chown $USER:$USER /opt/splunk + sudo chown -r $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps ls $SPLUNK_HOME/etc/apps From 837f8fde8230e2696339f36169a03e355277c79c Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:35:18 -0400 Subject: [PATCH 17/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 43000f68..fe75d8e1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,7 @@ jobs: export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} sudo tar -C /opt -zxf /tmp/splunk.tgz - sudo chown -r $USER:$USER /opt/splunk + sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps ls $SPLUNK_HOME/etc/apps From 5e093bd40629cb7a25d7415c04b93a24a25b01de Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:43:03 -0400 Subject: [PATCH 18/39] Update config.yml --- .circleci/config.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fe75d8e1..8e192243 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -78,8 +78,10 @@ jobs: sudo tar -C /opt -zxf /tmp/splunk.tgz sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps - - ls $SPLUNK_HOME/etc/apps + echo [user_info] >$SPLUNK_HOME/etc/system/local + echo USERNAME=Admin >$SPLUNK_HOME/etc/system/local + echo PASSWORD=Chang3d! >$SPLUNK_HOME/etc/system/local + /opt/splunk/bin/splunk start --accept-license #- python/load-cache - run: name: Install deps From af7d0987b2d38fa4f47819de806a4cf9f8b9e196 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:44:16 -0400 Subject: [PATCH 19/39] Update config.yml --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e192243..7273d1f4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -78,9 +78,9 @@ jobs: sudo tar -C /opt -zxf /tmp/splunk.tgz sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps - echo [user_info] >$SPLUNK_HOME/etc/system/local - echo USERNAME=Admin >$SPLUNK_HOME/etc/system/local - echo PASSWORD=Chang3d! >$SPLUNK_HOME/etc/system/local + 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: From 9a0f438ffece0ad7cf2af560e5f1e7a7c1e5d19d Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 15:49:14 -0400 Subject: [PATCH 20/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7273d1f4..0a4ba071 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,7 +86,6 @@ jobs: - run: name: Install deps command: | - export SPLUNK_HOME=/opt/splunk pip install --upgrade pip pip install --upgrade virtualenv unset PYENV_ROOT @@ -104,6 +103,7 @@ jobs: - python/save-cache - run: command: | + export SPLUNK_HOME=/opt/splunk source .venv/bin/activate python -m pytest --junitxml=test-results/results.xml --cov=solnlib --cov-report=html examples name: Test From b86a65947ad8996f6419a81a6dac08cc4abae5c8 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 16:00:45 -0400 Subject: [PATCH 21/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0a4ba071..5305afca 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -105,7 +105,7 @@ jobs: command: | export SPLUNK_HOME=/opt/splunk source .venv/bin/activate - python -m pytest --junitxml=test-results/results.xml --cov=solnlib --cov-report=html examples + python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: path: test-results From c685eccdf49ec219dc986f66752fdf5dae93cbfd Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 17:05:19 -0400 Subject: [PATCH 22/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5305afca..f7d9dfcd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,8 +103,8 @@ jobs: - python/save-cache - run: command: | - export SPLUNK_HOME=/opt/splunk source .venv/bin/activate + export SPLUNK_HOME=/opt/splunk python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: From 83b1a46afedcd91ecc24b40f1128e19ae9275c0b Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 17:14:40 -0400 Subject: [PATCH 23/39] Update config.yml --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f7d9dfcd..a53e341a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -104,8 +104,9 @@ jobs: - run: command: | source .venv/bin/activate - export SPLUNK_HOME=/opt/splunk - python -m pytest --junitxml=test-results/results.xml -v examples + export SPLUNK_HOME=/opt/splunk + ls /opt/splunk/bin + SPLUNK_HOME=/opt/splunk python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: path: test-results From 906da973f37891b532ebf32cb0d96cef21cb7029 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 17:20:04 -0400 Subject: [PATCH 24/39] Update config.yml --- .circleci/config.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a53e341a..b8295bbb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -104,9 +104,8 @@ jobs: - run: command: | source .venv/bin/activate - export SPLUNK_HOME=/opt/splunk - ls /opt/splunk/bin - SPLUNK_HOME=/opt/splunk python -m pytest --junitxml=test-results/results.xml -v examples + source /opt/splunk/bin/setSplunkEnv + python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: path: test-results From 20009508d57fcf5ebb6672daa3bece417843efd3 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:12:14 -0400 Subject: [PATCH 25/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b8295bbb..14a70394 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,8 +103,8 @@ jobs: - python/save-cache - run: command: | - source .venv/bin/activate source /opt/splunk/bin/setSplunkEnv + source .venv/bin/activate python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: From 5046ed475969eaf1ff9a68e1a545175a33d5d893 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:18:53 -0400 Subject: [PATCH 26/39] Update config.yml --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 14a70394..380f1907 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,9 +103,8 @@ jobs: - python/save-cache - run: command: | - source /opt/splunk/bin/setSplunkEnv source .venv/bin/activate - python -m pytest --junitxml=test-results/results.xml -v examples + SPLUNK_HOME=/opt/splunk/ python -m pytest --junitxml=test-results/results.xml -v examples name: Test - store_test_results: path: test-results From 68f58d6b1ecbf075b008f2b6213a81f4144954d9 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:30:56 -0400 Subject: [PATCH 27/39] Update splunkenv.py --- solnlib/splunkenv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solnlib/splunkenv.py b/solnlib/splunkenv.py index d8bc31f1..db62e94e 100644 --- a/solnlib/splunkenv.py +++ b/solnlib/splunkenv.py @@ -265,7 +265,7 @@ 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'), + btool_cli = [op.join(os.environ['SPLUNK_HOME'], 'bin', 'splunk', 'cmd', 'btool'), conf_name, 'list'] p = subprocess.Popen(btool_cli, stdout=subprocess.PIPE, From dd572d1f5ca41a801c42c3d967564f9848446854 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:37:37 -0400 Subject: [PATCH 28/39] Update splunkenv.py --- solnlib/splunkenv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solnlib/splunkenv.py b/solnlib/splunkenv.py index db62e94e..86786cd6 100644 --- a/solnlib/splunkenv.py +++ b/solnlib/splunkenv.py @@ -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', 'splunk', 'cmd', '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) From 399edf130dd8b6e2dda8a69f728acffcf1206ed6 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:49:32 -0400 Subject: [PATCH 29/39] matrix --- .circleci/config.yml | 7 ++++--- .gitignore | 2 +- .gitmodules | 3 +++ deps/build/addonfactory_test_matrix_splunk | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .gitmodules create mode 160000 deps/build/addonfactory_test_matrix_splunk diff --git a/.circleci/config.yml b/.circleci/config.yml index 380f1907..13c50ccb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,9 +65,10 @@ jobs: - run: name: Install Splunk command: | + pip install git+https://github.com/pixelb/crudini export SPLUNK_PRODUCT=splunk - export SPLUNK_VERSION=8.0.5 - export SPLUNK_BUILD=a1a6394cc5ae + export SPLUNK_VERSION=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<>" VERSION) + export SPLUNK_BUILD=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<>" 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 @@ -125,5 +126,5 @@ workflows: matrix: parameters: os: [linux] - splunk-version: ["8.0.5"] + splunk-version: ["7.2", "7.3", "8.0"] python-version: ["2.7.17", "3.7.4"] diff --git a/.gitignore b/.gitignore index bc80f9a6..73b389ef 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ .coverage* *.idea *.DS_Store* -build +/build dist docs/_build docs/solnlib diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..803ee42f --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/deps/build/addonfactory_test_matrix_splunk b/deps/build/addonfactory_test_matrix_splunk new file mode 160000 index 00000000..a1bb9adb --- /dev/null +++ b/deps/build/addonfactory_test_matrix_splunk @@ -0,0 +1 @@ +Subproject commit a1bb9adbc0a58e4530b1826f9352bd117ebc482a From 5f881a19aea72891eef094f19c11fae5887bcf8d Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 18:51:12 -0400 Subject: [PATCH 30/39] Update config.yml --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 13c50ccb..e4c15e32 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,6 +62,8 @@ jobs: executor: << parameters.os >> steps: - checkout + - run: git submodule sync + - run: git submodule update --init - run: name: Install Splunk command: | From be5fa10d9c23738e7e2bfb9a31d485bb6c5a4d8a Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 19:54:20 -0400 Subject: [PATCH 31/39] Update common.py --- tests/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.py b/tests/common.py index 3eb6aa2c..7cc94bea 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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[2] def communicate(self, input=None): if self._conf == 'server': From 7d478834c85ff50da99f2f45187c61865b09f28d Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 19:54:23 -0400 Subject: [PATCH 32/39] Update .gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 73b389ef..114d528f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ solnlib.egg-info/ venv/* *.log tools/solution_lib_release_env/* -.python-version \ No newline at end of file +.python-version +.venv +.vscode/settings.json From 7bdbb61c8f79e838239d8b67996238b3ae18802a Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:06:30 -0400 Subject: [PATCH 33/39] Update common.py --- tests/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.py b/tests/common.py index 7cc94bea..a911371e 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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[2] + self._conf = args[3] def communicate(self, input=None): if self._conf == 'server': From 9a7221c7dfd3782feacd12c7d789a20217edf6cd Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:33:49 -0400 Subject: [PATCH 34/39] Install the library in the test app --- .circleci/config.yml | 1 + examples/main.py | 33 ++++++------ examples/main.py.bak | 77 +++++++++++++++++++++++++++ examples/test_credentials.py | 3 +- examples/test_credentials.py.bak | 32 +++++++++++ examples/test_hec_event_writer.py | 5 +- examples/test_hec_event_writer.py.bak | 26 +++++++++ examples/test_kvstore.py | 3 +- examples/test_kvstore.py.bak | 69 ++++++++++++++++++++++++ examples/test_server_info.py | 19 +++---- examples/test_server_info.py.bak | 36 +++++++++++++ 11 files changed, 275 insertions(+), 29 deletions(-) create mode 100644 examples/main.py.bak create mode 100644 examples/test_credentials.py.bak create mode 100644 examples/test_hec_event_writer.py.bak create mode 100644 examples/test_kvstore.py.bak create mode 100644 examples/test_server_info.py.bak diff --git a/.circleci/config.yml b/.circleci/config.yml index e4c15e32..5f76f2d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,6 +81,7 @@ jobs: sudo tar -C /opt -zxf /tmp/splunk.tgz sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps + sudo cp -r solnlib $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 diff --git a/examples/main.py b/examples/main.py index a16143d7..8e91fed6 100644 --- a/examples/main.py +++ b/examples/main.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import os import os.path as op @@ -18,8 +19,8 @@ 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) @@ -27,9 +28,9 @@ def setup_environment(): 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) @@ -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.') diff --git a/examples/main.py.bak b/examples/main.py.bak new file mode 100644 index 00000000..a16143d7 --- /dev/null +++ b/examples/main.py.bak @@ -0,0 +1,77 @@ +import sys +import os +import os.path as op +import shutil + +sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) +from solnlib.splunkenv import make_splunkhome_path +from solnlib.splunkenv import get_splunk_bin +import context + +splunk_bin = get_splunk_bin() +source_dir = op.join(op.dirname(op.abspath(__file__)), 'data', context.app) +target_dir = make_splunkhome_path(['etc', 'apps', context.app]) +solnlib_lib_dir = op.join( + op.dirname(op.dirname(op.abspath(__file__))), 'solnlib') +solnlib_lib_target_dir = make_splunkhome_path( + ['etc', 'apps', context.app, 'bin', 'solnlib']) + + +def setup_environment(): + 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...' + os.system(splunk_bin + ' stop') + print 'Removing %s' % target_dir + if op.exists(target_dir): + shutil.rmtree(target_dir) + + +def run_test(): + import test_splunkenv + import test_server_info + import test_kvstore + import test_metadata + import test_acl + import test_credentials + import test_conf_manager + import test_user_access + import test_hec_config + import test_hec_event_writer + import test_time_parser + + print 'check splunk environment...' + test_splunkenv.test_splunkenv() + print 'check splunk server info...' + test_server_info.test_server_info() + print 'test kvstore...' + test_kvstore.test_kvstore() + print 'test metadata reader...' + test_metadata.test_metadata_reader() + print 'test acl manager...' + test_acl.test_acl_manager() + print 'test credential manager...' + test_credentials.test_credential_manager() + print 'test conf manager...' + test_conf_manager.test_conf_manager() + print 'test user access...' + test_user_access.test_user_access() + print 'test hec config...' + test_hec_config.test_hec_config() + print 'test hec eventwriter...' + test_hec_event_writer.test_hec_event_writer() + print 'test time parser...' + test_time_parser.test_time_parser() + +if __name__ == '__main__': + teardown_environment() + setup_environment() + run_test() + print 'Run tests success.' diff --git a/examples/test_credentials.py b/examples/test_credentials.py index 403bc17d..5d94d512 100644 --- a/examples/test_credentials.py +++ b/examples/test_credentials.py @@ -1,3 +1,4 @@ +from builtins import range import sys import os.path as op import pytest @@ -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 diff --git a/examples/test_credentials.py.bak b/examples/test_credentials.py.bak new file mode 100644 index 00000000..403bc17d --- /dev/null +++ b/examples/test_credentials.py.bak @@ -0,0 +1,32 @@ +import sys +import os.path as op +import pytest + +sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) +from solnlib import credentials +import context + + +def test_credential_manager(): + session_key = credentials.get_session_key( + context.username, context.password, scheme=context.scheme, + host=context.host, port=context.port) + + cm = credentials.CredentialManager(session_key, context.app, owner=context.owner, + realm=context.app, scheme=context.scheme, + host=context.host, port=context.port) + + cm.set_password('testuser1', 'password1') + assert cm.get_password('testuser1') == 'password1' + + long_password = ''.join(['1111111111' for i in xrange(30)]) + cm.set_password('testuser2', long_password) + assert cm.get_password('testuser2') == long_password + + cm.delete_password('testuser1') + with pytest.raises(credentials.CredentialNotExistException): + cm.get_password('testuser1') + + cm.delete_password('testuser2') + with pytest.raises(credentials.CredentialNotExistException): + cm.get_password('testuser2') diff --git a/examples/test_hec_event_writer.py b/examples/test_hec_event_writer.py index 36cb8d88..f5ff1226 100644 --- a/examples/test_hec_event_writer.py +++ b/examples/test_hec_event_writer.py @@ -1,3 +1,4 @@ +from builtins import range import sys import os.path as op @@ -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") diff --git a/examples/test_hec_event_writer.py.bak b/examples/test_hec_event_writer.py.bak new file mode 100644 index 00000000..36cb8d88 --- /dev/null +++ b/examples/test_hec_event_writer.py.bak @@ -0,0 +1,26 @@ +import sys +import os.path as op + +sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) +import context +from solnlib import credentials +from solnlib.modular_input import event_writer as hew + + +def test_hec_event_writer(): + session_key = credentials.get_session_key( + context.username, context.password, scheme=context.scheme, + host=context.host, port=context.port) + + ew = hew.HECEventWriter("test", session_key) + m1 = {} + for i in xrange(100): + m1[i] = "test1 data %s" % i + e1 = ew.create_event(m1, index="main", + host="testing", sourcetype="hec") + m2 = {} + for i in xrange(100): + m2[i] = "test2 data %s" % i + e2 = ew.create_event(m2, index="main", + host="testing", sourcetype="hec") + ew.write_events([e1, e2]) diff --git a/examples/test_kvstore.py b/examples/test_kvstore.py index 42eebdd0..a97eba8c 100644 --- a/examples/test_kvstore.py +++ b/examples/test_kvstore.py @@ -1,3 +1,4 @@ +from builtins import range import json import os.path as op import sys @@ -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 diff --git a/examples/test_kvstore.py.bak b/examples/test_kvstore.py.bak new file mode 100644 index 00000000..42eebdd0 --- /dev/null +++ b/examples/test_kvstore.py.bak @@ -0,0 +1,69 @@ +import json +import os.path as op +import sys +import time +import uuid + +import pytest + +sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) +from solnlib.credentials import get_session_key +import context +from solnlib.packages.splunklib import binding +from solnlib.packages.splunklib import client +from solnlib.packages.splunklib.binding import HTTPError + + +def test_kvstore(): + session_key = get_session_key( + context.username, context.password, scheme=context.scheme, + host=context.host, port=context.port) + kvstore = client.Service( + scheme=context.scheme, host=context.host, port=context.port, + token=session_key, app=context.app, owner=context.owner, + autologin=True).kvstore + fields = {'id': 'string', + 'name': 'string', + 'user': 'string'} + + last_ex = None + for i in xrange(3): + try: + kvstore.create('sessions', fields=fields) + break + except binding.HTTPError as e: + last_ex = e + time.sleep(2 ** (i + 1)) + else: + if last_ex: + raise last_ex + + collections = kvstore.list() + collection_data = None + for collection in collections: + if collection.name == 'sessions': + collection_data = collection.data + break + assert collection_data + + record = {'id': uuid.uuid4().hex, + 'name': 'session1', + 'user': 'admin'} + _key = collection_data.insert(json.dumps(record))['_key'] + resp_record = collection_data.query_by_id(_key) + resp_record = {key: resp_record[key] + for key in resp_record if not key.startswith('_')} + assert sorted(resp_record.values()) == sorted(record.values()) + + record = {'id': uuid.uuid4().hex, + 'name': 'session4', + 'user': 'test'} + collection_data.update(_key, json.dumps(record)) + resp_record = collection_data.query_by_id(_key) + resp_record = {key: resp_record[key] + for key in resp_record if not key.startswith('_')} + assert sorted(resp_record.values()) == sorted(record.values()) + + collection_data.delete_by_id(_key) + with pytest.raises(HTTPError): + collection_data.query_by_id(_key) diff --git a/examples/test_server_info.py b/examples/test_server_info.py index bdef68a1..6c9b7669 100644 --- a/examples/test_server_info.py +++ b/examples/test_server_info.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os.path as op import sys @@ -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) diff --git a/examples/test_server_info.py.bak b/examples/test_server_info.py.bak new file mode 100644 index 00000000..bdef68a1 --- /dev/null +++ b/examples/test_server_info.py.bak @@ -0,0 +1,36 @@ +import os.path as op +import sys + +sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) +from solnlib import server_info +from solnlib.credentials import get_session_key +import context + + +def test_server_info(): + session_key = get_session_key( + context.username, context.password, scheme=context.scheme, + host=context.host, port=context.port) + + si = server_info.ServerInfo(session_key, scheme=context.scheme, + host=context.host, port=context.port) + print 'Local splunk server info' + + print ' -name: ', si.server_name + + print ' -version: ', si.version + + print ' -is a cluster captain: ', si.is_captain() + + print ' -is a clound instance: ', si.is_cloud_instance() + + print ' -is a search head: ', si.is_search_head() + + 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 + else: + print ' -SHC members are: ', shc_members From 1a56ec00bf79ddbb6cfbaa9dd3a0bed54aab3bfc Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:42:24 -0400 Subject: [PATCH 35/39] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c2b58e30..cf75b5e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ setuptools-lint==0.4.1 pytest==2.9.1 pytest-cov==2.2.1 mock==2.0.0 -requests==2.24.0 \ No newline at end of file +requests==2.24.0 +future==0.18.2 \ No newline at end of file From c497d527eef251b136607165782f6a6c9f6efc47 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:50:10 -0400 Subject: [PATCH 36/39] Update config.yml --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f76f2d8..f6e60470 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,7 +81,8 @@ jobs: sudo tar -C /opt -zxf /tmp/splunk.tgz sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps - sudo cp -r solnlib $SPLUNK_HOME/etc/apps/solnlib_demo/bin + sudo cp -r solnlib $SPLUNK_HOME/etc/apps/solnlib_demo/bin/ + 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 From 5cdc88d82d40f2eda89eae80863fedd63fe9ece5 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:52:55 -0400 Subject: [PATCH 37/39] cleaup --- examples/main.py.bak | 77 --------------------------- examples/test_credentials.py.bak | 32 ----------- examples/test_hec_event_writer.py.bak | 26 --------- examples/test_kvstore.py.bak | 69 ------------------------ examples/test_server_info.py.bak | 36 ------------- 5 files changed, 240 deletions(-) delete mode 100644 examples/main.py.bak delete mode 100644 examples/test_credentials.py.bak delete mode 100644 examples/test_hec_event_writer.py.bak delete mode 100644 examples/test_kvstore.py.bak delete mode 100644 examples/test_server_info.py.bak diff --git a/examples/main.py.bak b/examples/main.py.bak deleted file mode 100644 index a16143d7..00000000 --- a/examples/main.py.bak +++ /dev/null @@ -1,77 +0,0 @@ -import sys -import os -import os.path as op -import shutil - -sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) -from solnlib.splunkenv import make_splunkhome_path -from solnlib.splunkenv import get_splunk_bin -import context - -splunk_bin = get_splunk_bin() -source_dir = op.join(op.dirname(op.abspath(__file__)), 'data', context.app) -target_dir = make_splunkhome_path(['etc', 'apps', context.app]) -solnlib_lib_dir = op.join( - op.dirname(op.dirname(op.abspath(__file__))), 'solnlib') -solnlib_lib_target_dir = make_splunkhome_path( - ['etc', 'apps', context.app, 'bin', 'solnlib']) - - -def setup_environment(): - 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...' - os.system(splunk_bin + ' stop') - print 'Removing %s' % target_dir - if op.exists(target_dir): - shutil.rmtree(target_dir) - - -def run_test(): - import test_splunkenv - import test_server_info - import test_kvstore - import test_metadata - import test_acl - import test_credentials - import test_conf_manager - import test_user_access - import test_hec_config - import test_hec_event_writer - import test_time_parser - - print 'check splunk environment...' - test_splunkenv.test_splunkenv() - print 'check splunk server info...' - test_server_info.test_server_info() - print 'test kvstore...' - test_kvstore.test_kvstore() - print 'test metadata reader...' - test_metadata.test_metadata_reader() - print 'test acl manager...' - test_acl.test_acl_manager() - print 'test credential manager...' - test_credentials.test_credential_manager() - print 'test conf manager...' - test_conf_manager.test_conf_manager() - print 'test user access...' - test_user_access.test_user_access() - print 'test hec config...' - test_hec_config.test_hec_config() - print 'test hec eventwriter...' - test_hec_event_writer.test_hec_event_writer() - print 'test time parser...' - test_time_parser.test_time_parser() - -if __name__ == '__main__': - teardown_environment() - setup_environment() - run_test() - print 'Run tests success.' diff --git a/examples/test_credentials.py.bak b/examples/test_credentials.py.bak deleted file mode 100644 index 403bc17d..00000000 --- a/examples/test_credentials.py.bak +++ /dev/null @@ -1,32 +0,0 @@ -import sys -import os.path as op -import pytest - -sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) -from solnlib import credentials -import context - - -def test_credential_manager(): - session_key = credentials.get_session_key( - context.username, context.password, scheme=context.scheme, - host=context.host, port=context.port) - - cm = credentials.CredentialManager(session_key, context.app, owner=context.owner, - realm=context.app, scheme=context.scheme, - host=context.host, port=context.port) - - cm.set_password('testuser1', 'password1') - assert cm.get_password('testuser1') == 'password1' - - long_password = ''.join(['1111111111' for i in xrange(30)]) - cm.set_password('testuser2', long_password) - assert cm.get_password('testuser2') == long_password - - cm.delete_password('testuser1') - with pytest.raises(credentials.CredentialNotExistException): - cm.get_password('testuser1') - - cm.delete_password('testuser2') - with pytest.raises(credentials.CredentialNotExistException): - cm.get_password('testuser2') diff --git a/examples/test_hec_event_writer.py.bak b/examples/test_hec_event_writer.py.bak deleted file mode 100644 index 36cb8d88..00000000 --- a/examples/test_hec_event_writer.py.bak +++ /dev/null @@ -1,26 +0,0 @@ -import sys -import os.path as op - -sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) -import context -from solnlib import credentials -from solnlib.modular_input import event_writer as hew - - -def test_hec_event_writer(): - session_key = credentials.get_session_key( - context.username, context.password, scheme=context.scheme, - host=context.host, port=context.port) - - ew = hew.HECEventWriter("test", session_key) - m1 = {} - for i in xrange(100): - m1[i] = "test1 data %s" % i - e1 = ew.create_event(m1, index="main", - host="testing", sourcetype="hec") - m2 = {} - for i in xrange(100): - m2[i] = "test2 data %s" % i - e2 = ew.create_event(m2, index="main", - host="testing", sourcetype="hec") - ew.write_events([e1, e2]) diff --git a/examples/test_kvstore.py.bak b/examples/test_kvstore.py.bak deleted file mode 100644 index 42eebdd0..00000000 --- a/examples/test_kvstore.py.bak +++ /dev/null @@ -1,69 +0,0 @@ -import json -import os.path as op -import sys -import time -import uuid - -import pytest - -sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) -from solnlib.credentials import get_session_key -import context -from solnlib.packages.splunklib import binding -from solnlib.packages.splunklib import client -from solnlib.packages.splunklib.binding import HTTPError - - -def test_kvstore(): - session_key = get_session_key( - context.username, context.password, scheme=context.scheme, - host=context.host, port=context.port) - kvstore = client.Service( - scheme=context.scheme, host=context.host, port=context.port, - token=session_key, app=context.app, owner=context.owner, - autologin=True).kvstore - fields = {'id': 'string', - 'name': 'string', - 'user': 'string'} - - last_ex = None - for i in xrange(3): - try: - kvstore.create('sessions', fields=fields) - break - except binding.HTTPError as e: - last_ex = e - time.sleep(2 ** (i + 1)) - else: - if last_ex: - raise last_ex - - collections = kvstore.list() - collection_data = None - for collection in collections: - if collection.name == 'sessions': - collection_data = collection.data - break - assert collection_data - - record = {'id': uuid.uuid4().hex, - 'name': 'session1', - 'user': 'admin'} - _key = collection_data.insert(json.dumps(record))['_key'] - resp_record = collection_data.query_by_id(_key) - resp_record = {key: resp_record[key] - for key in resp_record if not key.startswith('_')} - assert sorted(resp_record.values()) == sorted(record.values()) - - record = {'id': uuid.uuid4().hex, - 'name': 'session4', - 'user': 'test'} - collection_data.update(_key, json.dumps(record)) - resp_record = collection_data.query_by_id(_key) - resp_record = {key: resp_record[key] - for key in resp_record if not key.startswith('_')} - assert sorted(resp_record.values()) == sorted(record.values()) - - collection_data.delete_by_id(_key) - with pytest.raises(HTTPError): - collection_data.query_by_id(_key) diff --git a/examples/test_server_info.py.bak b/examples/test_server_info.py.bak deleted file mode 100644 index bdef68a1..00000000 --- a/examples/test_server_info.py.bak +++ /dev/null @@ -1,36 +0,0 @@ -import os.path as op -import sys - -sys.path.insert(0, op.dirname(op.dirname(op.abspath(__file__)))) -from solnlib import server_info -from solnlib.credentials import get_session_key -import context - - -def test_server_info(): - session_key = get_session_key( - context.username, context.password, scheme=context.scheme, - host=context.host, port=context.port) - - si = server_info.ServerInfo(session_key, scheme=context.scheme, - host=context.host, port=context.port) - print 'Local splunk server info' - - print ' -name: ', si.server_name - - print ' -version: ', si.version - - print ' -is a cluster captain: ', si.is_captain() - - print ' -is a clound instance: ', si.is_cloud_instance() - - print ' -is a search head: ', si.is_search_head() - - 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 - else: - print ' -SHC members are: ', shc_members From f048c2ec94493ddf2cb571bf92596a6f5480504d Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 20:57:07 -0400 Subject: [PATCH 38/39] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f6e60470..8c82d1d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -79,9 +79,9 @@ jobs: export SPLUNK_HOME=/opt/splunk wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL} sudo tar -C /opt -zxf /tmp/splunk.tgz - sudo chown -R $USER:$USER /opt/splunk sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps sudo cp -r solnlib $SPLUNK_HOME/etc/apps/solnlib_demo/bin/ + 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 From 3b8964b2869de7ce6b776212c28f129389d40a06 Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Tue, 11 Aug 2020 21:33:14 -0400 Subject: [PATCH 39/39] fix --- .circleci/config.yml | 1 + examples/.pytest.expect | 2 ++ requirements.txt | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 examples/.pytest.expect diff --git a/.circleci/config.yml b/.circleci/config.yml index 8c82d1d0..a7ca401c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,6 +81,7 @@ jobs: 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 diff --git a/examples/.pytest.expect b/examples/.pytest.expect new file mode 100644 index 00000000..cb39f936 --- /dev/null +++ b/examples/.pytest.expect @@ -0,0 +1,2 @@ +pytest-expect file v1 +(3, 7, 7, 'final', 0) diff --git a/requirements.txt b/requirements.txt index cf75b5e6..ed5c5a87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ pytest==2.9.1 pytest-cov==2.2.1 mock==2.0.0 requests==2.24.0 -future==0.18.2 \ No newline at end of file +future==0.18.2 +pytest-expect \ No newline at end of file