← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:amend_validate_args into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:amend_validate_args into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/450785
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:amend_validate_args into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
index 9f4f745..becb8c7 100644
--- a/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
+++ b/charms/focal/autopkgtest-web/webcontrol/helpers/exceptions.py
@@ -3,6 +3,13 @@ Http exceptions for autopkgtest-web
 """
 
 
+EXAMPLE_URL = (
+    "https://autopkgtest.ubuntu.com/request.cgi/?";
+    + "release=release&arch=arch&package=pkg&"
+    + "trigger=trigger1&trigger=trigger2"
+)
+
+
 class WebControlException(Exception):
     def __init__(self, message, exit_code):
         super().__init__(message)
@@ -78,3 +85,16 @@ class TooManyRequests(WebControlException):
             % requester,
             429,
         )
+
+
+class InvalidArgs(WebControlException):
+    def __init__(self, parameters):
+        super().__init__(
+            (
+                (
+                    "You have passed invalid args: %s\nPlease see an example url below:\n%s"
+                    % (",".join(parameters.keys()), EXAMPLE_URL)
+                )
+            ),
+            400,
+        )
diff --git a/charms/focal/autopkgtest-web/webcontrol/request/submit.py b/charms/focal/autopkgtest-web/webcontrol/request/submit.py
index 305cedf..ea22329 100644
--- a/charms/focal/autopkgtest-web/webcontrol/request/submit.py
+++ b/charms/focal/autopkgtest-web/webcontrol/request/submit.py
@@ -20,6 +20,7 @@ from distro_info import UbuntuDistroInfo
 from helpers.exceptions import (
     BadRequest,
     ForbiddenRequest,
+    InvalidArgs,
     NotFound,
     RequestInQueue,
     RequestRunning,
@@ -636,20 +637,5 @@ class Submit:
 
     def validate_args(self, parameters):
         base = ["arch", "release", "package", "triggers"]
-        example_url = (
-            "https://autopkgtest.ubuntu.com/request.cgi/?";
-            + "release=release&arch=arch&package=pkg&"
-            + "trigger=trigger1&trigger=trigger2"
-        )
         if not set(base).issubset(set(parameters.keys())):
-            raise ValueError(
-                (
-                    "Incorrect args passed.\nYou passed: %s\nWhereas %s is needed."
-                    + "\nPlease see an example test request url below:\n%s"
-                )
-                % (
-                    ",".join(list(parameters.keys())),
-                    ",".join(base),
-                    example_url,
-                )
-            )
+            raise InvalidArgs(parameters)

Follow ups