Skip to content

Commit

Permalink
Add molecule testing for role.
Browse files Browse the repository at this point in the history
Additionally: fix all identified trailing whitespace
  • Loading branch information
lewg committed May 4, 2016
1 parent 3a6e6a3 commit 107459a
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ venv/
*rpm
.bundle
ansible.cfg
.molecule
test.retry
.cache
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: restart kapacitord
service:
service:
name: kapacitor
state: restarted
138 changes: 138 additions & 0 deletions molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
# role specific overrides for molecule's config options. These will override ALL other config files.
molecule:
# # directory in CWD to place all temp files, etc.
# molecule_dir: .molecule

# # where temporary state will be stored (lives under molecule_dir)
# state_file: state

# # name of temporary vagrantfile / rakefile created during runs (lives under molecule_dir)
# vagrantfile_file: vagrantfile
# rakefile_file: rakefile

# # directories to ignore when doing trailing whitespace checks on files during verify command
# ignore_paths:
# - .git
# - .vagrant
# - .molecule

# # directory to look for serverspec tests
# serverspec_dir: spec

# directory to look for testinfra tests
# testinfra_dir: tests

# # template files to load when creating corresponding temporary files
# # this would be a good place to specify your own ansible.cfg template, for example
# vagrantfile_template: vagrantfile.j2
# ansible_config_template: ansible.cfg.j2
# rakefile_template: rakefile.j2

# # ssh arguments passed to `molecule login` command
# raw_ssh_args:
# - -o StrictHostKeyChecking=no
# - -o UserKnownHostsFile=/dev/null

# # sequence of commands to run when performing `molecule test`
test:
sequence:
- destroy
- create
- converge
# - idempotence
- verify

# configuration options for the internal call to ansible-playbook
ansible:
# # by default this lives under molecule_dir and is generated by molecule during execution
# config_file: ansible.cfg

# # playbook to execute during `molecule converge`
playbook: tests/test.yml

# # install role dependencies from that file with `ansible-galaxy` during `molecule converge`
# requirements_file: requirements.yml

# # verbosity for ansible-playbook
# verbose: vvvv

# # most CLI options to ansible-playbook can be passed in this format, even those not listed
# user: vagrant
# connection: ssh
# timeout: 30
# sudo: True
# sudo_user: False
# ask_sudo_pass: False
# ask_vault_pass: False
# vault_password_file: False
# limit: all
# diff: True
# tags: False
host_key_checking: False

# # this can be the path to a custom inventory script/directory
# # by default this lives under molecule_dir and is generated by molecule during execution
# inventory_file: ansible_inventory

# # raw ssh arguments passed to ansible-playbook
# raw_ssh_args:
# - -o UserKnownHostsFile=/dev/null
# - -o IdentitiesOnly=yes
# - -o ControlMaster=auto
# - -o ControlPersist=60s

# # any additional environment variables that ansible-playbook supports can be passed in here
# raw_env_vars:
# ANSIBLE_ACTION_PLUGINS: ../plugins

# configuration options for the internal call to vagrant
vagrant:
# vagrant arguments that are global to all instances
raw_config_args:
- "ssh.insert_key = false"
# - "vm.network 'forwarded_port', guest: 80, host: 8080"

# molecule's --platform option will look for these names
platforms:
- name: trusty64
box: trusty64
box_url: https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/14.04/providers/virtualbox.box
- name: centos72
box: bento/centos-7.2

providers:
- name: virtualbox
type: virtualbox
# options:
# memory: 512
# cpus: 2

instances:
- name: kapacitor-01
ansible_groups:
- kapacitor
interfaces:
- network_name: private_network
type: dhcp
auto_config: true
options:
# prevents vagrant-01 from becoming vagrant-01-rhel-7 (platform is appended by default)
append_platform_to_hostname: no
# vagrant arguments specific to this instance
# raw_config_args:
# - "vm.synced_folder '../projects/web', '/web'"

# - name: network-01
# ansible_groups:
# - group_1
# - group_2
# interfaces:
# - network_name: private_network
# type: dhcp
# auto_config: true
# - network_name: private_network
# type: dhcp
# auto_config: false
# options:
# append_platform_to_hostname: no
7 changes: 3 additions & 4 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Set templatized Kapacitor configuration
template:
src: kapacitor.conf.j2
template:
src: kapacitor.conf.j2
dest: "/etc/kapacitor/kapacitor.conf"
force: yes
backup: yes
Expand Down Expand Up @@ -36,7 +36,7 @@

- debug:
var: kapacitor_list_tasks

- name: Copy specified TICKscript scripts to remote host
copy:
src: "{{ item.tick }}"
Expand All @@ -53,4 +53,3 @@
command: kapacitor enable {{ item.name }}
when: kapacitor_list_tasks.stdout.find("{{ item.name }}") == -1
with_items: "{{ kapacitor_tasks_to_enable }}"

12 changes: 6 additions & 6 deletions tasks/install-debian.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
- name: Install any necessary dependencies [Debian/Ubuntu]
apt:
name: "{{ item }}"
state: present
update_cache: yes
apt:
name: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
with_items:
- python-httplib2
Expand All @@ -23,11 +23,11 @@
when: kapacitor_install_url is not defined or kapacitor_install_url == None

- name: Install Kapacitor packages [Debian/Ubuntu]
apt:
apt:
name: kapacitor
state: latest
when: kapacitor_install_url is not defined or kapacitor_install_url == None

- name: Download Kapacitor package via URL [Debian/Ubuntu]
command: curl -o /tmp/kapacitor-ansible-download.deb {{ kapacitor_install_url }}
when: kapacitor_install_url is defined and kapacitor_install_url != None
Expand Down
9 changes: 4 additions & 5 deletions tasks/install-redhat.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Install any necessary dependencies [RedHat/CentOS]
yum:
name: "{{ item }}"
yum:
name: "{{ item }}"
state: present
with_items:
- curl
Expand All @@ -15,14 +15,13 @@
when: kapacitor_install_url is not defined or kapacitor_install_url == None

- name: Install Kapacitor packages [RHEL/CentOS]
yum:
yum:
name: kapacitor
state: present
when: kapacitor_install_url is not defined or kapacitor_install_url == None

- name: Install Kapacitor from URL [RHEL/CentOS]
yum:
yum:
name: "{{ kapacitor_install_url }}"
state: present
when: kapacitor_install_url is defined and kapacitor_install_url != None

29 changes: 29 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- hosts: all
remote_user: root
vars:
- influxdb_install_version:
roles:
- role: ansible-kapacitor
influxdb_install_version: stable
kapacitor_tasks_to_enable:
- name: cpu_alert
type: stream
tick: cpu_alert.tick
dbrp: telegraf.default
- name: cpu_alert_batch
type: batch
tick: cpu_alert_batch.tick
dbrp: telegraf.default
- name: disk_alert
type: stream
tick: disk_alert.tick
dbrp: telegraf.default
kapacitor_influxdb_subscriptions:
- name: test_db
rps:
- rp_test_db
- name: test_db_2
rps:
- rp_test_db_one
- rp_test_db_two
19 changes: 19 additions & 0 deletions tests/test_kapacitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

def test_kapacitor_running_and_enabled(Service):
kapacitor = Service("kapacitor")
assert kapacitor.is_running
assert kapacitor.is_enabled

def test_kapacitor_config(File):
kapacitor_config = File("/etc/kapacitor/kapacitor.conf")
assert kapacitor_config.exists
assert 'test_db = ["rp_test_db"]' in kapacitor_config.content_string
assert 'test_db_2 = ["rp_test_db_one", "rp_test_db_two"]' in kapacitor_config.content_string

def test_tick_file(File):
tick_script = File("/tmp/cpu_alert.tick")
assert tick_script.exists

def test_tick_load(Command):
tick_load = Command("kapacitor list tasks")
assert "cpu_alert" in tick_load.stdout
2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ kapacitor_template_configuration: yes

# If supplied, will check for presence of database, and error if not found (useful for upgrade
# testing).
kapacitor_verify_database_is_present:
kapacitor_verify_database_is_present:

0 comments on commit 107459a

Please sign in to comment.