Adding REDIS as backend for salt cache

The patch adds ability to configure REDIS as cache
backed for salt-master to be used as distibuted cache
further.

Change-Id: I62a29713c23ad3f591f6e937bfc5b13eba92f402
Related-PROD: PROD-20581
diff --git a/README.rst b/README.rst
index 5eecf1a..6263e43 100644
--- a/README.rst
+++ b/README.rst
@@ -438,6 +438,22 @@
                   nic01: AC:DE:48:AA:AA:AA
                   nic02: AC:DE:48:AA:AA:BB
 
+To enable Redis plugin for the Salt caching subsystem. The below pillar structure should be used
+
+.. code-block:: yaml
+
+  salt:
+    master:
+      cache:
+        plugin: redis
+        host: localhost
+        port: 6379
+        db: '0'
+        password: pass_word
+        bank_prefix: 'MCP'
+        bank_keys_prefix: 'MCPKEY'
+        key_prefix: 'KEY'
+        separator: '@'
 
 
 Jinja options
diff --git a/metadata/service/master/cache/redis.yml b/metadata/service/master/cache/redis.yml
new file mode 100644
index 0000000..6de25a3
--- /dev/null
+++ b/metadata/service/master/cache/redis.yml
@@ -0,0 +1,18 @@
+parameters:
+  _param:
+    salt_cache_redis_host: 127.0.0.1
+    salt_cache_redis_port: 6379
+    salt_cache_redis_db: '0'
+    salt_cache_redis_password: ''
+  salt:
+    master:
+      cache:
+        plugin: redis
+        host: ${_param:salt_cache_redis_host}
+        port: ${_param:salt_cache_redis_port}
+        db: ${_param:salt_cache_redis_db}
+        password: ${_param:salt_cache_redis_password}
+        bank_prefix: 'MCP'
+        bank_keys_prefix: 'MCPKEY'
+        key_prefix: 'KEY'
+        separator: '@'
diff --git a/salt/files/cache/_redis.conf b/salt/files/cache/_redis.conf
new file mode 100644
index 0000000..15fa123
--- /dev/null
+++ b/salt/files/cache/_redis.conf
@@ -0,0 +1,11 @@
+{% from "salt/map.jinja" import master with context %}
+
+cache: redis
+cache.redis.host: {{ master.cache.get('host', 'localhost') }}
+cache.redis.port: {{ master.cache.get('port', '6379') }}
+cache.redis.db: {{ master.cache.get('db', '0')|yaml_squote }}
+cache.redis.password: {{ master.cache.get('password', '') }}
+cache.redis.bank_prefix: {{ master.cache.get('bank_prefix', 'MCP') }}
+cache.redis.bank_keys_prefix: {{ master.cache.get('bank_keys_prefix', 'MCPKEY') }}
+cache.redis.key_prefix: {{ master.cache.get('key_prefix', 'KEY') }}
+cache.redis.separator: {{ master.cache.get('separator', '@')|yaml_squote }}
diff --git a/salt/master/service.sls b/salt/master/service.sls
index 4e1f502..6cdff88 100644
--- a/salt/master/service.sls
+++ b/salt/master/service.sls
@@ -28,6 +28,20 @@
   - watch_in:
     - service: salt_master_service
 
+{%- if master.cache is defined %}
+
+/etc/salt/master.d/_{{ master.cache.plugin }}.conf:
+  file.managed:
+  - source: salt://salt/files/cache/_{{ master.cache.plugin }}.conf
+  - user: root
+  - template: jinja
+  - require:
+    - {{ master.install_state }}
+  - watch_in:
+    - service: salt_master_service
+
+{%- endif %}
+
 {%- if master.user is defined %}
 
 /etc/salt/master.d/_acl.conf: