github.com/nginxinc/kubernetes-ingress@v1.12.5/tests/suite/test_build_info.py (about)

     1  import pytest, logging, io
     2  from kubernetes.client.rest import ApiException
     3  from suite.resources_utils import get_first_pod_name
     4  
     5  @pytest.mark.ingresses
     6  @pytest.mark.smoke
     7  class TestBuildVersion:
     8      def test_build_version(
     9          self, ingress_controller, kube_apis, ingress_controller_prerequisites
    10      ):
    11          """
    12          Test Version tag of build i.e. 'Version=<VERSION>'
    13          """
    14          _info = self.send_build_info(kube_apis, ingress_controller_prerequisites)
    15          _version = _info[
    16              _info.find("Version=") + len("Version=") : _info.rfind("GitCommit=")
    17          ]
    18          logging.info(_version)
    19          assert _version != " "
    20  
    21      def test_build_gitcommit(
    22          self, ingress_controller, kube_apis, ingress_controller_prerequisites
    23      ):
    24          """
    25          Test Git Commit tag of build i.e. 'GitCommit=<GITCOMMIT>'
    26          """
    27          _info = self.send_build_info(kube_apis, ingress_controller_prerequisites)
    28          _commit = _info[_info.find("GitCommit=") :].lstrip().replace("GitCommit=", "")
    29          logging.info(_commit)
    30          assert _commit != ""
    31  
    32      def send_build_info(self, kube_apis, ingress_controller_prerequisites) -> str:
    33          """
    34          Helper function to get pod logs
    35          """
    36          pod_name = get_first_pod_name(
    37              kube_apis.v1, ingress_controller_prerequisites.namespace
    38          )
    39          try:
    40              api_response = kube_apis.v1.read_namespaced_pod_log(
    41                  name=pod_name,
    42                  namespace=ingress_controller_prerequisites.namespace,
    43                  limit_bytes=200,
    44              )
    45              logging.info(api_response)
    46          except ApiException as e:
    47              logging.exception(f"Found exception in reading the logs: {e}")
    48  
    49          br = io.StringIO(api_response)
    50          _log = br.readline()
    51          try:
    52              _info = _log[_log.find("Version") :].strip()
    53              logging.info(f"Version and GitCommit info: {_info}")
    54          except Exception as e:
    55              logging.exception(f"Tag labels not found")
    56  
    57          return _info