mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-09 04:10:27 -07:00
Merge pull request #214 from ericsysmin/gcsfuse_role_tests
This commit is contained in:
commit
c1a13a5a74
9 changed files with 281 additions and 0 deletions
10
.ansible-lint
Normal file
10
.ansible-lint
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
parseable: true
|
||||||
|
skip_list:
|
||||||
|
- ANSIBLE0010
|
||||||
|
use_default_rules: true
|
||||||
|
verbosity: 1
|
||||||
|
exclude_paths:
|
||||||
|
- ./roles/gcp_http_lb/
|
||||||
|
- ./tests/
|
||||||
|
- ./plugins
|
52
.github/workflows/gcsfuse.yml
vendored
Normal file
52
.github/workflows/gcsfuse.yml
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
name: "google.cloud.gcsfuse"
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- roles/gcsfuse/**
|
||||||
|
- .github/workflows/gcsfuse.yml
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- roles/gcsfuse/**
|
||||||
|
- .github/workflows/gcsfuse.yml
|
||||||
|
jobs:
|
||||||
|
gcsfuse:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
env:
|
||||||
|
PY_COLORS: 1
|
||||||
|
ANSIBLE_FORCE_COLOR: 1
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
molecule_distro:
|
||||||
|
- distro: ubuntu:16.04
|
||||||
|
command: /sbin/init
|
||||||
|
- distro: ubuntu:18.04
|
||||||
|
command: /lib/systemd/systemd
|
||||||
|
- distro: debian:9
|
||||||
|
command: /lib/systemd/systemd
|
||||||
|
collection_role:
|
||||||
|
- gcsfuse
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
path: ansible_collections/google/cloud
|
||||||
|
|
||||||
|
- name: Set up Python 3.8
|
||||||
|
uses: actions/setup-python@v1
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt install docker
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install molecule yamllint ansible-lint docker
|
||||||
|
|
||||||
|
- name: Run role test
|
||||||
|
run: >-
|
||||||
|
molecule --version &&
|
||||||
|
ansible --version &&
|
||||||
|
MOLECULE_COMMAND=${{ matrix.molecule_distro.command }}
|
||||||
|
MOLECULE_DISTRO=${{ matrix.molecule_distro.distro }}
|
||||||
|
molecule --debug test -s ${{ matrix.collection_role }}
|
33
.yamllint
Normal file
33
.yamllint
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
# Based on ansible-lint config
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
braces:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
brackets:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
colons:
|
||||||
|
max-spaces-after: -1
|
||||||
|
level: error
|
||||||
|
commas:
|
||||||
|
max-spaces-after: -1
|
||||||
|
level: error
|
||||||
|
comments: disable
|
||||||
|
comments-indentation: disable
|
||||||
|
document-start: disable
|
||||||
|
empty-lines:
|
||||||
|
max: 3
|
||||||
|
level: error
|
||||||
|
hyphens:
|
||||||
|
level: error
|
||||||
|
indentation: disable
|
||||||
|
key-duplicates: enable
|
||||||
|
line-length: disable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
new-lines:
|
||||||
|
type: unix
|
||||||
|
trailing-spaces: disable
|
||||||
|
truthy: disable
|
111
molecule/gcsfuse/Dockerfile.j2
Normal file
111
molecule/gcsfuse/Dockerfile.j2
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# Molecule managed
|
||||||
|
|
||||||
|
{% if item.registry is defined %}
|
||||||
|
FROM {{ item.registry.url }}/{{ item.image }}
|
||||||
|
{% else %}
|
||||||
|
FROM {{ item.image }}
|
||||||
|
{% endif %}
|
||||||
|
ENV container=docker
|
||||||
|
|
||||||
|
{# Initial Package Installs and Container Prep #}
|
||||||
|
{% if item.image.split(':', 1)[0] in ["ubuntu"] %}
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
locales software-properties-common rsyslog systemd systemd-cron sudo \
|
||||||
|
iproute2
|
||||||
|
RUN sed -i 's/^\($ModLoad imklog\)/#\1/' /etc/rsyslog.conf
|
||||||
|
{% elif item.image.split(':', 1)[0] in ["debian"] %}
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
sudo systemd systemd-sysv \
|
||||||
|
build-essential wget
|
||||||
|
{% elif item.image.split(':', 1)[0] in ["centos"] %}
|
||||||
|
{% if item.image in ["centos:7"] %}
|
||||||
|
RUN yum makecache fast && yum -y install deltarpm \
|
||||||
|
{% elif item.image in ["centos:8"] %}
|
||||||
|
RUN yum makecache --timer \
|
||||||
|
{% endif %}
|
||||||
|
&& yum -y install epel-release \
|
||||||
|
&& yum -y update \
|
||||||
|
&& yum -y install sudo which
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{# Install of Python2 #}
|
||||||
|
{% if item.image in ["ubuntu:16.04"] %}
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends python-setuptools wget \
|
||||||
|
&& wget https://bootstrap.pypa.io/get-pip.py \
|
||||||
|
&& python get-pip.py
|
||||||
|
{% elif item.image in ["debian:9"] %}
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends libffi-dev libssl-dev \
|
||||||
|
python-pip python-dev python-setuptools python-wheel
|
||||||
|
{% elif item.image in ["centos:7"] %}
|
||||||
|
RUN yum -y install python-pip
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# Install of Python3 #}
|
||||||
|
{% if item.image in ["ubuntu:18.04", "ubuntu:20.04", "debian:10"] %}
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
apt-utils python3-setuptools python3-pip
|
||||||
|
{% endif %}
|
||||||
|
{% if item.image in ["centos:8"] %}
|
||||||
|
RUN yum -y install hostname python3 python3-pip
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# Steps for cleanup #}
|
||||||
|
{% if item.image.split(':', 1)[0] in ["ubuntu", "debian"] %}
|
||||||
|
RUN rm -Rf /var/lib/apt/lists/* \
|
||||||
|
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
|
||||||
|
&& apt-get clean
|
||||||
|
{% elif item.image.split(':', 1)[0] in ["centos"] %}
|
||||||
|
RUN yum clean all
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# Steps for clenaup of systemd #}
|
||||||
|
{% if item.image in ["centos:7", "centos:8", "debian:9"] %}
|
||||||
|
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
|
||||||
|
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
|
||||||
|
rm -f /lib/systemd/system/multi-user.target.wants/*;\
|
||||||
|
rm -f /etc/systemd/system/*.wants/*;\
|
||||||
|
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||||
|
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||||
|
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||||
|
rm -f /lib/systemd/system/basic.target.wants/*;\
|
||||||
|
rm -f /lib/systemd/system/anaconda.target.wants/*; \
|
||||||
|
mkdir -p /run/systemd/system
|
||||||
|
{% endif %}
|
||||||
|
{% if item.image in ["ubuntu:18.04", "ubuntu:20.04"] %}
|
||||||
|
# Remove unnecessary getty and udev targets that result in high CPU usage when using
|
||||||
|
# multiple containers with Molecule (https://github.com/ansible/molecule/issues/1104)
|
||||||
|
RUN rm -f /lib/systemd/system/systemd*udev* \
|
||||||
|
&& rm -f /lib/systemd/system/getty.target
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% if item.image in ["centos:7", "centos:8"] %}
|
||||||
|
# Disable requiretty.
|
||||||
|
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if item.image.split(':', 1)[0] not in ["centos", "debian"] %}
|
||||||
|
# Fix potential UTF-8 errors with ansible-test.
|
||||||
|
RUN locale-gen en_US.UTF-8
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
# Install Ansible inventory file.
|
||||||
|
RUN mkdir -p /etc/ansible
|
||||||
|
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
|
||||||
|
|
||||||
|
{% if item.image in ["centos:7", "centos:8", "debian:9", "debian:10"] %}
|
||||||
|
VOLUME ["/sys/fs/cgroup"]
|
||||||
|
{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04"] %}
|
||||||
|
VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]
|
||||||
|
{% endif %}
|
||||||
|
{% if item.image in ["centos:7", "centos:8"] %}
|
||||||
|
CMD ["/usr/sbin/init"]
|
||||||
|
{% elif item.image in ["ubuntu:16.04", "ubuntu:18.04", "ubuntu:20.04", "debian:9", "debian:10"] %}
|
||||||
|
CMD ["/lib/systemd/systemd"]
|
||||||
|
{% endif %}
|
24
molecule/gcsfuse/converge.yml
Normal file
24
molecule/gcsfuse/converge.yml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
pre_tasks:
|
||||||
|
- name: Using apt update the packages
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
when: ansible_os_family == "Debian"
|
||||||
|
- name: Using apt update the packages
|
||||||
|
yum:
|
||||||
|
update_cache: yes
|
||||||
|
when: ansible_os_family == "RedHat"
|
||||||
|
- name: create containerd folder
|
||||||
|
file:
|
||||||
|
path: /etc/systemd/system/containerd.service.d
|
||||||
|
state: directory
|
||||||
|
when: ansible_service_mgr == "systemd"
|
||||||
|
- name: override file for containerd
|
||||||
|
copy:
|
||||||
|
src: files/override.conf
|
||||||
|
dest: /etc/systemd/system/containerd.service.d/override.conf
|
||||||
|
when: ansible_service_mgr == "systemd"
|
||||||
|
roles:
|
||||||
|
- role: google.cloud.gcsfuse
|
2
molecule/gcsfuse/files/override.conf
Normal file
2
molecule/gcsfuse/files/override.conf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[Service]
|
||||||
|
ExecStartPre=
|
20
molecule/gcsfuse/molecule.yml
Normal file
20
molecule/gcsfuse/molecule.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint: |
|
||||||
|
set -e
|
||||||
|
yamllint .
|
||||||
|
ansible-lint
|
||||||
|
platforms:
|
||||||
|
- name: instance
|
||||||
|
image: ${MOLECULE_DISTRO:-ubuntu:xenial}
|
||||||
|
privileged: true
|
||||||
|
command: ${MOLECULE_COMMAND:-"sleep infinity"}
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
playbooks:
|
||||||
|
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
|
20
molecule/gcsfuse/tests/test_default.py
Normal file
20
molecule/gcsfuse/tests/test_default.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import os
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_service(host):
|
||||||
|
service = host.service('docker')
|
||||||
|
|
||||||
|
assert service.is_running
|
||||||
|
assert service.is_enabled
|
||||||
|
|
||||||
|
|
||||||
|
def test_hosts_file(host):
|
||||||
|
f = host.file('/etc/hosts')
|
||||||
|
|
||||||
|
assert f.exists
|
||||||
|
assert f.user == 'root'
|
||||||
|
assert f.group == 'root'
|
9
molecule/gcsfuse/verify.yml
Normal file
9
molecule/gcsfuse/verify.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
# This is an example playbook to execute Ansible tests.
|
||||||
|
|
||||||
|
- name: Verify
|
||||||
|
hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: Example assertion
|
||||||
|
assert:
|
||||||
|
that: true
|
Loading…
Add table
Reference in a new issue