Fix getting params

Fix gettting params for cicd deploy

Close-bug: PROD-30306

Change-Id: I9bc51281d2fbf5be29bb437f5fac79252e565de0
diff --git a/jobs/pipelines/swarm-deploy-cicd.groovy b/jobs/pipelines/swarm-deploy-cicd.groovy
index 0183016..dd2df11 100644
--- a/jobs/pipelines/swarm-deploy-cicd.groovy
+++ b/jobs/pipelines/swarm-deploy-cicd.groovy
@@ -52,6 +52,12 @@
                 stage("Run Jenkins job on salt-master [deploy_openstack:${env.STACK_INSTALL}]") {
                     shared.run_job_on_day01_node(env.STACK_INSTALL, install_timeout)
                 }
+                stage("Create env_jenkins_cicd and env_k8s files") {
+                    shared.run_cmd("""\
+                        export TESTS_CONFIGS=\$(pwd)/${ENV_NAME}_salt_deployed.ini
+                        python ./tcp_tests/utils/create_env_jenkins_cicd.py
+                    """)
+                }
 
                 for (stack in "${env.STACK_INSTALL}".split(",")) {
                     stage("Sanity check the deployed component [${stack}]") {
diff --git a/tcp_tests/managers/saltmanager.py b/tcp_tests/managers/saltmanager.py
index 737edcd..a33bb11 100644
--- a/tcp_tests/managers/saltmanager.py
+++ b/tcp_tests/managers/saltmanager.py
@@ -14,7 +14,6 @@
 
 import netaddr
 import pkg_resources
-import yaml
 
 from collections import defaultdict
 
@@ -64,8 +63,8 @@
                               label="Install and configure salt")
         self.create_env_salt()
         self.create_env_jenkins_day01()
-        self.create_env_jenkins_cicd()
-        self.create_env_k8s()
+        # self.create_env_jenkins_cicd()
+        # self.create_env_k8s()
 
     def change_creds(self, username, password):
         self.__user = username
@@ -371,34 +370,21 @@
 
         env_jenkins_cicd_filename = pkg_resources.resource_filename(
             settings.__name__, 'utils/env_jenkins_cicd')
-        domain_name = self.get_single_pillar(
-            tgt="I@salt:master", pillar="_param:cluster_domain")
-        LOG.info("Domain: {}".format(domain_name))
-        cid01 = 'cid01.' + domain_name
-        LOG.info("{}".format(cid01))
-        command = "reclass -n {}".format(cid01)
-        LOG.info("{}".format(command))
-        cfg = self.__underlay.get_target_node_names('cfg01')[0]
-        LOG.info("cfg node_name: {}".format(cfg))
-        output = self.__underlay.check_call(
-            node_name=cfg,
-            cmd=command)
-        result = yaml.load(output.stdout_str)
-        jenkins_params = result.get(
-            'parameters', {}).get(
-            'jenkins', {}).get(
-            'client', {}).get(
-            'master', {})
-        if not jenkins_params:
+
+        tgt = 'I@docker:client:stack:jenkins and cid01*'
+        try:
+            jenkins_params = self.get_single_pillar(
+                tgt=tgt, pillar="jenkins:client:master")
+        except LookupError as e:
+            LOG.error("Skipping creation {0} because cannot get Jenkins CICD "
+                      "parameters from '{1}': {2}"
+                      .format(env_jenkins_cicd_filename, tgt, e.message))
             return
+
         jenkins_host = jenkins_params['host']
-        LOG.info("jenkins_host: {}".format(jenkins_host))
         jenkins_port = jenkins_params['port']
-        LOG.info("jenkins_port: {}".format(jenkins_port))
         jenkins_user = jenkins_params['username']
-        LOG.info("jenkins_user: {}".format(jenkins_user))
         jenkins_pass = jenkins_params['password']
-        LOG.info("jenkins_pass: {}".format(jenkins_pass))
 
         with open(env_jenkins_cicd_filename, 'w') as f:
             f.write(
@@ -426,46 +412,23 @@
 
         env_k8s_filename = pkg_resources.resource_filename(
             settings.__name__, 'utils/env_k8s')
-        domain_name = self.get_single_pillar(
-            tgt="I@salt:master", pillar="_param:cluster_domain")
-        LOG.info("Domain: {}".format(domain_name))
-        ctl01 = 'ctl01.' + domain_name
-        LOG.info("{}".format(ctl01))
-        command = "reclass -n {}".format(ctl01)
-        LOG.info("{}".format(command))
-        cfg = self.__underlay.get_target_node_names('cfg01')[0]
-        LOG.info("cfg node_name: {}".format(cfg))
-        output = self.__underlay.check_call(
-            node_name=cfg,
-            cmd=command)
-        result = yaml.load(output.stdout_str)
-        haproxy_params = result.get(
-            'parameters', {}).get(
-            'haproxy', {}).get(
-            'proxy', {}).get(
-            'listen', {}).get(
-            'k8s_secure', {}).get(
-            'binds', {})
-        if not haproxy_params:
+
+        tgt = 'I@haproxy:proxy:enabled:true and I@kubernetes:master and *01*'
+        try:
+            haproxy_params = self.get_single_pillar(
+                tgt=tgt, pillar="haproxy:proxy:listen:k8s_secure:binds")[0]
+            k8s_params = self.get_single_pillar(
+                tgt=tgt, pillar="kubernetes:master:admin")
+        except LookupError as e:
+            LOG.error("Skipping creation {0} because cannot get Kubernetes "
+                      "parameters from '{1}': {2}"
+                      .format(env_k8s_filename, tgt, e.message))
             return
-        k8s_params = result.get(
-            'kubernetes', {}).get(
-            'master', {}).get(
-            'admin', {})
-        if not k8s_params:
-            return
+
         kube_host = haproxy_params['address']
-        LOG.info("kube_host: {}".
-                 format(kube_host))
         kube_apiserver_port = haproxy_params['port']
-        LOG.info("kube_apiserver_port: {}".
-                 format(kube_apiserver_port))
         kubernetes_admin_user = k8s_params['username']
-        LOG.info("kubernetes_admin_user: {}".
-                 format(kubernetes_admin_user))
         kubernetes_admin_password = k8s_params['password']
-        LOG.info("kubernetes_admin_password: {}".
-                 format(kubernetes_admin_password))
 
         with open(env_k8s_filename, 'w') as f:
             f.write(
diff --git a/tcp_tests/utils/create_env_jenkins_cicd.py b/tcp_tests/utils/create_env_jenkins_cicd.py
new file mode 100644
index 0000000..ba73d6c
--- /dev/null
+++ b/tcp_tests/utils/create_env_jenkins_cicd.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+sys.path.append(os.getcwd())
+try:
+    from tcp_tests.fixtures import config_fixtures
+    from tcp_tests.managers import underlay_ssh_manager
+    from tcp_tests.managers import saltmanager as salt_manager
+except ImportError:
+    print("ImportError: Run the application from the tcp-qa directory or "
+          "set the PYTHONPATH environment variable to directory which contains"
+          " ./tcp_tests")
+    sys.exit(1)
+
+
+def main():
+    tests_configs = os.environ.get('TESTS_CONFIGS', None)
+    if not tests_configs or not os.path.isfile(tests_configs):
+        print("Please set TESTS_CONFIGS environment variable whith"
+              "the path to INI file with lab metadata.")
+        return 1
+    config = config_fixtures.config()
+    underlay = underlay_ssh_manager.UnderlaySSHManager(config)
+    saltmanager = salt_manager.SaltManager(config, underlay)
+    saltmanager.create_env_jenkins_cicd()
+    saltmanager.create_env_k8s()
+
+
+if __name__ == '__main__':
+    sys.exit(main())