Add kitchen tests
diff --git a/.gitignore b/.gitignore
index 6f76275..0bb08c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
tests/build/
*.swp
-*.pyc
\ No newline at end of file
+*.pyc
+.kitchen
diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml
new file mode 100644
index 0000000..554ad82
--- /dev/null
+++ b/.kitchen.docker.yml
@@ -0,0 +1,16 @@
+---
+driver:
+ name: docker
+ hostname: logrotate.ci.local
+ use_sudo: false
+
+provisioner:
+ salt_bootstrap_url: https://raw.githubusercontent.com/epcim/salt-bootstrap/add-apt-transport-https-ubuntu/bootstrap-salt.sh
+ grains:
+ noservices: True
+
+platforms:
+ - name: ubuntu-14.04
+ - name: ubuntu-16.04
+ - name: centos-7
+
diff --git a/.kitchen.openstack.yml b/.kitchen.openstack.yml
new file mode 100644
index 0000000..a1d32da
--- /dev/null
+++ b/.kitchen.openstack.yml
@@ -0,0 +1,44 @@
+---
+# https://docs.chef.io/config_yml_kitchen.html
+
+driver:
+ # OPENSTACK API
+ # https://github.com/test-kitchen/kitchen-openstack
+ name: openstack
+ openstack_auth_url: <%= ENV['OS_AUTH_URL'] %>/tokens
+ openstack_username: <%= ENV['OS_USERNAME'] || 'ci' %>
+ openstack_api_key: <%= ENV['OS_PASSWORD'] || 'ci' %>
+ openstack_tenant: <%= ENV['OS_TENANT_NAME'] || 'ci_jenkins' %>
+
+ #floating_ip_pool: <%= ENV['OS_FLOATING_IP_POOL'] || 'nova' %>
+ #key_name: <%= ENV['BOOTSTRAP_SSH_KEY_NAME'] || 'id_ed25519' %>
+ key_name: <%= ENV['BOOTSTRAP_SSH_KEY_NAME'] || 'bootstrap_insecure' %>
+ private_key_path: <%= ENV['BOOTSTRAP_SSH_KEY_PATH'] || "#{ENV['HOME']}/.ssh/id_rsa_bootstrap_insecure" %>
+
+ require_chef_omnibus: false #[e.g. 'true' or a version number if you need Chef]
+
+
+platforms:
+ - name: ubuntu-14.04
+ driver:
+ username: <%= ENV['OS_UBUNTU_IMAGE_USER'] || 'root' %>
+ image_ref: <%= ENV['OS_UBUNTU_IMAGE_REF'] || 'ubuntu-14-04-x64-1455869035' %>
+ flavor_ref: m1.medium
+ network_ref:
+ <% if ENV['OS_NETWORK_REF'] -%>
+ - <% ENV['OS_NETWORK_REF'] %>
+ <% else -%>
+ - ci-net
+ <% end -%>
+ # force update apt cache on the image
+ run_list:
+ - recipe[apt]
+ attributes:
+ apt:
+ compile_time_update: true
+transport:
+ username: <%= ENV['OS_UBUNTU_IMAGE_USER'] || 'root' %>
+
+
+# vim: sw=2 ts=2 sts=2 tw=125
+## EXAMPLES, dynamic kitchen driver, http://stackoverflow.com/questions/26516373/alternate-drivers-with-test-kitchen
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644
index 0000000..02deb83
--- /dev/null
+++ b/.kitchen.yml
@@ -0,0 +1,41 @@
+# vim: ft=yaml
+---
+driver:
+ name: vagrant
+ customize:
+ memory: 512
+ vm_hostname: logrotate.ci.local
+
+provisioner:
+ name: salt_solo
+ # As of 2016/06 http://bootstrap.saltstack.org do not handle ubuntu 16.04. and fails in docker container
+ # salt_bootstrap_url: https://bootstrap.saltstack.org
+ salt_bootstrap_url: https://raw.githubusercontent.com/epcim/salt-bootstrap/add-apt-transport-https-ubuntu/bootstrap-salt.sh
+ salt_install: bootstrap
+ salt_version: latest
+ formula: logrotate
+ log_level: info
+ state_top:
+ base:
+ "*":
+ - logrotate
+ pillars:
+ top.sls:
+ base:
+ "*":
+ - logrotate
+ logrotate.sls:
+ server:
+ ssl:
+ enabled: false
+
+platforms:
+ - name: bento/ubuntu-14.04
+ - name: bento/ubuntu-16.04
+ - name: bento/centos-7
+
+suites:
+ - name: server
+ provisioner:
+ pillars-from-files:
+ logrotate.sls: tests/pillar/server.sls
diff --git a/Makefile b/Makefile
index fc83783..8f8523a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,26 @@
RECLASSDIR=/usr/share/salt-formulas/reclass
FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-]*')
+MAKE_PID := $(shell echo $$PPID)
+JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
+
+ifneq ($(subst -j,,$(JOB_FLAG)),)
+JOBS := $(subst -j,,$(JOB_FLAG))
+else
+JOBS := 1
+endif
+
+KITCHEN_LOCAL_YAML?=.kitchen.yml
+KITCHEN_OPTS?="--concurrency=$(JOBS)"
+KITCHEN_OPTS_CREATE?=""
+KITCHEN_OPTS_CONVERGE?=""
+KITCHEN_OPTS_VERIFY?=""
+KITCHEN_OPTS_TEST?=""
+
all:
@echo "make install - Install into DESTDIR"
@echo "make test - Run tests"
+ @echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
@echo "make clean - Cleanup after tests run"
install:
@@ -21,6 +38,28 @@
test:
[ ! -d tests ] || (cd tests; ./run_tests.sh)
+kitchen: kitchen-create kitchen-converge kitchen-verify kitchen-list
+
+kitchen-create:
+ kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
+ [ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
+
+kitchen-converge:
+ kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
+
+kitchen-verify:
+ [ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+ [ -d tests/integration ] || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+
+kitchen-test:
+ [ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+ [ -d tests/integration ] || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+
+kitchen-list:
+ kitchen list
+
clean:
+ [ ! -x "$(shell which kitchen)" ] || kitchen destroy
+ [ ! -d .kitchen ] || rm -rf .kitchen
[ ! -d tests/build ] || rm -rf tests/build
[ ! -d build ] || rm -rf build