Merge pull request #19079 from Lendar/fix-s3-put

Fix PUT/DELETE in s3.query
This commit is contained in:
Joseph Hall 2014-12-18 08:47:15 -07:00
commit 74bd7f08d8

View File

@ -153,6 +153,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
try: try:
result = requests.request(method, requesturl, headers=headers, result = requests.request(method, requesturl, headers=headers,
data=data,
verify=verify_ssl) verify=verify_ssl)
response = result.content response = result.content
except requests.exceptions.HTTPError as exc: except requests.exceptions.HTTPError as exc:
@ -165,7 +166,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
log.debug('S3 Response Status Code: {0}'.format(result.status_code)) log.debug('S3 Response Status Code: {0}'.format(result.status_code))
if method == 'PUT': if method == 'PUT':
if result.getcode() == 200: if result.status_code == 200:
if local_file: if local_file:
log.debug('Uploaded from {0} to {1}'.format(local_file, path)) log.debug('Uploaded from {0} to {1}'.format(local_file, path))
else: else:
@ -175,14 +176,14 @@ def query(key, keyid, method='GET', params=None, headers=None,
log.debug('Failed to upload from {0} to {1}: {2}'.format( log.debug('Failed to upload from {0} to {1}: {2}'.format(
local_file, local_file,
path, path,
result.getcode(), result.status_code,
)) ))
else: else:
log.debug('Failed to create bucket {0}'.format(bucket)) log.debug('Failed to create bucket {0}'.format(bucket))
return return
if method == 'DELETE': if method == 'DELETE':
if str(result.getcode()).startswith('2'): if str(result.status_code).startswith('2'):
if path: if path:
log.debug('Deleted {0} from bucket {1}'.format(path, bucket)) log.debug('Deleted {0} from bucket {1}'.format(path, bucket))
else: else:
@ -192,7 +193,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
log.debug('Failed to delete {0} from bucket {1}: {2}'.format( log.debug('Failed to delete {0} from bucket {1}: {2}'.format(
path, path,
bucket, bucket,
result.getcode(), result.status_code,
)) ))
else: else:
log.debug('Failed to delete bucket {0}'.format(bucket)) log.debug('Failed to delete bucket {0}'.format(bucket))