-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from brettswift/feature/fix_acceptance_tests
Acceptance / integration test of the pipeline works
- Loading branch information
Showing
8 changed files
with
180 additions
and
20 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
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 |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
'flake8', | ||
'pytest-watch', | ||
'pytest-cov', | ||
'coveralls' | ||
'coveralls', | ||
'awscli' | ||
] | ||
|
||
extras = { | ||
|
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 |
---|---|---|
@@ -1,35 +1,119 @@ | ||
from cumulus.chain import chain, chaincontext | ||
from cumulus.steps import development | ||
import troposphere | ||
from stacker.blueprints.base import Blueprint | ||
import troposphere.codebuild | ||
|
||
from cumulus.chain import chain, chaincontext | ||
from cumulus.steps.development import pipeline, code_build_action, pipeline_stage, pipeline_source_action | ||
from cumulus.steps.development.approval_action import ApprovalAction | ||
|
||
|
||
class PipelineSimple(Blueprint): | ||
""" | ||
An example development that doesn't do anything interesting. | ||
""" | ||
|
||
VARIABLES = { | ||
# 'git-commit': {'type': basestring, 'description': 'git version'}, | ||
} | ||
|
||
def create_template(self): | ||
|
||
t = self.template | ||
t.add_description("development spike for dtf") | ||
|
||
instance = self.name + self.context.environment['env'] | ||
|
||
# TODO: give to builder | ||
the_chain = chain.Chain() | ||
the_chain.add(development.Pipeline(name="uptime-dev")) | ||
# bucket becomes: cumulus-acceptance-tests-123123-namespace | ||
pipeline_bucket_name = troposphere.Join('', [ | ||
self.context.namespace, | ||
"-", | ||
troposphere.Ref("AWS::AccountId"), | ||
"-", | ||
"automatedtests" | ||
]) | ||
|
||
the_chain.add(pipeline.Pipeline( | ||
name=self.name, | ||
bucket_name=pipeline_bucket_name, | ||
)) | ||
|
||
source_stage_name = "SourceStage" | ||
deploy_stage_name = "DeployStage" | ||
service_artifact = "ServiceArtifact" | ||
|
||
the_chain.add( | ||
pipeline_stage.PipelineStage(stage_name=source_stage_name) | ||
) | ||
|
||
the_chain.add( | ||
pipeline_source_action.PipelineSourceAction( | ||
action_name="MicroserviceSource", | ||
output_artifact_name=service_artifact, | ||
s3_bucket_name=pipeline_bucket_name, | ||
s3_object_key="artifact.tar.gz" | ||
) | ||
) | ||
|
||
the_chain.add( | ||
pipeline_stage.PipelineStage( | ||
stage_name=deploy_stage_name, | ||
), | ||
) | ||
|
||
the_chain.add(code_build_action.CodeBuildAction( | ||
action_name="DeployMyStuff", | ||
stage_name_to_add=deploy_stage_name, | ||
input_artifact_name=service_artifact, | ||
)) | ||
|
||
test_env = troposphere.codebuild.Environment( | ||
ComputeType='BUILD_GENERAL1_SMALL', | ||
Image='aws/codebuild/golang:1.10', | ||
Type='LINUX_CONTAINER', | ||
EnvironmentVariables=[ | ||
{'Name': 'URL', 'Value': "https://google.ca"} | ||
], | ||
) | ||
|
||
inline_echo_url_spec = """version: 0.2 | ||
phases: | ||
build: | ||
commands: | ||
- echo $URL | ||
""" | ||
|
||
the_chain.add(code_build_action.CodeBuildAction( | ||
action_name="NotificationSmokeTest", | ||
stage_name_to_add=deploy_stage_name, | ||
input_artifact_name=service_artifact, | ||
environment=test_env, | ||
buildspec='buildspec_smoke_test.yml', | ||
)) | ||
|
||
destroy_stage_name = "EchoAURL" | ||
the_chain.add( | ||
pipeline_stage.PipelineStage( | ||
stage_name=destroy_stage_name, | ||
), | ||
) | ||
|
||
# Example usage if you have a VPC | ||
# vpc_config = development.VpcConfig( | ||
# vpc_id='', | ||
# subnets=[ | ||
# 'subnet-1', | ||
# ] | ||
# ) | ||
the_chain.add(ApprovalAction( | ||
action_name="ApproveDestruction", | ||
stage_name_to_add=destroy_stage_name | ||
)) | ||
|
||
the_chain.add(development.CodeBuildStage()) # This should hopefully be more valuable, context maybe! | ||
the_chain.add(code_build_action.CodeBuildAction( | ||
action_name="DestroyRocketChat", | ||
stage_name_to_add=destroy_stage_name, | ||
input_artifact_name=service_artifact, | ||
buildspec=inline_echo_url_spec, | ||
)) | ||
|
||
chain_context = chaincontext.ChainContext( | ||
template=t, | ||
instance_name=self.name | ||
instance_name=instance | ||
) | ||
|
||
the_chain.run(chain_context) |
3 changes: 2 additions & 1 deletion
3
tests/stacker_test/conf/test.env → tests/stacker_test/conf/acceptance.env
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Used for your dev environment: | ||
# http://stacker.readthedocs.io/en/latest/environments.html | ||
namespace: int-test-dev | ||
namespace: acc | ||
env: ac |
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,11 @@ | ||
import boto3 | ||
import sys | ||
|
||
bucket_name = str(sys.argv[1]) | ||
|
||
print("deleting bucket %s " % bucket_name) | ||
|
||
session = boto3.Session() | ||
s3 = session.resource(service_name='s3') | ||
bucket = s3.Bucket(bucket_name) | ||
bucket.object_versions.delete() |
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 |
---|---|---|
@@ -1,4 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
stacker build conf/test.env stacker.yaml | ||
stacker destroy conf/test.env stacker.yaml --force | ||
ACCOUNT_ID=`aws sts get-caller-identity | jq .Account | tr -d '"' ` | ||
NAMESPACE=acc # must match the namespace in the conf file | ||
BUCKET="cumulus-${NAMESPACE}-${ACCOUNT_ID}-automatedtests" | ||
|
||
echo "Using account: ${ACCOUNT_ID}" | ||
echo "Using bucket: ${BUCKET}" | ||
|
||
set -e #Important. Script will exit appropriately if there is an error. | ||
|
||
stacker build conf/acceptance.env stacker.yaml --recreate-failed -t | ||
|
||
ARTIFACT_NAME='artifact.tar.gz' | ||
TEMP_DIR='ac_build' | ||
|
||
pushd ../../ # move to main folder | ||
mkdir -p ${TEMP_DIR} | ||
zip -r ${TEMP_DIR}/${ARTIFACT_NAME} ./ -x *.git* *./${TEMP_DIR}* *.eggs* *.idea* *.tox* | ||
|
||
aws s3 cp ./${TEMP_DIR}/${ARTIFACT_NAME} s3://${BUCKET}/${ARTIFACT_NAME} | ||
|
||
rm -rf ${TEMP_DIR} | ||
popd # return to test folder | ||
|
||
# TODO: wait for pipeline | ||
PIPELINE_NAME=$(stacker info conf/acceptance.env stacker.yaml 2>&1 | grep PipelineLogicalName | cut -f 3 -d " ") | ||
|
||
echo "Waiting for pipeline: ${PIPELINE_NAME}" | ||
|
||
# Get status from each stage in the pipeline | ||
pipeline_state=$(aws codepipeline get-pipeline-state --name ${PIPELINE_NAME} | jq -r '.stageStates[] | "\(.stageName) \(.latestExecution.status)"') | ||
|
||
# get shasum from expected and actual output. When they match we are at approval state | ||
expected_pipeline_state=$(echo -e "SourceStage Succeeded\nDeployStage Succeeded\nEchoAURL null" | shasum) | ||
actual_pipeline_state=$(echo ${pipeline_state} | shasum) | ||
|
||
set +e # don't exit with a failure, let the loop continue | ||
end=$((SECONDS+180)) | ||
pipeline_result=0 | ||
while [ $SECONDS -lt ${end} ]; do | ||
sleep 15 | ||
if [[ ${expected_pipeline_state} == ${actual_pipeline_state} ]] ; then | ||
echo "Pipeline Succeeded to approval step!" | ||
break; | ||
else | ||
if [[ ${pipeline_state} = *"Failed"* ]]; then | ||
echo "Pipeline Failed." | ||
pipeline_result=1 | ||
break; | ||
fi | ||
fi | ||
done | ||
|
||
aws s3 rm s3://${BUCKET} --recursive | ||
python delete_bucket_versions.py ${BUCKET} | ||
|
||
stacker destroy conf/acceptance.env stacker.yaml --force -t | ||
|
||
echo "Completed As Expected!" | ||
|
||
exit ${pipeline_result} # |
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