diff --git a/ci-scripts/args_parse.py b/ci-scripts/args_parse.py index 6206c67d69..16e23113ab 100644 --- a/ci-scripts/args_parse.py +++ b/ci-scripts/args_parse.py @@ -22,7 +22,7 @@ import constants as CONST #----------------------------------------------------------- -def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): +def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,CLUSTER): force_local = False date_fmt = None @@ -53,7 +53,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): RAN.ranRepository=matchReg.group(1) HTML.ranRepository=matchReg.group(1) CONTAINERS.ranRepository=matchReg.group(1) - SCA.ranRepository=matchReg.group(1) CLUSTER.ranRepository=matchReg.group(1) elif re.match(r'^\-\-eNB_AllowMerge=(.+)$|^\-\-ranAllowMerge=(.+)$', myArgv, re.IGNORECASE): if re.match(r'^\-\-eNB_AllowMerge=(.+)$', myArgv, re.IGNORECASE): @@ -66,7 +65,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): RAN.ranAllowMerge=True HTML.ranAllowMerge=True CONTAINERS.ranAllowMerge=True - SCA.ranAllowMerge=True CLUSTER.ranAllowMerge=True elif re.match(r'^\-\-eNBBranch=(.+)$|^\-\-ranBranch=(.+)$', myArgv, re.IGNORECASE): if re.match(r'^\-\-eNBBranch=(.+)$', myArgv, re.IGNORECASE): @@ -77,7 +75,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): RAN.ranBranch=matchReg.group(1) HTML.ranBranch=matchReg.group(1) CONTAINERS.ranBranch=matchReg.group(1) - SCA.ranBranch=matchReg.group(1) CLUSTER.ranBranch=matchReg.group(1) elif re.match(r'^\-\-eNBCommitID=(.*)$|^\-\-ranCommitID=(.*)$', myArgv, re.IGNORECASE): if re.match(r'^\-\-eNBCommitID=(.*)$', myArgv, re.IGNORECASE): @@ -88,7 +85,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): RAN.ranCommitID=matchReg.group(1) HTML.ranCommitID=matchReg.group(1) CONTAINERS.ranCommitID=matchReg.group(1) - SCA.ranCommitID=matchReg.group(1) CLUSTER.ranCommitID=matchReg.group(1) elif re.match(r'^\-\-eNBTargetBranch=(.*)$|^\-\-ranTargetBranch=(.*)$', myArgv, re.IGNORECASE): if re.match(r'^\-\-eNBTargetBranch=(.*)$', myArgv, re.IGNORECASE): @@ -99,7 +95,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): RAN.ranTargetBranch=matchReg.group(1) HTML.ranTargetBranch=matchReg.group(1) CONTAINERS.ranTargetBranch=matchReg.group(1) - SCA.ranTargetBranch=matchReg.group(1) CLUSTER.ranTargetBranch=matchReg.group(1) elif re.match(r'^\-\-eNBIPAddress=(.+)$|^\-\-eNB[1-2]IPAddress=(.+)$', myArgv, re.IGNORECASE): print("parameters --eNB*IPAddress ignored") @@ -112,7 +107,6 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER): matchReg = re.match(r'^\-\-eNBSourceCodePath=(.+)$', myArgv, re.IGNORECASE) RAN.eNBSourceCodePath=matchReg.group(1) CONTAINERS.eNBSourceCodePath=matchReg.group(1) - SCA.eNBSourceCodePath=matchReg.group(1) CLUSTER.eNBSourceCodePath=matchReg.group(1) elif re.match(r'^\-\-eNB1SourceCodePath=(.+)$', myArgv, re.IGNORECASE): print("parameter --eNB1SourceCodePath ignored") diff --git a/ci-scripts/cls_static_code_analysis.py b/ci-scripts/cls_static_code_analysis.py index 4e388847c7..3b4ee10f9b 100644 --- a/ci-scripts/cls_static_code_analysis.py +++ b/ci-scripts/cls_static_code_analysis.py @@ -29,38 +29,28 @@ from cls_ci_helper import archiveArtifact class StaticCodeAnalysis(): - def __init__(self): - - self.ranRepository = '' - self.ranBranch = '' - self.ranAllowMerge = False - self.ranCommitID = '' - self.ranTargetBranch = '' - self.eNBSourceCodePath = '' - - def LicenceAndFormattingCheck(self, ctx, node, HTML): + def LicenceAndFormattingCheck(ctx, node, HTML, d, branch, allowMerge, targetBranch): # Workspace is no longer recreated from scratch. # It implies that this method shall be called last within a build pipeline # where workspace is already created - lSourcePath = self.eNBSourceCodePath - if not node or not lSourcePath: - raise ValueError(f"{lSourcePath=} {node=}") + if not node or not d: + raise ValueError(f"{d=} {node=}") logging.debug('Building on server: ' + node) cmd = cls_cmd.getConnection(node) check_options = '' - if self.ranAllowMerge: - check_options = f'--build-arg MERGE_REQUEST=true --build-arg SRC_BRANCH={self.ranBranch}' - if self.ranTargetBranch == '': - if self.ranBranch != 'develop' and self.ranBranch != 'origin/develop': + if allowMerge: + check_options = f'--build-arg MERGE_REQUEST=true --build-arg SRC_BRANCH={branch}' + if targetBranch == '': + if branch != 'develop' and branch != 'origin/develop': check_options += ' --build-arg TARGET_BRANCH=develop' else: - check_options += f' --build-arg TARGET_BRANCH={self.ranTargetBranch}' + check_options += f' --build-arg TARGET_BRANCH={targetBranch}' - logDir = f'{lSourcePath}/cmake_targets/log/' + logDir = f'{d}/cmake_targets/log/' cmd.run(f'mkdir -p {logDir}') cmd.run('docker image rm oai-formatting-check:latest') - cmd.run(f'docker build --target oai-formatting-check --tag oai-formatting-check:latest {check_options} --file {lSourcePath}/ci-scripts/docker/Dockerfile.formatting.ubuntu {lSourcePath} > {logDir}/oai-formatting-check.txt 2>&1') + cmd.run(f'docker build --target oai-formatting-check --tag oai-formatting-check:latest {check_options} --file {d}/ci-scripts/docker/Dockerfile.formatting.ubuntu {d} > {logDir}/oai-formatting-check.txt 2>&1') cmd.run('docker image rm oai-formatting-check:latest') cmd.run('docker image prune --force') diff --git a/ci-scripts/main.py b/ci-scripts/main.py index 906f73f433..66e8b2091b 100644 --- a/ci-scripts/main.py +++ b/ci-scripts/main.py @@ -22,7 +22,7 @@ import constants as CONST import cls_oaicitest #main class for OAI CI test framework import cls_containerize #class Containerize for all container-based operations on RAN/UE objects -import cls_static_code_analysis #class for static code analysis +import cls_static_code_analysis as SCA import cls_cluster # class for building/deploying on cluster import cls_native # class for all native/source-based operations from cls_ci_helper import TestCaseCtx @@ -64,7 +64,6 @@ def ExecuteActionWithParam(action, ctx, node): global RAN global HTML global CONTAINERS - global SCA global CLUSTER if action == 'Build_eNB' or action == 'Build_Image' or action == 'Build_Proxy' or action == "Build_Cluster_Image" or action == "Build_Run_Tests": RAN.Build_eNB_args=test.findtext('Build_eNB_args') @@ -196,7 +195,7 @@ def ExecuteActionWithParam(action, ctx, node): success = CONTAINERS.Create_Workspace(node, HTML) elif action == 'LicenceAndFormattingCheck': - success = SCA.LicenceAndFormattingCheck(ctx, node, HTML) + success = SCA.StaticCodeAnalysis.LicenceAndFormattingCheck(ctx, node, HTML, RAN.eNBSourceCodePath, RAN.ranBranch, RAN.ranAllowMerge, RAN.ranTargetBranch) elif action == 'Push_Local_Registry': tag_prefix = test.findtext('tag_prefix') or "" @@ -294,7 +293,6 @@ CiTestObj = cls_oaicitest.OaiCiTest() RAN = ran.RANManagement() HTML = cls_oai_html.HTMLManagement() CONTAINERS = cls_containerize.Containerize() -SCA = cls_static_code_analysis.StaticCodeAnalysis() CLUSTER = cls_cluster.Cluster() #----------------------------------------------------------- @@ -304,7 +302,7 @@ CLUSTER = cls_cluster.Cluster() import args_parse # Force local execution, move all execution targets to localhost force_local = False -mode, force_local, date_fmt = args_parse.ArgsParse(sys.argv,CiTestObj,RAN,HTML,CONTAINERS,HELP,SCA,CLUSTER) +mode, force_local, date_fmt = args_parse.ArgsParse(sys.argv,CiTestObj,RAN,HTML,CONTAINERS,HELP,CLUSTER) fmt = "%(levelname)8s: %(message)s" if date_fmt: fmt = "[%(asctime)s] %(levelname)s %(message)s"