Merge "Fix Python version for Travis CI tests"
diff --git a/README.rst b/README.rst
index 5eecf1a..d3bdc0f 100644
--- a/README.rst
+++ b/README.rst
@@ -404,6 +404,11 @@
         - name: nic04
           bridge: br-public
           model: virtio
+        - name: nic05
+          bridge: br-prv
+          model: virtio
+          virtualport:
+            type: openvswitch
 
 
     salt:
@@ -438,6 +443,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
@@ -606,6 +627,18 @@
 Salt Minion
 -----------
 
+Minion ID by default trigger dependency on linux formula, as it uses fqdn configured from `linux.system.name` and
+`linux.system.domain` pillar. To override, provide exact minion ID you require. The same can be sate for master id rendered
+at `master.conf`.
+
+.. code-block:: yaml
+
+    salt:
+      minion:
+        id: minion1.production
+      master:
+        id: master.production
+
 Simplest Salt minion setup with central configuration node
 
 .. code-block:: yaml
diff --git a/_modules/virtng.py b/_modules/virtng.py
index f9f93b9..ce09508 100644
--- a/_modules/virtng.py
+++ b/_modules/virtng.py
@@ -430,67 +430,11 @@
 
 def _nic_profile(profile_name, hypervisor, **kwargs):
 
-    default = [{'eth0': {}}]
-    vmware_overlay = {'type': 'bridge', 'source': 'DEFAULT', 'model': 'e1000'}
-    kvm_overlay = {'type': 'bridge', 'source': 'br0', 'model': 'virtio'}
-    overlays = {
-            'kvm': kvm_overlay,
-            'qemu': kvm_overlay,
-            'esxi': vmware_overlay,
-            'vmware': vmware_overlay,
-            }
-
-    # support old location
-    config_data = __salt__['config.option']('virt.nic', {}).get(
-        profile_name, None
-    )
-
-    if config_data is None:
-        config_data = __salt__['config.get']('virt:nic', {}).get(
-            profile_name, default
-        )
-
-    interfaces = []
-
     def append_dict_profile_to_interface_list(profile_dict):
         for interface_name, attributes in profile_dict.items():
             attributes['name'] = interface_name
             interfaces.append(attributes)
 
-    # old style dicts (top-level dicts)
-    #
-    # virt:
-    #    nic:
-    #        eth0:
-    #            bridge: br0
-    #        eth1:
-    #            network: test_net
-    if isinstance(config_data, dict):
-        append_dict_profile_to_interface_list(config_data)
-
-    # new style lists (may contain dicts)
-    #
-    # virt:
-    #   nic:
-    #     - eth0:
-    #         bridge: br0
-    #     - eth1:
-    #         network: test_net
-    #
-    # virt:
-    #   nic:
-    #     - name: eth0
-    #       bridge: br0
-    #     - name: eth1
-    #       network: test_net
-    elif isinstance(config_data, list):
-        for interface in config_data:
-            if isinstance(interface, dict):
-                if len(interface) == 1:
-                    append_dict_profile_to_interface_list(interface)
-                else:
-                    interfaces.append(interface)
-
     def _normalize_net_types(attributes):
         '''
         Guess which style of definition:
@@ -514,6 +458,7 @@
 
         attributes['type'] = attributes.get('type', None)
         attributes['source'] = attributes.get('source', None)
+        attributes['virtualport'] = attributes.get('virtualport', None)
 
     def _apply_default_overlay(attributes):
         for key, value in overlays[hypervisor].items():
@@ -532,6 +477,40 @@
         else:
             attributes['mac'] = salt.utils.gen_mac()
 
+
+    default = [{'eth0': {}}]
+    vmware_overlay = {'type': 'bridge', 'source': 'DEFAULT', 'model': 'e1000'}
+    kvm_overlay = {'type': 'bridge', 'source': 'br0', 'model': 'virtio'}
+    overlays = {
+            'kvm': kvm_overlay,
+            'qemu': kvm_overlay,
+            'esxi': vmware_overlay,
+            'vmware': vmware_overlay,
+            }
+
+    # support old location
+    config_data = __salt__['config.option']('virt.nic', {}).get(
+        profile_name, None
+    )
+
+    if config_data is None:
+        config_data = __salt__['config.get']('virt:nic', {}).get(
+            profile_name, default
+        )
+
+    interfaces = []
+
+    if isinstance(config_data, dict):
+        append_dict_profile_to_interface_list(config_data)
+
+    elif isinstance(config_data, list):
+        for interface in config_data:
+            if isinstance(interface, dict):
+                if len(interface) == 1:
+                    append_dict_profile_to_interface_list(interface)
+                else:
+                    interfaces.append(interface)
+
     for interface in interfaces:
         _normalize_net_types(interface)
         _assign_mac(interface)
@@ -671,6 +650,18 @@
     xml = _gen_xml(name, cpu, mem, diskp, nicp, hypervisor, **kwargs)
 
     # TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
+    for _nic in nicp:
+        if _nic['virtualport']:
+            xml_doc = minidom.parseString(xml)
+            interfaces = xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("devices")[0].getElementsByTagName("interface")
+            for interface in interfaces:
+                if interface.getElementsByTagName('mac')[0].getAttribute('address').lower() == _nic['mac'].lower():
+                    vport_xml = xml_doc.createElement("virtualport")
+                    vport_xml.setAttribute("type", _nic['virtualport']['type'])
+                    interface.appendChild(vport_xml)
+            xml = xml_doc.toxml()
+
+    # TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
     if rng:
         rng_model = rng.get('model', 'random')
         rng_backend = rng.get('backend', '/dev/urandom')
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/control/virt.sls b/salt/control/virt.sls
index d508252..a2e56ff 100644
--- a/salt/control/virt.sls
+++ b/salt/control/virt.sls
@@ -20,7 +20,7 @@
 
 {%- if cluster.engine == "virt" %}
 
-libvirt_service:
+salt_libvirt_service:
   service.running:
   - name: {{ control.virt_service }}
   - enable: true
@@ -72,7 +72,7 @@
       {%- endif %}
   - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
   - require:
-    - libvirt_service
+    - salt_libvirt_service
 
 #salt_control_seed_{{ cluster_name }}_{{ node_name }}:
 #  module.run:
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/files/master.conf b/salt/files/master.conf
index bbfff60..ce24461 100644
--- a/salt/files/master.conf
+++ b/salt/files/master.conf
@@ -205,7 +205,7 @@
 
 file_recv: {{ master.get('file_recv', False) }}
 
-id: {{ system.name }}.{{ system.domain }}
+id: {{ master.id | default(system.name~"."~system.domain) }}
 
 {#-
 vim: syntax=jinja
diff --git a/salt/files/minion.conf b/salt/files/minion.conf
index 52e7009..fe028b4 100644
--- a/salt/files/minion.conf
+++ b/salt/files/minion.conf
@@ -21,7 +21,7 @@
 
 {%- endif %}
 
-id: {{ system.name }}.{{ system.domain }}
+id: {{ minion.id | default(system.name~"."~system.domain) }}
 
 {%- for opt in ['max_event_size', 'acceptance_wait_time_max',
   'acceptance_wait_time', 'random_reauth_delay', 'recon_default', 'recon_max',
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:
diff --git a/tests/pillar/control_virt_custom.sls b/tests/pillar/control_virt_custom.sls
index 6ca02ad..71cf37f 100644
--- a/tests/pillar/control_virt_custom.sls
+++ b/tests/pillar/control_virt_custom.sls
@@ -9,6 +9,25 @@
           image: snapshot.qcow
       - cinder-volume:
           size: 2048
+  nic:
+    control:
+    - name: nic01
+      bridge: br-pxe
+      model: virtio
+    - name: nic02
+      bridge: br-cp
+      model: virtio
+    - name: nic03
+      bridge: br-store-front
+      model: virtio
+    - name: nic04
+      bridge: br-public
+      model: virtio
+    - name: nic05
+      bridge: br-prv
+      model: virtio
+      virtualport:
+        type: openvswitch
 salt:
   minion:
     enabled: true
diff --git a/tests/pillar/minion_multi_master_failover.sls b/tests/pillar/minion_multi_master_failover.sls
index cffefec..5ad8eca 100644
--- a/tests/pillar/minion_multi_master_failover.sls
+++ b/tests/pillar/minion_multi_master_failover.sls
@@ -1,5 +1,6 @@
 salt:
   minion:
+    id: salt.ci.local
     enabled: true
     masters:
     - host: config01.dc01.domain.com