(WIP) Use dynamic IPv4 network pools for deploy clusters (#18)

*     Use dynamic IPv4 network pools for deploy clusters

    - Use 'config' object as an additional jinja option to load templates
    - Use 'address_pools' from 'config' object in
      virtual-mcp11-ovs and virtual-mcp11-dvr
    - Fill 'address_pools' in 'config' object from fuel-devops manager

*     Use dynamic IPv4 network pools for deploy clusters

    - Use 'config' object as an additional jinja option to load templates
    - Use 'address_pools' from 'config' object in
      virtual-mcp11-ovs and virtual-mcp11-dvr
    - Fill 'address_pools' in 'config' object from fuel-devops manager

* return removed 'test_install_k8s'

* Use 'sed' to replace IP addresses in the models to pre-generated

also, two new environment variables avaliable for mcp11-ovs/dvr:
- SALT_MODELS_REPOSITORY
- SALT_MODELS_COMMIT

* remove temporary env_config.py.bak
diff --git a/tcp_tests/fixtures/common_services_fixtures.py b/tcp_tests/fixtures/common_services_fixtures.py
index eb46f93..21c0e5d 100644
--- a/tcp_tests/fixtures/common_services_fixtures.py
+++ b/tcp_tests/fixtures/common_services_fixtures.py
@@ -19,7 +19,6 @@
 
 from tcp_tests import logger
 from tcp_tests.helpers import ext
-from tcp_tests.helpers import utils
 from tcp_tests import settings
 from tcp_tests.managers import common_services_manager
 
@@ -72,7 +71,7 @@
     # Create Salt cluster
     if not config.common_services.common_services_installed:
         steps_path = config.common_services_deploy.common_services_steps_path
-        commands = utils.read_template(steps_path)
+        commands = underlay.read_template(steps_path)
         common_services_actions.install(commands)
         hardware.create_snapshot(ext.SNAPSHOT.common_services_deployed)
 
diff --git a/tcp_tests/fixtures/openstack_fixtures.py b/tcp_tests/fixtures/openstack_fixtures.py
index cba8823..6ec700a 100644
--- a/tcp_tests/fixtures/openstack_fixtures.py
+++ b/tcp_tests/fixtures/openstack_fixtures.py
@@ -19,7 +19,6 @@
 
 from tcp_tests import logger
 from tcp_tests.helpers import ext
-from tcp_tests.helpers import utils
 from tcp_tests import settings
 from tcp_tests.managers import openstack_manager
 
@@ -71,7 +70,7 @@
     # Create Salt cluster
     if not config.openstack.openstack_installed:
         steps_path = config.openstack_deploy.openstack_steps_path
-        commands = utils.read_template(steps_path)
+        commands = underlay.read_template(steps_path)
         openstack_actions.install(commands)
         hardware.create_snapshot(ext.SNAPSHOT.openstack_deployed)
 
diff --git a/tcp_tests/fixtures/salt_fixtures.py b/tcp_tests/fixtures/salt_fixtures.py
index 57fb656..7efd296 100644
--- a/tcp_tests/fixtures/salt_fixtures.py
+++ b/tcp_tests/fixtures/salt_fixtures.py
@@ -19,7 +19,6 @@
 
 from tcp_tests import logger
 from tcp_tests.helpers import ext
-from tcp_tests.helpers import utils
 from tcp_tests import settings
 from tcp_tests.managers import saltmanager
 
@@ -67,8 +66,13 @@
     """
     # Create Salt cluster
     if config.salt.salt_master_host == '0.0.0.0':
-        commands = utils.read_template(config.salt_deploy.salt_steps_path)
-        LOG.info("##################Executing command ####### {0}".format(commands))
+        # Temporary workaround. Underlay should be extended with roles
+        salt_nodes = underlay.node_names()
+        config.salt.salt_master_host = \
+            underlay.host_by_node_name(salt_nodes[0])
+
+        commands = underlay.read_template(config.salt_deploy.salt_steps_path)
+        LOG.info("############ Executing command ####### {0}".format(commands))
         salt_actions.install(commands)
         hardware.create_snapshot(ext.SNAPSHOT.salt_deployed)
 
diff --git a/tcp_tests/fixtures/underlay_fixtures.py b/tcp_tests/fixtures/underlay_fixtures.py
index d7351bf..43024e3 100644
--- a/tcp_tests/fixtures/underlay_fixtures.py
+++ b/tcp_tests/fixtures/underlay_fixtures.py
@@ -137,17 +137,16 @@
                 and snapshot_needed:
             snapshot_name = utils.extract_name_from_mark(snapshot_needed) or \
                 "{}_passed".format(default_snapshot_name)
-            hardware.create_snapshot(snapshot_name)
 
         elif hasattr(request.node, 'rep_setup') and \
                 request.node.rep_setup.failed and fail_snapshot:
             snapshot_name = "{0}_prep_failed".format(default_snapshot_name)
-            hardware.create_snapshot(snapshot_name)
 
         elif hasattr(request.node, 'rep_call') and \
                 request.node.rep_call.failed and fail_snapshot:
             snapshot_name = "{0}_failed".format(default_snapshot_name)
-            hardware.create_snapshot(snapshot_name)
+
+        hardware.create_snapshot(snapshot_name)
 
     request.addfinalizer(test_fin)
 
diff --git a/tcp_tests/helpers/utils.py b/tcp_tests/helpers/utils.py
index 28314f6..9501e01 100644
--- a/tcp_tests/helpers/utils.py
+++ b/tcp_tests/helpers/utils.py
@@ -318,7 +318,7 @@
         self.write_content()
 
 
-def render_template(file_path):
+def render_template(file_path, options=None):
     required_env_vars = set()
     optional_env_vars = dict()
     def os_env(var_name, default=None):
@@ -334,9 +334,10 @@
 
         return var
 
-    options = {
-        'os_env': os_env,
-    }
+    if options is None:
+        options = {}
+    options.update({'os_env': os_env,})
+
     LOG.info("Reading template {0}".format(file_path))
 
     path, filename = os.path.split(file_path)
@@ -355,12 +356,6 @@
     return template
 
 
-def read_template(file_path):
-    """Read yaml as a jinja template"""
-    template = render_template(file_path)
-    return yaml.load(template)
-
-
 def extract_name_from_mark(mark):
     """Simple function to extract name from pytest mark
 
diff --git a/tcp_tests/managers/envmanager_devops.py b/tcp_tests/managers/envmanager_devops.py
index 0f01999..e25faef 100644
--- a/tcp_tests/managers/envmanager_devops.py
+++ b/tcp_tests/managers/envmanager_devops.py
@@ -61,6 +61,7 @@
             LOG.info("Environment doesn't exist, creating a new one")
             self._create_environment()
         self.set_dns_config()
+        self.set_address_pools_config()
 
     @property
     def _devops_config(self):
@@ -169,9 +170,11 @@
 
         :name: string
         """
-        LOG.info("Creating snapshot named '{0}'".format(name))
+        msg = "[ Create snapshot '{0}' ] {1}".format(name, description or '')
+        LOG.info("\n\n{0}\n{1}".format(msg, '*' * len(msg)))
+
         self.__config.hardware.current_snapshot = name
-        LOG.info("current config '{0}'".format(
+        LOG.info("Set current snapshot in config to '{0}'".format(
             self.__config.hardware.current_snapshot))
         if self._env is not None:
             LOG.info('trying to suspend ....')
@@ -184,6 +187,25 @@
             raise exceptions.EnvironmentIsNotSet()
         settings_oslo.save_config(self.__config, name, self._env.name)
 
+        if settings.VIRTUAL_ENV:
+            venv_msg = "source {0}/bin/activate;\n".format(settings.VIRTUAL_ENV)
+        else:
+            venv_msg = ""
+        LOG.info("To revert the snapshot:\n\n"
+                 "************************************\n"
+                 "{venv_msg}"
+                 "dos.py revert {env_name} {snapshot_name};\n"
+                 "dos.py resume {env_name};\n"
+                 "# dos.py time-sync {env_name};  # Optional\n"
+                 "ssh {login}@{salt_master_host}  # Password: {password}\n"
+                 "************************************\n"
+                 .format(venv_msg=venv_msg,
+                         env_name=settings.ENV_NAME,
+                         snapshot_name=name,
+                         login=settings.SSH_NODE_CREDENTIALS['login'],
+                         password=settings.SSH_NODE_CREDENTIALS['password'],
+                         salt_master_host=self.__config.salt.salt_master_host))
+
     def _get_snapshot_config_name(self, snapshot_name):
         """Get config name for the environment"""
         env_name = self._env.name
@@ -355,3 +377,8 @@
             self.__config.underlay.nameservers = [self.nameserver]
         if not self.__config.underlay.upstream_dns_servers:
             self.__config.underlay.upstream_dns_servers = [self.nameserver]
+
+    def set_address_pools_config(self):
+        """Store address pools CIDRs in config object"""
+        for ap in self._env.get_address_pools():
+            self.__config.underlay.address_pools[ap.name] = ap.net
diff --git a/tcp_tests/managers/underlay_ssh_manager.py b/tcp_tests/managers/underlay_ssh_manager.py
index 3185371..b22566d 100644
--- a/tcp_tests/managers/underlay_ssh_manager.py
+++ b/tcp_tests/managers/underlay_ssh_manager.py
@@ -18,6 +18,7 @@
 from devops.helpers import helpers
 from devops.helpers import ssh_client
 from paramiko import rsakey
+import yaml
 
 from tcp_tests import logger
 from tcp_tests.helpers import utils
@@ -367,6 +368,14 @@
             password=ssh_data['password'],
             private_keys=ssh_data['keys'])
 
+    def read_template(self, file_path):
+        """Read yaml as a jinja template"""
+        options = {
+            'config': self.__config,
+        }
+        template = utils.render_template(file_path, options=options)
+        return yaml.load(template)
+
     def ensure_running_service(self, service_name, host, check_cmd,
                                state_running='start/running'):
         """Check if the service_name running or try to restart it
diff --git a/tcp_tests/requirements.txt b/tcp_tests/requirements.txt
index 3bd15c0..a2e3de5 100644
--- a/tcp_tests/requirements.txt
+++ b/tcp_tests/requirements.txt
@@ -8,7 +8,7 @@
 docker-compose==1.7.1
 urllib3
 junit-xml
-jinja2
+jinja2>=2.1
 jira
 testrail
 functools32
diff --git a/tcp_tests/settings.py b/tcp_tests/settings.py
index 5ec518d..f451eaf 100644
--- a/tcp_tests/settings.py
+++ b/tcp_tests/settings.py
@@ -29,6 +29,9 @@
     'TIMESTAT_PATH_YAML', os.path.join(
         LOGS_DIR, 'timestat_{}.yaml'.format(time.strftime("%Y%m%d"))))
 
+VIRTUAL_ENV = os.environ.get("VIRTUAL_ENV", None)
+ENV_NAME = os.environ.get("ENV_NAME", None)
+
 LAB_CONFIG_NAME = os.environ.get('LAB_CONFIG_NAME', 'mk22-lab-basic')
 #LAB_CONFIGS_NAME = os.environ.get('LAB_NAME', 'mk22-lab-advanced')
 
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index 8190720..5bdf6b0 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -77,6 +77,12 @@
            default=[]),
     ct.Cfg('lvm', ct.JSONDict(),
            help="LVM settings for Underlay", default={}),
+    ct.Cfg('address_pools', ct.JSONDict(),
+           help="""Address pools (dynamically) allocated for the environment.
+                   May be used to determine CIDR for a specific network from
+                   tests or during the deployment process.
+                   {'pool_name1': '<cidr>', 'pool_name2': '<cidr>', ...}""",
+           default={}),
 ]
 
 
diff --git a/tcp_tests/templates/common-services/virtual-mcp11-dvr-common-services.yaml b/tcp_tests/templates/common-services/virtual-mcp11-dvr-common-services.yaml
index 1b85527..aaa80e6 100644
--- a/tcp_tests/templates/common-services/virtual-mcp11-dvr-common-services.yaml
+++ b/tcp_tests/templates/common-services/virtual-mcp11-dvr-common-services.yaml
@@ -1,4 +1,4 @@
-{% from 'virtual-mcp11-dvr.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-dvr.yaml' import HOSTNAME_CFG01 with context %}
 
 # Install support services
 - description: Install keepalived on ctl01
@@ -16,8 +16,10 @@
   skip_fail: true
 
 - description: Check the VIP
-  cmd: salt --hard-crash --state-output=mixed --state-verbose=False
-    -C 'I@keepalived:cluster' cmd.run 'ip a | grep 172.16.10.2' | grep -B1 172.16.10.2
+  cmd: |
+    OPENSTACK_CONTROL_ADDRESS=`salt-call --out=newline_values_only pillar.get _param:openstack_control_address`;
+    echo "_param:openstack_control_address (vip): ${OPENSTACK_CONTROL_ADDRESS}";
+    salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@keepalived:cluster' cmd.run "ip a | grep ${OPENSTACK_CONTROL_ADDRESS}" | grep -B1 ${OPENSTACK_CONTROL_ADDRESS}
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 5}
   skip_fail: false
diff --git a/tcp_tests/templates/common-services/virtual-mcp11-ovs-common-services.yaml b/tcp_tests/templates/common-services/virtual-mcp11-ovs-common-services.yaml
index 3dff868..ccbbfac 100644
--- a/tcp_tests/templates/common-services/virtual-mcp11-ovs-common-services.yaml
+++ b/tcp_tests/templates/common-services/virtual-mcp11-ovs-common-services.yaml
@@ -1,4 +1,4 @@
-{% from 'virtual-mcp11-ovs.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-ovs.yaml' import HOSTNAME_CFG01 with context %}
 
 # Install support services
 - description: Install keepalived on ctl01
@@ -16,8 +16,10 @@
   skip_fail: true
 
 - description: Check the VIP
-  cmd: salt --hard-crash --state-output=mixed --state-verbose=False
-    -C 'I@keepalived:cluster' cmd.run 'ip a | grep 172.16.10.2' | grep -B1 172.16.10.2
+  cmd: |
+    OPENSTACK_CONTROL_ADDRESS=`salt-call --out=newline_values_only pillar.get _param:openstack_control_address`;
+    echo "_param:openstack_control_address (vip): ${OPENSTACK_CONTROL_ADDRESS}";
+    salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@keepalived:cluster' cmd.run "ip a | grep ${OPENSTACK_CONTROL_ADDRESS}" | grep -B1 ${OPENSTACK_CONTROL_ADDRESS}
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 5}
   skip_fail: false
diff --git a/tcp_tests/templates/openstack/virtual-mcp11-dvr-openstack.yaml b/tcp_tests/templates/openstack/virtual-mcp11-dvr-openstack.yaml
index e518976..356ed7c 100644
--- a/tcp_tests/templates/openstack/virtual-mcp11-dvr-openstack.yaml
+++ b/tcp_tests/templates/openstack/virtual-mcp11-dvr-openstack.yaml
@@ -1,4 +1,4 @@
-{% from 'virtual-mcp11-dvr.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-dvr.yaml' import HOSTNAME_CFG01 with context %}
 
 # Install OpenStack control services
 
diff --git a/tcp_tests/templates/openstack/virtual-mcp11-ovs-openstack.yaml b/tcp_tests/templates/openstack/virtual-mcp11-ovs-openstack.yaml
index e9f809e..2a3a014 100644
--- a/tcp_tests/templates/openstack/virtual-mcp11-ovs-openstack.yaml
+++ b/tcp_tests/templates/openstack/virtual-mcp11-ovs-openstack.yaml
@@ -1,4 +1,4 @@
-{% from 'virtual-mcp11-ovs.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-ovs.yaml' import HOSTNAME_CFG01 with context %}
 
 # Install OpenStack control services
 
diff --git a/tcp_tests/templates/salt/virtual-mcp11-dvr-salt.yaml b/tcp_tests/templates/salt/virtual-mcp11-dvr-salt.yaml
index 18cdb24..4490973 100644
--- a/tcp_tests/templates/salt/virtual-mcp11-dvr-salt.yaml
+++ b/tcp_tests/templates/salt/virtual-mcp11-dvr-salt.yaml
@@ -1,40 +1,58 @@
-{% from 'virtual-mcp11-dvr.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-dvr.yaml' import HOSTNAME_CFG01 with context %}
+
+{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
+{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
+
+# Address pools for reclass cluster model are taken in the following order:
+# 1. environment variables,
+# 2. config.underlay.address_pools based on fuel-devops address pools
+#    (see generated '.ini' file after underlay is created),
+# 3. defaults
+{% set address_pools = config.underlay.address_pools %}
+{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
+{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
+{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
+{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
+
+{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
+{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
+{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
+{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
 
 # Install salt to the config node
 
+#- description: (moved to cloud-init config) Configure repository on the cfg01 node
+#  cmd:
+#    echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
+#    echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
+#    echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
+#    echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
+#    which wget >/dev/null || (apt-get update; apt-get install -y wget);
+#    echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
+#    wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
+#    echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
+#    wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
-- description: Configure repository on the cfg01 node
-  cmd:
-    echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
-    echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
-    echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
-    echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
-    which wget >/dev/null || (apt-get update; apt-get install -y wget);
-    echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
-    wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
-    echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
-    wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
-
-- description: Update packages on cfg01
-  cmd: apt-get clean; apt-get update
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
+#- description: Update packages on cfg01
+#  cmd: apt-get clean; eatmydata apt-get update
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
 - description: Installing salt master on cfg01
-  cmd:  apt-get install -y reclass git; apt-get install -y salt-master
+  cmd:  eatmydata apt-get install -y reclass git salt-master
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Install common packages on cfg01
-  cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
+#- description: (moved to cloud-init config) Install common packages on cfg01
+#  cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
 - description: Configure salt-master on cfg01
   cmd: |
@@ -74,8 +92,37 @@
 - description: Clone reclass models with submodules
   cmd: |
     ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
-    git clone -b master --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
+    git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
+
     mkdir -p /srv/salt/reclass/classes/service;
+
+    # Replace firstly to an intermediate value to avoid intersection between
+    # already replaced and replacing networks.
+    # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
+    # 192.168.10 -> 10.16.0 (generated network for admin)
+    # 10.16.0 -> <external network>
+    # So let's replace constant networks to the keywords, and then keywords to the desired networks.
+    find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
+
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
+
+    # Disable checkouting the model from remote repository
+    cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
+    # local storage
+      reclass:
+        storage:
+          data_source:
+            engine: local
+    EOF
+
+    # Show the changes to the console
+    cd /srv/salt/reclass/; git diff
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
@@ -92,7 +139,7 @@
     [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
     declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
     echo -e "\nInstalling all required salt formulas\n";
-    apt-get install -y "${formula_services[@]/#/salt-formula-}";
+    eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
     for formula_service in "${formula_services[@]}"; do
       echo -e "\nLink service metadata for formula ${formula_service} ...\n";
       [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
@@ -111,17 +158,30 @@
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Configure salt-minion on cfg01
+- description: Restart salt-master service
+  cmd: |
+     systemctl restart salt-master;
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 5}
+  skip_fail: false
+
+{% for ssh in config.underlay.ssh %}
+- description: Configure salt-minion on {{ ssh['node_name'] }}
   cmd: |
     [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
     cat << "EOF" >> /etc/salt/minion.d/minion.conf
-    id: {{ HOSTNAME_CFG01 }}
-    master: 127.0.0.1
+    id: {{ ssh['node_name'] }}
+    master: {{ config.salt.salt_master_host }}
     EOF
-    apt-get install -y salt-minion;
-  node_name: {{ HOSTNAME_CFG01 }}
+    eatmydata apt-get install -y salt-minion;
+    echo "Showing system info and metadata ...";
+    salt-call --no-color grains.items;
+    salt-call --no-color pillar.data;
+  node_name: {{ ssh['node_name'] }}
   retry: {count: 1, delay: 1}
   skip_fail: false
+{% endfor %}
+
 
 - description: Configure salt adoptors on cfg01
   cmd: |
@@ -131,16 +191,6 @@
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Restart services
-  cmd: |
-     systemctl restart salt-master;
-     systemctl restart salt-minion;
-     echo "Showing system info and metadata ...";
-     salt-call --no-color grains.items;
-     salt-call --no-color pillar.data;
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 5}
-  skip_fail: false
 
 # Prepare salt services and nodes settings
 - description: Run 'linux' formula on cfg01
@@ -189,7 +239,7 @@
   cmd: salt-key -A -y
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 5}
-  skip_fail: false
+  skip_fail: true
 
 - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
   cmd: salt --hard-crash --state-output=mixed --state-verbose=False
@@ -299,21 +349,20 @@
   retry: {count: 1, delay: 10}
   skip_fail: false
 
-#- description: Hack gtw node
-#  cmd: salt 'gtw*' cmd.run "ip addr del 172.16.10.110/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false
-#
-#- description: Hack cmp01 node
-#  cmd: salt 'cmp01*' cmd.run "ip addr del 172.16.10.105/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false
-#
-#- description: Hack cmp02 node
-#  cmd: salt 'cmp02*' cmd.run "ip addr del 172.16.10.106/24 dev ens4; ip addr flush dev ens4";
-#  node_name: {{ HOSTNAME_CFG01 }}
-#  retry: {count: 1, delay: 10}
-#  skip_fail: false
-#
+- description: Hack gtw node
+  cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 10}
+  skip_fail: false
+
+- description: Hack cmp01 node
+  cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 10}
+  skip_fail: false
+
+- description: Hack cmp02 node
+  cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 10}
+  skip_fail: false
diff --git a/tcp_tests/templates/salt/virtual-mcp11-ovs-salt.yaml b/tcp_tests/templates/salt/virtual-mcp11-ovs-salt.yaml
index bbb557d..5d47b9e 100644
--- a/tcp_tests/templates/salt/virtual-mcp11-ovs-salt.yaml
+++ b/tcp_tests/templates/salt/virtual-mcp11-ovs-salt.yaml
@@ -1,40 +1,58 @@
-{% from 'virtual-mcp11-ovs.jinja' import HOSTNAME_CFG01 with context %}
+{% from 'underlay/virtual-mcp11-ovs.yaml' import HOSTNAME_CFG01 with context %}
+
+{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
+{% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %}
+
+# Address pools for reclass cluster model are taken in the following order:
+# 1. environment variables,
+# 2. config.underlay.address_pools based on fuel-devops address pools
+#    (see generated '.ini' file after underlay is created),
+# 3. defaults
+{% set address_pools = config.underlay.address_pools %}
+{% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %}
+{% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %}
+{% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %}
+{% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %}
+
+{% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %}
+{% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %}
+{% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %}
+{% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %}
 
 # Install salt to the config node
 
+#- description: (moved to cloud-init config) Configure repository on the cfg01 node
+#  cmd:
+#    echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
+#    echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
+#    echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
+#    echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
+#    which wget >/dev/null || (apt-get update; apt-get install -y wget);
+#    echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
+#    wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
+#    echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
+#    wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
-- description: Configure repository on the cfg01 node
-  cmd:
-    echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
-    echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
-    echo "nameserver 172.18.208.44" >> /etc/resolv.conf;
-    echo "nameserver 8.8.8.8" >> /etc/resolv.conf;
-    which wget >/dev/null || (apt-get update; apt-get install -y wget);
-    echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
-    wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
-    echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
-    wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
-
-- description: Update packages on cfg01
-  cmd: apt-get clean; apt-get update
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
+#- description: Update packages on cfg01
+#  cmd: apt-get clean; eatmydata apt-get update
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
 - description: Installing salt master on cfg01
-  cmd:  apt-get install -y reclass git; apt-get install -y salt-master
+  cmd:  eatmydata apt-get install -y reclass git salt-master
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Install common packages on cfg01
-  cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 1}
-  skip_fail: false
+#- description: (moved to cloud-init config) Install common packages on cfg01
+#  cmd: eatmydata apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
+#  node_name: {{ HOSTNAME_CFG01 }}
+#  retry: {count: 1, delay: 1}
+#  skip_fail: false
 
 - description: Configure salt-master on cfg01
   cmd: |
@@ -74,8 +92,37 @@
 - description: Clone reclass models with submodules
   cmd: |
     ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
-    git clone -b master --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
+    git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass;
+
     mkdir -p /srv/salt/reclass/classes/service;
+
+    # Replace firstly to an intermediate value to avoid intersection between
+    # already replaced and replacing networks.
+    # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
+    # 192.168.10 -> 10.16.0 (generated network for admin)
+    # 10.16.0 -> <external network>
+    # So let's replace constant networks to the keywords, and then keywords to the desired networks.
+    find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} +
+
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} +
+    find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} +
+
+    # Disable checkouting the model from remote repository
+    cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml
+    # local storage
+      reclass:
+        storage:
+          data_source:
+            engine: local
+    EOF
+
+    # Show the changes to the console
+    cd /srv/salt/reclass/; git diff
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 1}
   skip_fail: false
@@ -92,7 +139,7 @@
     [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
     declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
     echo -e "\nInstalling all required salt formulas\n";
-    apt-get install -y "${formula_services[@]/#/salt-formula-}";
+    eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}";
     for formula_service in "${formula_services[@]}"; do
       echo -e "\nLink service metadata for formula ${formula_service} ...\n";
       [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
@@ -111,17 +158,30 @@
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Configure salt-minion on cfg01
+- description: Restart salt-master service
+  cmd: |
+     systemctl restart salt-master;
+  node_name: {{ HOSTNAME_CFG01 }}
+  retry: {count: 1, delay: 5}
+  skip_fail: false
+
+{% for ssh in config.underlay.ssh %}
+- description: Configure salt-minion on {{ ssh['node_name'] }}
   cmd: |
     [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
     cat << "EOF" >> /etc/salt/minion.d/minion.conf
-    id: {{ HOSTNAME_CFG01 }}
-    master: 127.0.0.1
+    id: {{ ssh['node_name'] }}
+    master: {{ config.salt.salt_master_host }}
     EOF
-    apt-get install -y salt-minion;
-  node_name: {{ HOSTNAME_CFG01 }}
+    eatmydata apt-get install -y salt-minion;
+    echo "Showing system info and metadata ...";
+    salt-call --no-color grains.items;
+    salt-call --no-color pillar.data;
+  node_name: {{ ssh['node_name'] }}
   retry: {count: 1, delay: 1}
   skip_fail: false
+{% endfor %}
+
 
 - description: Configure salt adoptors on cfg01
   cmd: |
@@ -131,16 +191,6 @@
   retry: {count: 1, delay: 1}
   skip_fail: false
 
-- description: Restart services
-  cmd: |
-     systemctl restart salt-master;
-     systemctl restart salt-minion;
-     echo "Showing system info and metadata ...";
-     salt-call --no-color grains.items;
-     salt-call --no-color pillar.data;
-  node_name: {{ HOSTNAME_CFG01 }}
-  retry: {count: 1, delay: 5}
-  skip_fail: false
 
 # Prepare salt services and nodes settings
 - description: Run 'linux' formula on cfg01
@@ -189,7 +239,7 @@
   cmd: salt-key -A -y
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 5}
-  skip_fail: false
+  skip_fail: true
 
 - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
   cmd: salt --hard-crash --state-output=mixed --state-verbose=False
@@ -300,19 +350,19 @@
   skip_fail: false
 
 - description: Hack gtw node
-  cmd: salt 'gtw*' cmd.run "ip addr del 172.16.10.110/24 dev ens4; ip addr flush dev ens4";
+  cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 10}
   skip_fail: false
 
 - description: Hack cmp01 node
-  cmd: salt 'cmp01*' cmd.run "ip addr del 172.16.10.105/24 dev ens4; ip addr flush dev ens4";
+  cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 10}
   skip_fail: false
 
 - description: Hack cmp02 node
-  cmd: salt 'cmp02*' cmd.run "ip addr del 172.16.10.106/24 dev ens4; ip addr flush dev ens4";
+  cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
   node_name: {{ HOSTNAME_CFG01 }}
   retry: {count: 1, delay: 10}
   skip_fail: false
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data-cfg01.yaml b/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data-cfg01.yaml
index 443e50c..45ad5cf 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data-cfg01.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data-cfg01.yaml
@@ -41,6 +41,26 @@
    - swapon /swapfile
    - echo "/swapfile   none    swap    defaults    0   0" >> /etc/fstab
 
+   ############## TCP Cloud cfg01 node ##################
+   #- sleep 120
+   - echo "Preparing base OS"
+
+   - echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
+   - echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
+   - echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
+   - echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
+   - which wget >/dev/null || (apt-get update; apt-get install -y wget);
+   - echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
+   - wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
+   - echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
+   - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
+
+   - apt-get clean
+   - apt-get update
+
+   # Install common packages
+   - eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree
+
    ########################################################
    # Node is ready, allow SSH access
    - echo "Allow SSH access ..."
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data1604.yaml b/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data1604.yaml
index 1013571..2c3cb6c 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data1604.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-dvr--user-data1604.yaml
@@ -43,11 +43,6 @@
    - swapon /swapfile
    - echo "/swapfile   none    swap    defaults   0   0" >> /etc/fstab
 
-   ########################################################
-   # Node is ready, allow SSH access
-   - echo "Allow SSH access ..."
-   - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
-   ########################################################
 
    ############## TCP Cloud cfg01 node ##################
    #- sleep 120
@@ -62,31 +57,16 @@
    - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -
 
    - apt-get clean
-   - apt-get update
-   - apt-get -y upgrade
+   - eatmydata apt-get update && apt-get -y upgrade
 
    # Install common packages
-   - apt-get install -y python-pip git
-   - apt-get install -y curl tmux byobu iputils-ping traceroute htop tree
+   - eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
 
-   - apt-get install -y salt-minion
-
-   # To be configured from inventory/fuel-devops by operator or autotests
-   - 'echo "id: {hostname}" >> /etc/salt/minion'
-   - 'echo "master: 192.168.10.100" >> /etc/salt/minion'
-
-   - echo "Restarting minion service with workarounds..."
-   - rm -f /etc/salt/pki/minion/minion_master.pub
-   - service salt-minion restart
-   - sleep 5
-   - rm -f /etc/salt/pki/minion/minion_master.pub
-   - service salt-minion restart
-
-   #- echo "Showing node metadata..."
-   #- salt-call pillar.data
-
-   #- echo "Running complete state ..."
-   #- salt-call state.sls linux,openssh,salt
+   ########################################################
+   # Node is ready, allow SSH access
+   - echo "Allow SSH access ..."
+   - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
+   ########################################################
 
   write_files:
    - path: /etc/network/interfaces
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-dvr.yaml b/tcp_tests/templates/underlay/virtual-mcp11-dvr.yaml
index 416c2c6..401cee7 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-dvr.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-dvr.yaml
@@ -1,7 +1,13 @@
+{% import 'underlay/virtual-mcp11-dvr--meta-data.yaml' as CLOUDINIT_META_DATA %}
+{% import 'underlay/virtual-mcp11-dvr--user-data-cfg01.yaml' as CLOUDINIT_USER_DATA_CFG01 %}
+{% import 'underlay/virtual-mcp11-dvr--user-data1604.yaml' as CLOUDINIT_USER_DATA_1604 %}
+
 ---
 aliases:
-  default_interface_model:
-    - &interface_model !os_env INTERFACE_MODEL, virtio
+ - &interface_model {{ os_env('INTERFACE_MODEL', 'virtio') }}
+ - &cloudinit_meta_data {{ CLOUDINIT_META_DATA }}
+ - &cloudinit_user_data_cfg01 {{ CLOUDINIT_USER_DATA_CFG01 }}
+ - &cloudinit_user_data_1604 {{ CLOUDINIT_USER_DATA_1604 }}
 
 {% set DOMAIN_NAME = os_env('LAB_CONFIG_NAME', 'virtual-mcp11-dvr') + '.local' %}
 {% set HOSTNAME_CFG01 = os_env('HOSTNAME_CFG01', 'cfg01.' + DOMAIN_NAME) %}
@@ -19,7 +25,7 @@
 
     address_pools:
       private-pool01:
-        net: 172.16.10.0/24:24
+        net: {{ os_env('PRIVATE_ADDRESS_POOL01', '10.60.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -36,7 +42,7 @@
             dhcp: [+90, -10]
 
       admin-pool01:
-        net: 192.168.10.0/24:24
+        net: {{ os_env('ADMIN_ADDRESS_POOL01', '10.70.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -53,7 +59,7 @@
             dhcp: [+90, -10]
 
       tenant-pool01:
-        net: 10.1.0.0/24:24
+        net: {{ os_env('TENANT_ADDRESS_POOL01', '10.80.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -70,7 +76,7 @@
             dhcp: [+10, -10]
 
       external-pool01:
-        net: 10.16.0.0/24:24
+        net: {{ os_env('EXTERNAL_ADDRESS_POOL01', '10.90.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -158,8 +164,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data-cfg01.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_cfg01
 
               interfaces:
                 - label: ens3
@@ -199,8 +205,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: &interfaces
                 - label: ens3
@@ -240,8 +246,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -269,8 +275,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -298,8 +304,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -325,8 +331,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
 
               interfaces: &all_interfaces
@@ -376,8 +382,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *all_interfaces
               network_config: *all_network_config
@@ -402,8 +408,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-dvr--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-dvr--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *all_interfaces
               network_config: *all_network_config
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data-cfg01.yaml b/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data-cfg01.yaml
index 443e50c..45ad5cf 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data-cfg01.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data-cfg01.yaml
@@ -41,6 +41,26 @@
    - swapon /swapfile
    - echo "/swapfile   none    swap    defaults    0   0" >> /etc/fstab
 
+   ############## TCP Cloud cfg01 node ##################
+   #- sleep 120
+   - echo "Preparing base OS"
+
+   - echo "172.18.248.114    jenkins.mcp.mirantis.net  gerrit.mcp.mirantis.net" >> /etc/hosts;
+   - echo "185.135.196.10    apt-mk.mirantis.com" >> /etc/hosts;
+   - echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
+   - echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
+   - which wget >/dev/null || (apt-get update; apt-get install -y wget);
+   - echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
+   - wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
+   - echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
+   - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
+
+   - apt-get clean
+   - apt-get update
+
+   # Install common packages
+   - eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree
+
    ########################################################
    # Node is ready, allow SSH access
    - echo "Allow SSH access ..."
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data1604.yaml b/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data1604.yaml
index 1013571..2c3cb6c 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data1604.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-ovs--user-data1604.yaml
@@ -43,11 +43,6 @@
    - swapon /swapfile
    - echo "/swapfile   none    swap    defaults   0   0" >> /etc/fstab
 
-   ########################################################
-   # Node is ready, allow SSH access
-   - echo "Allow SSH access ..."
-   - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
-   ########################################################
 
    ############## TCP Cloud cfg01 node ##################
    #- sleep 120
@@ -62,31 +57,16 @@
    - wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -
 
    - apt-get clean
-   - apt-get update
-   - apt-get -y upgrade
+   - eatmydata apt-get update && apt-get -y upgrade
 
    # Install common packages
-   - apt-get install -y python-pip git
-   - apt-get install -y curl tmux byobu iputils-ping traceroute htop tree
+   - eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc
 
-   - apt-get install -y salt-minion
-
-   # To be configured from inventory/fuel-devops by operator or autotests
-   - 'echo "id: {hostname}" >> /etc/salt/minion'
-   - 'echo "master: 192.168.10.100" >> /etc/salt/minion'
-
-   - echo "Restarting minion service with workarounds..."
-   - rm -f /etc/salt/pki/minion/minion_master.pub
-   - service salt-minion restart
-   - sleep 5
-   - rm -f /etc/salt/pki/minion/minion_master.pub
-   - service salt-minion restart
-
-   #- echo "Showing node metadata..."
-   #- salt-call pillar.data
-
-   #- echo "Running complete state ..."
-   #- salt-call state.sls linux,openssh,salt
+   ########################################################
+   # Node is ready, allow SSH access
+   - echo "Allow SSH access ..."
+   - sudo iptables -D INPUT -p tcp --dport 22 -j DROP
+   ########################################################
 
   write_files:
    - path: /etc/network/interfaces
diff --git a/tcp_tests/templates/underlay/virtual-mcp11-ovs.yaml b/tcp_tests/templates/underlay/virtual-mcp11-ovs.yaml
index 75ccfb7..a9d8601 100644
--- a/tcp_tests/templates/underlay/virtual-mcp11-ovs.yaml
+++ b/tcp_tests/templates/underlay/virtual-mcp11-ovs.yaml
@@ -1,7 +1,13 @@
+{% import 'underlay/virtual-mcp11-ovs--meta-data.yaml' as CLOUDINIT_META_DATA %}
+{% import 'underlay/virtual-mcp11-ovs--user-data-cfg01.yaml' as CLOUDINIT_USER_DATA_CFG01 %}
+{% import 'underlay/virtual-mcp11-ovs--user-data1604.yaml' as CLOUDINIT_USER_DATA_1604 %}
+
 ---
 aliases:
-  default_interface_model:
-    - &interface_model !os_env INTERFACE_MODEL, virtio
+ - &interface_model {{ os_env('INTERFACE_MODEL', 'virtio') }}
+ - &cloudinit_meta_data {{ CLOUDINIT_META_DATA }}
+ - &cloudinit_user_data_cfg01 {{ CLOUDINIT_USER_DATA_CFG01 }}
+ - &cloudinit_user_data_1604 {{ CLOUDINIT_USER_DATA_1604 }}
 
 {% set DOMAIN_NAME = os_env('LAB_CONFIG_NAME', 'virtual-mcp11-ovs') + '.local' %}
 {% set HOSTNAME_CFG01 = os_env('HOSTNAME_CFG01', 'cfg01.' + DOMAIN_NAME) %}
@@ -19,7 +25,7 @@
 
     address_pools:
       private-pool01:
-        net: 172.16.10.0/24:24
+        net: {{ os_env('PRIVATE_ADDRESS_POOL01', '10.60.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -36,7 +42,7 @@
             dhcp: [+90, -10]
 
       admin-pool01:
-        net: 192.168.10.0/24:24
+        net: {{ os_env('ADMIN_ADDRESS_POOL01', '10.70.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -53,7 +59,7 @@
             dhcp: [+90, -10]
 
       tenant-pool01:
-        net: 10.1.0.0/24:24
+        net: {{ os_env('TENANT_ADDRESS_POOL01', '10.80.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -70,7 +76,7 @@
             dhcp: [+10, -10]
 
       external-pool01:
-        net: 10.16.0.0/24:24
+        net: {{ os_env('EXTERNAL_ADDRESS_POOL01', '10.90.0.0/16:24') }}
         params:
           ip_reserved:
             gateway: +1
@@ -158,8 +164,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data-cfg01.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_cfg01
 
               interfaces:
                 - label: ens3
@@ -199,8 +205,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: &interfaces
                 - label: ens3
@@ -240,8 +246,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -269,8 +275,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -298,8 +304,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *interfaces
               network_config: *network_config
@@ -325,8 +331,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
 
               interfaces: &all_interfaces
@@ -376,8 +382,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *all_interfaces
               network_config: *all_network_config
@@ -402,8 +408,8 @@
                   format: raw
                   device: cdrom
                   bus: ide
-                  cloudinit_meta_data: !include virtual-mcp11-ovs--meta-data.yaml
-                  cloudinit_user_data: !include virtual-mcp11-ovs--user-data1604.yaml
+                  cloudinit_meta_data: *cloudinit_meta_data
+                  cloudinit_user_data: *cloudinit_user_data_1604
 
               interfaces: *all_interfaces
               network_config: *all_network_config
diff --git a/tcp_tests/templates/virtual-mcp11-dvr.jinja b/tcp_tests/templates/virtual-mcp11-dvr.jinja
deleted file mode 100644
index 1c5688c..0000000
--- a/tcp_tests/templates/virtual-mcp11-dvr.jinja
+++ /dev/null
@@ -1,2 +0,0 @@
-{% set DOMAIN_NAME = os_env('LAB_CONFIG_NAME', 'virtual-mcp11-dvr') + '.local' %}
-{% set HOSTNAME_CFG01 = os_env('HOSTNAME_CFG01', 'cfg01.' + DOMAIN_NAME) %}
diff --git a/tcp_tests/templates/virtual-mcp11-ovs.jinja b/tcp_tests/templates/virtual-mcp11-ovs.jinja
deleted file mode 100644
index 842731e..0000000
--- a/tcp_tests/templates/virtual-mcp11-ovs.jinja
+++ /dev/null
@@ -1,2 +0,0 @@
-{% set DOMAIN_NAME = os_env('LAB_CONFIG_NAME', 'virtual-mcp11-ovs') + '.local' %}
-{% set HOSTNAME_CFG01 = os_env('HOSTNAME_CFG01', 'cfg01.' + DOMAIN_NAME) %}
diff --git a/tcp_tests/tests/system/test_install_mcp11_ovs_newton.py b/tcp_tests/tests/system/test_install_mcp11_ovs_newton.py
index b19abf1..6c44de4 100644
--- a/tcp_tests/tests/system/test_install_mcp11_ovs_newton.py
+++ b/tcp_tests/tests/system/test_install_mcp11_ovs_newton.py
@@ -35,7 +35,7 @@
     #salt_call_cmd = 'salt-call --state-output=terse --state-verbose=False '  # For reduced output
 
     # @pytest.mark.snapshot_needed
-    # @pytest.mark.fail_snapshot
+    @pytest.mark.fail_snapshot
     def test_mcp11_newton_ovs_install(self, underlay, openstack_deployed,
                                      show_step):
         """Test for deploying an mcp environment and check it
diff --git a/tcp_tests/tests/system/test_mcp10_ovs_vxlan_install.py b/tcp_tests/tests/system/test_mcp10_ovs_vxlan_install.py
index 17f5439..00c9ee1 100644
--- a/tcp_tests/tests/system/test_mcp10_ovs_vxlan_install.py
+++ b/tcp_tests/tests/system/test_mcp10_ovs_vxlan_install.py
@@ -35,7 +35,7 @@
     #salt_call_cmd = 'salt-call --state-output=terse --state-verbose=False '  # For reduced output
 
     # @pytest.mark.snapshot_needed
-    # @pytest.mark.fail_snapshot
+    @pytest.mark.fail_snapshot
     def test_mcp10_ovs_vxlan_install(self, underlay, openstack_deployed,
                                      show_step):
         """Test for deploying an mcp environment and check it
diff --git a/tcp_tests/tests/system/test_opencontrail.py b/tcp_tests/tests/system/test_opencontrail.py
index 661b298..9452bda 100644
--- a/tcp_tests/tests/system/test_opencontrail.py
+++ b/tcp_tests/tests/system/test_opencontrail.py
@@ -28,7 +28,7 @@
     """Test class for testing OpenContrail on a TCP lab"""
 
     # @pytest.mark.snapshot_needed
-    # @pytest.mark.fail_snapshot
+    @pytest.mark.fail_snapshot
     def test_opencontrail(self, config, openstack_deployed,
                                  show_step, opencontrail):
         """Runner for Juniper contrail-tests
diff --git a/tcp_tests/tests/system/test_tcp_install.py b/tcp_tests/tests/system/test_tcp_install.py
index ae2871d..1ccb0d4 100644
--- a/tcp_tests/tests/system/test_tcp_install.py
+++ b/tcp_tests/tests/system/test_tcp_install.py
@@ -35,7 +35,7 @@
     #salt_call_cmd = 'salt-call --state-output=terse --state-verbose=False '  # For reduced output
 
     # @pytest.mark.snapshot_needed
-    # @pytest.mark.fail_snapshot
+    @pytest.mark.fail_snapshot
     def test_tcp_install_default(self, underlay, openstack_deployed,
                                  show_step, rally):
         """Test for deploying an tcp environment and check it
@@ -71,7 +71,7 @@
         assert res['failures'] == 0, fail_msg
 
     # @pytest.mark.snapshot_needed
-    # @pytest.mark.fail_snapshot
+    @pytest.mark.fail_snapshot
     def test_tcp_install_with_scripts(self, config, underlay, salt_deployed,
                                       show_step, rally):
         """Test for deploying an tcp environment with scripts and check it