From 27f05608729763b82a96b98af1b0b75a406c51e6 Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Apr 08 2020 15:25:31 +0000 Subject: Merge #511 `Resolve problem with connecting to Pulp` --- diff --git a/freshmaker/pulp.py b/freshmaker/pulp.py index c111754..33d2759 100644 --- a/freshmaker/pulp.py +++ b/freshmaker/pulp.py @@ -24,6 +24,8 @@ import json import requests +from freshmaker.utils import retry + class Pulp(object): """Interface to Pulp""" @@ -50,6 +52,7 @@ class Pulp(object): 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 @@ class Pulp(object): 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. diff --git a/tests/test_pulp.py b/tests/test_pulp.py index ad25cb1..3643ce4 100644 --- a/tests/test_pulp.py +++ b/tests/test_pulp.py @@ -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 @@ class TestPulp(helpers.FreshmakerTestCase): 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)