From 815750fb320c13d4e0ae2a11585c844e18e4cc94 Mon Sep 17 00:00:00 2001 From: ChunAn Wu Date: Thu, 28 Nov 2024 21:53:49 +0800 Subject: [PATCH] 1. Correct variable "url" to "urls" due to it's not single url but a list of url 2. add logger to fail case Signed-off-by: ChunAn Wu --- .../devices/zapper_iot/__init__.py | 12 +++++++----- .../devices/zapper_iot/parser.py | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/__init__.py b/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/__init__.py index 4c883634..1fad69a1 100644 --- a/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/__init__.py +++ b/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/__init__.py @@ -19,7 +19,7 @@ from testflinger_device_connectors.devices import ProvisioningError from testflinger_device_connectors.devices.zapper_iot.parser import ( validate_provision_plan, - validate_url, + validate_urls, ) logger = logging.getLogger(__name__) @@ -44,9 +44,11 @@ def _validate_configuration( raise ProvisioningError from e try: - url = self.job_data["provision_data"]["url"] - validate_url(url) + urls = self.job_data["provision_data"]["urls"] + validate_urls(urls) except KeyError: - url = [] + urls = [] + except ValueError as e: + raise ProvisioningError from e - return ((provision_plan, url), {}) + return ((provision_plan, urls), {}) diff --git a/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/parser.py b/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/parser.py index 59024bd4..1c09b509 100644 --- a/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/parser.py +++ b/device-connectors/src/testflinger_device_connectors/devices/zapper_iot/parser.py @@ -202,11 +202,13 @@ def validate_provision_plan(data): validate(instance=data, schema=TPLAN_SCHEMA) logger.info("the JSON data is valid") except jsonschema.exceptions.ValidationError as err: + logger.info("the JSON data is invalid") raise ValueError("the JSON data is invalid") from err -def validate_url(url): +def validate_urls(urls): """for verify url""" - for link in url: + for link in urls: if not validators.url(link): + logger.info("url %s is invalid", link) raise ValueError("url format is not correct")