Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail when we can't overwrite the summary file in the backup upload #16452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions conan/api/subapi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,23 @@ def upload_backup_sources(self, files):
for file in files:
basename = os.path.basename(file)
full_url = url + basename
is_summary = file.endswith(".json")
file_kind = "summary" if is_summary else "file"
try:
# Always upload summary .json but only upload blob if it does not already exist
if file.endswith(".json") or not uploader.exists(full_url, auth=None):
output.info(f"Uploading file '{basename}' to backup sources server")
if is_summary or not uploader.exists(full_url, auth=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to gracefully compare the existing summary file in the remote, and use the comparison for the warning?

output.info(f"Uploading {file_kind} '{basename}' to backup sources server")
uploader.upload(full_url, file, dedup=False, auth=None)
else:
output.info(f"File '{basename}' already in backup sources server, "
"skipping upload")
except (AuthenticationException, ForbiddenException) as e:
raise ConanException(f"The source backup server '{url}' needs authentication"
f"/permissions, please provide 'source_credentials.json': {e}")
if is_summary:
output.warning(f"Could not update summary '{basename}' in backup sources server. "
"Skipping updating file but continuing with upload. "
f"Missing permissions?: {e}")
else:
raise ConanException(f"The source backup server '{url}' needs authentication"
f"/permissions, please provide 'source_credentials.json': {e}")

output.success("Upload backup sources complete\n")
return files
28 changes: 24 additions & 4 deletions test/integration/cache/backup_sources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,16 @@ def get_internet_file(file):
def get_file(file):
return static_file(file, http_server_base_folder_backup1)

@http_server.server.put("/downloader1/<file>")
def put_file(file):
if file in os.listdir(http_server_base_folder_backup1):
return HTTPError(401, "You Are Not Allowed Here")
dest = os.path.join(http_server_base_folder_backup1, file)
with open(dest, 'wb') as f:
f.write(request.body.read())

@http_server.server.get("/downloader2/<file>")
def get_file(file):
def get_file_2(file):
return static_file(file, http_server_base_folder_backup2)

http_server.run_server()
Expand All @@ -555,16 +563,28 @@ def source(self):
sha256="{sha256}")
""")
client.save_home({"global.conf": f"core.sources:download_cache={download_cache_folder}\n"
f"core.sources:download_urls=['http://localhost:{http_server.port}/downloader1/', "
f"'origin', 'http://localhost:{http_server.port}/downloader2/']\n"})

f"core.sources:download_urls=['http://localhost:{http_server.port}/downloader1/', "
f"'origin', 'http://localhost:{http_server.port}/downloader2/']\n"
f"core.sources:upload_url=http://localhost:{http_server.port}/downloader1/\n"
"core.upload:retry=0\ncore.download:retry=0"})

client.save({"conanfile.py": conanfile})
client.run("create .")
assert f"Sources for http://localhost:{http_server.port}/internet/myfile.txt found in remote backup http://localhost:{http_server.port}/downloader2/" in client.out
# TODO: Check better message with Authentication error message
assert "failed in 'origin'" in client.out

# Now try to upload once to the first backup server. It's configured so it has write permissions but no overwrite
client.run("upload * -c -r=default")
upload_server_contents = os.listdir(http_server_base_folder_backup1)
assert sha256 in upload_server_contents
assert sha256 + ".json" in upload_server_contents

client.run("remove * -c -r=default")

client.run("upload * -c -r=default")
assert f"Could not update summary '{sha256}.json' in backup sources server" in client.out

def test_ok_when_origin_bad_sha256(self):
http_server_base_folder_internet = os.path.join(self.file_server.store, "internet")
http_server_base_folder_backup2 = os.path.join(self.file_server.store, "backup2")
Expand Down