1 # Copyright (c) 2017 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
21 boot_mode: "{{ boot_modes[YARD_IMG_ARCH] }}"
22 image_filename: "{{ release }}-server-cloudimg-{{ YARD_IMG_ARCH }}-{{ boot_mode }}.img"
23 image_path: "{{ release }}/current/{{ image_filename }}"
24 host: "{{ lookup('env', 'HOST')|default('cloud-images.ubuntu.com', true)}}"
25 image_url: "{{ lookup('env', 'IMAGE_URL')|default('https://' ~ host ~ '/' ~ image_path, true) }}"
26 image_dest: "{{ workspace }}/{{ image_filename }}"
27 sha256sums_path: "{{ release }}/current/SHA256SUMS"
28 sha256sums_filename: "{{ sha256sums_path|basename }}"
29 sha256sums_url: "{{ lookup('env', 'SHA256SUMS_URL')|default('https://' ~ host ~ '/' ~ sha256sums_path, true) }}"
31 workspace: "{{ lookup('env', 'workspace')|default('/tmp/workspace/yardstick', true) }}"
32 raw_imgfile_basename: "yardstick-{{ release }}-server.raw"
34 RedHat: cloud-utils-growpart
35 Debian: cloud-guest-utils
37 - PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
44 - package: name=parted state=present
45 - package: name=kpartx state=present
46 - package: name="{{ growpart_package[ansible_os_family] }}" state=present
49 imgfile: "{{ normal_image_file }}"
50 when: img_property == "normal"
53 imgfile: "{{ nsb_image_file }}"
54 when: img_property == "nsb"
57 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
60 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
63 - name: unmount all old mount points
69 - "{{ mountdir }}/proc"
71 - "/mnt/{{ release }}"
73 - name: kpartx -dv to delete all image partition device nodes
74 command: kpartx -dv "{{ raw_imgfile }}"
77 - name: Debug dump loop devices
79 register: losetup_output
86 - name: delete loop devices for image file
87 # use this because kpartx -dv will fail if raw_imgfile was delete
88 # but in theory we could have deleted file still attached to loopback device?
89 # use grep because of // and awk
90 shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -v -d
93 - name: delete {{ raw_imgfile }}
95 path: "{{ raw_imgfile }}"
99 - name: remove {{ mountdir }}
101 path: "{{ mountdir }}"
105 - name: remove {{ workspace }}
107 path: "{{ workspace }}"
110 - name: "fetch {{ image_url }} and verify "
111 fetch_url_and_verify:
112 url: "{{ image_url }}"
113 sha256url: "{{ sha256sums_url }}"
114 dest: "{{ image_dest }}"
116 - name: convert image to raw
117 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
119 - name: resize image to allow for more VNFs
120 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
122 - name: resize parition to allow for more VNFs
123 # use growpart because maybe it handles GPT better than parted
124 command: growpart {{ raw_imgfile }} 1
126 - name: create mknod devices in chroot
127 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
129 creates: "/dev/loop{{ item }}"
130 with_sequence: start=0 end=9
133 - name: find first partition device
134 command: kpartx -l "{{ raw_imgfile }}"
138 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
141 # assume / is the first partition
142 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
144 - name: use kpartx to create device nodes for the raw image loop device
145 # operate on the loop device to avoid /dev namespace missing devices
146 command: kpartx -avs "{{ raw_imgfile }}"
148 - name: parted dump raw image
149 command: parted "{{ raw_imgfile }}" print
156 - name: use blkid to find filesystem type of first partition device
157 command: blkid -o value -s TYPE {{ image_first_partition_device }}
161 image_fs_type: "{{ blkid_res.stdout.strip() }}"
163 msg: "We only support ext4 image filesystems because we have to resize"
164 when: image_fs_type != "ext4"
166 - name: fsck the image filesystem
167 command: "e2fsck -y -f {{ image_first_partition_device }}"
169 - name: resize filesystem to full partition size
170 command: resize2fs {{ image_first_partition_device }}
172 - name: fsck the image filesystem
173 command: "e2fsck -y -f {{ image_first_partition_device }}"
175 - name: make tmp disposable fstab
176 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
180 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
182 - name: mount first parition on image device
184 src: "{{ image_first_partition_device }}"
185 name: "{{ mountdir }}"
187 fstype: "{{ image_fs_type }}"
188 # !!!!!!! this is required otherwise we add entries to /etc/fstab
189 # and prevent the system from booting
190 fstab: "{{ fake_fstab }}"
193 - name: mount chroot /proc
196 name: "{{ mountdir }}/proc"
198 # !!!!!!! this is required otherwise we add entries to /etc/fstab
199 # and prevent the system from booting
200 fstab: "{{ fake_fstab }}"
203 - name: if arm copy qemu-aarch64-static into chroot
205 src: /usr/bin/qemu-aarch64-static
206 dest: "{{ mountdir }}/usr/bin"
207 when: 'YARD_IMG_ARCH == "arm64"'
209 - name: create ubuntu policy-rc.d workaround
211 content: "{{ '#!/bin/sh\nexit 101\n' }}"
212 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
214 when: "target_os == 'Ubuntu'"
216 - name: add chroot as host
218 name: "{{ mountdir }}"
219 groups: chroot_image,image_builder
221 ansible_python_interpreter: /usr/bin/python3
222 # set this host variable here
223 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
226 - name: include ubuntu_server_cloudimg_modify.yml
227 include: ubuntu_server_cloudimg_modify.yml
228 when: img_property == "normal"
230 - name: include ubuntu_server_cloudimg_modify_samplevnfs.yml
231 include: ubuntu_server_cloudimg_modify_samplevnfs.yml
232 when: img_property == "nsb"
236 - name: convert image to image file
237 command: "qemu-img convert -c -o compat=0.10 -O qcow2 {{ raw_imgfile }} {{ imgfile }}"
239 - name: run post build tasks
240 include: post_build_yardstick_image.yml
246 msg: "yardstick image = {{ imgfile }}"