UI deployment - Molecule tests (#147)

* Renamed scenario default to oracle

* Introduced ui molecule tests

* Readme

* Common prepare

* Shared test_all

* Moved test_docker_config to common

* Added ui tests

* Lint.
This commit is contained in:
Przemyslaw Rzad 2019-07-12 14:51:06 +02:00 committed by GitHub
parent 208cfafa95
commit 54f6fb5835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 152 additions and 10 deletions

@ -114,13 +114,20 @@ jobs:
key: initialize-{{ .Environment.CIRCLE_SHA1 }} key: initialize-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn workspace ui run coverage - run: yarn workspace ui run coverage
- run: yarn workspace ui run coveralls - run: yarn workspace ui run coveralls
deployment: deployment-oracle:
machine: machine:
image: circleci/classic:latest image: circleci/classic:latest
docker_layer_caching: true docker_layer_caching: true
steps: steps:
- checkout - checkout
- run: deployment/molecule/molecule.sh default - run: deployment/molecule/molecule.sh oracle
deployment-ui:
machine:
image: circleci/classic:latest
docker_layer_caching: true
steps:
- checkout
- run: deployment/molecule/molecule.sh ui
workflows: workflows:
version: 2 version: 2
tokenbridge: tokenbridge:
@ -148,4 +155,5 @@ workflows:
- oracle-e2e - oracle-e2e
- ui-e2e - ui-e2e
- monitor-e2e - monitor-e2e
- deployment - deployment-oracle
- deployment-ui

@ -28,4 +28,5 @@ Available scenarios:
Scenario | Description Scenario | Description
--- | --- --- | ---
default | Deploys oracle on Ubuntu host and checks some assertions oracle | Deploys and checks standalone Oracle on Ubuntu host
ui | Deploys and checks standalone UI on Ubuntu host

@ -28,7 +28,7 @@ provisioner:
options: options:
r: ["bug"] r: ["bug"]
playbooks: playbooks:
prepare: prepare.yml prepare: ../prepare.yml
converge: ../../site.yml converge: ../../site.yml
inventory: inventory:
host_vars: host_vars:
@ -40,8 +40,10 @@ verifier:
name: testinfra name: testinfra
lint: lint:
name: flake8 name: flake8
additional_files_or_dirs:
- ../../tests/*
scenario: scenario:
name: default name: oracle
test_sequence: test_sequence:
- lint - lint
- cleanup - cleanup

@ -36,7 +36,3 @@ def test_services(host, service):
def test_logging(host, filename): def test_logging(host, filename):
assert host.file(filename).exists assert host.file(filename).exists
assert host.file(filename).mode == 0o0644 assert host.file(filename).mode == 0o0644
def test_docker_config(host):
assert host.file('/etc/docker/daemon.json').exists

@ -0,0 +1,13 @@
---
- name: prepare
hosts: all
tasks:
- name: install apt packages
apt:
name: "{{ packages }}"
vars:
packages:
- apt-transport-https
- rsyslog
- shell: service rsyslog start
- shell: groupadd docker && chgrp docker /var/run/docker.sock

@ -28,3 +28,7 @@ def test_user(host):
def test_logging(host, filename): def test_logging(host, filename):
assert host.file(filename).exists assert host.file(filename).exists
assert host.file(filename).mode == 0o0644 assert host.file(filename).mode == 0o0644
def test_docker_config(host):
assert host.file('/etc/docker/daemon.json').exists

@ -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

@ -0,0 +1,56 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
enabled: True
options:
config-data:
ignore: ../../hosts.yml
platforms:
- name: ui-host
groups:
- example
children:
- ui
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:
ui-host:
syslog_server_port: "udp://127.0.0.1:514"
bridge_repo_branch: $CODEBASE_BRANCH
verifier:
name: testinfra
lint:
name: flake8
additional_files_or_dirs:
- ../../tests/*
scenario:
name: ui
test_sequence:
- lint
- cleanup
- destroy
- dependency
- syntax
- create
- prepare
- converge
- verify
- destroy

@ -0,0 +1,48 @@
import os
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('ui')
@pytest.mark.parametrize("name", [
("ui_ui_1")
])
def test_docker_containers(host, name):
container = host.docker(name)
assert container.is_running
@pytest.mark.parametrize("service", [
("tokenbridge-ui"),
("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/32-ui-docker.conf"),
("/etc/rsyslog.d/37-ui-remote-logging.conf")
])
def test_logging(host, filename):
assert host.file(filename).exists
assert host.file(filename).mode == 0o0644
def test_index_page_title(host):
assert host.run_test(
'curl -s http://localhost:3001 | '
'grep "<title>" | '
'grep -q "TokenBridge UI app"'
)
def test_index_page_error(host):
assert host.run_expect(
[1],
'curl -s http://localhost:3001 | '
'grep -i -q "error"'
)