diff --git a/.circleci/config.yml b/.circleci/config.yml index 92b96343..ec4d79a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -128,6 +128,13 @@ jobs: steps: - checkout - run: deployment/molecule/molecule.sh ui + deployment-monitor: + machine: + image: circleci/classic:latest + docker_layer_caching: true + steps: + - checkout + - run: deployment/molecule/molecule.sh monitor ultimate-native-to-erc: machine: image: circleci/classic:latest @@ -217,4 +224,5 @@ workflows: - monitor-e2e - deployment-oracle - deployment-ui + - deployment-monitor - ultimate-native-to-erc diff --git a/deployment/molecule/monitor/Dockerfile.j2 b/deployment/molecule/monitor/Dockerfile.j2 new file mode 100644 index 00000000..e6aa95d3 --- /dev/null +++ b/deployment/molecule/monitor/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/deployment/molecule/monitor/molecule.yml b/deployment/molecule/monitor/molecule.yml new file mode 100644 index 00000000..fb754f13 --- /dev/null +++ b/deployment/molecule/monitor/molecule.yml @@ -0,0 +1,56 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + enabled: True + options: + config-data: + ignore: ../../hosts.yml +platforms: + - name: monitor-host + groups: + - example + children: + - monitor + image: ubuntu:16.04 + privileged: true + network_mode: host + volumes: + - /var/run/docker.sock:/var/run/docker.sock +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: True + options: + r: ["bug"] + playbooks: + prepare: ../prepare.yml + converge: ../../site.yml + inventory: + host_vars: + monitor-host: + bridge_repo_branch: $CODEBASE_BRANCH + syslog_server_port: "udp://127.0.0.1:514" +verifier: + name: testinfra + lint: + name: flake8 + additional_files_or_dirs: + - ../../tests/* +scenario: + name: monitor + test_sequence: + - lint + - cleanup + - destroy + - dependency + - syntax + - create + - prepare + - converge + - verify + - destroy diff --git a/deployment/molecule/monitor/tests/test_monitor.py b/deployment/molecule/monitor/tests/test_monitor.py new file mode 100644 index 00000000..a3cee13d --- /dev/null +++ b/deployment/molecule/monitor/tests/test_monitor.py @@ -0,0 +1,54 @@ +import os +import pytest +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('monitor') + + +@pytest.mark.parametrize("name", [ + ("monitor_monitor_1") +]) +def test_docker_containers(host, name): + container = host.docker(name) + assert container.is_running + + +@pytest.mark.parametrize("service", [ + ("tokenbridge-monitor"), + ("rsyslog") +]) +def test_services(host, service): + assert host.service(service).is_enabled + assert host.service(service).is_running + + +@pytest.mark.parametrize("filename", [ + ("/etc/rsyslog.d/33-monitor-docker.conf"), + ("/etc/rsyslog.d/38-monitor-remote-logging.conf") +]) +def test_logging(host, filename): + assert host.file(filename).exists + assert host.file(filename).mode == 0o0644 + + +def test_home_exists(host): + assert host.run_test( + 'curl -s http://localhost:3003 | ' + 'grep -q -i "home"' + ) + + +def test_foreign_exists(host): + assert host.run_test( + 'curl -s http://localhost:3003 | ' + 'grep -q -i "foreign"' + ) + + +def test_no_error(host): + assert host.run_expect( + [1], + 'curl -s http://localhost:3003 | ' + 'grep -i -q "error"' + )