Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions framework/python/src/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ async def start_testrun(self, request: Request, response: Response):

device = self._session.get_device(body_json["device"]["mac_addr"])

# Check if requested device is known in the device repository
if device is None:
response.status_code = status.HTTP_404_NOT_FOUND
return self._generate_msg(
False, "A device with that MAC address could not be found")

# Check if device is fully configured
if device.status != "Valid":
response.status_code = status.HTTP_400_BAD_REQUEST
Expand All @@ -277,12 +283,6 @@ async def start_testrun(self, request: Request, response: Response):
False, "Testrun cannot be started " +
"whilst a test is running on another device")

# Check if requested device is known in the device repository
if device is None:
response.status_code = status.HTTP_404_NOT_FOUND
return self._generate_msg(
False, "A device with that MAC address could not be found")

device.firmware = body_json["device"]["firmware"]

# Check if config has been updated (device interface not default)
Expand Down Expand Up @@ -474,6 +474,14 @@ async def delete_report(self, request: Request, response: Response):
response.status_code = 404
return self._generate_msg(False, "Could not find device")

# Assign the reports folder path from testrun
reports_folder = self._testrun.get_reports_folder(device)

# Check if reports folder exists
if not os.path.exists(reports_folder):
response.status_code = 404
return self._generate_msg(False, "Report not found")

if self._testrun.delete_report(device, timestamp_formatted):
return self._generate_msg(True, "Deleted report")

Expand Down
18 changes: 8 additions & 10 deletions framework/python/src/core/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ def _load_test_reports(self, device):
device.clear_reports()

# Locate reports folder
reports_folder = os.path.join(self._root_dir,
LOCAL_DEVICES_DIR,
device.device_folder, 'reports')
reports_folder = self.get_reports_folder(device)

# Check if reports folder exists (device may have no reports)
if not os.path.exists(reports_folder):
Expand Down Expand Up @@ -280,18 +278,18 @@ def _load_test_reports(self, device):
test_report.set_mac_addr(device.mac_addr)
device.add_report(test_report)

def get_reports_folder(self, device):
"""Return the reports folder path for the device"""
return os.path.join(self._root_dir,
LOCAL_DEVICES_DIR,
device.device_folder, 'reports')

def delete_report(self, device: Device, timestamp):
LOGGER.debug(f'Deleting test report for device {device.model} ' +
f'at {timestamp}')

# Locate reports folder
reports_folder = os.path.join(self._root_dir,
LOCAL_DEVICES_DIR,
device.device_folder, 'reports')

# Check if reports folder exists (device may have no reports)
if not os.path.exists(reports_folder):
return False
reports_folder = self.get_reports_folder(device)

for report_folder in os.listdir(reports_folder):
if report_folder == timestamp:
Expand Down
54 changes: 54 additions & 0 deletions testing/api/devices/device_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"mac_addr": "00:1e:42:28:9e:4a",
"manufacturer": "Teltonika",
"model": "TRB140",
"type": "IoT Gateway",
"technology": "Hardware - Access Control",
"test_pack": "Device Qualification",
"additional_info": [
{
"question": "What type of device is this?",
"answer": "IoT Gateway"
},
{
"question": "Please select the technology this device falls into",
"answer": "Hardware - Access Control"
},
{
"question": "Does your device process any sensitive information?",
"answer": "Yes"
},
{
"question": "Can all non-essential services be disabled on your device?",
"answer": "Yes"
},
{
"question": "Is there a second IP port on the device?",
"answer": "Yes"
},
{
"question": "Can the second IP port on your device be disabled?",
"answer": "Yes"
}
],
"test_modules": {
"protocol": {
"enabled": true
},
"services": {
"enabled": false
},
"ntp": {
"enabled": true
},
"tls": {
"enabled": false
},
"connection": {
"enabled": true
},
"dns": {
"enabled": true
}
}
}
54 changes: 54 additions & 0 deletions testing/api/devices/device_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"mac_addr": "00:1e:42:35:73:c6",
"manufacturer": "Google",
"model": "First",
"type": "IoT Gateway",
"technology": "Hardware - Access Control",
"test_pack": "Device Qualification",
"additional_info": [
{
"question": "What type of device is this?",
"answer": "IoT Gateway"
},
{
"question": "Please select the technology this device falls into",
"answer": "Hardware - Access Control"
},
{
"question": "Does your device process any sensitive information?",
"answer": "Yes"
},
{
"question": "Can all non-essential services be disabled on your device?",
"answer": "Yes"
},
{
"question": "Is there a second IP port on the device?",
"answer": "Yes"
},
{
"question": "Can the second IP port on your device be disabled?",
"answer": "Yes"
}
],
"test_modules": {
"protocol": {
"enabled": true
},
"services": {
"enabled": false
},
"ntp": {
"enabled": true
},
"tls": {
"enabled": false
},
"connection": {
"enabled": true
},
"dns": {
"enabled": true
}
}
}
Loading