Molecule tests for deploying repository (#194)

* Squashed commits

* All jobs

* Rollback changes

* Dependencies

* Remove .git checking

* Resolve path issues

* New way of copying repository.

* Test non existing .git

* New repo task

* Typo

* Do not fail mkdir if folder exists

* Test double task

* zipping the archives

* Increase no_output_timeout because of slowly installing apt-get
This commit is contained in:
Przemyslaw Rzad 2019-09-06 15:24:30 +02:00 committed by GitHub
parent 443474e802
commit 54858ae597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 183 additions and 23 deletions

@ -170,19 +170,41 @@ jobs:
steps:
- checkout
- run: git submodule update --init
- run: deployment-e2e/molecule.sh oracle
- run:
name: Run the scenario
command: deployment-e2e/molecule.sh oracle
no_output_timeout: 40m
deployment-ui:
executor: tokenbridge-orb/machine-with-docker-caching
steps:
- checkout
- run: git submodule update --init
- run: deployment-e2e/molecule.sh ui
- run:
name: Run the scenario
command: deployment-e2e/molecule.sh ui
no_output_timeout: 40m
deployment-monitor:
executor: tokenbridge-orb/machine-with-docker-caching
steps:
- checkout
- run: git submodule update --init
- run: deployment-e2e/molecule.sh monitor
- run:
name: Run the scenario
command: deployment-e2e/molecule.sh monitor
no_output_timeout: 40m
deployment-repo:
executor: tokenbridge-orb/machine-with-docker-caching
steps:
- checkout
- run: git submodule update --init
- tokenbridge-orb/install-node
- tokenbridge-orb/install-yarn
- tokenbridge-orb/yarn-install-cached-on-machine
- run:
name: Run the scenario
command: deployment-e2e/molecule.sh repo
no_output_timeout: 40m
ultimate:
executor: tokenbridge-orb/machine-with-docker-caching
parameters:
@ -205,7 +227,7 @@ jobs:
- run:
name: Prepare the infrastructure
command: e2e-commons/up.sh deploy << parameters.scenario-name >>
no_output_timeout: 30m
no_output_timeout: 50m
- tokenbridge-orb/wait-for-oracle:
redis-key: << parameters.redis-key >>
- run:
@ -243,6 +265,7 @@ workflows:
- deployment-oracle
- deployment-ui
- deployment-monitor
- deployment-repo
- ultimate:
name: "ultimate: native to erc"
scenario-name: native-to-erc

@ -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,12 @@
---
- name: Install Repository
hosts: all
become: true
tasks:
- import_role:
name: ../../../deployment/roles/common
tasks_from: repo
# Test that running the task again works
- import_role:
name: ../../../deployment/roles/common
tasks_from: repo

@ -0,0 +1,30 @@
---
driver:
name: docker
platforms:
- name: repo-host
image: ubuntu:16.04
privileged: true
network_mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock
provisioner:
name: ansible
playbooks:
prepare: ../prepare.yml
converge: ./converge.yml
inventory:
host_vars:
repo-host:
bridge_repo_branch: master
verifier:
name: testinfra
scenario:
name: repo
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy

@ -0,0 +1,49 @@
import os
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.mark.parametrize("path", [
("/home/poadocker"),
("/home/poadocker/bridge"),
("/home/poadocker/bridge/commons"),
("/home/poadocker/bridge/e2e-commons"),
("/home/poadocker/bridge/deployment"),
("/home/poadocker/bridge/contracts"),
("/home/poadocker/bridge/oracle"),
("/home/poadocker/bridge/monitor"),
("/home/poadocker/bridge/ui"),
("/home/poadocker/bridge/parity")
])
def test_existing_folders(host, path):
assert host.file(path).exists
assert host.file(path).is_directory
@pytest.mark.parametrize("path", [
("/home/poadocker/bridge/package.json"),
("/home/poadocker/bridge/commons/package.json"),
("/home/poadocker/bridge/contracts/package.json"),
("/home/poadocker/bridge/oracle/package.json"),
("/home/poadocker/bridge/monitor/package.json"),
("/home/poadocker/bridge/ui/package.json")
])
def test_existing_package_json(host, path):
assert host.file(path).exists
assert host.file(path).is_file
@pytest.mark.parametrize("path", [
("/home/poadocker/bridge/Dockerfile.e2e"),
("/home/poadocker/bridge/contracts/Dockerfile"),
("/home/poadocker/bridge/parity/Dockerfile"),
("/home/poadocker/bridge/oracle/Dockerfile"),
("/home/poadocker/bridge/monitor/Dockerfile"),
("/home/poadocker/bridge/ui/Dockerfile")
])
def test_existing_docker_files(host, path):
assert host.file(path).exists
assert host.file(path).is_file

@ -0,0 +1,23 @@
import os
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.mark.parametrize("path", [
("/home/poadocker/bridge/node_modules"),
("/home/poadocker/bridge/ui/node_modules"),
("/home/poadocker/bridge/oracle/node_modules"),
("/home/poadocker/bridge/monitor/node_modules"),
("/home/poadocker/bridge/contracts/node_modules"),
])
def test_non_existing_node_modules(host, path):
assert not host.file(path).exists
@pytest.mark.parametrize("path", [
("/home/poadocker/bridge/.git")
])
def test_non_existing_git(host, path):
assert not host.file(path).exists

@ -1,25 +1,34 @@
---
- name: Create repo directory
file:
path: "{{ bridge_path }}"
state: directory
- name: Register files for copying
- name: Create archives of the monorepository
shell: |
git ls-tree -r HEAD --name-only
cd contracts; git ls-tree -r HEAD --name-only | sed -e 's/^/contracts\//'
register: rsync_files
(git ls-tree -r HEAD --name-only | sed '/^contracts$/d') | xargs tar zcfv monorepo.tar.gz --files-from -
cd contracts; (git ls-tree -r HEAD --name-only) | xargs tar zcfv ../contracts.tar.gz --files-from -
delegate_to: 127.0.0.1
become: false
args:
chdir: ".."
chdir: "{{ lookup('env', 'PWD') }}/.."
- name: Copy the files
synchronize:
dest: "{{ bridge_path }}"
src: ../../../..
rsync_opts:
- "--include=\"{{ item }}\""
- "--exclude='*'"
- "-avz"
with_items: rsync_files.stdout_lines
- name: Copy the archives
copy:
src: ../../../../{{ item }}
dest: "{{ bridge_path }}/"
with_items:
- monorepo.tar.gz
- contracts.tar.gz
- name: Untar the archives
shell: |
tar zxfv monorepo.tar.gz && rm monorepo.tar.gz
mkdir -p contracts && tar zxfv contracts.tar.gz -C ./contracts && rm contracts.tar.gz
args:
chdir: "{{ bridge_path }}"
- name: Remove local archives
shell: rm {{ item }}
delegate_to: 127.0.0.1
become: false
args:
chdir: "{{ lookup('env', 'PWD') }}/.."
with_items:
- monorepo.tar.gz
- contracts.tar.gz