add tests, debianism
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6f76275
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+tests/build/
+*.swp
+*.pyc
\ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..686bfe6
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,17 @@
+salt-formula-isc-dhcp (0.3) trusty; urgency=medium
+
+ * add tests
+
+ -- Jan Kaufman <jan.kaufman@tcpcloud.eu> Wed, 17 Feb 2016 13:50:01 +0200
+
+salt-formula-isc-dhcp (0.2) trusty; urgency=medium
+
+ * First public release
+
+ -- Filip Pytloun <filip.pytloun@tcpcloud.eu> Tue, 06 Oct 2015 16:38:53 +0200
+
+salt-formula-isc-dhcp (0.1) trusty; urgency=medium
+
+ * Initial release
+
+ -- Ales Komarek <ales.komarek@tcpcloud.eu> Thu, 13 Aug 2015 23:23:41 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..50a7f93
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-isc-dhcp
+Maintainer: Jan Kaufman <jan.kaufman@tcpcloud.eu>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9)
+Standards-Version: 3.9.6
+Homepage: http://www.tcpcloud.eu
+Vcs-Browser: https://github.com/tcpcloud/salt-formula-isc-dhcp
+Vcs-Git: https://github.com/tcpcloud/salt-formula-isc-dhcp.git
+
+Package: salt-formula-isc-dhcp
+Architecture: all
+Depends: ${misc:Depends}, salt-master, reclass
+Description: isc-dhcp salt formula
+ Install and configure isc-dhcp server
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..58fc69b
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-isc-dhcp
+Upstream-Contact: Jan Kaufman <jan.kaufman@tcpcloud.eu>
+Source: https://github.com/tcpcloud/salt-formula-isc-dhcp
+
+Files: *
+Copyright: 2014-2015 tcp cloud a.s.
+License: Apache-2.0
+ Copyright (C) 2014-2015 tcp cloud a.s.
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/install b/debian/install
new file mode 100644
index 0000000..d0678a3
--- /dev/null
+++ b/debian/install
@@ -0,0 +1,2 @@
+isc_dhcp/* /usr/share/salt-formulas/env/isc_dhcp/
+metadata/service/* /usr/share/salt-formulas/reclass/service/isc_dhcp/
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/isc_dhcp/map.jinja b/isc_dhcp/map.jinja
index 361a150..1786289 100644
--- a/isc_dhcp/map.jinja
+++ b/isc_dhcp/map.jinja
@@ -13,10 +13,10 @@
zone: {}
FreeBSD:
pkgs:
- - isc-dhcp42-server
+ - isc-dhcp42-server
service: isc-dhcpd
logging:
- facility: local7
+ facility: local7
defaults_config: /etc/rc.conf.d/dhcpd
config_dir: /usr/local/etc
dhcpd_config: /usr/local/etc/dhcpd.conf
diff --git a/isc_dhcp/server.sls b/isc_dhcp/server.sls
index 394e1d5..2037f01 100644
--- a/isc_dhcp/server.sls
+++ b/isc_dhcp/server.sls
@@ -63,4 +63,4 @@
- name: {{ server.service }}
- enable: true
-{%- endif %}
\ No newline at end of file
+{%- endif %}
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..1f289a6
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,3 @@
+name: "isc_dhcp"
+version: "0.2"
+source: "https://github.com/tcpcloud/salt-formula-isc-dhcp"
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
index 47b0739..65c08b5 100644
--- a/metadata/service/support.yml
+++ b/metadata/service/support.yml
@@ -1,5 +1,5 @@
parameters:
- isc-dhcp:
+ isc_dhcp:
_support:
collectd:
enabled: false
diff --git a/tests/pillar/server_single.sls b/tests/pillar/server_single.sls
new file mode 100644
index 0000000..7064099
--- /dev/null
+++ b/tests/pillar/server_single.sls
@@ -0,0 +1,24 @@
+isc_dhcp:
+ server:
+ enabled: true
+ omapi_port: 7911
+ omapi_key: iFdQ0kvpUo+3gzXGJTpjk7/dl9DI5SuDqMzasDUhBRGEg6VfNYUX+MAU14WoJJZDQbrvC4Pgsdfdsfdsfdsdf==
+ authoritative: true
+ interfaces:
+ - name: eth0
+ - name: eth1
+ domain_name: domain.com
+ name_servers:
+ - ns1.domain.com
+ host:
+ node1:
+ mac: 00:11:22:33:44:55:66
+ address: 192.168.0.1
+ hostname: domain.com
+ subnet:
+ testsubnet:
+ range: 10.0.0.1 10.0.0.100
+ netmask: 255.255.255.0
+ network: 10.0.0.0
+ pxeserver: 10.1.1.1
+
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..1f1316f
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+METADATA=${CURDIR}/../metadata.yml
+FORMULA_NAME=$(cat $METADATA | python -c "import sys,yaml; print yaml.load(sys.stdin)['name']")
+
+## Overrideable parameters
+PILLARDIR=${PILLARDIR:-${CURDIR}/pillar}
+BUILDDIR=${BUILDDIR:-${CURDIR}/build}
+VENV_DIR=${VENV_DIR:-${BUILDDIR}/virtualenv}
+DEPSDIR=${BUILDDIR}/deps
+
+SALT_FILE_DIR=${SALT_FILE_DIR:-${BUILDDIR}/file_root}
+SALT_PILLAR_DIR=${SALT_PILLAR_DIR:-${BUILDDIR}/pillar_root}
+SALT_CONFIG_DIR=${SALT_CONFIG_DIR:-${BUILDDIR}/salt}
+SALT_CACHE_DIR=${SALT_CACHE_DIR:-${SALT_CONFIG_DIR}/cache}
+
+SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR}"
+
+if [ "x${SALT_VERSION}" != "x" ]; then
+ PIP_SALT_VERSION="==${SALT_VERSION}"
+fi
+
+## Functions
+log_info() {
+ echo "[INFO] $*"
+}
+
+log_err() {
+ echo "[ERROR] $*" >&2
+}
+
+setup_virtualenv() {
+ log_info "Setting up Python virtualenv"
+ virtualenv $VENV_DIR
+ source ${VENV_DIR}/bin/activate
+ pip install salt${PIP_SALT_VERSION}
+}
+
+setup_pillar() {
+ [ ! -d ${SALT_PILLAR_DIR} ] && mkdir -p ${SALT_PILLAR_DIR}
+ echo "base:" > ${SALT_PILLAR_DIR}/top.sls
+ for pillar in ${PILLARDIR}/*; do
+ state_name=$(basename ${pillar%.sls})
+ echo -e " ${state_name}:\n - ${state_name}" >> ${SALT_PILLAR_DIR}/top.sls
+ done
+}
+
+setup_salt() {
+ [ ! -d ${SALT_FILE_DIR} ] && mkdir -p ${SALT_FILE_DIR}
+ [ ! -d ${SALT_CONFIG_DIR} ] && mkdir -p ${SALT_CONFIG_DIR}
+ [ ! -d ${SALT_CACHE_DIR} ] && mkdir -p ${SALT_CACHE_DIR}
+
+ echo "base:" > ${SALT_FILE_DIR}/top.sls
+ for pillar in ${PILLARDIR}/*.sls; do
+ state_name=$(basename ${pillar%.sls})
+ echo -e " ${state_name}:\n - ${FORMULA_NAME}" >> ${SALT_FILE_DIR}/top.sls
+ done
+
+ cat << EOF > ${SALT_CONFIG_DIR}/minion
+file_client: local
+cachedir: ${SALT_CACHE_DIR}
+verify_env: False
+
+file_roots:
+ base:
+ - ${SALT_FILE_DIR}
+ - ${CURDIR}/..
+
+pillar_roots:
+ base:
+ - ${SALT_PILLAR_DIR}
+ - ${PILLARDIR}
+EOF
+}
+
+fetch_dependency() {
+ dep_root="${DEPSDIR}/$(basename $1 .git)"
+ dep_metadata="${dep_root}/metadata.yml"
+
+ [ -d $dep_root ] && log_info "Dependency $1 already fetched" && return 0
+
+ log_info "Fetching dependency $1"
+ [ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
+ git clone $1 ${DEPSDIR}/$(basename $1 .git)
+
+ dep_name=$(cat $dep_metadata | python -c "import sys,yaml; print yaml.load(sys.stdin)['name']")
+ ln -s ${dep_root}/${dep_name} ${SALT_FILE_DIR}/${dep_name}
+
+ METADATA="${dep_metadata}" install_dependencies
+}
+
+install_dependencies() {
+ grep -E "^dependencies:" ${METADATA} >/dev/null || return 0
+ (python - | while read dep; do fetch_dependency "$dep"; done) << EOF
+import sys,yaml
+for dep in yaml.load(open('${METADATA}', 'ro'))['dependencies']:
+ print dep["source"]
+EOF
+}
+
+clean() {
+ log_info "Cleaning up ${BUILDDIR}"
+ [ -d ${BUILDDIR} ] && rm -rf ${BUILDDIR} || exit 0
+}
+
+salt_run() {
+ source ${VENV_DIR}/bin/activate
+ salt-call ${SALT_OPTS} $*
+}
+
+prepare() {
+ [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
+
+ setup_virtualenv
+ setup_pillar
+ setup_salt
+ install_dependencies
+}
+
+run() {
+ for pillar in ${PILLARDIR}/*.sls; do
+ state_name=$(basename ${pillar%.sls})
+ salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+ done
+}
+
+_atexit() {
+ RETVAL=$?
+ trap true INT TERM EXIT
+
+ if [ $RETVAL -ne 0 ]; then
+ log_err "Execution failed"
+ else
+ log_info "Execution successful"
+ fi
+ return $RETVAL
+}
+
+## Main
+trap _atexit INT TERM EXIT
+
+case $1 in
+ clean)
+ clean
+ ;;
+ prepare)
+ prepare
+ ;;
+ run)
+ run
+ ;;
+ *)
+ prepare
+ run
+ ;;
+esac