diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index a0a7014..5edc4a2 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -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: diff --git a/handlers/main.yml b/handlers/main.yml index 7aacbd7..d0961f5 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 @@ -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 diff --git a/tests/molecule/container-basic/molecule.yml b/tests/molecule/container-basic/molecule.yml index d69bee8..e3b14d4 100644 --- a/tests/molecule/container-basic/molecule.yml +++ b/tests/molecule/container-basic/molecule.yml @@ -1,9 +1,6 @@ --- dependency: name: galaxy - options: - role_file: molecule/requirements.yml - roles_path: "../../" driver: name: docker platforms: diff --git a/tests/molecule/container-basic/requirements.yml b/tests/molecule/container-basic/requirements.yml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/molecule/container-full/molecule.yml b/tests/molecule/container-full/molecule.yml index 1836bad..488969e 100644 --- a/tests/molecule/container-full/molecule.yml +++ b/tests/molecule/container-full/molecule.yml @@ -1,9 +1,6 @@ --- dependency: name: galaxy - options: - role_file: molecule/requirements.yml - roles_path: "../../" driver: name: docker platforms: diff --git a/tests/molecule/container-uninstall/converge.yml b/tests/molecule/container-uninstall/converge.yml new file mode 100644 index 0000000..54068ba --- /dev/null +++ b/tests/molecule/container-uninstall/converge.yml @@ -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 diff --git a/tests/molecule/container-uninstall/molecule.yml b/tests/molecule/container-uninstall/molecule.yml new file mode 100644 index 0000000..f17b900 --- /dev/null +++ b/tests/molecule/container-uninstall/molecule.yml @@ -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 diff --git a/tests/molecule/container-uninstall/tests/test_container_uninstall.py b/tests/molecule/container-uninstall/tests/test_container_uninstall.py new file mode 100644 index 0000000..c8099a0 --- /dev/null +++ b/tests/molecule/container-uninstall/tests/test_container_uninstall.py @@ -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."