Skip to content

Commit

Permalink
Merge pull request #5 from brettswift/fix/integration
Browse files Browse the repository at this point in the history
Make integration tests more resiiliant
  • Loading branch information
brettswift committed Aug 28, 2018
2 parents 6a95251 + d9d2619 commit 0471358
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
38 changes: 21 additions & 17 deletions tests/stacker_test/blueprints/pipeline_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PipelineSimple(Blueprint):
def create_template(self):

t = self.template
t.add_description("development spike for dtf")
t.add_description("Acceptance Tests for cumulus pipelines")

instance = self.name + self.context.environment['env']

Expand Down Expand Up @@ -62,11 +62,14 @@ def create_template(self):
),
)

the_chain.add(code_build_action.CodeBuildAction(
action_name="DeployMyStuff",
stage_name_to_add=deploy_stage_name,
input_artifact_name=service_artifact,
))
inline_ls_url_spec = """version: 0.2
phases:
build:
commands:
- ls -lah
- env
- curl $URL
"""

test_env = troposphere.codebuild.Environment(
ComputeType='BUILD_GENERAL1_SMALL',
Expand All @@ -77,21 +80,23 @@ def create_template(self):
],
)

inline_echo_url_spec = """version: 0.2
phases:
build:
commands:
- echo $URL
"""

the_chain.add(code_build_action.CodeBuildAction(
action_name="NotificationSmokeTest",
action_name="DeployMyStuff",
stage_name_to_add=deploy_stage_name,
input_artifact_name=service_artifact,
environment=test_env,
buildspec='buildspec_smoke_test.yml',
buildspec=inline_ls_url_spec,
))

# 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',
# ))

# TODO: integration tests don't confirm the below.. yet. Do it.
destroy_stage_name = "EchoAURL"
the_chain.add(
pipeline_stage.PipelineStage(
Expand All @@ -105,10 +110,9 @@ def create_template(self):
))

the_chain.add(code_build_action.CodeBuildAction(
action_name="DestroyRocketChat",
action_name="DestroyService",
stage_name_to_add=destroy_stage_name,
input_artifact_name=service_artifact,
buildspec=inline_echo_url_spec,
))

chain_context = chaincontext.ChainContext(
Expand Down
Empty file removed tests/stacker_test/junk/asdf.sh
Empty file.
29 changes: 17 additions & 12 deletions tests/stacker_test/run-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,36 @@ 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)"')
echo "Pipeline deployment started for pipeline: ${PIPELINE_NAME}"

# 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)
expected_pipeline_state=$(echo -e "SourceStage Succeeded\nDeployStage Succeeded\nEchoAURL InProgress" | shasum)

set +e # don't exit with a failure, let the loop continue
end=$((SECONDS+180))
pipeline_result=0
set +e # turn off error mode, ie don't exit with a failure, let the loop continue
end=$((SECONDS+600))
pipeline_result=1
while [ $SECONDS -lt ${end} ]; do
sleep 15
# Get status from each stage in the pipeline
pipeline_state=$(aws codepipeline get-pipeline-state --name ${PIPELINE_NAME} | jq -r '.stageStates[] | "\(.stageName) \(.latestExecution.status)"')
actual_pipeline_state=$(aws codepipeline get-pipeline-state --name ${PIPELINE_NAME} | jq -r '.stageStates[] | "\(.stageName) \(.latestExecution.status)"' | shasum)
echo ${pipeline_state}
echo Expected: ${expected_pipeline_state}
echo Actual: ${actual_pipeline_state}
# First check that the resulting shasum is identical to our expected state.
if [[ ${expected_pipeline_state} == ${actual_pipeline_state} ]] ; then
echo "Pipeline Succeeded to approval step!"
pipeline_result=0 #the only place this is set to true
break;
# If it isn't, fail if the pipeline failed. Otherwise continue and check again
else
if [[ ${pipeline_state} = *"Failed"* ]]; then
echo "Pipeline Failed."
pipeline_result=1
break;
else
printf "."
fi
fi
done
Expand All @@ -57,6 +62,6 @@ python delete_bucket_versions.py ${BUCKET}

stacker destroy conf/acceptance.env stacker.yaml --force -t

echo "Completed As Expected!"
echo "Completing with exit code ${pipeline_result}"

exit ${pipeline_result} #

0 comments on commit 0471358

Please sign in to comment.