From 7f21a196f95e64828ad725d3929fb1213c24b61f Mon Sep 17 00:00:00 2001 From: Jeremy Banker Date: Tue, 11 Jun 2024 01:18:57 +0000 Subject: [PATCH] Pre-rmisc fixes Signed-off-by: Jeremy Banker --- .gitignore | 1 + .vscode/launch.json | 5 ++++- src/python/controller/dependency.py | 16 +++++++++++++++- src/ui/src/app/app.component.html | 1 + .../src/app/management/management.component.ts | 14 +++++++++++++- src/ui/src/tommyknocker-api.service.ts | 6 ++++++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 67b2592..bf724ee 100644 --- a/.gitignore +++ b/.gitignore @@ -188,3 +188,4 @@ testem.log Thumbs.db src/python/state.pkl +src/python/statemachines.pkl diff --git a/.vscode/launch.json b/.vscode/launch.json index e1cfe23..e03ad49 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,7 +25,10 @@ ], "cwd": "${workspaceFolder}/src/python/", "console": "integratedTerminal", - "justMyCode": true + "justMyCode": true, + "env": { + "PYTHONPATH": "${workspaceFolder}/src/python/" + } }, { "name": "Python: FastAPI", diff --git a/src/python/controller/dependency.py b/src/python/controller/dependency.py index c675dc0..6eb432f 100644 --- a/src/python/controller/dependency.py +++ b/src/python/controller/dependency.py @@ -7,7 +7,7 @@ from controller.statemachines import TestStateMachine from controller.state import ControllerState, ControllerStateFactory from shared.models.objects import Test -import warnings +import pickle class ActiveStateMachines: _active_state_machines: Dict[UUID, TestStateMachine] = {} @@ -28,6 +28,18 @@ def remove_state_machine(self, test_id: UUID) -> None: self.logger.debug(f"Removing state machine for test {test_id}") self._active_state_machines.pop(test_id, None) + def persist_to_file(self, filename: str): + with open(filename, 'wb') as f: + pickle.dump(self, f) + + def load_from_file(self, filename: str): + try: + with open(filename, "rb") as f: + state = pickle.load(f) + self.__dict__.update(state.__dict__) + except: + pass + async def cycle_state_machines(self) -> None: to_remove = [] for test_id, state_machine in self._active_state_machines.items(): @@ -48,6 +60,7 @@ async def cycle_state_machines(self) -> None: self.remove_state_machine(test_id) except Exception as ex: self.logger.exception(f"Error removing state machine for test {test_id}: {ex}") + self.persist_to_file('statemachines.pkl') class ActiveStateMachinesFactory: @@ -57,6 +70,7 @@ class ActiveStateMachinesFactory: def get_active_state_machines(cls) -> ActiveStateMachines: if not cls._active_state_machines: cls._active_state_machines = ActiveStateMachines() + cls._active_state_machines.load_from_file('statemachines.pkl') return cls._active_state_machines ActiveStateMachinesDependency = Annotated[ActiveStateMachines, Depends(ActiveStateMachinesFactory.get_active_state_machines)] diff --git a/src/ui/src/app/app.component.html b/src/ui/src/app/app.component.html index 88119a5..a6cc9b5 100644 --- a/src/ui/src/app/app.component.html +++ b/src/ui/src/app/app.component.html @@ -30,6 +30,7 @@ Knocks Results Responses + Response Expectations Runners diff --git a/src/ui/src/app/management/management.component.ts b/src/ui/src/app/management/management.component.ts index 575e78a..708dcc6 100644 --- a/src/ui/src/app/management/management.component.ts +++ b/src/ui/src/app/management/management.component.ts @@ -1,5 +1,5 @@ import { Component, Injector, OnInit, Type, ViewChild } from '@angular/core'; -import { ICrudApiService, KnockAPIService, KnockerAPIService, MonitorAPIService, ResponseAPIService, ResultAPIService, RunnerAPIService, TestConfigurationAPIService, TestSuiteAPIService } from '../../tommyknocker-api.service'; +import { ICrudApiService, KnockAPIService, KnockerAPIService, MonitorAPIService, ResponseAPIService, ResponseExpectationAPIService, ResultAPIService, RunnerAPIService, TestConfigurationAPIService, TestSuiteAPIService } from '../../tommyknocker-api.service'; import { NgFor, NgIf, NgSwitch, NgSwitchCase, NgSwitchDefault } from '@angular/common'; import { ClarityModule } from "@clr/angular"; import { FormsModule } from '@angular/forms'; @@ -139,6 +139,18 @@ const management_types: {[id: string]: IManagementType} = { ], service: TestSuiteAPIService, empty_item: { id: '', configuration_id: '' } + }, + response_expectations: { + name: 'Response Expectation', + description: 'Response expectations dictate if a response is expected or not, and the timeout allowed for that response to occur.', + columns: [ + { name: 'id', title: 'ID', input_type: InputType.Input, copyable: true}, + { name: 'response_id', title: "Response", input_type: InputType.Lookup, lookup_interface: ResponseAPIService, createable: true, updateable: true}, + { name: 'expected', title: "Expected", input_type: InputType.Input, createable: true, updateable: true}, + { name: 'timeout', title: "Timeout", input_type: InputType.Input, createable: true, updateable: true} + ], + service: ResponseExpectationAPIService, + empty_item: {id: '', response_id: '', expected: true, timeout: 60} } }; diff --git a/src/ui/src/tommyknocker-api.service.ts b/src/ui/src/tommyknocker-api.service.ts index 75e4a04..8f8978c 100644 --- a/src/ui/src/tommyknocker-api.service.ts +++ b/src/ui/src/tommyknocker-api.service.ts @@ -76,6 +76,12 @@ export class ResponseAPIService extends BaseAPIService { @Injectable({ providedIn: 'root' }) +export class ResponseExpectationAPIService extends BaseAPIService { + override api_path = '/response-expectations' +} +@Injectable({ + providedIn: 'root' +}) export class KnockAPIService extends BaseAPIService { override api_path = '/knocks'; }