Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from newrelic/functional_tests
Browse files Browse the repository at this point in the history
Adding some more functional tests
  • Loading branch information
Julien4218 authored May 26, 2020
2 parents 45f4211 + b02d44e commit 18cf4ca
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 1 deletion.
26 changes: 26 additions & 0 deletions molecule/backup-with-preexisting-config/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi

# Create pre-existing yml file to test backup
RUN mkdir /var/lib/tomcat8/newrelic
RUN echo "Old App Name" >> /var/lib/tomcat8/newrelic/newrelic.yml
22 changes: 22 additions & 0 deletions molecule/backup-with-preexisting-config/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
19 changes: 19 additions & 0 deletions molecule/backup-with-preexisting-config/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Converge
hosts: all
tasks:
- name: "Run agent install role"
include_role:
name: "newrelic-java-agent-ansible-role"
vars:
nr_java_agent_config:
license_key: YOUR_LICENSE_KEY
app_name: Molecule backup test
collector_host: localhost

server_type: tomcat
server_root: /var/lib/tomcat8
jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh
server_user: tomcat8
server_group: tomcat8
restart_web_server: false
14 changes: 14 additions & 0 deletions molecule/backup-with-preexisting-config/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: ubuntu:18.04
pre_build_image: False
privileged: True
provisioner:
name: ansible
verifier:
name: ansible
25 changes: 25 additions & 0 deletions molecule/backup-with-preexisting-config/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
tasks:
- name: Make sure the backup file was created
wait_for:
path: /var/lib/tomcat8/newrelic/newrelic.yml.orig
search_regex: Old App Name
timeout: 1

- name: Make sure the new app name is in the newrelic.yml file
wait_for:
path: /var/lib/tomcat8/newrelic/newrelic.yml
search_regex: Molecule backup test
timeout: 1

- name: Make sure .prev is _not_ created
block:
- stat:
path: /var/lib/tomcat8/newrelic/newrelic.yml.prev
register: prev
- assert:
that: not prev.stat.exists
22 changes: 22 additions & 0 deletions molecule/backup-without-preexisting-config/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi
22 changes: 22 additions & 0 deletions molecule/backup-without-preexisting-config/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
51 changes: 51 additions & 0 deletions molecule/backup-without-preexisting-config/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
- name: Converge
hosts: all
tasks:
- name: "Run agent install role once"
include_role:
name: "newrelic-java-agent-ansible-role"
vars:
nr_java_agent_config:
license_key: YOUR_LICENSE_KEY
app_name: Molecule backup first run
collector_host: localhost

server_type: tomcat
server_root: /var/lib/tomcat8
jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh
server_user: tomcat8
server_group: tomcat8
restart_web_server: false

- name: "Run agent install role again - create .orig"
include_role:
name: "newrelic-java-agent-ansible-role"
vars:
nr_java_agent_config:
license_key: YOUR_LICENSE_KEY
app_name: Molecule backup second run
collector_host: localhost

server_type: tomcat
server_root: /var/lib/tomcat8
jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh
server_user: tomcat8
server_group: tomcat8
restart_web_server: false

- name: "Run agent install role once more - create .prev"
include_role:
name: "newrelic-java-agent-ansible-role"
vars:
nr_java_agent_config:
license_key: YOUR_LICENSE_KEY
app_name: Molecule backup third run
collector_host: localhost

server_type: tomcat
server_root: /var/lib/tomcat8
jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh
server_user: tomcat8
server_group: tomcat8
restart_web_server: false
14 changes: 14 additions & 0 deletions molecule/backup-without-preexisting-config/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: ubuntu:18.04
pre_build_image: False
privileged: True
provisioner:
name: ansible
verifier:
name: ansible
17 changes: 17 additions & 0 deletions molecule/backup-without-preexisting-config/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
tasks:
- name: Make sure the .orig backup file was created correctly
wait_for:
path: /var/lib/tomcat8/newrelic/newrelic.yml.orig
search_regex: Molecule backup first run
timeout: 1

- name: Make sure the .prev backup file was created correctly
wait_for:
path: /var/lib/tomcat8/newrelic/newrelic.yml.prev
search_regex: Molecule backup second run
timeout: 1
22 changes: 22 additions & 0 deletions molecule/respect_restart_web_server_false/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Molecule managed

{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}

{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi
22 changes: 22 additions & 0 deletions molecule/respect_restart_web_server_false/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
20 changes: 20 additions & 0 deletions molecule/respect_restart_web_server_false/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include newrelic-java-agent"
include_role:
name: "newrelic-java-agent-ansible-role"
vars:
nr_java_agent_config:
license_key: YOUR_LICENSE_KEY
app_name: Tomcat Molecule test
collector_host: localhost

server_type: tomcat
server_root: /var/lib/tomcat8
jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh
server_user: tomcat8
server_group: tomcat8
service_name: tomcat8
restart_web_server: false
14 changes: 14 additions & 0 deletions molecule/respect_restart_web_server_false/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: ubuntu:18.04
pre_build_image: False
privileged: True
provisioner:
name: ansible
verifier:
name: ansible
17 changes: 17 additions & 0 deletions molecule/respect_restart_web_server_false/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
tasks:
- name: Wait for tomcat to (not) restart
pause:
seconds: 10
- name: Make sure agent log does not exist
block:
- name:
stat:
path: /var/lib/tomcat8/newrelic/logs/newrelic_agent.log
register: log_file
- assert:
that: not log_file.stat.exists
6 changes: 5 additions & 1 deletion tasks/backup_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
group: "{{ server_group }}"
mode: "0640"
become: true
# This task is not idempotent on the second run, only on subsequent runs,
# so disable idempotence testing.
tags:
- molecule-idempotence-notest

# If neither .prev nor .orig exists, we've never run before.
# Copy the existing newrelic.yml to .orig no matter what.
Expand All @@ -56,7 +60,7 @@
group: "{{ server_group }}"
mode: "0640"
become: true
# This task is not idempotent on the first run, only on subsequent runs,
# This task is not idempotent on the second run, only on subsequent runs,
# so disable idempotence testing.
tags:
- molecule-idempotence-notest
4 changes: 4 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
become: true
notify:
- restart web server
# This task always updates the newrelic.yml file's modified
# timestamp, so it is technically not idempotent
tags:
- molecule-idempotence-notest

- name: Remove newrelic.yml.new
file:
Expand Down

0 comments on commit 18cf4ca

Please sign in to comment.