← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~troyanov/maas:backport-054c519-3.2 into maas:3.2

 

Anton Troyanov has proposed merging ~troyanov/maas:backport-054c519-3.2 into maas:3.2.

Commit message:
chore(cli): include str(SSLError) in CommandError

(cherry picked from commit 054c51921c64b02def247d8b0c8d7a7b4d1b2616)

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~troyanov/maas/+git/maas/+merge/439280
-- 
Your team MAAS Maintainers is requested to review the proposed merge of ~troyanov/maas:backport-054c519-3.2 into maas:3.2.
diff --git a/src/maascli/api.py b/src/maascli/api.py
index 1a4c14c..e5afe81 100644
--- a/src/maascli/api.py
+++ b/src/maascli/api.py
@@ -52,8 +52,7 @@ def http_request(
     except httplib2.ssl.SSLError as error:
         raise CommandError(
             "Certificate verification failed, use --insecure/-k to "
-            "disable the certificate check."
-            f"{getattr(error, 'reason', '')}"
+            "disable the certificate check.\n" + str(error)
         )
 
 
diff --git a/src/maascli/tests/test_api.py b/src/maascli/tests/test_api.py
index 9b2f659..99450e5 100644
--- a/src/maascli/tests/test_api.py
+++ b/src/maascli/tests/test_api.py
@@ -129,7 +129,14 @@ class TestFunctions(MAASTestCase):
 
     def test_http_request_raises_error_if_cert_verify_fails(self):
         self.patch(
-            httplib2.Http, "request", Mock(side_effect=httplib2.ssl.SSLError())
+            httplib2.Http,
+            "request",
+            Mock(
+                side_effect=httplib2.ssl.SSLError(
+                    997,
+                    "ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]",
+                )
+            ),
         )
         error = self.assertRaises(
             CommandError,
@@ -139,7 +146,8 @@ class TestFunctions(MAASTestCase):
         )
         error_expected = (
             "Certificate verification failed, use --insecure/-k to "
-            "disable the certificate check."
+            "disable the certificate check.\n"
+            "ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]"
         )
         self.assertEqual(error_expected, "%s" % error)
 

Follow ups