Skip to content

Commit

Permalink
openstack: Test manifest creation
Browse files Browse the repository at this point in the history
Add a script for testing OpenStack manifest generation.

Co-Authored-By: Matthew Booth <mbooth@redhat.com>
  • Loading branch information
pierreprinetti and mdbooth committed Nov 30, 2020
1 parent 64ec239 commit 3f25b03
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 0 deletions.
118 changes: 118 additions & 0 deletions hack/test-manifests-openstack.sh
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
3 changes: 3 additions & 0 deletions images/openstack/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COPY --from=builder /go/src/github.com/openshift/installer/bin/openshift-install
COPY --from=builder /go/src/github.com/openshift/installer/upi /var/lib/openshift-install/upi
COPY --from=builder /go/src/github.com/openshift/installer/images/openstack/rdo-train.repo /etc/yum.repos.d/rdo-train.repo
COPY --from=builder /go/src/github.com/openshift/installer/images/openstack/rdo-train.gpg /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Cloud
COPY --from=builder /go/src/github.com/openshift/installer/hack/test-manifests-openstack.sh /go/src/github.com/openshift/installer/scripts/openstack/manifest-tests /var/lib/openshift-install/manifest-tests

# Install Dependendencies for tests
# https://github.com/openshift/origin/blob/6114cbc507bf18890f009f16ee424a62007bc390/images/tests/Dockerfile.rhel
Expand All @@ -30,6 +31,8 @@ RUN yum update -y && \

RUN ansible-galaxy collection install ansible.netcommon openstack.cloud

RUN python -m pip install yq

# The Continuous Integration machinery relies on Route53 for DNS while testing the cluster.
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
Expand Down
4 changes: 4 additions & 0 deletions scripts/openstack/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approvers:
- openstack-approvers
reviewers:
- openstack-reviewers
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}
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
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

0 comments on commit 3f25b03

Please sign in to comment.