Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.devtools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
bob
bob.devtools
Commits
0436c422
Commit
0436c422
authored
5 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[mirror] Implement download retries with random pauses
parent
22944814
No related branches found
No related tags found
No related merge requests found
Pipeline
#34636
failed
5 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/devtools/mirror.py
+42
-21
42 additions, 21 deletions
bob/devtools/mirror.py
with
42 additions
and
21 deletions
bob/devtools/mirror.py
+
42
−
21
View file @
0436c422
...
@@ -11,6 +11,8 @@ https://github.com/valassis-digital-media/conda-mirror
...
@@ -11,6 +11,8 @@ https://github.com/valassis-digital-media/conda-mirror
import
os
import
os
import
bz2
import
bz2
import
json
import
json
import
time
import
random
import
hashlib
import
hashlib
import
fnmatch
import
fnmatch
import
tempfile
import
tempfile
...
@@ -207,30 +209,49 @@ def download_packages(packages, repodata, channel_url, dest_dir, arch, dry_run):
...
@@ -207,30 +209,49 @@ def download_packages(packages, repodata, channel_url, dest_dir, arch, dry_run):
temp_dest
=
os
.
path
.
join
(
download_dir
,
p
)
temp_dest
=
os
.
path
.
join
(
download_dir
,
p
)
logger
.
info
(
'
[download: %d/%d] %s -> %s
'
,
k
,
total
,
url
,
temp_dest
)
logger
.
info
(
'
[download: %d/%d] %s -> %s
'
,
k
,
total
,
url
,
temp_dest
)
if
not
dry_run
:
package_retries
=
10
logger
.
debug
(
'
[checking: %d/%d] %s
'
,
k
,
total
,
url
)
while
package_retries
:
r
=
requests
.
get
(
url
,
stream
=
True
,
allow_redirects
=
True
)
logger
.
info
(
'
[download: %d/%d] %s -> %s (%s bytes)
'
,
k
,
total
,
url
,
temp_dest
,
r
.
headers
[
'
Content-length
'
])
open
(
temp_dest
,
'
wb
'
).
write
(
r
.
raw
.
read
())
# verify that checksum matches
if
len
(
expected_hash
)
==
32
:
#md5
logger
.
info
(
'
[verify: %d/%d] md5(%s) == %s?
'
,
k
,
total
,
temp_dest
,
expected_hash
)
else
:
#sha256
logger
.
info
(
'
[verify: %d/%d] sha256(%s) == %s?
'
,
k
,
total
,
temp_dest
,
expected_hash
)
if
not
dry_run
:
if
not
dry_run
:
logger
.
debug
(
'
[checking: %d/%d] %s
'
,
k
,
total
,
url
)
r
=
requests
.
get
(
url
,
stream
=
True
,
allow_redirects
=
True
)
logger
.
info
(
'
[download: %d/%d] %s -> %s (%s bytes)
'
,
k
,
total
,
url
,
temp_dest
,
r
.
headers
[
'
Content-length
'
])
open
(
temp_dest
,
'
wb
'
).
write
(
r
.
raw
.
read
())
# verify that checksum matches
if
len
(
expected_hash
)
==
32
:
#md5
if
len
(
expected_hash
)
==
32
:
#md5
actual_hash
=
_md5sum
(
temp_dest
)
logger
.
info
(
'
[verify: %d/%d] md5(%s) == %s?
'
,
k
,
total
,
temp_dest
,
expected_hash
)
else
:
#sha256
else
:
#sha256
actual_hash
=
_sha256sum
(
temp_dest
)
logger
.
info
(
'
[verify: %d/%d] sha256(%s) == %s?
'
,
k
,
total
,
assert
actual_hash
==
expected_hash
,
'
Checksum of locally
'
\
temp_dest
,
expected_hash
)
'
downloaded version of %s does not match
'
\
'
(actual:%r != %r:expected)
'
%
(
url
,
actual_hash
,
if
not
dry_run
:
expected_hash
)
if
len
(
expected_hash
)
==
32
:
#md5
actual_hash
=
_md5sum
(
temp_dest
)
else
:
#sha256
actual_hash
=
_sha256sum
(
temp_dest
)
if
actual_hash
!=
expected_hash
:
wait_time
=
random
.
randint
(
10
,
61
)
logger
.
warning
(
'
Checksum of locally downloaded
'
\
'
version of %s does not match
'
\
'
(actual:%r != %r:expected) - retrying
'
\
'
after %d seconds
'
,
(
url
,
actual_hash
,
expected_hash
,
wait_time
)
os
.
unlink
(
temp_dest
)
time
.
sleep
(
wait_time
)
package_retries
-=
1
continue
else
:
break
# final check, before we continue
assert
actual_hash
==
expected_hash
,
'
Checksum of locally
'
\
'
downloaded version of %s does not match
'
\
'
(actual:%r != %r:expected)
'
%
(
url
,
actual_hash
,
expected_hash
)
# move
# move
local_dest
=
os
.
path
.
join
(
dest_dir
,
arch
,
p
)
local_dest
=
os
.
path
.
join
(
dest_dir
,
arch
,
p
)
...
...
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