/
install-iso-pre
executable file
·258 lines (199 loc) · 6.73 KB
/
install-iso-pre
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
set -e
. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/log.sh
check_params()
{
log_info "start check params"
local required_vars=(
"iso_os"
"iso_arch"
"iso_version"
"group_id"
"VG_NAME"
"HTTP_SERVER_HOST"
"HTTP_SERVER_PORT"
"HTTP_ROOT_DIR"
"secrets_ROOTFS_ROOT_PASSWD"
"rootfs_disk"
"RSYNC_SERVER_HOST"
"RSYNC_SERVER_PORT"
"TFTP_SERVER_HOST"
"NFS_SERVER_HOST"
"NFS_ROOT_DIR"
"LAB_Z9_URL"
"secrets_MY_TOKEN"
)
for i in "${required_vars[@]}"
do
[ -n "$(eval echo \$$i)" ] || die "cannot get value of var: $i"
done
}
prepare_vg()
{
log_info "start create vg:$VG_NAME"
local disk
for disk in "${rootfs_disk[@]}"
do
log_info "start handle disk: $disk"
pvdisplay ${disk} > /dev/null || pvcreate -y ${disk} || die "create pv failed: $disk"
if vgdisplay ${VG_NAME} > /dev/null; then
# if pv not in vg: add disk to vg
pvdisplay $disk | grep 'VG Name' | grep -w $VG_NAME || {
vgextend -y ${VG_NAME} ${disk} || die "vgextend failed: $disk"
}
else
vgcreate -y ${VG_NAME} ${disk} || die "vgcreate failed: $disk"
fi
done
}
create_lv()
{
log_info "start create lv:$LV_NAME"
lvcreate -y -L 30G -n ${LV_NAME} ${VG_NAME} || die "create logical volume failed."
mkfs.ext4 /dev/mapper/${VG_NAME}-${LV_NAME}
}
prepare_lv()
{
log_info "start prepare logical volume"
local iso_version=${iso_version//-/_}
# activate lvm
vgscan --cache
vgchange -ay || vgchange -ay $VG_NAME
# VG_NAME defines in job.yaml
export VG_NAME
export LV_NAME="${iso_os}_${iso_arch}_${iso_version}_${group_id}"
# lv existed
lvdisplay /dev/mapper/${VG_NAME}-${LV_NAME} > /dev/null && {
log_info "iso already install to this testbox, so rootfs maybe already generated ok. please check it."
exit 0
}
# lv not existed
prepare_vg
create_lv
}
generate_ks()
{
log_info "start generate $ks_file"
local nic=$(ip route get ${LKP_SERVER} | awk '{print $3; exit}')
cat > ${ks_file} <<-EOF
# Use network installation
url --url="http://${HTTP_SERVER_HOST}:${HTTP_SERVER_PORT}/${HTTP_ROOT_DIR}/${iso_os}/${iso_arch}/${iso_version}/"
# Network information
network --bootproto=dhcp --device=${nic} --ipv6=auto --activate
network --hostname=localhost.localdomain
# Specifies a list of disks for the installation program to use. All other disks are ignored.
ignoredisk --only-use=${rootfs_disk#/dev/}
# if installation target is a logical volume, bootloader should be none.
bootloader --location=none
logvol / --vgname=${VG_NAME} --name=${LV_NAME} --useexisting
EOF
curl -s http://${OS_HTTP_HOST}:${OS_HTTP_PORT}/os/install/ks/template/${iso_os}-${iso_arch}-${iso_version}.ks >> $ks_file
}
upload_ks()
{
log_info "start upload ks to rsync-server: ${RSYNC_SERVER_HOST}:${RSYNC_SERVER_PORT}"
rsync -vrtopg --port ${RSYNC_SERVER_PORT} ${ks_file} ${RSYNC_SERVER_HOST}::ks/ || die "upload ks to rsync-server failed, please check."
}
prepare_ks()
{
log_info "start prepare kickstart file"
local ks_file=/tmp/${iso_os}_${iso_arch}_${iso_version}.ks
generate_ks
upload_ks
}
prepare_submit()
{
${LKP_SRC}/sbin/install-dependencies.sh
export CCI_REPOS="/c"
mkdir -p $CCI_REPOS && cd $CCI_REPOS
git clone $LAB_Z9_URL || die "clone lab-z9 git repo failed: $LAB_Z9_URL"
git clone https://gitee.com/wu_fengguang/lkp-tests.git
cp -a $LKP_SRC/. ./lkp-tests/
export LKP_SRC=$(realpath ./lkp-tests/)
local config_yaml="/etc/compass-ci/defaults/sparrow.yaml"
mkdir -p $(dirname $config_yaml)
cat >> $config_yaml <<-EOF
SCHED_HOST: ${SCHED_HOST}
SCHED_PORT: ${SCHED_PORT}
my_account: ${my_account}
my_name: ${secrets_MY_NAME}
my_email: ${secrets_MY_EMAIL}
my_token: ${secrets_MY_TOKEN}
lab: z9
EOF
}
prepare_install_iso_yaml()
{
log_info "start prepare install-iso.yaml"
local tftp_root="tftp://${TFTP_SERVER_HOST}/EFI/BOOT/${iso_os}/${iso_arch}/${iso_version}"
local custom_ipxe
custom_ipxe="#!ipxe\\\\n"
custom_ipxe="${custom_ipxe}\\\\ndhcp"
custom_ipxe="${custom_ipxe}\\\\ninitrd ${tftp_root}/initrd.img"
custom_ipxe="${custom_ipxe}\\\\nkernel ${tftp_root}/vmlinuz ro console=ttyS0 initrd=initrd.img ip=dhcp inst.ks=http://${HTTP_SERVER_HOST}:${HTTP_SERVER_PORT}/os/install/ks/${iso_os}_${iso_arch}_${iso_version}.ks"
custom_ipxe="${custom_ipxe}\\\\nboot\\\\n"
log_info "custom_ipxe: $custom_ipxe"
sed -i "/custom_ipxe:/ccustom_ipxe: \"${custom_ipxe}\"" ${install_iso_yaml}
}
submit_install_iso_yaml()
{
log_info "start submit install-iso.yaml"
local install_iso_yaml="${LKP_SRC}/jobs/install-iso.yaml"
[ -f "${install_iso_yaml}" ] || die "cannot find ${install_iso_yaml}"
prepare_install_iso_yaml
${LKP_SRC}/sbin/submit \
${install_iso_yaml} \
queue=$queue \
testbox=$testbox || die "submit ${install_iso_yaml} failed"
}
submit_install_iso_firstboot_yaml()
{
log_info "start submit install-iso-firstboot.yaml"
local firstboot_yaml="${LKP_SRC}/jobs/install-iso-firstboot.yaml"
[ -f "${firstboot_yaml}" ] || die "cannot find ${firstboot_yaml}"
custom_ipxe="#!ipxe\\\\n"
custom_ipxe="${custom_ipxe}\\\\ndhcp"
custom_ipxe="${custom_ipxe}\\\\ninitrd http://${OS_HTTP_HOST}:${OS_HTTP_PORT}/os/${iso_os}/${iso_arch}/${iso_version}/initrd.lkp"
custom_ipxe="${custom_ipxe}\\\\ninitrd http://${INITRD_HTTP_HOST}:${INITRD_HTTP_PORT}/initrd/custom_bootstrap/reboot-after-systemd-logind.cgz"
custom_ipxe="${custom_ipxe}\\\\nkernel http://${OS_HTTP_HOST}:${OS_HTTP_PORT}/os/${iso_os}/${iso_arch}/${iso_version}/boot/vmlinuz ip=dhcp root=/dev/mapper/${VG_NAME}-${LV_NAME} initrd=initrd.lkp initrd=reboot-after-systemd-logind.cgz local rw"
custom_ipxe="${custom_ipxe}\\\\nboot\\\\n"
sed -i "/custom_ipxe:/ccustom_ipxe: \"${custom_ipxe}\"" $firstboot_yaml
${LKP_SRC}/sbin/submit \
${firstboot_yaml} \
suite=install-iso-firstboot \
group_id=${group_id} \
queue=$queue \
testbox=$testbox || die "submit ${firstboot_yaml} failed"
}
submit_install_iso_sync_rootfs_yaml()
{
log_info "start submit install-iso-sync-rootfs.yaml"
local sync_rootfs_yaml="${LKP_SRC}/jobs/install-iso-sync-rootfs.yaml"
[ -f "${sync_rootfs_yaml}" ] || die "cannot find ${sync_rootfs_yaml}"
${LKP_SRC}/sbin/submit \
${sync_rootfs_yaml} \
suite=install-iso-sync-rootfs \
group_id=${group_id} \
install-iso-sync-rootfs.iso_os=${iso_os} \
install-iso-sync-rootfs.iso_arch=${iso_arch} \
install-iso-sync-rootfs.iso_version=${iso_version} \
install-iso-sync-rootfs.NFS_SERVER_HOST=${NFS_SERVER_HOST} \
install-iso-sync-rootfs.NFS_ROOT_DIR=${NFS_ROOT_DIR} \
install-iso-sync-rootfs.VG_NAME=${VG_NAME} \
queue=$queue \
testbox=$testbox || die "submit job failed: ${sync_rootfs_yaml}"
}
main()
{
check_params
prepare_lv
prepare_ks
prepare_submit
submit_install_iso_yaml
submit_install_iso_firstboot_yaml
submit_install_iso_sync_rootfs_yaml
}
main