Skip to content

Commit

Permalink
feat(helper/models): Add platformfilter
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nuclearcat committed Oct 14, 2024
1 parent ed2c354 commit e27ba56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
43 changes: 25 additions & 18 deletions kernelci/api/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 "
Expand Down
3 changes: 3 additions & 0 deletions kernelci/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e27ba56

Please sign in to comment.