diff --git a/ci-scripts/Jenkinsfile-GitLab-COTS-UE-Test b/ci-scripts/Jenkinsfile-GitLab-COTS-UE-Test index ef9e34d7c67963ddc2af3310997f9eaeb5f7cd31..0c8efa674152b3a64cabd31bf2c1692b5db1215d 100644 --- a/ci-scripts/Jenkinsfile-GitLab-COTS-UE-Test +++ b/ci-scripts/Jenkinsfile-GitLab-COTS-UE-Test @@ -123,25 +123,10 @@ pipeline { } if ((branchNames[ii] == "develop") && (baseTags[ii] == "develop")) { destTags[ii] = getLastCommitFromBranch(ii, repoNames[ii], branchNames[ii]) - baseTags[ii] = getCorrectBaseTag(imageNames[ii], destTags[ii]) } else { destTags[ii] = baseTags[ii] } } - // Checking if all needed images are on cetautomatix to be pushed - imageStatus = 0 - for (ii = 0; ii < imageNames.size(); ii++) { - imageStatus += checkImageInfo(imageNames[ii], baseTags[ii]) - } - if (imageStatus > 0) { - coreDeploy = false - gnbDeploy = false - testStart0 = false - testStart1 = false - testStop0 = false - testStop1 = false - error ("Some images are not present!") - } } } } @@ -153,17 +138,11 @@ pipeline { [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.cn_oc_credentials}", usernameVariable: 'OC_Username', passwordVariable: 'OC_Password'] ]) { sh "oc login -u ${OC_Username} -p ${OC_Password}" - sh "oc whoami -t | sudo podman login -u ${OC_Username} --password-stdin ${oc_registry_url} --tls-verify=false" logoutToDo = true - } - sh "oc project ${oc_project_name}" - for (ii = 0; ii < imageNames.size(); ii++) { - pushToOpenshiftRegistry (imageNames[ii], baseTags[ii], destTags[ii]) - appendImageInfo(imageNames[ii], destTags[ii]) - } - // Checking that will-be-used tags have been pushed - for (ii = 0; ii < imageNames.size(); ii++) { - sh "oc describe is ${imageNames[ii]} | grep ${destTags[ii]}" + sh "oc project ${oc_project_name}" + for (ii = 0; ii < imageNames.size(); ii++) { + sh "./ci-scripts/checkOcRegistry.py --image-name ${imageNames[ii]} --tag ${destTags[ii]} --project ${oc_project_name} -u ${OC_Username}" + } } // Putting the new tags in charts // Let's work now in the basic chart folder @@ -386,7 +365,6 @@ pipeline { sh "oc get pods -o wide" deployedCore = false } - sh "sudo podman logout ${oc_registry_url}" sh 'oc logout' logoutToDo = false } @@ -445,7 +423,6 @@ pipeline { } } if (logoutToDo) { - sh "sudo podman logout ${oc_registry_url}" sh 'oc logout' } sh 'zip -r cn5g_cots_ue_test_logs.zip archives' @@ -495,54 +472,6 @@ def getLastCommitFromBranch(index, repoName, branchName) { return "${branchName}-${shaone}" } -def getCorrectBaseTag(imageName, destTag) { - baseTag = "develop" - try { - sh "sudo podman images | grep ${imageName} | grep ${destTag}" - baseTag = destTag - } catch (Exception e) { - echo "Still using develop as base tag" - } - return baseTag -} - -def checkImageInfo (imageName, origTag) { - status = 0 - sh "echo 'Tested Tag is ${imageName}:${origTag}' > archives/${imageName}-image-info.log" - try { - sh "sudo podman image inspect --format='Size = {{.Size}} bytes' ${imageName}:${origTag} >> archives/${imageName}-image-info.log" - sh "sudo podman image inspect --format='Date = {{.Created}}' ${imageName}:${origTag} >> archives/${imageName}-image-info.log" - } catch (Exception e) { - echo "${imageName} Image tag to test (${imageName}:${origTag} does not exist!" - status = 1 - } - return status -} - -def appendImageInfo (imageName, destTag) { - sh "echo 'OC Pushed Tag is ${imageName}:${destTag}' >> archives/${imageName}-image-info.log" -} - -def pushToOpenshiftRegistry (imageName, origTag, destTag) { - noHttpsURL = oc_registry_url.replaceAll("https://", "") - sh "sudo podman rmi ${noHttpsURL}/${oc_project_name}/${imageName}:${destTag} || true" - sh "sudo podman image tag ${imageName}:${origTag} ${noHttpsURL}/${oc_project_name}/${imageName}:${destTag}" - cnt = 0 - while (cnt < 4) { - try { - sh "sudo podman push --tls-verify=false ${noHttpsURL}/${oc_project_name}/${imageName}:${destTag}" - cnt = 10 - } catch (Exception e) { - echo "Network issue when pushing? Trying again!" - cnt += 1 - } - } - sh "sudo podman rmi ${noHttpsURL}/${oc_project_name}/${imageName}:${destTag} || true" - if (cnt != 10) { - error "Could not push" - } -} - def checkCoreNetworkDeployment() { status = 0 sh 'mkdir -p archives' diff --git a/ci-scripts/checkCOTS-UE-Testing.py b/ci-scripts/checkCOTS-UE-Testing.py index 5c6a44329f8afa5fea902b0fd8a83cad460605d5..3f5aa04c8d9e819731b43980a30bd26e0e75e702 100755 --- a/ci-scripts/checkCOTS-UE-Testing.py +++ b/ci-scripts/checkCOTS-UE-Testing.py @@ -176,12 +176,19 @@ def nfDetails(nfName): size = f'{(sizeInt/1000000000):.3f} Gbytes' else: size = f'{(sizeInt/1000000):.1f} Mbytes' + result = re.search('Image Size:\\t*(?P<imageSize>[0-9\.]+)MB', line) + if result is not None: + sizeInt = float(result.group('imageSize')) * 2.6 + size = f'{sizeInt:.1f} Mbytes' result = re.search('Date = (?P<imageDate>[0-9\-]+ [0-9\:]+)', line) if result is not None: creationDate = result.group('imageDate') result = re.search('Date = (?P<imageDate>[0-9\-]+T[0-9\:]+)', line) if result is not None: creationDate = re.sub('T', ' ', result.group('imageDate')) + result = re.search('"(?P<imageDate>[0-9\-]+T[0-9\:]+)Z"', line) + if result is not None: + creationDate = re.sub('T', ' ', result.group('imageDate')) return generate_image_table_row(contName, fullTag, ocTag, creationDate, size) diff --git a/ci-scripts/checkOcRegistry.py b/ci-scripts/checkOcRegistry.py new file mode 100755 index 0000000000000000000000000000000000000000..9677053c7ad937a29631e6789ff539b4be06acdc --- /dev/null +++ b/ci-scripts/checkOcRegistry.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +""" +Licensed to the OpenAirInterface (OAI) Software Alliance under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The OpenAirInterface Software Alliance licenses this file to You under +the OAI Public License, Version 1.1 (the "License"); you may not use this file +except in compliance with the License. +You may obtain a copy of the License at + + http://www.openairinterface.org/?page_id=698 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +------------------------------------------------------------------------------ +For more information about the OpenAirInterface (OAI) Software Alliance: + contact@openairinterface.org +--------------------------------------------------------------------- +""" + +import argparse +import logging +import re +import sys +import time +import common.python.cls_cmd as cls_cmd + +logging.basicConfig( + level=logging.DEBUG, + stream=sys.stdout, + format="[%(asctime)s] %(levelname)8s: %(message)s" +) + +oc_registry_url = 'https://default-route-openshift-image-registry.apps.oai.cs.eurecom.fr' + +def _parse_args() -> argparse.Namespace: + """Parse the command line args + + Returns: + argparse.Namespace: the created parser + """ + example_text = '''example: + ./ci-scripts/checkOcRegistry.py --help + ./ci-scripts/checkOcRegistry.py --image-name iName --tag tName''' + + parser = argparse.ArgumentParser(description='OAI 5G CORE NETWORK Utility tool', + epilog=example_text, + formatter_class=argparse.RawDescriptionHelpFormatter) + + # Container Name + parser.add_argument( + '--image-name', '-in', + action='store', + required=True, + help='Image Name to check', + ) + + # Tag + parser.add_argument( + '--tag', '-t', + action='store', + required=True, + help='Image Tag to check', + ) + + # OC project + parser.add_argument( + '--project', '-p', + action='store', + required=True, + help='Openshift project', + ) + + # OC username + parser.add_argument( + '--username', '-u', + action='store', + required=True, + help='Openshift Account', + ) + return parser.parse_args() + +def checkImageInfo(imageName, imageTag): + myCmds = cls_cmd.LocalCmd() + ret = myCmds.run(f'oc describe istag {imageName}:{imageTag}', silent=True) + if ret.returncode != 0: + logging.error(f'Image Tag {imageName}:{imageTag} not present in OC registry') + myCmds.close() + return -1 + myCmds.run(f'echo "Tested Tag is {imageName}:{imageTag}" > archives/{imageName}-image-info.log') + myCmds.run(f'oc describe istag {imageName}:{imageTag} | grep "Image Size:" >> archives/{imageName}-image-info.log') + ret = myCmds.run(f'oc describe istag {imageName}:{imageTag} | grep --color=never "Image Name:" | sed -e "s#Image Name:.*sha256#{imageName}@sha256#"', silent=True) + myCmds.run(f'oc get -o json isimage {ret.stdout} | jq .image.dockerImageMetadata.Created >> archives/{imageName}-image-info.log') + myCmds.run(f'echo "OC Pushed Tag is {imageName}:{imageTag}" >> archives/{imageName}-image-info.log') + myCmds.close() + return 0 + +def pushToOcProjectRegistry(imageName, imageTag, ocProject, ocUser): + myCmds = cls_cmd.LocalCmd() + myCmds.run(f'oc whoami -t | sudo podman login -u {ocUser} --password-stdin {oc_registry_url} --tls-verify=false') + noHttpsURL = re.sub("https://", "", oc_registry_url) + logging.debug(f'noHttpsURL is {noHttpsURL}') + myCmds.run(f'sudo podman rmi {noHttpsURL}/{ocProject}/{imageName}:{imageTag} || true') + myCmds.run(f'sudo podman image tag {imageName}:{imageTag} {noHttpsURL}/{ocProject}/{imageName}:{imageTag}') + cnt = 0 + while (cnt < 4): + cnt += 1 + ret = myCmds.run(f'sudo podman push --tls-verify=false {noHttpsURL}/{ocProject}/{imageName}:{imageTag}') + if ret.returncode == 0: + cnt = 10 + myCmds.run(f'sudo podman rmi {noHttpsURL}/{ocProject}/{imageName}:{imageTag} || true') + myCmds.run(f'sudo podman logout {oc_registry_url}') + myCmds.close() + if cnt == 10: + return 0 + else: + return -1 + +if __name__ == '__main__': + # Parse the arguments + args = _parse_args() + + firstStatus = checkImageInfo(args.image_name, args.tag) + # If image is already on the OC registry, we are done + if firstStatus == 0: + sys.exit(0) + + pushStatus = pushToOcProjectRegistry(args.image_name, args.tag, args.project, args.username) + if pushStatus == -1: + sys.exit(-1) + + checkImageInfo(args.image_name, args.tag) + sys.exit(0)