-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script for testing OpenStack manifest generation. Co-Authored-By: Matthew Booth <mbooth@redhat.com>
- Loading branch information
1 parent
64ec239
commit 3f25b03
Showing
6 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuxo pipefail | ||
|
||
[[ $(type -P yq) ]] || { >&2 echo "Required tool 'yq' not found in PATH" ; exit 1; } | ||
|
||
declare \ | ||
tests_dir='./scripts/openstack/manifest-tests' \ | ||
openshift_install='./bin/openshift-install' \ | ||
api_fip='' \ | ||
os_cloud='' \ | ||
external_network='' \ | ||
compute_flavor='' | ||
|
||
print_help() { | ||
set +x | ||
|
||
echo -e "Test the OpenStack manifest generation." | ||
echo | ||
echo -e "Required configuration:" | ||
echo | ||
echo -e "\\t-c\\tOS_CLOUD" | ||
echo -e "\\t-e\\tExternal network" | ||
echo -e "\\t-f\\tA valid flavor" | ||
echo | ||
echo -e "Use:" | ||
echo -e "\\t${0} -c <cloud> -e <external network> -f <flavor> [-a <fip>] [-i <openshift-install>] [-t <test-dir>]" | ||
echo | ||
echo -e 'Additional arguments:' | ||
echo -e "\\t-a\\tapiFloatingIP" | ||
echo -e "\\t-i\\tpath to openshift-install (defaults to '${openshift_install}')" | ||
echo -e "\\t-t\\tpath to the tests to be run (defaults to '${tests_dir}')" | ||
} | ||
|
||
fill_install_config() { | ||
declare -r \ | ||
template="$1" \ | ||
pull_secret="'"'{"auths":{"registry.svc.ci.openshift.org":{"auth":"QW4gYWN0dWFsIHB1bGwgc2VjcmV0IGlzIG5vdCBuZWNlc3NhcnkK"}}}'"'" | ||
|
||
sed ' | ||
s|${\?OS_CLOUD}\?|'"${os_cloud}"'|; | ||
s|${\?EXTERNAL_NETWORK}\?|'"${external_network}"'|; | ||
s|${\?COMPUTE_FLAVOR}\?|'"${compute_flavor}"'|; | ||
s|${\?API_FIP}\?|'"${api_fip}"'|; | ||
s|${\?PULL_SECRET}\?|'"${pull_secret}"'|; | ||
' "$template" | ||
} | ||
|
||
validate_configuration() { | ||
set +x | ||
declare -a required_values=("os_cloud" "external_network" "compute_flavor") | ||
declare fail=false | ||
|
||
for val in "${required_values[@]}"; do | ||
declare required=${!val:-} | ||
if [ -z "${required}" ]; then | ||
>&2 echo "Missing required argument '${val}'." | ||
fail=true | ||
fi | ||
done | ||
|
||
if [ "$fail" = true ]; then | ||
print_help | ||
exit 1 | ||
fi | ||
set -x | ||
} | ||
|
||
while getopts a:c:e:f:i:t:h o; do | ||
case "$o" in | ||
a) api_fip="$OPTARG" ;; | ||
c) os_cloud="$OPTARG" ;; | ||
e) external_network="$OPTARG" ;; | ||
f) compute_flavor="$OPTARG" ;; | ||
i) openshift_install="$OPTARG" ;; | ||
t) tests_dir="$OPTARG" ;; | ||
h) print_help; exit 0 ;; | ||
*) print_help; exit 1 ;; | ||
esac | ||
done | ||
readonly api_fip os_cloud external_network compute_flavor openshift_install tests_dir | ||
|
||
declare -a temp_dirs | ||
cleanup() { | ||
for temp_dir in "${temp_dirs[@]}"; do | ||
rm -rf "$temp_dir" | ||
done | ||
} | ||
trap cleanup EXIT | ||
|
||
validate_configuration | ||
|
||
>&2 echo "Running the tests from '${tests_dir}' against the Installer binary '${openshift_install}'." | ||
|
||
declare -i failed_tests=0 | ||
for testcase in "${tests_dir}"/* ; do | ||
if [ -d "$testcase" ]; then | ||
assets_dir="$(mktemp -d)" | ||
temp_dirs+=("$assets_dir") | ||
fill_install_config "${testcase}/install-config.yaml" > "${assets_dir}/install-config.yaml" | ||
"$openshift_install" create manifests --dir "$assets_dir" | ||
for t in "${testcase}"/*.sh; do | ||
if $t "$assets_dir"; then | ||
echo "PASS: '$t'" | ||
else | ||
declare -i f="$?" | ||
echo "FAIL: $f failed tests in '$t'." | ||
failed_tests=$((failed_tests+f)) | ||
fi | ||
done | ||
fi | ||
done | ||
|
||
if [ $failed_tests == 0 ]; then | ||
echo 'PASS' | ||
else | ||
echo "FAIL: ${failed_tests} failed tests." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
approvers: | ||
- openstack-approvers | ||
reviewers: | ||
- openstack-reviewers |
39 changes: 39 additions & 0 deletions
39
scripts/openstack/manifest-tests/additional-security-group/install-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: v1 | ||
baseDomain: shiftstack.example.com | ||
clusterID: manifests1 | ||
controlPlane: | ||
hyperthreading: Enabled | ||
architecture: amd64 | ||
name: master | ||
platform: | ||
openstack: | ||
type: ${COMPUTE_FLAVOR} | ||
additionalSecurityGroupIDs: | ||
- aaaaaaaa-bbbb-4ccc-dddd-111111111111 | ||
replicas: 3 | ||
compute: | ||
- name: worker | ||
platform: | ||
openstack: | ||
type: ${COMPUTE_FLAVOR} | ||
additionalSecurityGroupIDs: | ||
- aaaaaaaa-bbbb-4ccc-dddd-000000000000 | ||
replicas: 3 | ||
metadata: | ||
name: manifests1 | ||
networking: | ||
clusterNetwork: | ||
- cidr: 10.128.0.0/14 | ||
hostPrefix: 23 | ||
machineNetwork: | ||
- cidr: 10.0.128.0/17 | ||
networkType: OpenShiftSDN | ||
serviceNetwork: | ||
- 172.30.0.0/16 | ||
platform: | ||
openstack: | ||
cloud: ${OS_CLOUD} | ||
externalNetwork: ${EXTERNAL_NETWORK} | ||
computeFlavor: ${COMPUTE_FLAVOR} # deprecated in 4.7 | ||
lbFloatingIP: ${API_FIP} | ||
pullSecret: ${PULL_SECRET} |
31 changes: 31 additions & 0 deletions
31
scripts/openstack/manifest-tests/additional-security-group/test_masters.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuxo pipefail | ||
|
||
declare -r assets_dir="$1" | ||
|
||
declare -a machines=( | ||
"${assets_dir}/openshift/99_openshift-cluster-api_master-machines-0.yaml" | ||
"${assets_dir}/openshift/99_openshift-cluster-api_master-machines-1.yaml" | ||
"${assets_dir}/openshift/99_openshift-cluster-api_master-machines-2.yaml" | ||
) | ||
|
||
declare -i exit_code=0 | ||
|
||
for machine in "${machines[@]}"; do | ||
if ! [ -f "$machine" ]; then | ||
>&2 echo "Machine resource $machine not found" | ||
exit_code=$((exit_code+1)) | ||
fi | ||
|
||
if ! >/dev/null yq -e '.spec.providerSpec.value.securityGroups[] | select(.uuid=="aaaaaaaa-bbbb-4ccc-dddd-111111111111")' "$machine"; then | ||
>&2 echo "Security group UUID not found in Machine $machine" | ||
>&2 echo | ||
>&2 echo 'The file was:' | ||
>&2 cat "$machine" | ||
>&2 echo | ||
exit_code=$((exit_code+1)) | ||
fi | ||
done | ||
|
||
exit $exit_code |
25 changes: 25 additions & 0 deletions
25
scripts/openstack/manifest-tests/additional-security-group/test_workers.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -Eeuxo pipefail | ||
|
||
declare -r assets_dir="$1" | ||
|
||
declare machineset="${assets_dir}/openshift/99_openshift-cluster-api_worker-machineset-0.yaml" | ||
|
||
declare -i exit_code=0 | ||
|
||
if ! [ -f "$machineset" ]; then | ||
>&2 echo 'MachineSet not found' | ||
exit_code=$((exit_code+1)) | ||
fi | ||
|
||
if ! >/dev/null yq -e '.spec.template.spec.providerSpec.value.securityGroups[] | select(.uuid=="aaaaaaaa-bbbb-4ccc-dddd-000000000000")' "$machineset"; then | ||
>&2 echo 'Security group UUID not found in the MachineSet' | ||
>&2 echo | ||
>&2 echo 'The file was:' | ||
>&2 cat "$machineset" | ||
>&2 echo | ||
exit_code=$((exit_code+1)) | ||
fi | ||
|
||
exit $exit_code |