Merge "Store kubernetes server version after conformance tests"
diff --git a/tcp_tests/managers/k8s/cluster.py b/tcp_tests/managers/k8s/cluster.py
index db7bb18..1531f0d 100644
--- a/tcp_tests/managers/k8s/cluster.py
+++ b/tcp_tests/managers/k8s/cluster.py
@@ -92,6 +92,7 @@
         self.api_autoscaling = client.AutoscalingV1Api(api_client)
         self.api_batch = client.BatchV1Api(api_client)
         self.api_rbac_auth = client.RbacAuthorizationV1Api(api_client)
+        self.api_version = client.VersionApi(api_client)
 
         self.nodes = K8sNodeManager(self)
         self.pods = K8sPodManager(self)
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index cc0a924..d84451f 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -315,6 +315,7 @@
                 r.check_call(cmd, raise_on_err=False)
                 LOG.info("Downloading the artifact {0}".format(log_file))
                 r.download(destination=log_file, target=os.getcwd())
+        self.store_server_version(os.path.join(os.getcwd(), 'env_k8s_version'))
 
     def combine_xunit(self, path, output):
         """
@@ -379,6 +380,26 @@
         LOG.debug("{0}\nresult:\n{1}".format(cmd, result['stdout']))
         return result['stdout']
 
+    def store_server_version(self, env_file_path):
+        """Store Kubernetes server version in bash source file"""
+
+        def digits(string):
+            return ''.join(n for n in string if n.isdigit())
+
+        ver = self.api.api_version.get_code()
+        LOG.debug("Got Kubernetes server version:\n{0}".format(ver))
+
+        env_version = ("export KUBE_SERVER_VERSION={0}.{1}\n"
+                       "export KUBE_SERVER_GIT_VERSION={2}\n"
+                       .format(digits(ver.major),
+                               digits(ver.minor),
+                               ver.git_version))
+
+        LOG.info("Kubernetes server version is stored to {0}:\n{1}"
+                 .format(env_file_path, env_version))
+        with open(env_file_path, 'w') as kver:
+            kver.write(env_version)
+
 
 class K8SKubectlCli(object):
     """ Contain kubectl cli commands and api wrappers"""
diff --git a/tcp_tests/utils/env_k8s b/tcp_tests/utils/env_k8s
index 39764d0..01e20fd 100755
--- a/tcp_tests/utils/env_k8s
+++ b/tcp_tests/utils/env_k8s
@@ -20,21 +20,15 @@
     unset kube_apiserver_port
     unset kubernetes_admin_user
     unset kubernetes_admin_password
-    unset kubernetes_version_major
-    unset kubernetes_version_minor
 else
     KUBE_TARGET='I@haproxy:proxy:enabled:true and I@kubernetes:master and *01*'
     export kube_host=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" pillar.get haproxy:proxy:listen:k8s_secure:binds:address)
     export kube_apiserver_port=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" pillar.get haproxy:proxy:listen:k8s_secure:binds:port)
     export kubernetes_admin_user=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" pillar.get kubernetes:master:admin:username)
     export kubernetes_admin_password=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" pillar.get kubernetes:master:admin:password)
-    export kubernetes_version_major=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" cmd.run "curl -s 127.0.0.1:8080/version|grep major| cut -d'\"' -f4|sed 's/[^0-9]*//g'")
-    export kubernetes_version_minor=$(${PYTHONPATH}/tcp_tests/utils/get_param.py -C "${KUBE_TARGET}" cmd.run "curl -s 127.0.0.1:8080/version|grep minor| cut -d'\"' -f4|sed 's/[^0-9]*//g'")
 fi
 
 echo "export kube_host='$kube_host'  # Kubernetes API host"
 echo "export kube_apiserver_port='${kube_apiserver_port}'  # Kubernetes API port"
 echo "export kubernetes_admin_user='${kubernetes_admin_user}'  # Kubernetes admin user"
 echo "export kubernetes_admin_password='${kubernetes_admin_password}'  # Kubernetes admin password"
-echo "export kubernetes_version_major='${kubernetes_version_major}'   # Kubernetes version major"
-echo "export kubernetes_version_minor='${kubernetes_version_minor}'   # Kubernetes version minor"