-
Notifications
You must be signed in to change notification settings - Fork 15
Add /history and device config endpoints #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,7 +14,8 @@ | |
|
|
||
| """Track device object information.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Dict | ||
| from dataclasses import dataclass, field | ||
|
|
||
| @dataclass | ||
| class Device(): | ||
|
|
@@ -24,17 +25,38 @@ class Device(): | |
| mac_addr: str = None | ||
| manufacturer: str = None | ||
| model: str = None | ||
| test_modules: str = None | ||
| test_modules: Dict = field(default_factory=dict) | ||
| ip_addr: str = None | ||
| firmware: str = None | ||
| device_folder: str = None | ||
| reports = [] | ||
| max_device_reports: int = None | ||
|
|
||
| def add_report(self, report): | ||
| self.reports.append(report) | ||
|
|
||
| def get_reports(self): | ||
| return self.reports | ||
|
|
||
| # TODO: Add ability to remove reports once test reports have been cleaned up | ||
|
|
||
| def to_json(self): | ||
| """Returns the device as a python dictionary. This is used for the | ||
| # system status API endpoint and in the report.""" | ||
|
Comment on lines
43
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these references to json be changed to dict since these aren't really returning json? |
||
| device_json = {} | ||
| device_json['mac_addr'] = self.mac_addr | ||
| device_json['manufacturer'] = self.manufacturer | ||
| device_json['model'] = self.model | ||
| if self.firmware is not None: | ||
| device_json['firmware'] = self.firmware | ||
| return device_json | ||
|
|
||
| def to_config_json(self): | ||
| """Returns the device as a python dictionary. Fields relevant to the device | ||
| config json file are exported.""" | ||
| device_json = {} | ||
| device_json['mac_addr'] = self.mac_addr | ||
| device_json['manufacturer'] = self.manufacturer | ||
| device_json['model'] = self.model | ||
| device_json['test_modules'] = self.test_modules | ||
| return device_json | ||
This file contains hidden or 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 hidden or 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,84 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Store previous test run information.""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| DATE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S' | ||
|
|
||
| class TestReport(): | ||
| """Represents a previous Test Run report.""" | ||
|
|
||
| def __init__(self, | ||
| status='Non-Compliant', | ||
| started=None, | ||
| finished=None, | ||
| total_tests=0 | ||
| ): | ||
| self._device = {} | ||
| self._status: str = status | ||
| self._started = started | ||
| self._finished = finished | ||
| self._total_tests = total_tests | ||
| self._results = [] | ||
|
|
||
| def get_status(self): | ||
| return self._status | ||
|
|
||
| def get_started(self): | ||
| return self._started | ||
|
|
||
| def get_finished(self): | ||
| return self._finished | ||
|
|
||
| def get_duration_seconds(self): | ||
| diff = self._finished - self._started | ||
| return diff.total_seconds() | ||
|
|
||
| def get_duration(self): | ||
| return str(datetime.timedelta(seconds=self.get_duration_seconds())) | ||
|
|
||
| def add_test(self, test): | ||
| self._results.append(test) | ||
|
|
||
| def to_json(self): | ||
| report_json = {} | ||
| report_json['device'] = self._device | ||
| report_json['status'] = self._status | ||
| report_json['started'] = self._started.strftime(DATE_TIME_FORMAT) | ||
| report_json['finished'] = self._finished.strftime(DATE_TIME_FORMAT) | ||
| report_json['tests'] = {'total': self._total_tests, | ||
| 'results': self._results} | ||
| return report_json | ||
|
|
||
| def from_json(self, json_file): | ||
|
|
||
| self._device['mac_addr'] = json_file['device']['mac_addr'] | ||
| self._device['manufacturer'] = json_file['device']['manufacturer'] | ||
| self._device['model'] = json_file['device']['model'] | ||
|
|
||
| if 'firmware' in self._device: | ||
| self._device['firmware'] = json_file['device']['firmware'] | ||
|
|
||
| self._status = json_file['status'] | ||
| self._started = datetime.strptime(json_file['started'], DATE_TIME_FORMAT) | ||
| self._finished = datetime.strptime(json_file['finished'], DATE_TIME_FORMAT) | ||
| self._total_tests = json_file['tests']['total'] | ||
|
|
||
| # Loop through test results | ||
| for test_result in json_file['tests']['results']: | ||
| self.add_test(test_result) | ||
|
|
||
| return self |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.