Skip to content

Commit

Permalink
Add automatic clean up for firewall and clean up Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ykim-akamai committed Jun 6, 2024
1 parent f4c9184 commit 667d493
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,40 @@ gendocs:

# if want to add all the test add the tag --tags never at the end
# ansible-test integration $(TEST_ARGS) --tags never
integration-test: create-integration-config
integration-test: create-integration-config create-e2e-firewall
@echo "Running Integration Test(s)..."
ansible-test integration $(TEST_ARGS)

test: integration-test
create-e2e-firewall:
@echo "Running create e2e firewall playbook..."
@if ansible-playbook scripts/create_e2e_cloud_firewall.yaml > /dev/null; then \
echo "Successfully created firewall"; \
else \
echo "Failed to create firewall"; \
fi

delete-e2e-firewall:
@echo "Running delete e2e firewall playbook..."
@if ansible-playbook scripts/delete_e2e_cloud_firewall.yaml > /dev/null; then \
echo "Successfully deleted firewall"; \
else \
echo "Failed to delete firewall"; \

test: integration-test delete-e2e-firewall

testall: create-integration-config
./scripts/test_all.sh

unittest:
ansible-test units --target-python default


create-integration-config:
ifneq ("${LINODE_TOKEN}", "")
@echo -n > $(INTEGRATION_CONFIG)
ansible-playbook scripts/create_e2e_cloud_firewall.yaml
@echo "api_token: ${LINODE_TOKEN}" >> $(INTEGRATION_CONFIG);
else ifneq ("${LINODE_API_TOKEN}", "")
@echo -n > $(INTEGRATION_CONFIG)
ansible-playbook scripts/create_e2e_cloud_firewall.yaml
@echo "api_token: ${LINODE_API_TOKEN}" >> $(INTEGRATION_CONFIG);
else
echo "LINODE_API_TOKEN must be set"; \
Expand Down
36 changes: 36 additions & 0 deletions scripts/delete_e2e_cloud_firewall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: Delete Linode E2E Cloud Firewall
hosts: localhost
gather_facts: yes

vars:
linode_api_token: "{{ lookup('env', 'LINODE_TOKEN') | default(lookup('env', 'LINODE_API_TOKEN')) }}"

tasks:
- name: Read firewall ID from configuration file
slurp:
src: "../tests/integration/integration_config.yml"
register: config_file

- name: Set firewall_id fact from configuration file
set_fact:
firewall_id: "{{ (config_file.content | b64decode).splitlines() | select('match', '^firewall_id: ') | first | regex_replace('^firewall_id: ', '') }}"

- name: Ensure firewall_id is set
fail:
msg: "firewall_id not found in configuration file."
when: firewall_id is not defined or firewall_id == ""

- name: Find the firewall by ID
linode.cloud.firewall_info:
id: "{{ firewall_id }}"
register: firewall_info

- name: Delete the firewall
linode.cloud.firewall:
label: "{{ firewall_info.firewall.label }}"
state: absent
register: delete_firewall

- name: Display Deletion Info
debug:
var: delete_firewall

0 comments on commit 667d493

Please sign in to comment.