Skip to content

Commit

Permalink
Merge pull request #31 from O1ahmad/ahmad/add_container_uninstall_tests
Browse files Browse the repository at this point in the history
chore: add initial container uninstall scenario tests
  • Loading branch information
O1ahmad authored Jan 9, 2025
2 parents 4014ce0 + 47f5fcc commit 49e5c91
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 15 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ jobs:
molecule:
strategy:
matrix:
scenario: [systemd-basic, systemd-full, systemd-uninstall, container-basic, container-full]
scenario:
- systemd-basic
- systemd-full
- systemd-uninstall
- container-basic
- container-full
- container-uninstall
runs-on: ubuntu-latest

steps:
Expand Down
16 changes: 8 additions & 8 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
---
# --- Container Handlers ---
- name: Container uninstall
listen: Uninstall Service
community.docker.docker_container:
name: "{{ name }}"
state: absent
when: setup_mode == 'container'

# --- Storage Handlers ---
- name: Remove host data directory
listen: Uninstall Service
Expand Down Expand Up @@ -60,14 +68,6 @@
- setup_mode == 'systemd'
- destination_directory is defined

# --- Container Handlers ---
- name: Container uninstall
listen: Uninstall Service
community.docker.docker_container:
name: "{{ name }}"
state: absent
when: setup_mode == 'container'

# --- Kubernetes Handlers ---
- name: Uninstall Helm release
listen: Uninstall Service
Expand Down
3 changes: 0 additions & 3 deletions tests/molecule/container-basic/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
dependency:
name: galaxy
options:
role_file: molecule/requirements.yml
roles_path: "../../"
driver:
name: docker
platforms:
Expand Down
Empty file.
3 changes: 0 additions & 3 deletions tests/molecule/container-full/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
---
dependency:
name: galaxy
options:
role_file: molecule/requirements.yml
roles_path: "../../"
driver:
name: docker
platforms:
Expand Down
75 changes: 75 additions & 0 deletions tests/molecule/container-uninstall/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
- name: Converge
hosts: all
become: true
roles:
- role: basic-service
vars:
uninstall: false
setup_mode: container
name: full-container
image: prom/prometheus:latest
user: root
command: --config.file=/etc/prometheus/prometheus.yml
cpus: 2
memory: 1024M
network_mode: bridge
ports:
prometheus:
ingressPort: 9090
servicePort: 9090
host_data_dir: /test/mnt/prometheus
config:
prometheus-config:
destinationPath: /etc/prometheus/prometheus.yml
data: |
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
config_env:
PROMETHEUS_STORAGE_PATH: "/prometheus"
data_dirs:
prometheus-data:
hostPath: /tmp/prometheus
appPath: /prometheus
restart_policy: always
- role: basic-service
vars:
uninstall: true
setup_mode: container
name: full-container
image: prom/prometheus:latest
user: root
command: --config.file=/etc/prometheus/prometheus.yml
cpus: 2
memory: 1024M
network_mode: bridge
ports:
prometheus:
ingressPort: 9090
servicePort: 9090
host_data_dir: /test/mnt/prometheus
config:
prometheus-config:
destinationPath: /etc/prometheus/prometheus.yml
data: |
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
config_env:
PROMETHEUS_STORAGE_PATH: "/prometheus"
data_dirs:
prometheus-data:
hostPath: /tmp/prometheus
appPath: /prometheus
restart_policy: always
31 changes: 31 additions & 0 deletions tests/molecule/container-uninstall/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: docker:24.0.5-dind
privileged: true
network_mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /test/mnt:/test/mnt
provisioner:
name: ansible
playbooks:
prepare: ../prepare-docker.yml
env:
ANSIBLE_ROLES_PATH: "../../../../"
verifier:
name: testinfra
directory: ./tests
scenario:
name: container-uninstall
test_sequence:
- dependency
- create
- prepare
- converge
- verify
- destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def test_container_removed(host):
"""Verify the container has been removed."""
container = host.run("docker ps -a --filter 'name=full-container' --format '{{.Names}}'")
assert container.stdout.strip() == "", "The container 'full-container' still exists."

def test_config_directory_removed(host):
"""Verify the configuration directory has been removed."""
config_dir = host.file("/test/mnt/etc/prometheus")
assert not config_dir.exists, "The configuration directory still exists."

def test_data_directory_removed(host):
"""Verify the data directory has been removed."""
data_dir = host.file("/tmp/prometheus")
assert not data_dir.exists, "The data directory still exists."

def test_host_data_directory_removed(host):
"""Verify the host data directory has been removed."""
host_data_dir = host.file("/test/mnt/prometheus")
assert not host_data_dir.exists, "The host data directory still exists."

0 comments on commit 49e5c91

Please sign in to comment.