add yardstick iruya 9.0.0 release notes
[yardstick.git] / build_yardstick_image / tasks / pre_build.yml
1 # Copyright (c) 2018 Intel Corporation.\r
2 #\r
3 # Licensed under the Apache License, Version 2.0 (the "License");\r
4 # you may not use this file except in compliance with the License.\r
5 # You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 # Unless required by applicable law or agreed to in writing, software\r
10 # distributed under the License is distributed on an "AS IS" BASIS,\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 # See the License for the specific language governing permissions and\r
13 # limitations under the License.\r
14 ---\r
15 - name: Group\r
16   group_by:\r
17     key: image_builder\r
18 \r
19 - package: name=parted state=present\r
20   environment: "{{ proxy_env }}"\r
21 \r
22 - package: name=kpartx state=present\r
23   environment: "{{ proxy_env }}"\r
24 \r
25 - package: name="{{ growpart_package[ansible_os_family] }}" state=present\r
26   environment: "{{ proxy_env }}"\r
27 \r
28 - set_fact:\r
29     imgfile: "{{ normal_image_file }}"\r
30   when: img_prop_item == "normal"\r
31 \r
32 - set_fact:\r
33     imgfile: "{{ nsb_image_file }}"\r
34   when: img_prop_item == "nsb"\r
35 \r
36 - set_fact:\r
37     mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"\r
38     raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"\r
39 \r
40 # cleanup non-lxd\r
41 - name: unmount all old mount points\r
42   mount:\r
43     name: "{{ item }}"\r
44     state: unmounted\r
45   with_items:\r
46     # order matters\r
47     - "{{ mountdir }}/proc"\r
48     - "{{ mountdir }}/run"\r
49     - "{{ mountdir }}"\r
50     - "/mnt/{{ release }}"\r
51 \r
52 - name: kpartx -dv to delete all image partition device nodes\r
53   command: kpartx -dv "{{ raw_imgfile }}"\r
54   ignore_errors: true\r
55 \r
56 - name: Debug dump loop devices\r
57   command: losetup -a\r
58   ignore_errors: true\r
59 \r
60 - name: delete loop devices for image file\r
61   # use this because kpartx -dv will fail if raw_imgfile was delete\r
62   # but in theory we could have deleted file still attached to loopback device?\r
63   # use grep because of // and awk\r
64   shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -v -d\r
65   ignore_errors: true\r
66 \r
67 - name: Debug dump loop devices again\r
68   command: losetup -a\r
69   ignore_errors: true\r
70 \r
71 - name: delete {{ raw_imgfile }}\r
72   file:\r
73     path: "{{ raw_imgfile }}"\r
74     state: absent\r
75 \r
76 # common\r
77 - name: remove {{ mountdir }}\r
78   file:\r
79     path: "{{ mountdir }}"\r
80     state: absent\r
81 \r
82 # download-common\r
83 - name: remove {{ workspace }}\r
84   file:\r
85     path: "{{ workspace }}"\r
86     state: directory\r
87 \r
88 - name: "fetch {{ image_url }} and verify "\r
89   fetch_url_and_verify:\r
90     url: "{{ image_url }}"\r
91     sha256url: "{{ sha256sums_url }}"\r
92     dest: "{{ image_dest }}"\r
93 \r
94 - name: convert image to raw\r
95   command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"\r
96 \r
97 - name: resize image to allow for more VNFs\r
98   command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"\r
99 \r
100 - name: resize parition to allow for more VNFs\r
101   # use growpart because maybe it handles GPT better than parted\r
102   command: growpart {{ raw_imgfile }}  1\r
103 \r
104 - name: create mknod devices in chroot\r
105   command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"\r
106   args:\r
107     creates: "/dev/loop{{ item }}"\r
108   with_sequence: start=0 end=9\r
109   tags: mknod_devices\r
110 \r
111 - name: find first partition device\r
112   command: kpartx -l "{{ raw_imgfile }}"\r
113   register: kpartx_res\r
114 \r
115 - set_fact:\r
116     image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"\r
117 \r
118 - set_fact:\r
119     # assume / is the first partition\r
120     image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"\r
121 \r
122 - name: use kpartx to create device nodes for the raw image loop device\r
123   # operate on the loop device to avoid /dev namespace missing devices\r
124   command: kpartx -avs "{{ raw_imgfile }}"\r
125 \r
126 - name: parted dump raw image\r
127   command: parted "{{ raw_imgfile }}" print\r
128   register: parted_res\r
129 \r
130 - debug:\r
131     var: parted_res\r
132     verbosity: 2\r
133 \r
134 - name: use blkid to find filesystem type of first partition device\r
135   command: blkid -o value -s TYPE {{ image_first_partition_device }}\r
136   register: blkid_res\r
137 \r
138 - set_fact:\r
139     image_fs_type: "{{ blkid_res.stdout.strip() }}"\r
140 \r
141 - fail:\r
142     msg: "We only support ext4 image filesystems because we have to resize"\r
143   when: image_fs_type != "ext4"\r
144 \r
145 - name: fsck the image filesystem\r
146   command: "e2fsck -y -f {{ image_first_partition_device  }}"\r
147 \r
148 - name: resize filesystem to full partition size\r
149   command: resize2fs {{ image_first_partition_device }}\r
150 \r
151 - name: fsck the image filesystem\r
152   command: "e2fsck -y -f {{ image_first_partition_device  }}"\r
153 \r
154 - name: make tmp disposable fstab\r
155   command: mktemp --tmpdir fake_fstab.XXXXXXXXXX\r
156   register: mktemp_res\r
157 \r
158 - set_fact:\r
159     fake_fstab: "{{ mktemp_res.stdout.strip() }}"\r
160 \r
161 - name: mount first parition on image device\r
162   mount:\r
163     src: "{{ image_first_partition_device }}"\r
164     name: "{{ mountdir }}"\r
165     # fstype is required\r
166     fstype: "{{ image_fs_type }}"\r
167     # !!!!!!! this is required otherwise we add entries to /etc/fstab\r
168     # and prevent the system from booting\r
169     fstab: "{{ fake_fstab }}"\r
170     state: mounted\r
171 \r
172 - name: mount chroot /proc\r
173   mount:\r
174     src: none\r
175     name: "{{ mountdir }}/proc"\r
176     fstype: proc\r
177     # !!!!!!! this is required otherwise we add entries to /etc/fstab\r
178     # and prevent the system from booting\r
179     fstab: "{{ fake_fstab }}"\r
180     state: mounted\r
181 \r
182 - name: mount chroot /run\r
183   mount:\r
184     src: /run\r
185     name: "{{ mountdir }}/run"\r
186     fstype: tmpfs\r
187     opts: bind\r
188     # !!!!!!! this is required otherwise we add entries to /etc/fstab\r
189     # and prevent the system from booting\r
190     fstab: "{{ fake_fstab }}"\r
191     state: mounted\r
192 \r
193 - name: if arm copy qemu-aarch64-static into chroot\r
194   copy:\r
195     src: /usr/bin/qemu-aarch64-static\r
196     dest: "{{ mountdir }}/usr/bin"\r
197   when: img_arch == arch_arm64\r
198 \r
199 - name: create ubuntu policy-rc.d workaround\r
200   copy:\r
201     content: "{{ '#!/bin/sh\nexit 101\n' }}"\r
202     dest: "{{ mountdir }}/usr/sbin/policy-rc.d"\r
203     mode: 0755\r
204   when: "target_os == 'Ubuntu'"\r
205 \r
206 - name: add chroot as host\r
207   add_host:\r
208     name: "{{ mountdir }}"\r
209     groups: chroot_image,image_builder\r
210     connection: chroot\r
211     ansible_python_interpreter: /usr/bin/python3\r
212     # set this host variable here\r
213     nameserver_ip: "{{ ansible_dns.nameservers[0] }}"\r
214     image_type: vm\r