Added Kitchen tests and Travis
Change-Id: Ic56650e5dab61f7dd8fecbc2d3d0e57bc5f69132
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..aa8e42a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.kitchen
+tests/build/
+*.swp
+*.pyc
+.ropeproject
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644
index 0000000..9014285
--- /dev/null
+++ b/.kitchen.yml
@@ -0,0 +1,52 @@
+---
+driver:
+ name: docker
+ hostname: telegraf.ci.local
+ use_sudo: false
+
+provisioner:
+ name: salt_solo
+ salt_install: bootstrap
+ salt_bootstrap_url: https://bootstrap.saltstack.com
+ salt_version: latest
+ require_chef: false
+ log_level: error
+ formula: telegraf
+ grains:
+ noservices: True
+ dependencies:
+ - name: linux
+ repo: git
+ source: https://github.com/salt-formulas/salt-formula-linux
+ state_top:
+ base:
+ "*":
+ - linux.system.repo
+ - telegraf
+ pillars:
+ top.sls:
+ base:
+ "*":
+ - telegraf
+ - linux_repo_extra
+ pillars-from-files:
+ linux_repo_extra.sls: tests/pillar/repo_extra.sls
+
+verifier:
+ name: inspec
+ sudo: true
+
+
+platforms:
+ - name: <%=ENV['PLATFORM'] || 'ubuntu-xenial'%>
+ driver_config:
+ image: <%=ENV['PLATFORM'] || 'trevorj/salty-whales:xenial'%>
+ platform: ubuntu
+
+suites:
+
+ - name: telegraf_agent
+ provisioner:
+ pillars-from-files:
+ telegraf.sls: tests/pillar/telegraf_agent.sls
+# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..7a77247
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,39 @@
+sudo: required
+services:
+ - docker
+
+install:
+ - pip install PyYAML
+ - pip install virtualenv
+ - |
+ test -e Gemfile || cat <<EOF > Gemfile
+ source 'https://rubygems.org'
+ gem 'rake'
+ gem 'test-kitchen'
+ gem 'kitchen-docker'
+ gem 'kitchen-inspec'
+ gem 'inspec'
+ gem 'kitchen-salt', :git => 'https://github.com/salt-formulas/kitchen-salt.git'
+ - bundle install
+
+env:
+ - PLATFORM=trevorj/salty-whales:trusty
+ - PLATFORM=trevorj/salty-whales:xenial
+
+before_script:
+ - set -o pipefail
+ - make test | tail
+
+script:
+ - test ! -e .kitchen.yml || bundle exec kitchen test -t tests/integration
+
+notifications:
+ webhooks:
+ urls:
+ - https://webhooks.gitter.im/e/6123573504759330786b
+ on_success: change # options: [always|never|change] default: always
+ on_failure: never # options: [always|never|change] default: always
+ on_start: never # options: [always|never|change] default: always
+ on_cancel: never # options: [always|never|change] default: always
+ on_error: never # options: [always|never|change] default: always
+ email: false
diff --git a/telegraf/agent.sls b/telegraf/agent.sls
index 105b0c9..fc03f2c 100644
--- a/telegraf/agent.sls
+++ b/telegraf/agent.sls
@@ -31,8 +31,10 @@
- template: jinja
- require:
- pkg: telegraf_packages
+ {%- if not grains.get('noservices', False)%}
- watch_in:
- service: telegraf_service
+ {%- endif %}
- defaults:
name: {{ name }}
values: {{ values }}
@@ -41,7 +43,7 @@
telegraf_user:
user.present:
- name: telegraf
- - groups:
+ - optional_groups:
- docker
- require:
- pkg: telegraf_packages
@@ -53,8 +55,10 @@
- name: {{ agent.dir.config }}/input-{{ name }}.conf
- require:
- pkg: telegraf_packages
+ {%- if not grains.get('noservices', False)%}
- watch_in:
- service: telegraf_service
+ {%- endif %}
{%- endif %}
{%- endfor %}
@@ -71,14 +75,18 @@
- template: jinja
- require:
- pkg: telegraf_packages
+ {%- if not grains.get('noservices', False)%}
- watch_in:
- service: telegraf_service
+ {%- endif %}
- defaults:
name: {{ name }}
values: {{ values }}
{%- endfor %}
+{%- if not grains.get('noservices', False)%}
+
telegraf_service:
service.running:
- name: telegraf
@@ -87,3 +95,5 @@
- file: telegraf_config
{%- endif %}
+
+{%- endif %}
diff --git a/tests/pillar/repo_extra.sls b/tests/pillar/repo_extra.sls
new file mode 100644
index 0000000..742a90f
--- /dev/null
+++ b/tests/pillar/repo_extra.sls
@@ -0,0 +1,8 @@
+linux:
+ system:
+ enabled: true
+ repo:
+ mcp_extra_repo:
+ source: "deb [arch=amd64] http://apt-mk.mirantis.com/{{ grains.get('oscodename') }}/ nightly extra"
+ architectures: amd64
+ key_url: "http://apt-mk.mirantis.com/public.gpg"
diff --git a/tests/pillar/telegraf_agent.sls b/tests/pillar/telegraf_agent.sls
index 1b8d362..c0d4f33 100644
--- a/tests/pillar/telegraf_agent.sls
+++ b/tests/pillar/telegraf_agent.sls
@@ -6,9 +6,56 @@
metric_batch_size: 1000
metric_buffer_limit: 10000
collection_jitter: 2
+ flush_interval: 10
+ flush_jitter: 2
+ precision: ms
+ logfile: etc/telegraf/log
+ debug: true
+ quiet: false
+ hostname: hostname
+ omit_hostname: false
+ global_tags:
+ user: $USER
+ static_tag: global_tag_1
output:
prometheus_client:
bind:
address: 127.0.0.1
port: 9126
engine: prometheus
+ input:
+ cpu:
+ totalcpu: totalcpu_value
+ tags:
+ cpu_tag_1: cpu_value_1
+ disk:
+ mountpoints: 2
+ tags:
+ disk_tag_1: disk_value_1
+ diskio:
+ skip_serial_number: false
+ tags:
+ diskio_tag_1: diskio_value_1
+ docker:
+ endpoint: endpoint_name
+ tags:
+ docker_tag_1: docker_value_1
+ mem:
+ tags:
+ mem_tag_1: mem_value_1
+ net:
+ tags:
+ net_tag_1: net_value_1
+ netstat:
+ tags:
+ netstat_tag_1: netstat_value_1
+ processes:
+ tags:
+ processes_tag_1: processes_value_1
+ procstat:
+ pid_file: pid_file_name
+ tags:
+ procstat_tag_1: procstat_value_1
+ system:
+ tags:
+ system_tag_1: system_value_1
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 3f42101..a4cac88 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -18,7 +18,7 @@
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}"
+SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR} --log-file=/dev/null"
if [ "x${SALT_VERSION}" != "x" ]; then
PIP_SALT_VERSION="==${SALT_VERSION}"
@@ -44,6 +44,7 @@
[ ! -d ${SALT_PILLAR_DIR} ] && mkdir -p ${SALT_PILLAR_DIR}
echo "base:" > ${SALT_PILLAR_DIR}/top.sls
for pillar in ${PILLARDIR}/*; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
state_name=$(basename ${pillar%.sls})
echo -e " ${state_name}:\n - ${state_name}" >> ${SALT_PILLAR_DIR}/top.sls
done
@@ -56,6 +57,7 @@
echo "base:" > ${SALT_FILE_DIR}/top.sls
for pillar in ${PILLARDIR}/*.sls; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
state_name=$(basename ${pillar%.sls})
echo -e " ${state_name}:\n - ${FORMULA_NAME}" >> ${SALT_FILE_DIR}/top.sls
done
@@ -64,6 +66,7 @@
file_client: local
cachedir: ${SALT_CACHE_DIR}
verify_env: False
+minion_id_caching: False
file_roots:
base:
@@ -125,6 +128,7 @@
run() {
for pillar in ${PILLARDIR}/*.sls; do
+ grep ${FORMULA_NAME}: ${pillar} &>/dev/null || continue
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