33import requests
44
55import pdcupdater .services
6+ import pdcupdater .utils
67
78log = logging .getLogger (__name__ )
89
@@ -54,17 +55,7 @@ def handle(self, pdc, msg):
5455 if branch ['active' ] is False :
5556 return
5657
57- self ._retire_branch (pdc , branch )
58-
59- @staticmethod
60- def _retire_branch (pdc , branch ):
61- """ Internal method for retiring a branch in PDC. """
62- today = datetime .utcnow ().date ()
63- for sla in branch ['slas' ]:
64- sla_eol = datetime .strptime (sla ['eol' ], '%Y-%m-%d' ).date ()
65- if sla_eol > today :
66- pdc ['component-branch-slas' ][sla ['id' ]]._ \
67- += {'eol' : str (today )}
58+ _retire_branch (pdc , branch )
6859
6960 @staticmethod
7061 def _namespace_to_pdc (namespace ):
@@ -96,31 +87,6 @@ def _pdc_to_namespace(pdc_type):
9687 else :
9788 return pdc_to_namespace [pdc_type ]
9889
99- @staticmethod
100- def _is_retired_in_cgit (namespace , repo , branch , requests_session = None ):
101- """ Internal method to determine if a branch is retired in cgit. """
102- if requests_session is None :
103- requests_session = requests .Session ()
104-
105- cgit_url = 'https://src.fedoraproject.org/cgit'
106- # Check to see if they have a dead.package file in dist-git
107- url = '{base}/{namespace}/{repo}.git/plain/dead.package?h={branch}'
108- response = requests_session .head (url .format (
109- base = cgit_url ,
110- namespace = namespace ,
111- repo = repo ,
112- branch = branch ,
113- ))
114-
115- # If there is a dead.package, then the branch is retired in cgit
116- if response .status_code in [200 , 404 ]:
117- return response .status_code == 200
118- else :
119- raise ValueError (
120- 'The connection to cgit failed. Retirement status could not '
121- 'be determined. The status code was: {0}. The content was: '
122- '{1}' .format (response .status_code , response .content ))
123-
12490 def audit (self , pdc ):
12591 """ Returns the difference in retirement status in PDC and dist-git.
12692
@@ -135,14 +101,14 @@ def audit(self, pdc):
135101 for branch in pdc .get_paged (pdc ['component-branches' ]._ ):
136102 branch_str = '{type}/{global_component}#{name}' .format (** branch )
137103 log .debug ('Considering {0}' .format (branch_str ))
138- retired_in_cgit = self . _is_retired_in_cgit (
104+ retired_in_dist_git = _is_retired_in_dist_git (
139105 namespace = self ._pdc_to_namespace (branch ['type' ]),
140106 repo = branch ['global_component' ],
141107 branch = branch ['name' ],
142108 requests_session = session
143109 )
144110
145- if retired_in_cgit :
111+ if retired_in_dist_git :
146112 branches_retired_in_distgit .add (branch_str )
147113 if not branch ['active' ]:
148114 branches_retired_in_pdc .add (branch_str )
@@ -166,12 +132,47 @@ def initialize(self, pdc):
166132 for branch in pdc .get_paged (pdc ['component-branches' ]._ , active = True ):
167133 log .debug ('Considering {type}/{global_component}#{name}'
168134 .format (** branch ))
169- retired_in_cgit = self . _is_retired_in_cgit (
135+ retired_in_dist_git = _is_retired_in_dist_git (
170136 namespace = self ._pdc_to_namespace (branch ['type' ]),
171137 repo = branch ['global_component' ],
172138 branch = branch ['name' ],
173139 requests_session = session
174140 )
175141
176- if retired_in_cgit :
177- self ._retire_branch (pdc , branch )
142+ if retired_in_dist_git :
143+ _retire_branch (pdc , branch )
144+
145+ @pdcupdater .utils .retry (wait_on = requests .exceptions .ConnectionError )
146+ def _is_retired_in_dist_git (namespace , repo , branch , requests_session = None ):
147+ if requests_session is None :
148+ requests_session = requests .Session ()
149+
150+ base = 'https://src.fedoraproject.org/'
151+ # Check to see if they have a dead.package file in dist-git
152+ url = '{base}/{namespace}/{repo}/raw/{branch}/f/dead.package'
153+ response = requests_session .head (url .format (
154+ base = base ,
155+ namespace = namespace ,
156+ repo = repo ,
157+ branch = branch ,
158+ ))
159+
160+ # If there is a dead.package, then the branch is retired in dist_git
161+ if response .status_code in [200 , 404 ]:
162+ return response .status_code == 200
163+ else :
164+ raise ValueError (
165+ 'The connection to dist_git failed. Retirement status could not '
166+ 'be determined. The status code was: {0}. The content was: '
167+ '{1}' .format (response .status_code , response .content ))
168+
169+
170+ @pdcupdater .utils .retry (wait_on = requests .exceptions .ConnectionError )
171+ def _retire_branch (pdc , branch ):
172+ """ Internal method for retiring a branch in PDC. """
173+ today = datetime .utcnow ().date ()
174+ for sla in branch ['slas' ]:
175+ sla_eol = datetime .strptime (sla ['eol' ], '%Y-%m-%d' ).date ()
176+ if sla_eol > today :
177+ pdc ['component-branch-slas' ][sla ['id' ]]._ \
178+ += {'eol' : str (today )}
0 commit comments