#511 Resolve problem with connecting to Pulp
Merged 4 years ago by gnaponie. Opened 4 years ago by apaplaus.
apaplaus/freshmaker pulp-outage-fix  into  master

file modified
+4
@@ -24,6 +24,8 @@ 

  import json

  import requests

  

+ from freshmaker.utils import retry

+ 

  

  class Pulp(object):

      """Interface to Pulp"""
@@ -50,6 +52,7 @@ 

          r.raise_for_status()

          return r.json()

  

+     @retry(wait_on=requests.exceptions.RequestException)

      def get_content_set_by_repo_ids(self, repo_ids):

          """Get content_sets by repository IDs

  
@@ -69,6 +72,7 @@ 

          return [repo['notes']['content_set'] for repo in repos

                  if 'content_set' in repo['notes']]

  

+     @retry(wait_on=requests.exceptions.RequestException)

      def get_docker_repository_name(self, cdn_repo):

          """

          Getting docker repository name from pulp using cdn repo name.

file modified
+18
@@ -24,6 +24,7 @@ 

  import json

  

  from unittest.mock import patch

+ from requests import exceptions

  

  from freshmaker.pulp import Pulp

  from tests import helpers
@@ -180,3 +181,20 @@ 

              auth=(self.username, self.password))

  

          self.assertEqual(repo_name, "scl/foo-526")

+ 

+     @patch('freshmaker.pulp.requests.post')

+     @patch('freshmaker.pulp.requests.get')

+     def test_retrying_calls(self, get, post):

+         get.side_effect = exceptions.HTTPError("Connection error: get")

+         post.side_effect = exceptions.HTTPError("Connection error: post")

+ 

+         pulp = Pulp(self.server_url, username=self.username,

+                     password=self.password)

+ 

+         with self.assertRaises(exceptions.HTTPError):

+             pulp.get_docker_repository_name("test")

+         self.assertGreater(get.call_count, 1)

+ 

+         with self.assertRaises(exceptions.HTTPError):

+             pulp.get_content_set_by_repo_ids(['test1', 'test2'])

+         self.assertGreater(post.call_count, 1)

Retry querying Pulp if first try was unsuccessful. Retries will be done for some time defined in config file.

Resolves: FACTORY-5883

LGTM. Could you please squash these two commits into one?

rebased onto 51b10cd64349b4f3643492e3330fd695b26e9de6

4 years ago

LGTM. Could you please squash these two commits into one?

Done)

rebased onto a1cdd61

4 years ago

Commit 27f0560 fixes this pull-request

Pull-Request has been merged by gnaponie

4 years ago

Pull-Request has been merged by gnaponie

4 years ago