Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ AWS_REGION
```

### 2. Launch the tests
Once the environment variables are set, run `./tests/run.sh`.
Once the environment variables are set, run `./tests/run.sh aws`.

## Or, if you already have a cluster running

Expand Down
96 changes: 62 additions & 34 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ set -e

set -eo pipefail

BACKEND="${1}"
LEAVE_RUNNING="${LEAVE_RUNNING:-n}" # do not teardown after successful initialization
SMOKE_TEST_OUTPUT="Never executed. Problem with one of previous stages"
[ -z ${PULL_SECRET_PATH+x} ] && (echo "Please set PULL_SECRET_PATH"; exit 1)
[ -z ${DOMAIN+x} ] && DOMAIN="tectonic-ci.de"
[ -z ${JOB_NAME+x} ] && PREFIX="${USER:-test}" || PREFIX="ci-${JOB_NAME#*/}"
CLUSTER_NAME=$(echo "${PREFIX}-$(uuidgen -r | cut -c1-5)" | tr '[:upper:]' '[:lower:]')
TECTONIC="${PWD}/tectonic-dev/installer/tectonic"
exec &> >(tee -a "$CLUSTER_NAME.log")
exec &> >(tee -ai "$CLUSTER_NAME.log")

function destroy() {
echo -e "\\e[34m Exiting... Destroying Tectonic...\\e[0m"
Expand All @@ -24,8 +26,6 @@ function destroy() {
echo -e "\\e[34m So Long, and Thanks for All the Fish\\e[0m"
}

trap destroy EXIT

echo -e "\\e[36m Starting build process...\\e[0m"
bazel build tarball smoke_tests
# In future bazel build could be extracted to another job which could be running in docker container like this:
Expand All @@ -34,6 +34,7 @@ bazel build tarball smoke_tests
echo -e "\\e[36m Unpacking artifacts...\\e[0m"
tar -zxf bazel-bin/tectonic-dev.tar.gz
cp bazel-bin/tests/smoke/linux_amd64_pure_stripped/go_default_test tectonic-dev/smoke
chmod 755 tectonic-dev/smoke
cd tectonic-dev

### HANDLE SSH KEY ###
Expand All @@ -42,25 +43,36 @@ if [ ! -f ~/.ssh/id_rsa.pub ]; then
ssh-keygen -qb 2048 -t rsa -f ~/.ssh/id_rsa -N "" </dev/zero
fi

if test -z "${AWS_REGION+x}"
then
echo -e "\\e[36m Calculating the AWS region...\\e[0m"
AWS_REGION="$(aws configure get region)" ||
AWS_REGION="${AWS_REGION:-us-east-1}"
fi
export AWS_DEFAULT_REGION="${AWS_REGION}"
unset AWS_SESSION_TOKEN

### ASSUME ROLE ###
echo -e "\\e[36m Setting up AWS credentials...\\e[0m"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/tf-tectonic-installer"
RES="$(aws sts assume-role --role-arn="${ROLE_ARN}" --role-session-name="jenkins-${CLUSTER_NAME}" --query Credentials --output json)" &&
export AWS_SECRET_ACCESS_KEY="$(echo "${RES}" | jq --raw-output '.SecretAccessKey')" &&
export AWS_ACCESS_KEY_ID="$(echo "${RES}" | jq --raw-output '.AccessKeyId')" &&
export AWS_SESSION_TOKEN="$(echo "${RES}" | jq --raw-output '.SessionToken')" &&
CONFIGURE_AWS_ROLES=True ||
CONFIGURE_AWS_ROLES=False
case "${BACKEND}" in
aws)
if test -z "${AWS_REGION+x}"
then
echo -e "\\e[36m Calculating the AWS region...\\e[0m"
AWS_REGION="$(aws configure get region)" ||
AWS_REGION="${AWS_REGION:-us-east-1}"
fi
export AWS_DEFAULT_REGION="${AWS_REGION}"
unset AWS_SESSION_TOKEN

### ASSUME ROLE ###
echo -e "\\e[36m Setting up AWS credentials...\\e[0m"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/tf-tectonic-installer"
RES="$(aws sts assume-role --role-arn="${ROLE_ARN}" --role-session-name="jenkins-${CLUSTER_NAME}" --query Credentials --output json)" &&
export AWS_SECRET_ACCESS_KEY="$(echo "${RES}" | jq --raw-output '.SecretAccessKey')" &&
export AWS_ACCESS_KEY_ID="$(echo "${RES}" | jq --raw-output '.AccessKeyId')" &&
export AWS_SESSION_TOKEN="$(echo "${RES}" | jq --raw-output '.SessionToken')" &&
CONFIGURE_AWS_ROLES=True ||
CONFIGURE_AWS_ROLES=False
;;
libvirt)
[ -z ${IMAGE_PATH+x} ] && (echo "Please set libvirt IMAGE_PATH" >&2; exit 1)
;;
*)
echo "unrecognized backend: ${BACKEND}" >&2
echo "Use ${0} BACKEND, where BACKEND is aws or libvirt" >&2
exit 1
esac

echo -e "\\e[36m Creating Tectonic configuration...\\e[0m"
python <<-EOF >"${CLUSTER_NAME}.yaml"
Expand All @@ -70,34 +82,50 @@ python <<-EOF >"${CLUSTER_NAME}.yaml"

import yaml

with open('examples/tectonic.aws.yaml') as f:
with open('examples/tectonic.${BACKEND}.yaml') as f:
config = yaml.load(f)
config['name'] = '${CLUSTER_NAME}'
with open(os.path.expanduser(os.path.join('~', '.ssh', 'id_rsa.pub'))) as f:
config['admin']['sshKey'] = f.read()
config['baseDomain'] = '${DOMAIN}'
with open('${PULL_SECRET_PATH}') as f:
config['pullSecret'] = f.read()
config['aws']['region'] = '${AWS_REGION}'
config['aws']['extraTags'] = {
'expirationDate': (
datetime.datetime.utcnow() + datetime.timedelta(hours=4)
).strftime('%Y-%m-%dT%H:%M+0000'),
}
if ${CONFIGURE_AWS_ROLES:-False}:
config['aws']['master']['iamRoleName'] = 'tf-tectonic-master-node'
config['aws']['worker']['iamRoleName'] = 'tf-tectonic-worker-node'
if '${BACKEND}' == 'aws':
config['aws']['region'] = '${AWS_REGION}'
config['aws']['extraTags'] = {
'expirationDate': (
datetime.datetime.utcnow() + datetime.timedelta(hours=4)
).strftime('%Y-%m-%dT%H:%M+0000'),
}
if ${CONFIGURE_AWS_ROLES:-False}:
config['aws']['master']['iamRoleName'] = 'tf-tectonic-master-node'
config['aws']['worker']['iamRoleName'] = 'tf-tectonic-worker-node'
elif '${BACKEND}' == 'libvirt':
config['libvirt']['imagePath'] = '${IMAGE_PATH}'
yaml.safe_dump(config, sys.stdout)
EOF

echo -e "\\e[36m Initializing Tectonic...\\e[0m"
"${TECTONIC}" init --config="${CLUSTER_NAME}".yaml

trap destroy EXIT

echo -e "\\e[36m Deploying Tectonic...\\e[0m"
"${TECTONIC}" install --dir="${CLUSTER_NAME}"
echo -e "\\e[36m Running smoke test...\\e[0m"
export SMOKE_KUBECONFIG="${PWD}/${CLUSTER_NAME}/generated/auth/kubeconfig"
export SMOKE_NODE_COUNT="5" # Sum of all nodes (master + worker)
export SMOKE_MANIFEST_PATHS="${PWD}/${CLUSTER_NAME}/generated"
case "${BACKEND}" in
aws)
export SMOKE_NODE_COUNT=5 # Sum of all nodes (boostrap + master + worker)
;;
libvirt)
export SMOKE_NODE_COUNT=4
;;
esac
exec 5>&1
SMOKE_TEST_OUTPUT=$(./smoke -test.v --cluster | tee >(cat - >&5))
if test "${LEAVE_RUNNING}" = y; then
echo "leaving running; tear down manually with: cd ${PWD} && installer/tectonic destroy --dir=${CLUSTER_NAME}"
trap - EXIT
fi
SMOKE_TEST_OUTPUT=$(./smoke -test.v --cluster | tee -i >(cat - >&5))