#2166 backend: try multiple attempts of creating GPG keys
Merged 4 months ago by praiskup. Opened 4 months ago by frostyx.
copr/ frostyx/copr create-keys-attempts  into  main

file modified
+5 -3
@@ -6,12 +6,12 @@ 

  

  from subprocess import Popen, PIPE, SubprocessError

  import json

- 

  import os

- from requests import request

  

  from packaging import version

  

+ from copr_common.request import SafeRequest

+ from copr_backend.helpers import get_redis_logger

  from .exceptions import CoprSignError, CoprSignNoKeyError, \

      CoprKeygenRequestError

  
@@ -194,10 +194,12 @@ 

          "name_email": create_gpg_email(username, projectname)

      })

  

+     log = get_redis_logger(opts, "sign", "actions")

      keygen_url = "http://{}/gen_key".format(opts.keygen_host)

      query = dict(url=keygen_url, data=data, method="post")

      try:

-         response = request(**query)

+         request = SafeRequest(log=log)

+         response = request.send(**query)

      except Exception as e:

          raise CoprKeygenRequestError(

              msg="Failed to create key-pair for user: {},"

file modified
+3 -3
@@ -145,7 +145,7 @@ 

          with pytest.raises(CoprSignError):

              _sign_one(fake_path, self.usermail, "sha256", MagicMock())

  

-     @mock.patch("copr_backend.sign.request")

+     @mock.patch("copr_backend.sign.SafeRequest.send")

      def test_create_user_keys(self, mc_request):

          mc_request.return_value.status_code = 200

          create_user_keys(self.username, self.projectname, self.opts)
@@ -158,7 +158,7 @@ 

          )

          assert mc_request.call_args == expected_call

  

-     @mock.patch("copr_backend.sign.request")

+     @mock.patch("copr_backend.sign.SafeRequest.send")

      def test_create_user_keys_error_1(self, mc_request):

          mc_request.side_effect = IOError()

          with pytest.raises(CoprKeygenRequestError) as err:
@@ -167,7 +167,7 @@ 

          assert "Failed to create key-pair" in str(err)

  

  

-     @mock.patch("copr_backend.sign.request")

+     @mock.patch("copr_backend.sign.SafeRequest.send")

      def test_create_user_keys(self, mc_request):

          for code in [400, 401, 404, 500, 599]:

              mc_request.return_value.status_code = code

Build succeeded.

Commit c9e7c52 fixes this pull-request

Pull-Request has been merged by praiskup

4 months ago