Skip to content

Commit

Permalink
refactor(hardware-details): alter response
Browse files Browse the repository at this point in the history
- Changed all response fields to snake case
- Changed response structure
- Added commonDetails.py to group all common types between hardware and
  tree details
- Added types for hardware details in the BE and in the FE

Part of #731
Part of #700
  • Loading branch information
murilx committed Jan 17, 2025
1 parent e890f2e commit 4004405
Show file tree
Hide file tree
Showing 24 changed files with 438 additions and 381 deletions.
24 changes: 12 additions & 12 deletions backend/kernelCI_app/helpers/hardwareDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ def get_hardware_trees_data(
for idx, tree in enumerate(trees_query_set):
trees.append(
{
"treeName": tree["build__checkout__tree_name"],
"gitRepositoryBranch": tree[
"tree_name": tree["build__checkout__tree_name"],
"git_repository_branch": tree[
"build__checkout__git_repository_branch"
],
"gitRepositoryUrl": tree["build__checkout__git_repository_url"],
"headGitCommitName": tree["build__checkout__git_commit_name"],
"headGitCommitHash": tree["build__checkout__git_commit_hash"],
"headGitCommitTag": tree["build__checkout__git_commit_tags"],
"git_repository_url": tree["build__checkout__git_repository_url"],
"head_git_commit_name": tree["build__checkout__git_commit_name"],
"head_git_commit_hash": tree["build__checkout__git_commit_hash"],
"head_git_commit_tag": tree["build__checkout__git_commit_tags"],
"index": str(idx),
}
)
Expand All @@ -132,14 +132,14 @@ def get_trees_with_status_summary(
trees_with_status_count: List[Dict] = []
for tree in trees:
summary = tree_status_summary.get(tree["index"])
trees_with_status_count.append({**tree, "selectedCommitStatusSummary": summary})
trees_with_status_count.append({**tree, "selected_commit_status": summary})

return trees_with_status_count


def get_displayed_commit(*, tree: Dict, selected_commit: Optional[str]):
if (not selected_commit) or (selected_commit == SELECTED_HEAD_TREE_VALUE):
return tree["headGitCommitHash"]
return tree["head_git_commit_hash"]
return selected_commit


Expand All @@ -161,9 +161,9 @@ def get_trees_with_selected_commit(

selected.append(
{
"tree_name": tree["treeName"],
"git_repository_branch": tree["gitRepositoryBranch"],
"git_repository_url": tree["gitRepositoryUrl"],
"tree_name": tree["tree_name"],
"git_repository_branch": tree["git_repository_branch"],
"git_repository_url": tree["git_repository_url"],
"index": tree["index"],
"git_commit_hash": displayed_commit,
"is_tree_selected": is_tree_selected,
Expand Down Expand Up @@ -306,7 +306,7 @@ def get_history(record: Dict):
"status": record["status"],
"path": record["path"],
"duration": record["duration"],
"startTime": record["start_time"],
"start_time": record["start_time"],
}


Expand Down
2 changes: 1 addition & 1 deletion backend/kernelCI_app/helpers/treeDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_current_row_data(current_row: dict) -> dict:
"duration": current_row_data["test_duration"],
"path": current_row_data["test_path"],
"start_time": current_row_data["test_start_time"],
"hardware": current_row[tmp_test_env_comp_key],
"environment_compatible": current_row[tmp_test_env_comp_key],
"config": current_row_data["build_config_name"],
"log_url": current_row_data["test_log_url"],
"architecture": current_row_data["build_architecture"],
Expand Down
113 changes: 113 additions & 0 deletions backend/kernelCI_app/typeModels/commonDetails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from datetime import datetime
from typing import Dict, List, Optional, Union

from pydantic import BaseModel


class TestStatusCount(BaseModel):
PASS: Optional[int] = None
ERROR: Optional[int] = None
FAIL: Optional[int] = None
SKIP: Optional[int] = None
NULL: Optional[int] = None


class BuildStatusCount(BaseModel):
valid: int
invalid: int
null: int


class TestArchSummaryItem(BaseModel):
arch: str
compiler: str
status: TestStatusCount


class BuildConfigs(BuildStatusCount):
valid: int
invalid: int
null: int


class IncidentsInfo(BaseModel):
incidentsCount: int


class TestIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class BuildsIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class BuildArchitectures(BuildStatusCount):
compilers: List[str]


class Misc(BaseModel):
platform: str


class TestHistoryItem(BaseModel):
id: str
status: Optional[str]
duration: Optional[Union[int, float]]
path: Optional[str]
start_time: Optional[Union[datetime, str]]
environment_compatible: Optional[Union[str, List[str]]] = None
# TODO: When these fields are added to hardwareDetails, there shouldn't be any need for `= None` anymore
config: Optional[str] = None
log_url: Optional[str] = None
architecture: Optional[str] = None
compiler: Optional[str] = None
misc: Optional[Misc] = None


class BuildHistoryItem(BaseModel):
id: str
architecture: Optional[str]
config_name: Optional[str]
misc: Optional[dict]
config_url: Optional[str]
compiler: Optional[str]
valid: Optional[bool]
duration: Optional[Union[int, float]]
log_url: Optional[str]
start_time: Optional[Union[datetime, str]]
git_repository_url: Optional[str]
git_repository_branch: Optional[str]


class TestSummary(BaseModel):
status: TestStatusCount
architectures: List[TestArchSummaryItem]
configs: Dict[str, TestStatusCount]
issues: List[TestIssuesItem]
unknown_issues: int
fail_reasons: Dict[str, int]
failed_platforms: List[str]
environment_compatible: Optional[Dict] = None
environment_misc: Optional[Dict] = None
platforms: Optional[Dict[str, TestStatusCount]]


class BuildSummary(BaseModel):
status: BuildStatusCount
architectures: Dict[str, BuildArchitectures]
configs: Dict[str, BuildConfigs]
issues: List[BuildsIssuesItem]
unknown_issues: int


class Summary(BaseModel):
builds: BuildSummary
boots: TestSummary
tests: TestSummary
28 changes: 22 additions & 6 deletions backend/kernelCI_app/typeModels/hardwareDetails.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import Annotated, Any, Dict, List, Literal, Optional, Union

from kernelCI_app.typeModels.commonDetails import BuildHistoryItem, Summary, TestHistoryItem
from kernelCI_app.typeModels.databases import StatusValues
from pydantic import BaseModel, BeforeValidator, Field

Expand Down Expand Up @@ -47,17 +48,32 @@ class CommitHistoryValidCheckout(BaseModel):
start_time: datetime


class HardwareDetailsFullResponse(BaseModel):
builds: Dict
tests: Dict
boots: Dict
class Tree(BaseModel):
index: str
tree_name: Optional[str]
git_repository_branch: Optional[str]
git_repository_url: Optional[str]
head_git_commit_name: Optional[str]
head_git_commit_hash: Optional[str]
head_git_commit_tag: Optional[List[str]]
selected_commit_status: Optional[Dict]


class HardwareSummary(Summary):
trees: List[Tree]
configs: List[str]
archs: List[str]
architectures: List[str]
compilers: List[str]
trees: List[Dict]
compatibles: List[str]


class HardwareDetailsFullResponse(BaseModel):
builds: List[BuildHistoryItem]
boots: List[TestHistoryItem]
tests: List[TestHistoryItem]
summary: HardwareSummary


type HardwareTreeList = List[Dict[str, str]]

PossibleTestType = Literal["test", "boot"]
126 changes: 17 additions & 109 deletions backend/kernelCI_app/typeModels/treeDetails.py
Original file line number Diff line number Diff line change
@@ -1,145 +1,53 @@
from datetime import datetime
from typing import Dict, List, Optional, Set

from kernelCI_app.typeModels.commonDetails import (
Summary,
BuildHistoryItem,
TestArchSummaryItem,
TestIssuesItem,
TestStatusCount,
TestHistoryItem,
)
from pydantic import BaseModel
from typing import List, Dict, Optional, Set, Union


class TreeLatestPathParameters(BaseModel):
tree_name: str
branch: str


class TestStatusCount(BaseModel):
PASS: Optional[int] = None
ERROR: Optional[int] = None
FAIL: Optional[int] = None
SKIP: Optional[int] = None
NULL: Optional[int] = None


class TestArchSummaryItem(BaseModel):
arch: str
compiler: str
status: TestStatusCount


class BuildStatusCount(BaseModel):
valid: int
invalid: int
null: int


class BuildConfigs(BuildStatusCount):
valid: int
invalid: int
null: int


class BuildArchitectures(BuildStatusCount):
compilers: List[str]


class IncidentsInfo(BaseModel):
incidentsCount: int


class TestIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class TestEnvironmentCompatibleCount(TestStatusCount):
pass


class TestEnvironmentMiscCount(TestStatusCount):
pass


class BuildsIssuesItem(BaseModel):
id: str
comment: Optional[str]
report_url: Optional[str]
incidents_info: IncidentsInfo


class TestSummary(BaseModel):
status: TestStatusCount
architectures: List[TestArchSummaryItem]
configs: Dict[str, TestStatusCount]
issues: List[TestIssuesItem]
unknown_issues: int
enviroment_compatible: Dict[str, TestEnvironmentCompatibleCount]
enviroment_misc: Dict[str, TestEnvironmentMiscCount]
enviroment_compatible: Dict[str, TestStatusCount]
enviroment_misc: Dict[str, TestStatusCount]
fail_reasons: Dict[str, int]
failed_platforms: List[str]


class BuildSummary(BaseModel):
status: BuildStatusCount
architectures: Dict[str, BuildArchitectures]
configs: Dict[str, BuildConfigs]
issues: List[BuildsIssuesItem]
unknown_issues: int


class Summary(BaseModel):
builds: BuildSummary
boots: TestSummary
tests: TestSummary
class TreeSummary(Summary):
hardware: Set[str]
tree_url: str
git_commit_tags: Optional[List[str]]


class SummaryResponse(BaseModel):
summary: Summary


class Misc(BaseModel):
platform: str


class TestHistory(BaseModel):
id: str
status: Optional[str]
duration: Optional[Union[int, float]]
path: Optional[str]
start_time: Optional[Union[datetime, str]]
hardware: Optional[Union[str, List[str]]]
config: Optional[str]
log_url: Optional[str]
architecture: Optional[str]
compiler: Optional[str]
misc: Optional[Misc]
summary: TreeSummary


class BootResponse(BaseModel):
bootHistory: List[TestHistory]
bootHistory: List[TestHistoryItem]


class TestResponse(BaseModel):
testHistory: List[TestHistory]


class BuildItem(BaseModel):
id: str
architecture: Optional[str]
config_name: Optional[str]
misc: Optional[dict]
config_url: Optional[str]
compiler: Optional[str]
valid: Optional[bool]
duration: Optional[Union[int, float]]
log_url: Optional[str]
start_time: Optional[Union[datetime, str]]
git_repository_url: Optional[str]
git_repository_branch: Optional[str]
testHistory: List[TestHistoryItem]


class BuildsResponse(BaseModel):
builds: List[BuildItem]
builds: List[BuildHistoryItem]


class TreeQueryParameters(BaseModel):
Expand Down
Loading

0 comments on commit 4004405

Please sign in to comment.