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
85 - name: delete loop devices for image file
86 # use this because kpartx -dv will fail if raw_imgfile was delete
87 # but in theory we could have deleted file still attached to loopback device?
88 # use grep because of // and awk
89 shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -d
92 - name: delete {{ raw_imgfile }}
94 path: "{{ raw_imgfile }}"
98 - name: remove {{ mountdir }}
100 path: "{{ mountdir }}"
104 - name: remove {{ workspace }}
106 path: "{{ workspace }}"
109 - name: "fetch {{ image_url }} and verify "
110 fetch_url_and_verify:
111 url: "{{ image_url }}"
112 sha256url: "{{ sha256sums_url }}"
113 dest: "{{ image_dest }}"
115 - name: convert image to raw
116 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
118 - name: resize image to allow for more VNFs
119 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
121 - name: resize parition to allow for more VNFs
122 # use growpart because maybe it handles GPT better than parted
123 command: growpart {{ raw_imgfile }} 1
125 - name: create mknod devices in chroot
126 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
128 creates: "/dev/loop{{ item }}"
129 with_sequence: start=0 end=9
132 - name: find first partition device
133 command: kpartx -l "{{ raw_imgfile }}"
137 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
140 # assume / is the first partition
141 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
143 - name: use kpartx to create device nodes for the raw image loop device
144 # operate on the loop device to avoid /dev namespace missing devices
145 command: kpartx -avs "{{ raw_imgfile }}"
147 - name: parted dump raw image
148 command: parted "{{ raw_imgfile }}" print
155 - name: use blkid to find filesystem type of first partition device
156 command: blkid -o value -s TYPE {{ image_first_partition_device }}
160 image_fs_type: "{{ blkid_res.stdout.strip() }}"
162 msg: "We only support ext4 image filesystems because we have to resize"
163 when: image_fs_type != "ext4"
165 - name: fsck the image filesystem
166 command: "e2fsck -y -f {{ image_first_partition_device }}"
168 - name: resize filesystem to full partition size
169 command: resize2fs {{ image_first_partition_device }}
171 - name: fsck the image filesystem
172 command: "e2fsck -y -f {{ image_first_partition_device }}"
174 - name: make tmp disposable fstab
175 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
179 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
181 - name: mount first parition on image device
183 src: "{{ image_first_partition_device }}"
184 name: "{{ mountdir }}"
186 fstype: "{{ image_fs_type }}"
187 # !!!!!!! this is required otherwise we add entries to /etc/fstab
188 # and prevent the system from booting
189 fstab: "{{ fake_fstab }}"
192 - name: mount chroot /proc
195 name: "{{ mountdir }}/proc"
197 # !!!!!!! this is required otherwise we add entries to /etc/fstab
198 # and prevent the system from booting
199 fstab: "{{ fake_fstab }}"
202 - name: if arm copy qemu-aarch64-static into chroot
204 src: /usr/bin/qemu-aarch64-static
205 dest: "{{ mountdir }}/usr/bin"
206 when: 'YARD_IMG_ARCH == "arm64"'
208 - name: create ubuntu policy-rc.d workaround
210 content: "{{ '#!/bin/sh\nexit 101\n' }}"
211 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
213 when: "target_os == 'Ubuntu'"
215 - name: add chroot as host
217 name: "{{ mountdir }}"
218 groups: chroot_image,image_builder
220 ansible_python_interpreter: /usr/bin/python3
221 # set this host variable here
222 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
225 - name: include ubuntu_server_cloudimg_modify.yml
226 include: ubuntu_server_cloudimg_modify.yml
227 when: img_property == "normal"
229 - name: include ubuntu_server_cloudimg_modify_samplevnfs.yml
230 include: ubuntu_server_cloudimg_modify_samplevnfs.yml
231 when: img_property == "nsb"
235 - name: convert image to image file
236 command: "qemu-img convert -c -o compat=0.10 -O qcow2 {{ raw_imgfile }} {{ imgfile }}"
238 - name: run post build tasks
239 include: post_build_yardstick_image.yml
245 msg: "yardstick image = {{ imgfile }}"