Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
package_alerts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
linuxsupport
cronjobs
package_alerts
Commits
8c385317
Commit
8c385317
authored
1 year ago
by
Ben Morrice
Browse files
Options
Downloads
Patches
Plain Diff
Add retry logic to get_changelog function
parent
6374ab79
No related branches found
Branches containing commit
No related tags found
1 merge request
!9
Various improvements
Pipeline
#6329850
failed
1 year ago
Stage: build
Stage: deploy_test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package_alerts/package_alerts
+28
-10
28 additions, 10 deletions
package_alerts/package_alerts
with
28 additions
and
10 deletions
package_alerts/package_alerts
+
28
−
10
View file @
8c385317
...
@@ -82,17 +82,35 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False):
...
@@ -82,17 +82,35 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False):
def
get_changelog
(
token
,
checksum
):
def
get_changelog
(
token
,
checksum
):
"""
get the changelog for a rpm, which requires downloading it
"""
"""
get the changelog for a rpm, which requires downloading it
"""
url
=
f
"
https://api.access.redhat.com/management/v1/packages/
{
checksum
}
/download
"
# We don't usually retry stuff from api calls as the script runs
result
=
call_api
(
token
,
url
,
stream
=
True
)
# frequently, however - in this case a failure results in a blank
# changelog which is not very useful
attempts
=
0
max_attempts
=
3
rpm_downloaded
=
False
temp_file
=
generate_temp_file
(
"
checksum
"
)
temp_file
=
generate_temp_file
(
"
checksum
"
)
# TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth
url
=
f
"
https://api.access.redhat.com/management/v1/packages/
{
checksum
}
/download
"
with
open
(
temp_file
,
"
wb
"
)
as
f
:
while
attempts
<
max_attempts
:
try
:
attempts
+=
1
for
chunk
in
result
.
iter_content
(
chunk_size
=
1024
):
result
=
call_api
(
token
,
url
,
stream
=
True
)
if
chunk
:
if
result
.
status_code
==
200
:
f
.
write
(
chunk
)
# TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth
except
:
with
open
(
temp_file
,
"
wb
"
)
as
f
:
f
.
close
()
try
:
for
chunk
in
result
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
f
.
write
(
chunk
)
rpm_downloaded
=
True
except
:
print
(
f
"
Saving changelog appeared to have failed. Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
f
.
close
()
if
rpm_downloaded
:
break
else
:
print
(
f
"
API call failed, Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
if
not
rpm_downloaded
:
print
(
f
"
Changelog failed to download, exiting
"
,
flush
=
True
)
sys
.
exit
(
1
)
# TODO: maybe have some better logic instead of the head command
# TODO: maybe have some better logic instead of the head command
changelog
=
do_execute
(
f
"
rpm -qp
{
temp_file
}
--changelog | head -20
"
,
return_output
=
True
)
changelog
=
do_execute
(
f
"
rpm -qp
{
temp_file
}
--changelog | head -20
"
,
return_output
=
True
)
# Even though we are running through a container, let's clean up after ourselves
# Even though we are running through a container, let's clean up after ourselves
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment