Skip to content

Commit

Permalink
Consolitate dev and test environments
Browse files Browse the repository at this point in the history
  • Loading branch information
john-odonnell committed Sep 18, 2023
1 parent c835429 commit 552bb2e
Show file tree
Hide file tree
Showing 62 changed files with 578 additions and 1,197 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ tests/*/coverage/
tests/*/junit/
tests/*/reports/

tests/*/conjur.pem
tests/*/conjur-enterprise.pem
tests/*/access_token
dev/conjur.pem
dev/access_token
dev/tmp

**/test-files/output
**/conjur-intro/
bot
coverage
junit
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dev/conjur-intro"]
path = dev/conjur-intro
url = https://github.com/conjurdemos/conjur-intro
110 changes: 73 additions & 37 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,67 +36,94 @@ pipeline {

stage('Run integration tests with Conjur Open Source') {
stages {
stage('Ansible v8 - latest') {
parallel {
stage('Testing conjur_variable lookup plugin') {
stage('Ansible v8 (core 2.15) - latest') {
stages {
stage('Deploy Conjur') {
steps {
sh './ci/test.sh -d conjur_variable'
junit 'tests/conjur_variable/junit/*'
sh './dev/start.sh -v 8'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -d conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
stage('Run tests') {
parallel {
stage('Testing conjur_variable lookup plugin') {
steps {
sh './ci/test.sh -d -t conjur_variable'
junit 'tests/conjur_variable/junit/*'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -d -t conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
}
}
}
}
}
}

stage('Ansible v7') {
stage('Ansible v7 (core 2.14)') {
when {
anyOf {
branch 'main'
buildingTag()
}
}
parallel {
stage('Testing conjur_variable lookup plugin') {
stages {
stage('Deploy Conjur') {
steps {
sh './ci/test.sh -v 7 -d conjur_variable'
junit 'tests/conjur_variable/junit/*'
sh './dev/start.sh -v 7'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -v 7 -d conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
stage('Run tests') {
parallel {
stage('Testing conjur_variable lookup plugin') {
steps {
sh './ci/test.sh -d -t conjur_variable'
junit 'tests/conjur_variable/junit/*'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -d -t conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
}
}
}
}
}
}

stage('Ansible v6 - latest') {
stage('Ansible v6 (core 2.13)') {
when {
anyOf {
branch 'main'
buildingTag()
}
}
parallel {
stage('Testing conjur_variable lookup plugin') {
stages {
stage('Deploy Conjur') {
steps {
sh './ci/test.sh -v 6 -d conjur_variable'
junit 'tests/conjur_variable/junit/*'
sh './dev/start.sh -v 6'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -v 6 -d conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
stage('Run tests') {
parallel {
stage('Testing conjur_variable lookup plugin') {
steps {
sh './ci/test.sh -d -t conjur_variable'
junit 'tests/conjur_variable/junit/*'
}
}

stage('Testing conjur_host_identity role') {
steps {
sh './ci/test.sh -d -t conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
}
}
}
}
}
Expand All @@ -106,17 +133,26 @@ pipeline {

stage('Run integration tests with Conjur Enterprise') {
stages {
stage("Testing conjur_variable lookup plugin") {
stage('Deploy Conjur Enterprise') {
steps {
sh './ci/test.sh -e -d conjur_variable'
junit 'tests/conjur_variable/junit/*'
sh './dev/start.sh -e -v 8'
}
}
stage('Run tests') {
parallel {
stage("Testing conjur_variable lookup plugin") {
steps {
sh './ci/test.sh -d -t conjur_variable'
junit 'tests/conjur_variable/junit/*'
}
}

stage("Testing conjur_host_identity role") {
steps {
sh './ci/test.sh -e -d conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
stage("Testing conjur_host_identity role") {
steps {
sh './ci/test.sh -d -t conjur_host_identity'
junit 'roles/conjur_host_identity/tests/junit/*'
}
}
}
}
}
Expand Down
153 changes: 82 additions & 71 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -ex
source "$(git rev-parse --show-toplevel)/dev/util.sh"

# Test runner for Ansible Conjur Collection

Expand All @@ -14,98 +15,108 @@ target=""
# Flags to be applied to testing scripts
flags=""

declare -x ANSIBLE_VERSION="${ANSIBLE_VERSION:-8}"
declare -x PYTHON_VERSION="${PYTHON_VERSION:-3.11}"
# Indicate whether to start a new test env or use an existing one
start_dev_env="true"

# Print usage instructions
function help {
echo "Test runner for Ansible Conjur Collection"

echo "-a Run all test files in default test directories"
echo "-v <ver> Run tests against the given Ansible major version"
echo "-p <ver> Run tests against an Ansible node using the given Python version"
echo "-d <arg> Run test file in given directory. Valid options are: ${test_directories[*]} all"
echo "-e Run tests against Conjur Enterprise. Default: Conjur Open Source"
echo " This option is currently only available when testing against the conjur_variable plugin"
echo "-h View help and available commands"
exit 1
cat <<EOF
Conjur Ansible Collection :: Test runner
$0 [options]
-a Run all test files in default test directories.
-d Run tests against the existing development environment. This option
overrides -e, -p and -v in favor of existing services.
-e Deploy Conjur Enterprise. (Default: Conjur Open Source)
-h Print usage information.
-p <version> Run the Ansible service with the desired Python version. (Default: 3.11)
-t Run test files in a given directory. Valid options are:
${test_directories[*]} ${role_directories[*]} all
-v <version> Run the Ansible service with the desired Ansible Community Package
version. (Default: 8)
EOF
}

# Run a `test.sh` file in a given subdirectory of the top-level `tests` directory
# Expected directory structure is "tests/<plugin>/test.sh"
function run_test {
pushd "${PWD}/tests/${1}"
echo "Running ${1} tests..."
./test.sh "$flags"
popd
pushd "${PWD}/tests/${1}"
echo "Running ${1} tests..."
./test.sh "$flags"
popd
}

# Run a `test.sh` file for a given role
# Expected directory structure is "roles/<role>/tests/test.sh"
function run_role_test {
pushd "${PWD}/roles/${1}/tests"
echo "Running ${1} tests..."
./test.sh "$flags"
popd
pushd "${PWD}/roles/${1}/tests"
echo "Running ${1} tests..."
./test.sh "$flags"
popd
}

# Handles input to dictate wether all tests should be ran, or just one set
function handle_input {
if [[ -n ${target} ]]; then
for test_dir in "${test_directories[@]}"; do
if [[ ${target} == "${test_dir}" ]]; then
run_test ${target}
exit 0
fi
done
for test_dir in "${role_directories[@]}"; do
if [[ ${target} == "${test_dir}" ]]; then
run_role_test ${target}
exit 0
fi
done
echo "Error: unrecognized test directory given: ${target}"
echo ""
help
else
echo "Running all tests..."
for test_dir in "${test_directories[@]}"; do
run_test "${test_dir}"
done
for test_dir in "${role_directories[@]}"; do
run_role_test "${test_dir}"
done
function run_tests {
if [[ "$target" == "all" ]]; then
echo "Running all tests..."
for test_dir in "${test_directories[@]}"; do
run_test "${test_dir}"
done
for test_dir in "${role_directories[@]}"; do
run_role_test "${test_dir}"
done
exit 0
else
for test_dir in "${test_directories[@]}"; do
if [[ "$target" == "$test_dir" ]]; then
run_test "$target"
exit 0
fi
done
for test_dir in "${role_directories[@]}"; do
if [[ ${target} == "${test_dir}" ]]; then
run_role_test ${target}
exit 0
fi
fi
echo "Error: unrecognized test directory given: ${target}"
echo ""
help
done
fi
}

# Exit if no input given
if [[ $# -eq 0 ]] ; then
echo "Error: No test directory or flag given"
echo ""
help
echo "Error: No test directory or flag given"
echo ""
help
exit 1
fi

while getopts ad:ehv:p: option; do
case "$option" in
a) handle_input
;;
d) target=${OPTARG}
handle_input
;;
e) flags="-e"
;;
h) help
;;
v) ANSIBLE_VERSION="${OPTARG}"
;;
p) PYTHON_VERSION="${OPTARG}"
;;
* )
echo "$1 is not a valid option"
help
exit 1
;;
esac
while getopts adehp:t:v: option; do
case "$option" in
a) target='all' ;;
d) start_dev_env="false" ;;
e) flags="$flags -e" ;;
h) help && exit 0 ;;
p) flags="$flags -p ${OPTARG}" ;;
t) target="${OPTARG}" ;;
v) flags="$flags -v ${OPTARG}" ;;
*)
echo "$1 is not a valid option"
help
exit 1 ;;
esac
done

function main {
if [[ "$start_dev_env" == "true" ]]; then
pushd "$(dev_dir)"
./start.sh "$flags"
popd
fi

run_tests
}

main
Loading

0 comments on commit 552bb2e

Please sign in to comment.