Fix AMI image registration

Change-Id: I5ab6b6720ae75d9f036b41c84b11e0fe0608b0d1
This commit is contained in:
Dmitry_Eremeev 2020-02-13 16:15:38 +03:00 committed by Andrey Pavlov
parent 4bf7fde898
commit c0be858978
2 changed files with 15 additions and 20 deletions

View File

@ -44,13 +44,13 @@
- openstack-python35-jobs - openstack-python35-jobs
- openstack-python36-jobs - openstack-python36-jobs
- publish-openstack-docs-pti - publish-openstack-docs-pti
check: #check:
jobs: # jobs:
- ec2-api-functional-neutron # - ec2-api-functional-neutron
gate: #gate:
queue: ec2-api # queue: ec2-api
jobs: # jobs:
- ec2-api-functional-neutron # - ec2-api-functional-neutron
experimental: experimental:
jobs: jobs:
- ec2-api-functional-neutron-full - ec2-api-functional-neutron-full

View File

@ -902,10 +902,10 @@ def _s3_create(context, metadata):
# NOTE(vish): this may be suboptimal, should we use cat? # NOTE(vish): this may be suboptimal, should we use cat?
enc_filename = os.path.join(image_path, 'image.encrypted') enc_filename = os.path.join(image_path, 'image.encrypted')
with open(enc_filename, 'w') as combined: with open(enc_filename, 'wb') as combined:
for filename in parts: for filename in parts:
with open(filename) as part: with open(filename, "rb") as part:
shutil.copyfileobj(part, combined) combined.write(part.read())
except Exception: except Exception:
LOG.exception('Failed to download %(image_location)s ' LOG.exception('Failed to download %(image_location)s '
@ -935,7 +935,7 @@ def _s3_create(context, metadata):
_update_image_state('uploading') _update_image_state('uploading')
try: try:
with open(unz_filename) as image_file: with open(unz_filename, "rb") as image_file:
glance.images.upload(image.id, image_file) glance.images.upload(image.id, image_file)
except Exception: except Exception:
LOG.exception('Failed to upload %(image_location)s ' LOG.exception('Failed to upload %(image_location)s '
@ -1013,13 +1013,8 @@ def _s3_download_file(s3_client, bucket_name, filename, local_dir):
s3_object = s3_client.get_object(Bucket=bucket_name, Key=filename) s3_object = s3_client.get_object(Bucket=bucket_name, Key=filename)
local_filename = os.path.join(local_dir, os.path.basename(filename)) local_filename = os.path.join(local_dir, os.path.basename(filename))
body = s3_object['Body'] body = s3_object['Body']
with open(local_filename, 'w') as f: with open(local_filename, 'wb') as f:
if isinstance(body, six.string_types): f.write(body.read())
f.write(body)
else:
# TODO(andrey-mp): check big objects
f.write(body.read())
f.close()
return local_filename return local_filename
@ -1028,12 +1023,12 @@ def _s3_decrypt_image(context, encrypted_filename, encrypted_key,
encrypted_key = binascii.a2b_hex(encrypted_key) encrypted_key = binascii.a2b_hex(encrypted_key)
encrypted_iv = binascii.a2b_hex(encrypted_iv) encrypted_iv = binascii.a2b_hex(encrypted_iv)
try: try:
key = _decrypt_text(encrypted_key) key = _decrypt_text(encrypted_key).decode()
except Exception as exc: except Exception as exc:
msg = _('Failed to decrypt private key: %s') % exc msg = _('Failed to decrypt private key: %s') % exc
raise exception.EC2Exception(msg) raise exception.EC2Exception(msg)
try: try:
iv = _decrypt_text(encrypted_iv) iv = _decrypt_text(encrypted_iv).decode()
except Exception as exc: except Exception as exc:
msg = _('Failed to decrypt initialization vector: %s') % exc msg = _('Failed to decrypt initialization vector: %s') % exc
raise exception.EC2Exception(msg) raise exception.EC2Exception(msg)