Store kubernetes server version after conformance tests

To use with xunit_reporter

Log output example:

  -- Kubernetes server version is stored to ./env_k8s_version:
  export KUBE_SERVER_VERSION=1.10
  export KUBE_SERVER_GIT_VERSION=v1.10.4-4+971831eb5eb3db

Usage example:

  . ./env_k8s_version
  report ... --testrail-suite "[MCP][k8s]Hyperkube ${KUBE_SERVER_VERSION}.x"

Change-Id: Ia27b9e16142d5bb30f5dee5030095c2eb4e8e08c
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"""