setup-compute.sh 13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/sh

##
## Setup a OpenStack compute node for Nova.
##

set -x

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

15 16
DIRNAME=`dirname $0`

17
# Grab our libs
18
. "$DIRNAME/setup-lib.sh"
19

David Johnson's avatar
David Johnson committed
20
if [ "$CONTROLLER" = "$HOSTNAME" -o "$NETWORKMANAGER" = "$HOSTNAME" ]; then
21 22 23 24 25 26 27
    exit 0;
fi

if [ -f $OURDIR/setup-compute-done ]; then
    exit 0
fi

28 29
logtstart "compute"

30 31 32 33
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi

34 35 36 37 38
#
# This is a nasty bug in oslo_service; see 
# https://review.openstack.org/#/c/256267/
#
if [ $OSVERSION -ge $OSKILO ]; then
39
    maybe_install_packages ${PYPKGPREFIX}-oslo.service
40 41 42
    patch -d / -p0 < $DIRNAME/etc/oslo_service-liberty-sig-MAINLOOP.patch
fi

43 44
maybe_install_packages nova-compute sysfsutils
maybe_install_packages libguestfs-tools libguestfs0 python-guestfs
45

46 47 48 49 50 51
#
# Once we install packages, if the user wants a bigger VM disk space
# area, we make that and copy anything in /var/lib/nova into it (which
# may include stuff that was just installed).  Then we bind mount it to
# /var/lib/nova .
#
52 53 54 55
ROOTDISK=
if [ -e /dev/sda ]; then
    ROOTDISK=/dev/sda
    ROOTDEV=sda
56
    ROOTPART=4
57 58 59
elif [ -e /dev/nvme0n1 ]; then
    ROOTDISK=/dev/nvme0n1
    ROOTDEV=nvme0n1
60
    ROOTPART=p4
61
fi
62 63 64 65 66 67 68 69 70

#
# Try to use LVM for this if possible; otherwise try to fall back to
# partition 4.
# Check to see if we already have an `emulab` VG.  This would occur
# if the user requested a temp dataset.  If this happens, we simple
# rename it to the VG name we expect.
#
mkdir -p /storage
71
vgdisplay emulab
72 73 74 75 76 77 78 79 80 81 82 83 84 85
if [ $? -eq 0 -a "$COMPUTE_EXTRA_NOVA_DISK_SPACE" = "1" ]; then
    LVM=1
    VGNAME="openstack-volumes"

    vgrename emulab $VGNAME
    sed -i -re "s/^(.*)(\/dev\/emulab)(.*)$/\1\/dev\/$VGNAME\3/" /etc/fstab

    lvcreate -l 75%FREE -n nova $VGNAME
    if [ -f /sbin/mkfs.ext4 ]; then
	mkfs.ext4 /dev/$VGNAME/nova
    else
	mkfs.ext3 /dev/$VGNAME/nova
    fi
    mkdir -p /mnt/var-lib-nova
86
    echo "/dev/$VGNAME/nova /mnt/var-lib-nova none defaults,bind 0 0" \
87
	 >> /etc/fstab
88
    mount /dev/$VGNAME/nova /mnt/var-lib-nova
89 90 91
    chown nova:nova /mnt/var-lib-nova
    rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
    mount -o bind /mnt/var-lib-nova /var/lib/nova
92
    echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
93
	 >> /etc/fstab
94 95 96 97
elif [ "$COMPUTE_EXTRA_NOVA_DISK_SPACE" = "1" ]; then
    #
    # See if we can try to use an LVM instead of just the 4th partition.
    #
98
    lsblk -n -P -b -o NAME,FSTYPE,MOUNTPOINT,PARTTYPE,PARTUUID,TYPE,PKNAME,SIZE | perl -e 'my %devs = (); while (<STDIN>) { $_ =~ s/([A-Z0-9a-z]+=)/;\$$1/g; eval "$_"; if (!($TYPE eq "disk" || $TYPE eq "part")) { next; }; if (exists($devs{$PKNAME})) { delete $devs{$PKNAME}; } if ($FSTYPE eq "" && $MOUNTPOINT eq "" && ($PARTTYPE eq "" || $PARTTYPE eq "0x0") && (int($SIZE) > 3221225472)) { $devs{$NAME} = "/dev/$NAME"; } }; print join(" ",values(%devs))."\n"' > /tmp/devs
David Johnson's avatar
David Johnson committed
99
    DEVS=`cat /tmp/devs`
100 101 102 103 104 105 106
    if [ -n "$DEVS" ]; then
	VGNAME="openstack-volumes"
	pvcreate $DEVS
	vgcreate $VGNAME $DEVS
	lvcreate -l 75%FREE -n nova $VGNAME
	if [ -f /sbin/mkfs.ext4 ]; then
	    mkfs.ext4 /dev/$VGNAME/nova
107
	else
108
	    mkfs.ext3 /dev/$VGNAME/nova
109
	fi
110 111 112 113
	mkdir -p /mnt/var-lib-nova
	echo "/dev/$VGNAME/nova /mnt/var-lib-nova none defaults,bind 0 0" \
	     >> /etc/fstab
	mount /dev/$VGNAME/nova /mnt/var-lib-nova
114 115 116 117
	chown nova:nova /mnt/var-lib-nova
	rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
	mount -o bind /mnt/var-lib-nova /var/lib/nova
	echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
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
	     >> /etc/fstab
    elif [ -e $ROOTDISK ]; then
	PART="${ROOTDISK}${ROOTPART}"
	mkdir -p /mnt/var-lib-nova
	FORCEARG=""
	if [ ! -e $PART ]; then
	    echo "*** WARNING: attempting to create max-size $PART from free space!"
	    START=`sfdisk -F $ROOTDISK | tail -1 | awk '{ print $1; }'`
	    SIZE=`sfdisk -F $ROOTDISK | tail -1 | awk '{ print $3; }'`
	    sfdisk -d $ROOTDISK > /tmp/nparts.out
	    if [ $? -eq 0 -a -s /tmp/nparts.out ]; then
		echo "$PART : start=$START,size=$SIZE" >>/tmp/nparts.out
		cat /tmp/nparts.out | sfdisk $ROOTDISK --force
		if [ ! $? -eq 0 ]; then
		    echo "*** ERROR: failed to create new $PART!"
		else
		    # Need to force mkextrafs.pl because sfdisk cannot set a
		    # partition type of 0, and mkextrafs.pl will only work
		    # normally with part-type 0.
		    FORCEARG="-f"
		    partprobe
		    sleep 10
		fi
	    else
		echo "*** ERROR: could not dump $PART partitions!"
	    fi
	fi
	/usr/local/etc/emulab/mkextrafs.pl $FORCEARG -r $ROOTDEV -s 4 /mnt/var-lib-nova
	if [ $? = 0 ]; then
	    chown nova:nova /mnt/var-lib-nova
	    rsync -avz /var/lib/nova/ /mnt/var-lib-nova/
	    mount -o bind /mnt/var-lib-nova /var/lib/nova
	    echo "/mnt/var-lib-nova /var/lib/nova none defaults,bind 0 0" \
		 >> /etc/fstab
	else
	    echo "*** ERROR: could not make larger Nova /var/lib/nova dir!"
	fi
155 156
    fi
fi
157 158
crudini --set /etc/nova/nova.conf DEFAULT auth_strategy keystone
crudini --set /etc/nova/nova.conf DEFAULT my_ip ${MGMTIP}
David Johnson's avatar
David Johnson committed
159 160 161 162 163
if [ $OSVERSION -lt $OSNEWTON ]; then
    crudini --set /etc/nova/nova.conf glance host $CONTROLLER
else
    crudini --set /etc/nova/nova.conf glance api_servers http://$CONTROLLER:9292
fi
164 165 166 167
crudini --set /etc/nova/nova.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/nova/nova.conf DEFAULT debug ${DEBUG_LOGGING}

if [ $OSVERSION -lt $OSKILO ]; then
168
    crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
169 170 171
    crudini --set /etc/nova/nova.conf DEFAULT rabbit_host $CONTROLLER
    crudini --set /etc/nova/nova.conf DEFAULT rabbit_userid ${RABBIT_USER}
    crudini --set /etc/nova/nova.conf DEFAULT rabbit_password "${RABBIT_PASS}"
172 173 174 175 176 177 178 179 180 181 182
elif [ $OSVERSION -lt $OSNEWTON ]; then
    crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
    crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	rabbit_host $CONTROLLER
    crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	rabbit_userid ${RABBIT_USER}
    crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	rabbit_password "${RABBIT_PASS}"
else
    crudini --set /etc/nova/nova.conf DEFAULT transport_url $RABBIT_URL
fi
183

184
if [ $OSVERSION -lt $OSKILO ]; then
185 186 187
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	auth_uri http://${CONTROLLER}:5000/v2.0
    crudini --set /etc/nova/nova.conf keystone_authtoken \
188
	identity_uri http://${CONTROLLER}:${KADMINPORT}
189 190 191 192 193 194 195 196 197 198
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	admin_tenant_name service
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	admin_user nova
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	admin_password "${NOVA_PASS}"
else
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	auth_uri http://${CONTROLLER}:5000
    crudini --set /etc/nova/nova.conf keystone_authtoken \
199
	auth_url http://${CONTROLLER}:${KADMINPORT}
200
    crudini --set /etc/nova/nova.conf keystone_authtoken \
201
	${AUTH_TYPE_PARAM} password
202
    crudini --set /etc/nova/nova.conf keystone_authtoken \
203
	${PROJECT_DOMAIN_PARAM} default
204
    crudini --set /etc/nova/nova.conf keystone_authtoken \
205
	${USER_DOMAIN_PARAM} default
206 207 208 209 210 211
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	project_name service
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	username nova
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	password "${NOVA_PASS}"
212
fi
David Johnson's avatar
David Johnson committed
213

214 215 216
if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
    crudini --set /etc/nova/nova.conf keystone_authtoken \
	memcached_servers ${CONTROLLER}:11211
217 218 219 220 221 222 223
fi

if [ $OSVERSION -ge $OSKILO ]; then
    crudini --set /etc/nova/nova.conf oslo_concurrency \
	lock_path /var/lib/nova/tmp
fi

224 225 226 227
if [ $OSVERSION -ge $OSOCATA ]; then
    crudini --set /etc/nova/nova.conf placement \
	os_region_name $REGION
    crudini --set /etc/nova/nova.conf placement \
228
	auth_url http://${CONTROLLER}:${KADMINPORT}/v3
229 230 231 232 233 234 235 236 237 238 239 240 241
    crudini --set /etc/nova/nova.conf placement \
	${AUTH_TYPE_PARAM} password
    crudini --set /etc/nova/nova.conf placement \
	${PROJECT_DOMAIN_PARAM} default
    crudini --set /etc/nova/nova.conf placement \
	${USER_DOMAIN_PARAM} default
    crudini --set /etc/nova/nova.conf placement \
	project_name service
    crudini --set /etc/nova/nova.conf placement \
	username placement
    crudini --set /etc/nova/nova.conf placement \
	password "${PLACEMENT_PASS}"
fi
242

243 244
if [ $OSVERSION -ge $OSLIBERTY -a $OSVERSION -lt $OSNEWTON ]; then
    crudini --set /etc/nova/nova.conf enabled_apis 'osapi_compute,metadata'
245 246 247 248 249 250
    crudini --set /etc/nova/nova.conf DEFAULT \
	network_api_class nova.network.neutronv2.api.API
    crudini --set /etc/nova/nova.conf DEFAULT \
	security_group_api neutron
    crudini --set /etc/nova/nova.conf DEFAULT \
	linuxnet_interface_driver nova.network.linux_net.NeutronLinuxBridgeInterfaceDriver
251 252 253
fi
if [ $OSVERSION -ge $OSLIBERTY ]; then
    crudini --set /etc/nova/nova.conf DEFAULT use_neutron True
254 255 256
    crudini --set /etc/nova/nova.conf DEFAULT \
	firewall_driver nova.virt.firewall.NoopFirewallDriver
fi
257

258
VNCSECTION="DEFAULT"
259
VNCENABLEKEY="vnc_enabled"
260 261
if [ $OSVERSION -ge $OSLIBERTY ]; then
    VNCSECTION="vnc"
262
    VNCENABLEKEY="enabled"
263 264 265
fi

cname=`getfqdn $CONTROLLER`
266 267 268 269 270 271 272 273 274 275 276 277
if [ $OSVERSION -lt $OSQUEENS ]; then
    crudini --set /etc/nova/nova.conf $VNCSECTION \
        vncserver_listen ${MGMTIP}
    crudini --set /etc/nova/nova.conf $VNCSECTION \
	vncserver_proxyclient_address ${MGMTIP}
else
    crudini --set /etc/nova/nova.conf $VNCSECTION \
        server_listen ${MGMTIP}
    crudini --set /etc/nova/nova.conf $VNCSECTION \
	server_proxyclient_address ${MGMTIP}
fi

David Johnson's avatar
David Johnson committed
278 279 280
#
# https://bugs.launchpad.net/nova/+bug/1635131
#
281
if [ $OSVERSION -ge $OSNEWTON ]; then
David Johnson's avatar
David Johnson committed
282 283 284 285 286 287 288 289
    chost=`host $cname | sed -E -n -e 's/^(.* has address )(.*)$/\\2/p'`
    crudini --set /etc/nova/nova.conf $VNCSECTION \
	novncproxy_base_url "http://${chost}:6080/vnc_auto.html"
else
    crudini --set /etc/nova/nova.conf $VNCSECTION \
	novncproxy_base_url "http://${cname}:6080/vnc_auto.html"
fi

290
#
291
# Change $VNCENABLEKEY = True for x86 -- but for aarch64, there is
292 293 294 295
# no video device, for KVM mode, anyway, it seems.
#
ARCH=`uname -m`
if [ "$ARCH" = "aarch64" ] ; then
296
    if [ $OSVERSION -le $OSKILO ]; then
297
	crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY False
298 299
    else
	# QEMU/Nova on Liberty gives aarch64 a vga adapter/bus.
300
	crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY True
301
    fi
302
else
303
    crudini --set /etc/nova/nova.conf $VNCSECTION $VNCENABLEKEY True
304 305
fi

David Johnson's avatar
David Johnson committed
306
if [ ${ENABLE_NEW_SERIAL_SUPPORT} = 1 ]; then
307 308 309 310
    crudini --set /etc/nova/nova.conf serial_console enabled true
    crudini --set /etc/nova/nova.conf serial_console listen $MGMTIP
    crudini --set /etc/nova/nova.conf serial_console proxyclient_address $MGMTIP
    crudini --set /etc/nova/nova.conf serial_console base_url ws://${cname}:6083/
David Johnson's avatar
David Johnson committed
311 312
fi

313 314 315
crudini --set /etc/nova/nova-compute.conf DEFAULT \
    compute_driver libvirt.LibvirtDriver
crudini --set /etc/nova/nova-compute.conf libvirt virt_type kvm
316

317 318 319 320 321 322 323 324 325 326
if [ ${ENABLE_HOST_PASSTHROUGH} = 1 ]; then
    # turn off MSR emulation
    echo 1 > /sys/module/kvm/parameters/ignore_msrs
    # persist the setting in case we reboot
    echo "options kvm ignore_msrs=1" >> /etc/modprobe.d/qemu-system-x86.conf

    # Set the "host-passthrough" mode for libvirt
    crudini --set /etc/nova/nova-compute.conf libvirt cpu_mode host-passthrough
fi

327
if [ "$ARCH" = "aarch64" ] ; then
328 329
    crudini --set /etc/nova/nova-compute.conf libvirt cpu_mode custom
    crudini --set /etc/nova/nova-compute.conf libvirt cpu_model host
330

331
    if [ $OSVERSION -ge $OSLIBERTY -a $OSVERSION -le $OSMITAKA ]; then
332 333
	crudini --set /etc/nova/nova-compute.conf libvirt video_type vga
	crudini --set /etc/nova/nova-compute.conf libvirt use_usb_tablet False
334
    elif [ $OSVERSION -gt $OSMITAKA -a $OSVERSION -lt $OSPIKE ]; then
335
	crudini --set /etc/nova/nova-compute.conf libvirt video_type vga
336 337 338 339 340
	crudini --set /etc/nova/nova-compute.conf libvirt use_usb_tablet False
	crudini --set /etc/nova/nova-compute.conf DEFAULT pointer_model ps2mouse
    elif [ $OSVERSION -eq $OSPIKE ]; then
	patch -d / -p0 < $DIRNAME/etc/nova-pike-aarch64-virtio-video.patch
	crudini --set /etc/nova/nova-compute.conf libvirt video_type virtio
341
	crudini --set /etc/nova/nova-compute.conf DEFAULT pointer_model ps2mouse
342 343
    elif [ $OSVERSION -eq $OSQUEENS ]; then
	patch -d / -p0 < $DIRNAME/etc/nova-queens-aarch64-libvirt-bios-default.patch
344 345
    elif [ $OSVERSION -eq $OSROCKY ]; then
	patch -d / -p0 < $DIRNAME/etc/nova-rocky-aarch64-libvirt-bios-default.patch
346
    fi
David Johnson's avatar
David Johnson committed
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
elif [ "$ARCH" = "ppc64le" ] ; then
    ppc64_cpu --smt=off
    if [ -e /etc/rc.local ]; then
	cat <<EOF >>/etc/rc.local

ppc64_cpu --smt=off
EOF
    else
	cat <<EOF >/etc/rc.local
#!/bin/sh

ppc64_cpu --smt=off
EOF
	chmod 755 /etc/rc.local
    fi
362 363
fi

David Johnson's avatar
David Johnson committed
364 365 366 367 368 369
if [ ${OSCODENAME} = "juno" ]; then
    #
    # Patch quick :(
    #
    patch -d / -p0 < $DIRNAME/etc/nova-juno-root-device-name.patch
fi
370

371 372 373 374 375 376 377 378
#
# Somewhere libvirt-guests.service defaulted to suspending the guests.  Fix that.
#
if [ -f /etc/default/libvirt-guests ]; then
    echo ON_SHUTDOWN=shutdown >> /etc/default/libvirt-guests
    service_restart libvirt-guests
fi

379 380
service_restart nova-compute
service_enable nova-compute
381 382
service_restart libvirt-bin
service_enable libvirt-bin
383 384 385 386 387 388

# XXXX ???
# rm -f /var/lib/nova/nova.sqlite

touch $OURDIR/setup-compute-done

389 390
logtend "compute"

391
exit 0