From e27ba56f95074251c6bddb6f0d2a64b6252bc6b3 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 9 Oct 2024 13:40:50 +0300 Subject: [PATCH] feat(helper/models): Add platformfilter Add filter that allows to restrict tests on specific platform. This feature required for proper bisection implementation, as some tests might be scheduled on multiple platforms. Rework a bit code to avoid null variables. Signed-off-by: Denys Fedoryshchenko --- kernelci/api/helper.py | 43 ++++++++++++++++++++++++------------------ kernelci/api/models.py | 3 +++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/kernelci/api/helper.py b/kernelci/api/helper.py index d8bfbd9444..c8fc51d45f 100644 --- a/kernelci/api/helper.py +++ b/kernelci/api/helper.py @@ -385,26 +385,26 @@ def create_job_node(self, job_config, input_node, runtime=None, platform=None): """Create a new job node based on input and configuration""" jobfilter = input_node.get('jobfilter') + platform_filter = input_node.get('platform_filter') treeid = input_node.get('treeid') submitter = input_node.get('submitter') - try: - job_node = { - 'kind': job_config.kind, - 'parent': input_node['id'], - 'name': job_config.name, - 'path': input_node['path'] + [job_config.name], - 'group': job_config.name, - 'artifacts': {}, - 'jobfilter': jobfilter, - 'treeid': treeid, - 'submitter': submitter, - 'data': { - 'kernel_revision': input_node['data']['kernel_revision'], - }, - } - except KeyError as error: - print(f"Missing key {error} in input node") - return None + job_node = { + 'kind': job_config.kind, + 'parent': input_node['id'], + 'name': job_config.name, + 'path': input_node['path'] + [job_config.name], + 'group': job_config.name, + 'artifacts': {}, + 'treeid': treeid, + 'submitter': submitter, + 'data': { + 'kernel_revision': input_node['data']['kernel_revision'], + }, + } + if jobfilter: + job_node['jobfilter'] = jobfilter + if platform_filter: + job_node['platform_filter'] = platform_filter # if jobfilter not null, verify if job_config.name exist in jobfilter if jobfilter and job_config.name not in jobfilter: @@ -434,7 +434,14 @@ def create_job_node(self, job_config, input_node, print(f"Not creating node {input_node['id']} due to runtime rules " f"for {runtime.config.name}") return None + # Filter by platform if it is test job only if platform: + # if platform_filter not null, verify if platform.name exist in platform_filter + if platform_filter and platform.name not in platform_filter\ + and job_config.kind == 'job': + print(f"Filtered: Platform {platform.name} not found in platform_filter " + f"for node {input_node['id']}") + return None job_node['data']['platform'] = platform.name if not self.should_create_node(platform.rules, job_node, input_node): print(f"Not creating node {input_node['id']} due to platform rules " diff --git a/kernelci/api/models.py b/kernelci/api/models.py index 0fe9f36c48..f8767616be 100644 --- a/kernelci/api/models.py +++ b/kernelci/api/models.py @@ -204,6 +204,9 @@ class Node(DatabaseModel): jobfilter: Optional[List[str]] = Field( description="Restrict jobs that can be scheduled by this node" ) + platform_filter: Optional[List[str]] = Field( + description="Restrict test jobs to be scheduled on specific platforms", + ) created: datetime = Field( default_factory=datetime.utcnow, description="Timestamp of node creation"