Skip to content

Commit

Permalink
v1.6.1 (#32)
Browse files Browse the repository at this point in the history
## v1.6.1

|||
|---|---|
|Date|2022-09
|Kind| BUGFIX release
|Author|mschiess@akamai.com

- **Minor improvements** 
  - Dropped CLI installation verification for CLI's not used by ULS
- **Housekeeping**
  - Added parallel testing processes to speed up testing (see [Testing Readme](../test/README.md))
  - added randomization tokens for "mocked" edgerc file (to avoid race condition in prallel testing)
  • Loading branch information
MikeSchiessl committed Oct 5, 2022
1 parent 72d97f5 commit d6859db
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bin/config/global_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

# Common global variables / constants
__version__ = "1.6.0"
__version__ = "1.6.1"
__tool_name_long__ = "Akamai Unified Log Streamer"
__tool_name_short__ = "ULS"

Expand Down
35 changes: 21 additions & 14 deletions bin/modules/UlsTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import config.global_config as uls_config


def uls_check_sys(root_path):
def uls_check_sys(root_path, uls_input=None):
"""
Collect ULS requirements information and request input if failing
"""
Expand All @@ -36,30 +36,37 @@ def _check_cli_installed(cli_bin):
aka_log.log.warning(f"Uhoh - seems like {cli_bin} is not installed. "
f"Please follow docs/COMMAND_LINE_USAGE.md "
f"to setup the required environment cli tools")
skip_verification = input("Continue anyway ? (y|N)")
if skip_verification.lower() == "y" or skip_verification.lower() == "yes":
print(f"Continuing without {cli_bin} - please be do not use any stream this cli provides")
else:
aka_log.log.critical(f"Missing {cli_bin} - exiting")
sys.exit(1)
#skip_verification = input("Continue anyway ? (y|N)")
#if skip_verification.lower() == "y" or skip_verification.lower() == "yes":
# print(f"Continuing without {cli_bin} - please be do not use any stream this cli provides")
#else:
aka_log.log.critical(f"Missing {cli_bin} - exiting")
sys.exit(1)
else:
return True
except Exception as my_error:
aka_log.log.critical(f"Error checking the cli'tools ")

_check_cli_installed(root_path + "/" + uls_config.bin_eaa_cli)
_check_cli_installed(root_path + "/" + uls_config.bin_etp_cli)
_check_cli_installed(root_path + "/" + uls_config.bin_mfa_cli)
_check_cli_installed(root_path + "/" + uls_config.bin_gc_cli)
_check_cli_installed(root_path + "/" + uls_config.bin_linode_cli)
if uls_input == "EAA":
_check_cli_installed(root_path + "/" + uls_config.bin_eaa_cli)
elif uls_input == "ETP":
_check_cli_installed(root_path + "/" + uls_config.bin_etp_cli)
elif uls_input == "MFA":
_check_cli_installed(root_path + "/" + uls_config.bin_mfa_cli)
elif uls_input == "GC":
_check_cli_installed(root_path + "/" + uls_config.bin_gc_cli)
elif uls_input == "LINODE":
_check_cli_installed(root_path + "/" + uls_config.bin_linode_cli)
else:
aka_log.log.critical(f"No input specified: {uls_input} - exiting")
sys.exit(1)


def uls_version(root_path):
"""
Collect ULS Version information and display it on STDOUT
"""

my_edgerc_mock_file = root_path + "/" + uls_config.edgerc_mock_file
my_edgerc_mock_file = root_path + "/" + uls_config.edgerc_mock_file + str(round(time.time() * 1000))
def _get_cli_version(cli_bin, edgerc_mock_file):
try:
if "gc" in cli_bin or 'linode' in cli_bin:
Expand Down
2 changes: 1 addition & 1 deletion bin/uls.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main():
autoresume_file = autoresume_data['filename']

# Check CLI Environment
UlsTools.uls_check_sys(root_path=root_path)
UlsTools.uls_check_sys(root_path=root_path, uls_input=uls_args.input)

# Create & Start monitoring Instance
my_monitor = UlsMonitoring.UlsMonitoring(stopEvent=stopEvent,
Expand Down
15 changes: 15 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Version History

## v1.6.1

|||
|---|---|
|Date|2022-09
|Kind| BUGFIX release
|Author|mschiess@akamai.com

- **Minor improvements**
- Dropped CLI installation verification for CLI's not used by ULS
- **Housekeeping**
- Added parallel testing processes to speed up testing (see [Testing Readme](../test/README.md))
- added randomization tokens for "mocked" edgerc file (to avoid race condition in prallel testing)


## v1.6.0

|||
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kubernetes/helm/akamai-uls/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: akamai-uls
description: Akamai Universal Log Streamer Helm installation

type: application
version: 1.6.0
appVersion: "1.6.0"
version: 1.6.1
appVersion: "1.6.1"
8 changes: 7 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## BATS

We decided to go with [bats](https://bats-core.readthedocs.io/en/stable/) as it provides everything we need for automated cli testing.
We decided to go with [bats](https://bats-core.readthedocs.io/en/stable/) as it provides everything we need for automated cli testing.
### 20221004
Added "Bats" parallel jobs funktion (requires GNU prallel to work) in order to speed up testes



The bats job needs to get run from the GIT ULS root directory:
```bash
Expand All @@ -20,9 +24,11 @@ For better testing stability, we packed the required dependencies into the test
- [bats-assert](https://github.com/ztombol/bats-assert.git) checked out under `bats` directory
- [bats-support](https://github.com/ztombol/bats-support.git) checked out under `bats` directory
- `timeout` command is available
- "GNU parallel" --> `brew install parallel`
- ULS and the CLI's are installed
- working (fully fledged `.edgerc` file - or the inline MOCKED one)
- mocked edgerc is currently failing with EAA
- helm isntallation (linting)


## Installation
Expand Down
5 changes: 3 additions & 2 deletions test/basic_test.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bats

#BATS_NO_PARALLELIZE_WITHIN_FILE=true

# Variables
# ULS Binary
Expand All @@ -26,7 +27,7 @@ current_version=$(cat docs/CHANGELOG.md | grep "##" | head -n 1 | sed 's/.* v//'
}

@test "uls.py --version" {
run ${uls_bin} --version
run $uls_bin --version
assert_output --partial "Akamai Unified Log Streamer Version information"
[ "$status" -eq 0 ]
}
Expand All @@ -45,7 +46,7 @@ current_version=$(cat docs/CHANGELOG.md | grep "##" | head -n 1 | sed 's/.* v//'

@test "uls.py --version - Version output should be ($current_version) according to CHANGELOG" {
run $uls_bin --version
assert_output --partial "$current_version"
assert_output --partial $current_version
[ "$status" -eq 0 ]
}

Expand Down
4 changes: 2 additions & 2 deletions test/negative_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ load 'bats/bats-assert/load.bash'
}

@test "AUTORESUME - corrupt file (wrong quoting within file )" {
echo "{'aa': 'bb'}" > /tmp/uls_eaa_access.ckpt
run $uls_bin --input eaa --feed access --output raw --autoresume --autoresumepath /tmp/
echo "{'aa': 'bb'}" > /tmp/uls_eaa_admin.ckpt
run $uls_bin --input eaa --feed admin --output raw --autoresume --autoresumepath /tmp/
assert_output --partial "Expecting property name enclosed in double quotes: line 1 column 2 (char 1) - Exiting."
[ "$status" -eq 1 ]
rm -fr /tmp/uls_eaa_access.ckpt
Expand Down
52 changes: 26 additions & 26 deletions test/positive_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ uls_bin=bin/uls.py
mocked_edgerc=FALSE

# TIMEOUT
uls_test_timeout=60
uls_kill_timeout=90
uls_test_timeout=90
uls_kill_timeout=120


### Switch between mocked and real edgerc
Expand Down Expand Up @@ -51,28 +51,28 @@ load 'bats/bats-assert/load.bash'
assert_output --partial $eaa_access_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}
@test "EAA - ADMIN" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input eaa --feed admin --output raw --edgerc $uls_edgerc --section $uls_section
assert_output --partial ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}
@test "EAA - CONHEALTH" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input eaa --feed admin --output raw --edgerc $uls_edgerc --section $uls_section
assert_output ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}
@test "EAA - DEVINV" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input eaa --feed devinv --output raw --edgerc $uls_edgerc --section $uls_section
assert_output --partial $eaa_devinv_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## ETP
Expand All @@ -81,31 +81,31 @@ load 'bats/bats-assert/load.bash'
assert_output --partial $etp_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

@test "ETP - AUP" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed aup --output raw --edgerc $uls_edgerc --section $uls_section
assert_output --partial $etp_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

@test "ETP - DNS" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed dns --output raw --edgerc $uls_edgerc --section $uls_section
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed dns --output raw --edgerc $uls_edgerc --section $uls_section
assert_output --partial $etp_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

@test "ETP - PROXY" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed proxy --output raw --edgerc $uls_edgerc --section $uls_section
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed proxy --output raw --edgerc $uls_edgerc --section $uls_section
assert_output --partial $etp_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## MFA
Expand All @@ -114,7 +114,7 @@ load 'bats/bats-assert/load.bash'
assert_output ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## GUARDICORE
Expand All @@ -123,34 +123,34 @@ load 'bats/bats-assert/load.bash'
assert_output --partial $gc_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## LINODE
@test "LINODE - AUDIT" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input linode --feed audit --output raw --edgerc $uls_edgerc --section $uls_section
assert_output ""
assert_output --partial ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## FILE OUTPUT
@test "FILE: ETP - THREAT" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed threat --output file --filename "/tmp/uls_tmplogfile.log" --edgerc $uls_edgerc --section $uls_section
assert_output ""
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed threat --output file --filename "/tmp/uls_tmplogfile1.log" --edgerc $uls_edgerc --section $uls_section
assert_output --partial ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
rm -fr /tmp/uls_tmplogfile.log
}

@test "FILEACTION: ETP - THREAT" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed threat --output file --filename "/tmp/uls_tmplogfile.log" --filebackup 1 --fileaction "/bin/zip '%s'" --edgerc $uls_edgerc --section $uls_section
assert_output ""
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input etp --feed threat --output file --filename "/tmp/uls_tmplogfile2.log" --filebackup 1 --fileaction "/bin/zip '%s'" --edgerc $uls_edgerc --section $uls_section
assert_output --partial ""
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
rm -fr /tmp/uls_tmplogfile.log
}

Expand All @@ -160,15 +160,15 @@ load 'bats/bats-assert/load.bash'
assert_output --partial "detection_time"
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

@test "TRANSFORM - JMESPATH" {
run timeout --kill-after=$uls_kill_timeout --signal=2 --preserve-status $uls_test_timeout $uls_bin --input eaa --feed access --output raw --transformation jmespath --transformationpattern '[geo_country, geo_state]' --edgerc $uls_edgerc --section $uls_section
assert_output --partial $jmespath_assert
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
}

## AUTORESUME
Expand All @@ -179,11 +179,11 @@ load 'bats/bats-assert/load.bash'
#assert_output --partial " seems to be empty"
#assert_output --partial "The specified directory tmp does not exist or privileges are missing - exiting"
#[ "$status" -eq 124 ] #return value from timeout without --preserve status
[ "$status" -eq 100 ] #return value from uls when interrupted --> with --preserve status on timeout
[ "$status" -eq 100 ] || [ "$status" -eq 130 ] || [ "$status" -eq 2 ] #return value from uls when interrupted --> with --preserve status on timeout
rm -f /tmp/uls_eaa_access.ckpt
}

## EAA
## HELM LINT
@test "LINT the HELM CHART" {
run helm lint docs/examples/kubernetes/helm/akamai-uls --strict
assert_output --partial "0 chart(s) failed"
Expand Down
7 changes: 6 additions & 1 deletion test/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/bash
# test.sh [file - $tests_available] [regex merge]
tests_available="basic positive negative "
parallel_tests=10

function do_test() {
if [ -f "test/$1_test.bats" ] ; then
echo -e "$1 TESTING\n"
bats test/$1_test.bats $filter
if [ ${parallel_tests} > 1 ] ; then
bats --jobs ${parallel_tests} test/$1_test.bats $filter
else
bats test/$1_test.bats $filter
fi
my_exitcode=$?
if [ $my_exitcode -ne 0 ] ; then
echo "Test \"$1\" failed - exiting"
Expand Down

0 comments on commit d6859db

Please sign in to comment.