Version specified on pillar

Change-Id: Ib5db9f151baaf3fa0bca97a5457cf836bc57b88c
diff --git a/.kitchen.yml b/.kitchen.yml
index 90b13c5..e6d3f6b 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -30,10 +30,16 @@
     top.sls:
       base:
         "*":
+          - versions
+          - repos
           - galera
-          - galeracluster_debian_repo
+    versions.sls:
+      galera:
+        version:
+          mysql: <%= ENV['MYSQL_VER'] || '5.6' %>
+          galera: <%= ENV['GALERA_VER'] || '3' %>
   pillars-from-files:
-    galeracluster_debian_repo.sls: tests/pillar/repo_galeracluster.sls
+    repos.sls: tests/pillar/repo_galeracluster.sls
 
 verifier:
   name: inspec
diff --git a/.travis.yml b/.travis.yml
index 25c8368..4ebfd34 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,10 +17,14 @@
   - bundle install
 
 env:
-    - PLATFORM=trevorj/salty-whales:trusty SUITE=master_cluster
-    - PLATFORM=trevorj/salty-whales:xenial SUITE=master_cluster
-    - PLATFORM=trevorj/salty-whales:trusty SUITE=slave_cluster
-    - PLATFORM=trevorj/salty-whales:xenial SUITE=slave_cluster
+    - PLATFORM=trevorj/salty-whales:trusty SUITE=master_cluster MYSQL_VER=5.6 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:xenial SUITE=master_cluster MYSQL_VER=5.6 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:trusty SUITE=slave_cluster  MYSQL_VER=5.6 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:xenial SUITE=slave_cluster  MYSQL_VER=5.6 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:trusty SUITE=master_cluster MYSQL_VER=5.7 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:xenial SUITE=master_cluster MYSQL_VER=5.7 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:trusty SUITE=slave_cluster  MYSQL_VER=5.7 GALERA_VER=3
+    - PLATFORM=trevorj/salty-whales:xenial SUITE=slave_cluster  MYSQL_VER=5.7 GALERA_VER=3
 
 before_script:
   - set -o pipefail
diff --git a/README.rst b/README.rst
index 05ea8da..4873cfa 100644
--- a/README.rst
+++ b/README.rst
@@ -13,6 +13,9 @@
 .. code-block:: yaml
 
     galera:
+      version:
+        mysql: 5.6
+        galera: 3
       master:
         enabled: true
         name: openstack
diff --git a/galera/map.jinja b/galera/map.jinja
index 2db08d1..c9e21cc 100644
--- a/galera/map.jinja
+++ b/galera/map.jinja
@@ -1,68 +1,126 @@
+{% set mysql_version  = pillar.galera.get('version', {}).get('mysql', '5.6') %}
+{% set galera_version = pillar.galera.get('version', {}).get('galera', '3')  %}
 
-{%- set master = salt['grains.filter_by']({
-  'default': {
-    'max_connections': 20000,
-    'innodb_buffer_pool_size': '3138M',
-  },
-  'Debian': {
-    'pkgs': ['mysql-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
-    'service': 'mysql',
-    'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
-    'log_file': '/var/log/mysql.log',
-    'socket': '/var/run/mysqld/mysqld.sock',
-    'config': '/etc/mysql/my.cnf',
-  },
-  'RedHat': {
-    'pkgs': ['galera', 'mariadb-galera-server', 'mariadb', 'MySQL-python', 'rsync', 'percona-xtrabackup', 'psmisc', 'socat'],
-    'xtrabackup_repo': 'http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm',
-    'service': 'mariadb',
-    'wsrep_provider': '/usr/lib64/galera/libgalera_smm.so',
-    'log_file': '/var/log/mariadb/mariadb.log',
-    'socket': '/var/run/mariadb/mysqld.sock',
-    'config': '/etc/my.cnf',
-  },
-}, merge=pillar.galera.get('master', {}), base='default') %}
+{%- load_yaml as master %}
+  default:
+    max_connections: 20000
+    innodb_buffer_pool_size: '3138M'
+  Debian:
+    pkgs:
+    - mysql-wsrep-{{ mysql_version }}
+    - galera-{{ galera_version }}
+    - rsync
+    - python-mysqldb
+    - psmisc
+    - netcat
+    - percona-xtrabackup
+    - socat
+    - libdbd-mysql
+    - python-pymysql
+    service: mysql
+    wsrep_provider: /usr/lib/galera/libgalera_smm.so
+    log_file: /var/log/mysql.log
+    socket: /var/run/mysqld/mysqld.sock
+    config: /etc/mysql/my.cnf
+  RedHat:
+    pkgs:
+    - galera
+    - mariadb-galera-server
+    - mariadb
+    - MySQL-python
+    - rsync
+    - percona-xtrabackup
+    - psmisc
+    - socat
+    xtrabackup_repo: http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
+    service: mariadb
+    wsrep_provider: /usr/lib64/galera/libgalera_smm.so
+    log_file: /var/log/mariadb/mariadb.log
+    socket: /var/run/mariadb/mysqld.sock
+    config: /etc/my.cnf
+{%- endload %}
+{%- set _pillar = pillar.galera.get('master', {}) %}
+{%- if  _pillar|length > 1 %}
+{%- set master = salt['grains.filter_by'](master, merge=_pillar, base='default') %}
+{%- else %}
+{%- set master = salt['grains.filter_by'](master, base='default') %}
+{%- endif %}
 
-{%- set slave = salt['grains.filter_by']({
-  'default': {
-    'max_connections': 20000,
-    'innodb_buffer_pool_size': '3138M',
-  },
-  'Debian': {
-    'pkgs': ['mysql-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
-    'service': 'mysql',
-    'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
-    'log_file': '/var/log/mysql.log',
-    'socket': '/var/run/mysqld/mysqld.sock',
-    'config': '/etc/mysql/my.cnf',
-  },
-  'RedHat': {
-    'pkgs': ['galera', 'mariadb-galera-server', 'mariadb', 'MySQL-python', 'rsync', 'percona-xtrabackup', 'psmisc', 'socat'],
-    'xtrabackup_repo': 'http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm',
-    'service': 'mariadb',
-    'wsrep_provider': '/usr/lib64/galera/libgalera_smm.so',
-    'log_file': '/var/log/mariadb/mariadb.log',
-    'socket': '/var/run/mariadb/mysqld.sock',
-    'config': '/etc/my.cnf',
-    },
-  }, merge=salt['grains.filter_by']({
-  'trusty': {
-    'pkgs': ['mysql-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'libmysqlclient18', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
-    'service': 'mysql',
-    'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
-    'log_file': '/var/log/mysql.log',
-    'socket': '/var/run/mysqld/mysqld.sock',
-    'config': '/etc/mysql/my.cnf',
-    },
-  'xenial': {
-    'pkgs': ['mysql-wsrep-5.6', 'galera-3', 'rsync', 'python-mysqldb', 'libmysqlclient-dev', 'psmisc', 'netcat', 'percona-xtrabackup', 'socat', 'libdbd-mysql', 'python-pymysql'],
-    'service': 'mysql',
-    'wsrep_provider': '/usr/lib/galera/libgalera_smm.so',
-    'log_file': '/var/log/mysql.log',
-    'socket': '/var/run/mysqld/mysqld.sock',
-    'config': '/etc/mysql/my.cnf',
-    },
-}, grain='oscodename', merge=pillar.galera.get('slave', {})), base='default') %}
+
+{%- load_yaml as slave %}
+  default:
+    max_connections: 20000
+    innodb_buffer_pool_size: '3138M'
+  Debian:
+    pkgs:
+    - mysql-wsrep-{{ mysql_version }}
+    - galera-{{ galera_version }}
+    - rsync
+    - python-mysqldb
+    - libmysqlclient18
+    - psmisc
+    - netcat
+    - percona-xtrabackup
+    - socat
+    - libdbd-mysql
+    - python-pymysql
+    service: mysql
+    wsrep_provider: /usr/lib/galera/libgalera_smm.so
+    log_file: /var/log/mysql.log
+    socket: /var/run/mysqld/mysqld.sock
+    config: /etc/mysql/my.cnf
+  RedHat:
+    pkgs:
+    - galera
+    - mariadb-galera-server
+    - mariadb
+    - MySQL-python
+    - rsync
+    - percona-xtrabackup
+    - psmisc
+    - socat
+    xtrabackup_repo: http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
+    service: mariadb
+    wsrep_provider: /usr/lib64/galera/libgalera_smm.so
+    log_file: /var/log/mariadb/mariadb.log
+    socket: /var/run/mariadb/mysqld.sock
+    config: /etc/my.cnf
+{%- endload %}
+{%- load_yaml as slave_oscodename %}
+  trusty:
+    pkgs:
+    - mysql-wsrep-{{ mysql_version }}
+    - galera-{{ galera_version }}
+    - rsync
+    - python-mysqldb
+    - libmysqlclient18
+    - psmisc
+    - netcat
+    - percona-xtrabackup
+    - socat
+    - libdbd-mysql
+    - python-pymysql
+  xenial:
+    pkgs:
+    - mysql-wsrep-{{ mysql_version }}
+    - galera-{{ galera_version }}
+    - rsync
+    - python-mysqldb
+    - libmysqlclient-dev
+    - psmisc
+    - netcat
+    - percona-xtrabackup
+    - socat
+    - libdbd-mysql
+    - python-pymysql
+{%- endload %}
+{%- set _pillar = pillar.galera.get('slave', {}) %}
+{%- if  _pillar|length > 1 %}
+{%- set _oscodename = salt['grains.filter_by'](slave_oscodename, grain='oscodename', merge=_pillar) %}
+{%- else %}
+{%- set _oscodename = salt['grains.filter_by'](slave_oscodename, grain='oscodename') %}
+{%- endif %}
+{%- set slave = salt['grains.filter_by'](slave, merge=_oscodename, base='default') %}
 
 {% set clustercheck = salt['grains.filter_by']({
   'Debian': {
diff --git a/galera/master.sls b/galera/master.sls
index 9fc1f9f..274f983 100644
--- a/galera/master.sls
+++ b/galera/master.sls
@@ -36,6 +36,7 @@
     - pkg: galera_packages
 
 {%- if grains.os_family == 'Debian' %}
+
 galera_run_dir:
   file.directory:
   - name: /var/run/mysqld
diff --git a/tests/pillar/master_cluster.sls b/tests/pillar/master_cluster.sls
index a8f0633..3a5d91f 100644
--- a/tests/pillar/master_cluster.sls
+++ b/tests/pillar/master_cluster.sls
@@ -1,53 +1,58 @@
-  galera:
-    master:
-      enabled: true
-      name: galeracluster
-      bind:
-        address: 127.0.0.1
-        port: 3306
-      maintenance_password: password
-      admin:
-        user: root
-        password: password
-      members:
-      - host: 127.0.0.1
-        port: 4567
-      - host: 127.0.0.1
-        port: 4567
-      - host: 127.0.0.1
-        port: 4567
-    clustercheck:
-      enabled: True
-      user: clustercheck
+galera:
+  master:
+    enabled: true
+    name: galeracluster
+    bind:
+      address: 127.0.0.1
+      port: 3306
+    maintenance_password: password
+    admin:
+      user: root
       password: password
-      available_when_donor: 1
-      available_when_readonly: 1
-      port: 9200
-      max_connections: 20000
-      innodb_buffer_pool_size: 3138M
-  mysql:
-    server:
-      database:
-        mydb:
-          encoding: 'utf8'
-      users:
-      - name: haproxy
-        host: localhost
-      - name: haproxy
-        host: '%'
-      - name: haproxy
-        host: 127.0.0.1
-      - name: clustercheck
-        #host: localhost
-        password: password
-        database: '*.*'
-        grants: PROCESS
-      - name: inspector
-        host: 127.0.0.1
-        password: password
-        databases:
-          - database: mydb
-            table: mytable
-            grant_option: True
-            grants:
-            - all privileges
+    members:
+    - host: 127.0.0.1
+      port: 4567
+    - host: 127.0.0.1
+      port: 4567
+    - host: 127.0.0.1
+      port: 4567
+  clustercheck:
+    enabled: True
+    user: clustercheck
+    password: password
+    available_when_donor: 1
+    available_when_readonly: 1
+    port: 9200
+    max_connections: 20000
+    innodb_buffer_pool_size: 3138M
+mysql:
+  server:
+    enabled: true
+    bind:
+      address: 0.0.0.0
+      port: 3306
+      protocol: tcp
+    database:
+      mydb:
+        encoding: 'utf8'
+    users:
+    - name: haproxy
+      host: localhost
+    - name: haproxy
+      host: '%'
+    - name: haproxy
+      host: 127.0.0.1
+    - name: clustercheck
+      #host: localhost
+      password: password
+      database: '*.*'
+      grants: PROCESS
+    - name: inspector
+      host: 127.0.0.1
+      password: password
+      databases:
+        - database: mydb
+          table: mytable
+          grant_option: True
+          grants:
+          - all privileges
diff --git a/tests/pillar/repo_galeracluster.sls b/tests/pillar/repo_galeracluster.sls
index a23ea1a..461b584 100644
--- a/tests/pillar/repo_galeracluster.sls
+++ b/tests/pillar/repo_galeracluster.sls
@@ -3,7 +3,7 @@
     enabled: true
     repo:
       galeracluster:
-        source: 'deb http://releases.galeracluster.com/galera-3/ubuntu {{ grains.get('oscodename') }} main'
+        source: 'deb http://releases.galeracluster.com/galera-{{ pillar.galera.version.galera }}/ubuntu {{ grains.get('oscodename') }} main'
         key_id: BC19DDBA
         key_server: hkp://p80.pool.sks-keyservers.net:80
         pin:
@@ -11,7 +11,7 @@
           priority: 1001
           package: '*'
       mysql-wsrep:
-        source: 'deb http://releases.galeracluster.com/mysql-wsrep-5.6/ubuntu {{ grains.get('oscodename') }} main'
+        source: 'deb http://releases.galeracluster.com/mysql-wsrep-{{ pillar.galera.version.mysql }}/ubuntu {{ grains.get('oscodename') }} main'
         key_id: BC19DDBA
         key_server: hkp://p80.pool.sks-keyservers.net:80
         pin: