CI: move CentOS image preparation into pre-run

Change-Id: I1243ad5c0cafd722d40d17e95cb7174ff3bafdf1
This commit is contained in:
Dmitry Tantsur 2018-07-06 11:28:06 +02:00
parent 72d8d48646
commit 864459e219
3 changed files with 140 additions and 130 deletions

View File

@ -99,7 +99,19 @@
description: |
Integration job using Glance as image source.
parent: metalsmith-integration-base
pre-run: playbooks/integration/centos-image.yaml
run: playbooks/integration/run.yaml
vars:
centos_image_name: CentOS-7-x86_64-GenericCloud
centos_image_url: https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2.xz
centos_image_file: ~/CentOS-7-x86_64-GenericCloud.qcow2
centos_kernel_file: ~/CentOS-7-x86_64-GenericCloud.kernel
centos_initramfs_file: ~/CentOS-7-x86_64-GenericCloud.initramfs
centos_partition_file: ~/CentOS-7-x86_64-GenericCloud-root.qcow2
centos_glance_whole_disk_image: test-centos-wholedisk
centos_glance_kernel_image: test-centos-kernel
centos_glance_initramds_image: test-centos-initramfs
centos_glance_root_image: test-centos-partition
- project:
templates:

View File

@ -1,109 +1,136 @@
- name: Install guestfish
package:
name: libguestfs-tools
state: present
become: true
- name: Make kernel files readable (workaround for Ubuntu)
shell: chmod 0644 /boot/vmlinuz-*
become: true
- name: Set CentOS image name
set_fact:
centos_image_name: CentOS-7-x86_64-GenericCloud
- name: Set CentOS image facts
set_fact:
centos_image_url: https://cloud.centos.org/centos/7/images/{{ centos_image_name }}.qcow2.xz
centos_image_file: ~/{{ centos_image_name }}.qcow2
centos_kernel_file: ~/{{ centos_image_name }}.kernel
centos_initramfs_file: ~/{{ centos_image_name }}.initramfs
centos_partition_file: ~/{{ centos_image_name }}-root.qcow2
- name: Download the CentOS image
get_url:
url: "{{ centos_image_url }}"
dest: "{{ centos_image_file }}.xz"
register: centos_image_result
until: centos_image_result | succeeded
retries: 3
delay: 10
- name: Unpack the CentOS image
command: xz -d {{ centos_image_file }}.xz
- name: Print filesystems from the image
command: virt-filesystems -a {{ centos_image_file }} -l --extra --block-devices
- name: Create a temporary directory for extraction
tempfile:
state: directory
suffix: boot
register: temp_dir
- name: Extract kernel/ramdisk from the image
command: >
virt-get-kernel -a {{ centos_image_file }}
-o {{ temp_dir.path }} --unversioned-names
- hosts: all
environment:
LIBGUESTFS_DEBUG: 1
OS_CLOUD: devstack-admin
- name: Copy the kernel and ramdisk to the target directory
copy:
src: "{{ temp_dir.path }}/{{ item.src }}"
dest: "{{ item.dest }}"
remote_src: yes
with_items:
- src: vmlinuz
dest: "{{ centos_kernel_file }}"
- src: initramfs
dest: "{{ centos_initramfs_file }}"
tasks:
- name: Install guestfish
package:
name: libguestfs-tools
state: present
become: true
- name: Extract the root file system
command: virt-tar-out -a {{ centos_image_file }} / {{ temp_dir.path }}/root.tar
environment:
LIBGUESTFS_DEBUG: 1
- name: Make kernel files readable (workaround for Ubuntu)
shell: chmod 0644 /boot/vmlinuz-*
become: true
- name: Extract /etc/fstab and /etc/selinux/config
command: >
tar -f {{ temp_dir.path }}/root.tar
-C {{ temp_dir.path }} --extract {{ item }}
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Download the CentOS image
get_url:
url: "{{ centos_image_url }}"
dest: "{{ centos_image_file }}.xz"
register: centos_image_result
until: centos_image_result | succeeded
retries: 3
delay: 10
- name: Remove /etc/fstab and /etc/selinux/config from the archive
command: tar -f {{ temp_dir.path }}/root.tar --delete {{ item }}
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Unpack the CentOS image
command: xz -d {{ centos_image_file }}.xz
- name: Edit /etc/fstab to replace UUID with LABEL
command: sed -i 's/UUID=[^ ]* /\/dev\/vda2 /' {{ temp_dir.path}}/etc/fstab
- name: Print filesystems from the image
command: virt-filesystems -a {{ centos_image_file }} -l --extra --block-devices
- name: Rewrite /etc/selinux/config to disable selinux
copy:
dest: "{{ temp_dir.path }}/etc/selinux/config"
content: "SELINUX=disabled"
- name: Create a temporary directory for extraction
tempfile:
state: directory
suffix: boot
register: temp_dir
- name: Add edited /etc/fstab and /etc/selinux/config back
command: >
tar -f {{ temp_dir.path }}/root.tar
-C {{ temp_dir.path }}
--append {{ item }} --owner root --group root
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Extract kernel/ramdisk from the image
command: >
virt-get-kernel -a {{ centos_image_file }}
-o {{ temp_dir.path }} --unversioned-names
environment:
LIBGUESTFS_DEBUG: 1
- name: Pack the root file system into a partition image
command: virt-make-fs {{ temp_dir.path }}/root.tar {{ centos_partition_file }}
environment:
LIBGUESTFS_DEBUG: 1
- name: Copy the kernel and ramdisk to the target directory
copy:
src: "{{ temp_dir.path }}/{{ item.src }}"
dest: "{{ item.dest }}"
remote_src: yes
with_items:
- src: vmlinuz
dest: "{{ centos_kernel_file }}"
- src: initramfs
dest: "{{ centos_initramfs_file }}"
- name: Print filesystems from the image
command: virt-filesystems -a {{ centos_partition_file }} -l --extra --block-devices
- name: Extract the root file system
command: virt-tar-out -a {{ centos_image_file }} / {{ temp_dir.path }}/root.tar
environment:
LIBGUESTFS_DEBUG: 1
- name: Remove the temporary directory
file:
state: absent
path: "{{ temp_dir.path }}"
- name: Extract /etc/fstab and /etc/selinux/config
command: >
tar -f {{ temp_dir.path }}/root.tar
-C {{ temp_dir.path }} --extract {{ item }}
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Remove /etc/fstab and /etc/selinux/config from the archive
command: tar -f {{ temp_dir.path }}/root.tar --delete {{ item }}
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Edit /etc/fstab to replace UUID with LABEL
command: sed -i 's/UUID=[^ ]* /\/dev\/vda2 /' {{ temp_dir.path}}/etc/fstab
- name: Rewrite /etc/selinux/config to disable selinux
copy:
dest: "{{ temp_dir.path }}/etc/selinux/config"
content: "SELINUX=disabled"
- name: Add edited /etc/fstab and /etc/selinux/config back
command: >
tar -f {{ temp_dir.path }}/root.tar
-C {{ temp_dir.path }}
--append {{ item }} --owner root --group root
with_items:
- ./etc/fstab
- ./etc/selinux/config
- name: Pack the root file system into a partition image
command: virt-make-fs {{ temp_dir.path }}/root.tar {{ centos_partition_file }}
environment:
LIBGUESTFS_DEBUG: 1
- name: Print filesystems from the image
command: virt-filesystems -a {{ centos_partition_file }} -l --extra --block-devices
- name: Remove the temporary directory
file:
state: absent
path: "{{ temp_dir.path }}"
- name: Upload the CentOS whole-disk image
command: >
openstack image create --disk-format qcow2
--public --file {{ centos_image_file }}
{{ centos_glance_whole_disk_image }}
when: centos_glance_whole_disk_image is defined
- name: Upload the CentOS kernel image
command: >
openstack image create --disk-format aki --container-format aki \
--public --file {{ centos_kernel_file }} -f value -c id
{{ centos_glance_kernel_image }}
register: centos_kernel_id
failed_when: centos_kernel_id.stdout == ""
when: centos_glance_kernel_image is defined
- name: Upload the CentOS initramfs image
command: >
openstack image create --disk-format ari --container-format ari \
--public --file {{ centos_initramfs_file }} -f value -c id
{{ centos_glance_initramds_image }}
register: centos_initramfs_id
failed_when: centos_initramfs_id.stdout == ""
when: centos_glance_initramds_image is defined
- name: Upload the CentOS partition image
command: >
openstack image create --disk-format qcow2
--public --file {{ centos_partition_file }}
--property kernel_id={{ centos_kernel_id.stdout }}
--property ramdisk_id={{ centos_initramfs_id.stdout }}
{{ centos_glance_root_image }}
when: centos_glance_root_image is defined

View File

@ -5,52 +5,23 @@
tasks:
- include: ssh-key.yaml
- include: centos-image.yaml
- name: Upload the CentOS whole-disk image
command: >
openstack image create --disk-format qcow2
--public --file {{ centos_image_file }} test-centos-wholedisk
- name: Upload the CentOS kernel image
command: >
openstack image create --disk-format aki --container-format aki \
--public --file {{ centos_kernel_file }} -f value -c id test-centos-kernel
register: centos_kernel_id
failed_when: centos_kernel_id.stdout == ""
- name: Upload the CentOS initramfs image
command: >
openstack image create --disk-format ari --container-format ari \
--public --file {{ centos_initramfs_file }} -f value -c id test-centos-initramfs
register: centos_initramfs_id
failed_when: centos_initramfs_id.stdout == ""
- name: Upload the CentOS partition image
command: >
openstack image create --disk-format qcow2
--public --file {{ centos_partition_file }}
--property kernel_id={{ centos_kernel_id.stdout }}
--property ramdisk_id={{ centos_initramfs_id.stdout }}
test-centos-partition
- name: Test partition image with netboot
include: exercise.yaml
vars:
image: test-centos-partition
image: "{{ centos_glance_root_image }}"
precreate_port: false
netboot: true
- name: Test whole-disk image with local boot
include: exercise.yaml
vars:
image: test-centos-wholedisk
image: "{{ centos_glance_whole_disk_image }}"
precreate_port: false
netboot: false
- name: Test partition image with local boot and port
include: exercise.yaml
vars:
image: test-centos-partition
image: "{{ centos_glance_root_image }}"
precreate_port: true
netboot: false