Update underlay ssh host by VCP hodes

Change-Id: I6125db762a0974143a2454b288d3a42e9b6c5829
diff --git a/tcp_tests/fixtures/salt_fixtures.py b/tcp_tests/fixtures/salt_fixtures.py
index 52749bb..d72b1fc 100644
--- a/tcp_tests/fixtures/salt_fixtures.py
+++ b/tcp_tests/fixtures/salt_fixtures.py
@@ -63,7 +63,6 @@
     # Create Salt cluster
     if config.salt.salt_master_host == '0.0.0.0':
         # Temporary workaround. Underlay should be extended with roles
-        salt_nodes = underlay.node_names()
         config.salt.salt_master_host = \
             underlay.host_by_node_role(
                 node_role=ext.UNDERLAY_NODE_ROLES.salt_master)
@@ -71,6 +70,13 @@
         commands = underlay.read_template(config.salt_deploy.salt_steps_path)
         LOG.info("############ Executing command ####### {0}".format(commands))
         salt_actions.install(commands)
+
+        salt_nodes = salt_actions.get_ssh_data()
+        config.underlay.ssh = config.underlay.ssh + \
+            [node for node in salt_nodes
+             if not any(node['node_name'] == n['node_name']
+                        for n in config.underlay.ssh)]
+
         hardware.create_snapshot(ext.SNAPSHOT.salt_deployed)
 
     else:
diff --git a/tcp_tests/managers/saltmanager.py b/tcp_tests/managers/saltmanager.py
index d02d7db..4a58e93 100644
--- a/tcp_tests/managers/saltmanager.py
+++ b/tcp_tests/managers/saltmanager.py
@@ -12,6 +12,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import netaddr
+
 from collections import defaultdict
 
 from datetime import datetime
@@ -155,3 +157,38 @@
     def get_pillar(self, tgt, pillar):
         result = self.local(tgt=tgt, fun='pillar.get', args=pillar)
         return result['return']
+
+    def get_ssh_data(self):
+        """Generate ssh config for Underlay
+
+        :param roles: list of strings
+        """
+
+        pool_name = self.__config.underlay.net_mgmt
+        pool_net = netaddr.IPNetwork(self.__config.underlay.address_pools[
+            self.__config.underlay.net_mgmt])
+        hosts = self.local('*', 'grains.item', ['host', 'ipv4'])
+
+        if len(hosts.get('return', [])) == 0:
+            raise LookupError("Hosts is empty or absent")
+        hosts = hosts['return'][0]
+        if len(hosts) == 0:
+            raise LookupError("Hosts is empty or absent")
+
+        def host(node_name, ip):
+            return {
+                'roles': ['salt_minion'],
+                'keys': [
+                    k['private'] for k in self.__config.underlay.ssh_keys
+                ],
+                'node_name': node_name,
+                'host': ip,
+                'address_pool': pool_name,
+                'login': settings.SSH_NODE_CREDENTIALS['login'],
+                'password': settings.SSH_NODE_CREDENTIALS['password']
+            }
+
+        return [
+            host(k, next(i for i in v['ipv4'] if i in pool_net))
+            for k, v in hosts.items()
+            if next(i for i in v['ipv4'] if i in pool_net)]
diff --git a/tcp_tests/requirements.txt b/tcp_tests/requirements.txt
index 26b84b9..a4149a8 100644
--- a/tcp_tests/requirements.txt
+++ b/tcp_tests/requirements.txt
@@ -17,3 +17,4 @@
 python-k8sclient==0.4.0
 salt-pepper
 setuptools<=36.2.0
+netaddr
diff --git a/tcp_tests/settings_oslo.py b/tcp_tests/settings_oslo.py
index 1847a61..1092c8b 100644
--- a/tcp_tests/settings_oslo.py
+++ b/tcp_tests/settings_oslo.py
@@ -59,6 +59,8 @@
 _default_k8s_steps = pkg_resources.resource_filename(
     __name__, 'templates/{0}/k8s.yaml'.format(
         settings.LAB_CONFIG_NAME))
+_default_net_mgm = os.environ.get("NET_MGMT", "admin-pool01")
+
 
 hardware_opts = [
     ct.Cfg('manager', ct.String(),
@@ -110,6 +112,7 @@
                 "then a key pair will be generated automatically"),
     ct.Cfg('ssh_key_file', ct.String(), default=os.path.abspath('./id_rsa'),
            help='Path (local) to file with private key authorized on nodes'),
+    ct.Cfg('net_mgmt', ct.String(), default=_default_net_mgm)
 ]