Merge pull request #11 from Martin819/master

Added Kitchen tests and Travis [WIP]
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644
index 0000000..399e817
--- /dev/null
+++ b/.kitchen.yml
@@ -0,0 +1,61 @@
+---
+driver:
+  name: docker
+  hostname: etcd.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: etcd
+  grains:
+    noservices: True
+  state_top:
+    base:
+      "*":
+        - linux
+        - etcd
+  pillars:
+    top.sls:
+      base:
+        "*":
+          - debian_etcd_repo
+          - etcd
+  dependencies:
+    - name: linux
+      repo: git
+      source: https://github.com/salt-formulas/salt-formula-linux.git
+  pillars-from-files:
+    debian_etcd_repo.sls: tests/pillar/repo_etcd.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: cluster
+    provisioner:
+      pillars-from-files:
+        etcd.sls: tests/pillar/cluster.sls
+
+  - name: proxy
+    provisioner:
+      pillars-from-files:
+        etcd.sls: tests/pillar/proxy.sls
+
+  - name: single
+    provisioner:
+      pillars-from-files:
+        etcd.sls: tests/pillar/single.sls
+# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ca01e68
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,40 @@
+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
\ No newline at end of file
diff --git a/etcd/map.jinja b/etcd/map.jinja
index cd2aa98..70e91cf 100644
--- a/etcd/map.jinja
+++ b/etcd/map.jinja
@@ -1,3 +1,4 @@
+
 {% set server = salt['grains.filter_by']({
     'Debian': {
         'pkgs': ['etcd', 'python-etcd'],
@@ -7,4 +8,13 @@
         'pkgs': [],
         'services': []
     },
-}, merge=salt['pillar.get']('etcd:server')) %}
+}, merge=salt['grains.filter_by']({
+    'trusty': {
+        'pkgs': ['etcd'],
+        'services': ['etcd']
+    },
+    'xenial': {
+        'pkgs': ['etcd', 'python-etcd'],
+        'services': ['etcd']
+    },
+}, grain='oscodename', merge=salt['pillar.get']('etcd:server'))) %}
\ No newline at end of file
diff --git a/etcd/server/service.sls b/etcd/server/service.sls
index 72c39ea..70bbf91 100644
--- a/etcd/server/service.sls
+++ b/etcd/server/service.sls
@@ -9,8 +9,10 @@
 {%- if server.get('engine', 'systemd') %}
   - require:
     - file: /etc/default/etcd
+  {% if not grains.get('noservices', False) %}
   - watch_in:
     - service: etcd
+  {% endif %}
 {%- endif %}
 
 
@@ -58,8 +60,10 @@
     - group: root
     - require:
       - dockerng: copy-etcd-binaries
+    {% if not grains.get('noservices', False) %}
     - watch_in:
       - service: etcd
+    {% endif %}
 
 {% endfor %}
 
@@ -107,8 +111,10 @@
 {%- else %}
         initial_cluster_state: existing
 {%- endif %}
+    {% if not grains.get('noservices', False) %}
     - watch_in:
       - service: etcd
+    {% endif %}
 
 /var/lib/etcd/:
   file.directory:
@@ -124,6 +130,8 @@
     - require:
       - file: /var/lib/etcd/
 
+{% if not grains.get('noservices', False) %}
+
 etcd:
   service.running:
   - enable: True
@@ -132,3 +140,5 @@
 {%- endif %}
 
 {%- endif %}
+
+{%- endif %}
\ No newline at end of file
diff --git a/metadata.yml b/metadata.yml
index 43c307e..6f84faa 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,3 +1,6 @@
 name: "etcd"
 version: "0.1"
-source: "https://github.com/tcpcloud/salt-formula-etcd"
+source: "https://github.com/salt-formulas/salt-formula-etcd"
+dependencies:
+- name: linux
+  source: "https://github.com/salt-formulas/salt-formula-linux"
\ No newline at end of file
diff --git a/tests/pillar/repo_etcd.sls b/tests/pillar/repo_etcd.sls
new file mode 100644
index 0000000..ece8131
--- /dev/null
+++ b/tests/pillar/repo_etcd.sls
@@ -0,0 +1,9 @@
+linux:
+  system:
+    name: hostname
+    enabled: true
+    repo:
+      docker:
+        source: 'deb http://ppa.launchpad.net/cloud-green/trusty-backports/ubuntu trusty main'
+        key_id: E6396E0A9EA00B88BF1D40C434EDB5B7EC1764A6
+        key_server: hkp://p80.pool.sks-keyservers.net:80
\ No newline at end of file