-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status update endpoint to receive updates from Testflinger
- Loading branch information
Showing
8 changed files
with
379 additions
and
1 deletion.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
backend/migrations/versions/2024_06_03_2038-00fe81a03705_create_test_status_update_tables.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"""Create test status update tables | ||
Revision ID: 00fe81a03705 | ||
Revises: 33c0383ea9ca | ||
Create Date: 2024-06-03 20:38:47.346523+00:00 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "00fe81a03705" | ||
down_revision = "33c0383ea9ca" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"test_status_update", | ||
sa.Column("agent_id", sa.String(), nullable=False), | ||
sa.Column("job_queue", sa.String(), nullable=False), | ||
sa.Column("test_execution_id", sa.Integer(), nullable=False), | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["test_execution_id"], | ||
["test_execution.id"], | ||
name=op.f("test_status_update_test_execution_id_fkey"), | ||
ondelete="CASCADE", | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("test_status_update_pkey")), | ||
) | ||
op.create_index( | ||
op.f("test_status_update_test_execution_id_ix"), | ||
"test_status_update", | ||
["test_execution_id"], | ||
unique=False, | ||
) | ||
op.create_table( | ||
"test_event", | ||
sa.Column( | ||
"event_name", | ||
sa.Enum( | ||
"STARTED_SETUP", | ||
"STARTED_PROVISION", | ||
"STARTED_FIRMWARE_UPDATE", | ||
"STARTED_TEST", | ||
"STARTED_ALLOCATE", | ||
"STARTED_RESERVE", | ||
"STARTED_CLEANUP", | ||
"ENDED_SETUP", | ||
"ENDED_PROVISION", | ||
"ENDED_FIRMWARE_UPDATE", | ||
"ENDED_TEST", | ||
"ENDED_ALLOCATE", | ||
"ENDED_RESERVE", | ||
"ENDED_CLEANUP", | ||
"CANCELLED", | ||
"GLOBAL_TIMEOUT", | ||
"OUTPUT_TIMEOUT", | ||
"RECOVERY_FAILED", | ||
"FAILED", | ||
name="testeventenum", | ||
), | ||
nullable=False, | ||
), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
sa.Column("detail_msg", sa.String(), nullable=False), | ||
sa.Column("test_status_update_id", sa.Integer(), nullable=False), | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["test_status_update_id"], | ||
["test_status_update.id"], | ||
name=op.f("test_event_test_status_update_id_fkey"), | ||
ondelete="CASCADE", | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("test_event_pkey")), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("test_event") | ||
op.drop_index( | ||
op.f("test_status_update_test_execution_id_ix"), table_name="test_status_update" | ||
) | ||
op.drop_table("test_status_update") | ||
# ### end Alembic commands ### | ||
op.execute("DROP TYPE IF EXISTS testeventenum") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
backend/test_observer/controllers/test_executions/status_update.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session, joinedload | ||
|
||
from test_observer.data_access.models import ( | ||
TestStatusUpdate, | ||
TestEvent, | ||
TestExecution, | ||
) | ||
|
||
from test_observer.data_access.setup import get_db | ||
|
||
from .logic import delete_previous_status_update | ||
from .models import StatusUpdateRequest | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/{id}/status_update") | ||
def status_update(id: int, request: StatusUpdateRequest, db: Session = Depends(get_db)): | ||
test_execution = db.get( | ||
TestExecution, | ||
id, | ||
options=[ | ||
joinedload(TestExecution.test_status_update).joinedload( | ||
TestStatusUpdate.events | ||
), | ||
], | ||
) | ||
if test_execution is None: | ||
raise HTTPException(status_code=404, detail="TestExecution not found") | ||
|
||
delete_previous_status_update(db, test_execution) | ||
|
||
test_status_update = TestStatusUpdate( | ||
agent_id=request.agent_id, | ||
job_queue=request.job_queue, | ||
test_execution=test_execution, | ||
) | ||
for event in request.events: | ||
test_event = TestEvent( | ||
event_name=event.event_name, | ||
timestamp=event.timestamp, | ||
detail_msg=event.detail_msg, | ||
) | ||
test_status_update.events.append(test_event) | ||
db.add(test_status_update) | ||
db.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.