Update upload-image-swift
This updates upload-image-swift with some changes that have merged to the originating role in opendev/zuul-providers. Hopefully with this change, we can move opendev to use this role. This anticipates https://review.opendev.org/956219 by adding a default value of zuul.image_build_name. That change is not set as a dependency because it's not strictly necessary and it's harmless if it merges out of order (or not at all). Change-Id: Ib26ae8e54174650a2d082ef2504ef70f4804dbc4
This commit is contained in:
@@ -4,6 +4,10 @@ This uploads a filesystem image (for example, one built by diskimage
|
|||||||
builder) to an OpenStack Object Store (Swift) container. The role
|
builder) to an OpenStack Object Store (Swift) container. The role
|
||||||
returns an artifact to Zuul suitable for use by the zuul-launcher.
|
returns an artifact to Zuul suitable for use by the zuul-launcher.
|
||||||
|
|
||||||
|
If a `raw` or `vhd` image is provided and the `zstd` command is
|
||||||
|
available, it will be compressed in the way that zuul-launcher
|
||||||
|
expects.
|
||||||
|
|
||||||
**Role Variables**
|
**Role Variables**
|
||||||
|
|
||||||
.. zuul:rolevar:: upload_image_swift_cloud_config
|
.. zuul:rolevar:: upload_image_swift_cloud_config
|
||||||
@@ -33,7 +37,7 @@ returns an artifact to Zuul suitable for use by the zuul-launcher.
|
|||||||
any objects in the bucket older than this time.
|
any objects in the bucket older than this time.
|
||||||
|
|
||||||
.. zuul:rolevar:: upload_image_swift_image_name
|
.. zuul:rolevar:: upload_image_swift_image_name
|
||||||
:default: `{{ build_diskimage_image_name }}`
|
:default: `{{ build_diskimage_image_name | default(zuul.image_build_name) }}`
|
||||||
|
|
||||||
The Zuul image name for use by zuul-launcher (e.g., `debian-bookworm`).
|
The Zuul image name for use by zuul-launcher (e.g., `debian-bookworm`).
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
upload_image_swift_image_name: '{{ build_diskimage_image_name }}'
|
upload_image_swift_image_name: '{{ build_diskimage_image_name | default(zuul.image_build_name) }}'
|
||||||
upload_image_swift_delete_after: 0
|
upload_image_swift_delete_after: 0
|
||||||
upload_image_swift_filename: '{{ build_diskimage_image_root }}/{{ build_diskimage_image_name }}.{{ upload_image_swift_extension }}'
|
upload_image_swift_filename: '{{ build_diskimage_image_root }}/{{ build_diskimage_image_name }}.{{ upload_image_swift_extension }}'
|
||||||
upload_image_swift_name: '{{ zuul.build }}-{{ build_diskimage_image_name }}.{{ upload_image_swift_extension }}'
|
upload_image_swift_name: '{{ zuul.build }}-{{ build_diskimage_image_name }}.{{ upload_image_swift_extension }}'
|
||||||
|
@@ -23,6 +23,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import openstack
|
import openstack
|
||||||
|
import requests.adapters
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
import keystoneauth1.exceptions
|
import keystoneauth1.exceptions
|
||||||
|
|
||||||
@@ -34,13 +35,25 @@ SEGMENT_SIZE = 500000000 # 500MB
|
|||||||
def get_cloud(cloud):
|
def get_cloud(cloud):
|
||||||
if isinstance(cloud, dict):
|
if isinstance(cloud, dict):
|
||||||
config = openstack.config.loader.OpenStackConfig().get_one(**cloud)
|
config = openstack.config.loader.OpenStackConfig().get_one(**cloud)
|
||||||
return openstack.connection.Connection(
|
conn = openstack.connection.Connection(
|
||||||
config=config,
|
config=config,
|
||||||
pool_executor=concurrent.futures.ThreadPoolExecutor(
|
pool_executor=concurrent.futures.ThreadPoolExecutor(
|
||||||
max_workers=10
|
max_workers=10
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
return openstack.connect(cloud=cloud)
|
conn = openstack.connect(cloud=cloud)
|
||||||
|
# This backoff configuration should produce this sequence of delays:
|
||||||
|
# 0 1 2 4 8 16 32 60 60...
|
||||||
|
retries = requests.adapters.Retry(
|
||||||
|
total=15,
|
||||||
|
backoff_factor=1,
|
||||||
|
backoff_max=60,
|
||||||
|
)
|
||||||
|
conn.session.mount(
|
||||||
|
'http://', requests.adapters.HTTPAdapter(max_retries=retries))
|
||||||
|
conn.session.mount(
|
||||||
|
'https://', requests.adapters.HTTPAdapter(max_retries=retries))
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
def _add_etag_to_manifest(self, *args, **kw):
|
def _add_etag_to_manifest(self, *args, **kw):
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Run the checksums in the background while we're uploading
|
# Run the checksums in the background while we're working
|
||||||
- name: Get sha256 hash
|
- name: Get sha256 hash
|
||||||
stat:
|
stat:
|
||||||
path: '{{ upload_image_swift_filename }}'
|
path: '{{ upload_image_swift_filename }}'
|
||||||
@@ -15,15 +15,41 @@
|
|||||||
poll: 0
|
poll: 0
|
||||||
register: md5_task
|
register: md5_task
|
||||||
|
|
||||||
|
- name: Check if zstd is installed
|
||||||
|
shell: "command -v zstd || exit 1"
|
||||||
|
register: zstd_installed
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Compress image
|
||||||
|
when:
|
||||||
|
- "zstd_installed.rc == 0"
|
||||||
|
- "upload_image_swift_format in ['raw', 'vhd']"
|
||||||
|
command: zstd '{{ upload_image_swift_filename }}'
|
||||||
|
|
||||||
|
- name: Set extension
|
||||||
|
set_fact:
|
||||||
|
zj_upload_image_swift_extension: ''
|
||||||
|
|
||||||
|
- name: Set extension
|
||||||
|
when:
|
||||||
|
- "zstd_installed.rc == 0"
|
||||||
|
- "upload_image_swift_format in ['raw', 'vhd']"
|
||||||
|
set_fact:
|
||||||
|
zj_upload_image_swift_extension: '.zst'
|
||||||
|
|
||||||
- name: Upload image to swift
|
- name: Upload image to swift
|
||||||
upload_image_swift:
|
upload_image_swift:
|
||||||
cloud: '{{ upload_image_swift_cloud_config }}'
|
cloud: '{{ upload_image_swift_cloud_config }}'
|
||||||
container: '{{ upload_image_swift_container }}'
|
container: '{{ upload_image_swift_container }}'
|
||||||
filename: '{{ upload_image_swift_filename }}'
|
filename: '{{ upload_image_swift_filename }}{{ zj_upload_image_swift_extension }}'
|
||||||
name: '{{ upload_image_swift_name }}'
|
name: '{{ upload_image_swift_name }}{{ zj_upload_image_swift_extension }}'
|
||||||
delete_after: '{{ upload_image_swift_delete_after }}'
|
delete_after: '{{ upload_image_swift_delete_after }}'
|
||||||
register: upload_results
|
register: upload_results
|
||||||
|
|
||||||
|
- name: Delete uncompressed image
|
||||||
|
when: "upload_image_swift_format in ['raw', 'vhd']"
|
||||||
|
command: rm '{{ upload_image_swift_filename }}'
|
||||||
|
|
||||||
- name: Wait for sha256
|
- name: Wait for sha256
|
||||||
async_status:
|
async_status:
|
||||||
jid: "{{ sha256_task.ansible_job_id }}"
|
jid: "{{ sha256_task.ansible_job_id }}"
|
||||||
|
Reference in New Issue
Block a user