Skip to content

Commit

Permalink
1. Correct variable "url" to "urls" due to it's not single url
Browse files Browse the repository at this point in the history
   but a list of url
2. add logger to fail case

Signed-off-by: ChunAn Wu <[email protected]>
  • Loading branch information
kiya956 committed Nov 29, 2024
1 parent 79ba119 commit 815750f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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), {})
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 815750f

Please sign in to comment.