From 847d4906e796eeb3e8a08a4bb5209054425ab9cc Mon Sep 17 00:00:00 2001 From: ykim-1 Date: Thu, 25 Jul 2024 12:30:21 -0700 Subject: [PATCH] improve e2e firewall creation/deletion error handling and clean up --- Makefile | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1c5a50d0..3fa8c156 100644 --- a/Makefile +++ b/Makefile @@ -62,26 +62,42 @@ gendocs: # ansible-test integration $(TEST_ARGS) --tags never integration-test: create-integration-config create-e2e-firewall @echo "Running Integration Test(s)..." - ansible-test integration $(TEST_ARGS) + OUTPUT=$$(ansible-test integration $(TEST_ARGS) 2>&1); \ + TEST_EXIT_CODE=$$?; \ + echo "$$OUTPUT" \ + @echo "Running Cleanup for E2E firewall..." \ + make delete-e2e-firewall; \ + if [ $$TEST_EXIT_CODE -ne 0 ]; then \ + echo "Integration tests failed, check RECAP above for more details..."; \ + fi; \ + exit $$TEST_EXIT_CODE create-e2e-firewall: @echo "Running create e2e firewall playbook..." - @if ansible-playbook e2e_scripts/cloud_security_scripts/cloud_e2e_firewall/ansible_linode/create_e2e_cloud_firewall.yaml > /dev/null; then \ - echo "Successfully created e2e firewall"; \ - else \ - echo "Failed to create e2e firewall. Please update the cloud firewall scripts using `git submodule update --init` if yaml file doesn't exist"; \ + @OUTPUT=$$(ansible-playbook e2e_scripts/cloud_security_scripts/cloud_e2e_firewall/ansible_linode/create_e2e_cloud_firewall.yaml 2>&1); \ + FAILED_COUNT=$$(echo "$$OUTPUT" | grep "failed=" | awk -F 'failed=' '{print $$2}' | awk '{print $$1}'); \ + if [ "$$FAILED_COUNT" -gt 0 ]; then \ + echo "Playbook execution failed:"; \ + echo "$$OUTPUT"; \ exit 1; \ + else \ + echo "E2E Cloud firewall created successfully."; \ fi + delete-e2e-firewall: @echo "Running delete e2e firewall playbook..." - @if ansible-playbook e2e_scripts/cloud_security_scripts/cloud_e2e_firewall/ansible_linode/delete_e2e_cloud_firewall.yaml > /dev/null; then \ - echo "Successfully deleted e2e firewall"; \ + @OUTPUT=$$(ansible-playbook e2e_scripts/cloud_security_scripts/cloud_e2e_firewall/ansible_linode/delete_e2e_cloud_firewall.yaml 2>&1); \ + FAILED_COUNT=$$(echo "$$OUTPUT" | grep "failed=" | awk -F 'failed=' '{print $$2}' | awk '{print $$1}'); \ + if [ "$$FAILED_COUNT" -gt 0 ]; then \ + echo "Playbook execution failed:"; \ + echo "$$OUTPUT"; \ + exit 1; \ else \ - echo "Failed to delete e2e firewall"; \ - fi + echo "E2E Cloud firewall deleted successfully."; \ + fi -test: integration-test delete-e2e-firewall +test: integration-test testall: ./scripts/test_all.sh