Use new internal _request_post_file function 49/13549/3
authorBengt Thuree <bthuree@linuxfoundation.org>
Thu, 15 Nov 2018 09:46:41 +0000 (20:46 +1100)
committerBengt Thuree <bthuree@linuxfoundation.org>
Mon, 19 Nov 2018 07:51:58 +0000 (18:51 +1100)
Refactor deploy_nexus_zip to use new internal function
_request_post_file

Change-Id: I42c1d7f1fae299680fb20483e0f14e62b85c5885
Signed-off-by: Bengt Thuree <bthuree@linuxfoundation.org>
lftools/deploy.py

index d64d759..a83f6f6 100644 (file)
@@ -334,21 +334,9 @@ def deploy_nexus_zip(nexus_url, nexus_repo, nexus_path, zip_file):
         nexus_path)
     log.debug('Uploading {} to {}'.format(zip_file, url))
 
-    upload_file = open(zip_file, 'rb')
-
-    files = {'file': upload_file}
-    resp = requests.post(url, files=files)
+    resp = _request_post_file(url, zip_file)
     log.debug('{}: {}'.format(resp.status_code, resp.text))
 
-    if resp.status_code == 400:
-        raise requests.HTTPError("Repository is read only: {}".format(nexus_repo))
-    elif resp.status_code == 404:
-        raise requests.HTTPError("Did not find repository with ID: {}".format(nexus_repo))
-
-    if not str(resp.status_code).startswith('20'):
-        raise requests.HTTPError("Failed to upload to Nexus with status code: {}.\n{}\n{}".format(
-            resp.status_code, resp.text, zipfile.ZipFile(zip_file).infolist()))
-
 
 def nexus_stage_repo_create(nexus_url, staging_profile_id):
     """Create a Nexus staging repo.