Browse Source

Updated fuel-bootstrap-image-builder

Change-Id: I87b0be96b0f7274a2fdd0f139fb72933c12e7439
Andrey Shestakov 3 years ago
parent
commit
a8defc0a84

+ 1
- 0
deployment_scripts/fuel-bootstrap-image-builder/Makefile View File

@@ -15,6 +15,7 @@ install:
15 15
 	install -d -m 755 $(DESTDIR)$(PREFIX)/bin
16 16
 	install -d -m 755 $(DESTDIR)$(PREFIX)/share/fuel-bootstrap-image
17 17
 	install -m 755 -t $(DESTDIR)$(PREFIX)/bin $(top_srcdir)/bin/fuel-bootstrap-image
18
+	install -m 755 -t $(DESTDIR)$(PREFIX)/bin $(top_srcdir)/bin/fuel-bootstrap-image-set
18 19
 	tar cf - -C $(top_srcdir) share | tar xf - -C $(DESTDIR)$(PREFIX)
19 20
 
20 21
 dist: $(top_builddir)/fuel-bootstrap-image-builder-$(VERSION).tar.gz

+ 32
- 33
deployment_scripts/fuel-bootstrap-image-builder/bin/fuel-bootstrap-image View File

@@ -11,11 +11,10 @@ global_conf="/etc/fuel-bootstrap-image.conf"
11 11
 [ -z "$MOS_VERSION" ] && MOS_VERSION="7.0"
12 12
 [ -z "$DISTRO_RELEASE" ] && DISTRO_RELEASE="trusty"
13 13
 [ -z "$MIRROR_DISTRO" ] && MIRROR_DISTRO="http://archive.ubuntu.com/ubuntu"
14
-[ -z "$MIRROR_MOS" ] && MIRROR_MOS="http://mirror.fuel-infra.org/mos-repos/$MOS_VERSION/cluster/base/$DISTRO_RELEASE"
14
+[ -z "$MIRROR_MOS" ] && MIRROR_MOS="http://mirror.fuel-infra.org/mos-repos/ubuntu/$MOS_VERSION"
15 15
 [ -z "$KERNEL_FLAVOR" ] && KERNEL_FLAVOR="-generic-lts-trusty"
16 16
 [ -z "$ARCH" ] && ARCH="amd64"
17 17
 [ -z "$DESTDIR" ] && DESTDIR="/var/www/nailgun/bootstrap/ubuntu"
18
-[ -z "$BOOTSTRAP_SSH_KEYS" ] && BOOTSTRAP_SSH_KEYS="$datadir/ubuntu/files/root/.ssh/authorized_keys"
19 18
 
20 19
 BOOTSTRAP_FUEL_PKGS_DFLT="openssh-server ntp"
21 20
 
@@ -48,11 +47,13 @@ apt_setup ()
48 47
 	local root="$1"
49 48
 	local sources_list="${root}/etc/apt/sources.list"
50 49
 	local apt_prefs="${root}/etc/apt/preferences"
51
-	local mos_codename="mos${MOS_VERSION}-${DISTRO_RELEASE}"
52
-	local broken_repo=''
50
+	local mos_codename="mos${MOS_VERSION}"
53 51
 	local release_file="$MIRROR_MOS/dists/$mos_codename/Release"
54 52
 	if ! wget -q -O /dev/null "$release_file" 2>/dev/null; then
55
-		broken_repo='yes'
53
+		cat >&2 <<-EOF
54
+		$MYSELF: broken MOS repo: no $release_file"
55
+		EOF
56
+		exit 2
56 57
 	fi
57 58
 	mkdir -p "${sources_list%/*}"
58 59
 
@@ -60,20 +61,11 @@ apt_setup ()
60 61
 	deb $MIRROR_DISTRO ${DISTRO_RELEASE}         main universe multiverse restricted
61 62
 	deb $MIRROR_DISTRO ${DISTRO_RELEASE}-security main universe multiverse restricted
62 63
 	deb $MIRROR_DISTRO ${DISTRO_RELEASE}-updates  main universe multiverse restricted
64
+	deb $MIRROR_MOS ${mos_codename}          main
65
+	deb $MIRROR_MOS ${mos_codename}-security main
66
+	deb $MIRROR_MOS ${mos_codename}-updates  main
67
+	deb $MIRROR_MOS ${mos_codename}-holdback main
63 68
 	EOF
64
-	if [ -z "$broken_repo" ]; then
65
-		cat >> "$sources_list" <<-EOF
66
-		deb $MIRROR_MOS ${mos_codename}          main
67
-		deb $MIRROR_MOS ${mos_codename}-security main
68
-		deb $MIRROR_MOS ${mos_codename}-updates  main
69
-		deb $MIRROR_MOS ${mos_codename}-holdback main
70
-		EOF
71
-	else
72
-		# TODO(asheplyakov): remove this after perestroika repo gets fixed
73
-		cat >> "$sources_list" <<-EOF
74
-		deb $MIRROR_MOS ${DISTRO_RELEASE} main
75
-		EOF
76
-	fi
77 69
 	if [ -n "$EXTRA_DEB_REPOS" ]; then
78 70
 		l="$EXTRA_DEB_REPOS"
79 71
 		IFS='|'
@@ -312,20 +304,20 @@ cleanup_chroot ()
312 304
 
313 305
 install_agent ()
314 306
 {
315
-        local root="$1"
316
-        local package_path="$2"
317
-        local full_path=`ls $package_path/fuel-agent*.deb`
318
-        local package=`basename $full_path`
319
-        cp $full_path $root/tmp
320
-        chroot "$root" env \
321
-                LC_ALL=C \
322
-                DEBIAN_FRONTEND=noninteractive \
323
-                DEBCONF_NONINTERACTIVE_SEEN=true \
324
-                TMPDIR=/tmp \
325
-                TMP=/tmp \
326
-                gdebi -n /tmp/$package
327
-
328
-        rm -f $root/tmp/$package
307
+	local root="$1"
308
+	local package_path="$2"
309
+	local full_path=`ls $package_path/fuel-agent*.deb`
310
+	local package=`basename $full_path`
311
+	cp $full_path $root/tmp
312
+	chroot "$root" env \
313
+		LC_ALL=C \
314
+		DEBIAN_FRONTEND=noninteractive \
315
+		DEBCONF_NONINTERACTIVE_SEEN=true \
316
+		TMPDIR=/tmp \
317
+		TMP=/tmp \
318
+		gdebi -n /tmp/$package
319
+
320
+	rm -f $root/tmp/$package
329 321
 }
330 322
 
331 323
 recompress_initramfs ()
@@ -392,7 +384,14 @@ build_image ()
392 384
 	install_agent "$root" $AGENT_PACKAGE_PATH
393 385
 	recompress_initramfs "$root"
394 386
 	copy_conf_files "$root" $GONFIG_SOURCE
395
-	install_ssh_keys "$root" $BOOTSTRAP_SSH_KEYS
387
+	if [ -n "$BOOTSTRAP_SSH_KEYS" ]; then
388
+		install_ssh_keys "$root" $BOOTSTRAP_SSH_KEYS
389
+	else
390
+		cat >&2 <<-EOF
391
+		$MYSELF: Warning: no ssh keys specified
392
+		$MYSELF: bootstrap nodes won't be available via ssh
393
+		EOF
394
+	fi
396 395
 	restore_resolv_conf "$root"
397 396
 	cleanup_chroot "$root"
398 397
 	mk_squashfs_image "$root"

+ 111
- 0
deployment_scripts/fuel-bootstrap-image-builder/bin/fuel-bootstrap-image-set View File

@@ -0,0 +1,111 @@
1
+#!/bin/sh
2
+# Script for switching between the Ubuntu and CentOS based bootstrap images.
3
+# Usage: fuel-bootstrap-image-set centos|ubuntu
4
+set -e
5
+MYSELF="${0##*/}"
6
+ASTUTE_YAML="/etc/fuel/astute.yaml"
7
+cobbler_manifest="/etc/puppet/modules/nailgun/examples/cobbler-only.pp"
8
+astute_manifest="/etc/puppet/modules/nailgun/examples/astute-only.pp"
9
+ubuntu_bootstrap_dir="/var/www/nailgun/bootstrap/ubuntu"
10
+
11
+run_puppet () {
12
+	local container="$1"
13
+	local manifest="$2"
14
+	local ret=''
15
+	set +e
16
+	dockerctl shell "$container" puppet apply --detailed-exitcodes -dv "$manifest"
17
+	ret=$?
18
+	set -e
19
+	if [ "$ret" = "0" ] || [ "$ret" = "2" ]; then
20
+		return 0
21
+	else
22
+		cat >&2 <<-EOF
23
+		$MYSELF: puppet apply $manifest failed: exit code $ret
24
+		$MYSELF: container: $container
25
+		EOF
26
+		exit 1
27
+	fi
28
+}
29
+
30
+maybe_build_ubuntu_bootstrap ()
31
+{
32
+	local log='/var/log/fuel-bootstrap-image-build.log'
33
+	local need_rebuild=''
34
+	for item in linux initramfs.img root.squashfs; do
35
+		if [ ! -f "$ubuntu_bootstrap_dir/$item" ]; then
36
+			need_rebuild='yes'
37
+		fi
38
+	done
39
+	if [ -n "$need_rebuild" ]; then
40
+		cat >&2 <<-EOF
41
+		$MYSELF: info: Ubuntu bootstrap image does not exist, building one
42
+		$MYSELF: info: build log is available at $log
43
+		EOF
44
+		if ! fuel-bootstrap-image >>"$log" 2>&1; then
45
+			cat >&2 <<-EOF
46
+			$MYSELF: error: failed to build Ubuntu bootstrap image
47
+			$MYSELF: error: see $log for more details
48
+			EOF
49
+			exit 1
50
+		fi
51
+	fi
52
+}
53
+
54
+maybe_restart_dnsmasq () {
55
+	if ! dockerctl shell cobbler service dnsmasq status >/dev/null; then
56
+		dockerctl shell cobbler service dnsmasq restart
57
+	fi
58
+}
59
+
60
+verify_bootstrap_flavor () {
61
+	local flavor="$1"
62
+	if [ -z "$flavor" ]; then
63
+		cat >&2 <<-EOF
64
+		$MYSELF: error: no bootstrap image specified
65
+		Usage: $MYSELF centos|ubuntu
66
+		EOF
67
+		exit 1
68
+	fi
69
+	case "$flavor" in
70
+		centos|CentOS)
71
+			flavor='centos'
72
+			;;
73
+		ubuntu|Ubuntu)
74
+			flavor='ubuntu'
75
+			;;
76
+		*)
77
+			cat >&2 <<-EOF
78
+			$MYSELF: error: unknown bootstrap image: $flavor
79
+			$MYSELF: available bootstrap images: ubuntu, centos
80
+			EOF
81
+			exit 1
82
+			;;
83
+	esac
84
+}
85
+
86
+write_astute_yaml () {
87
+	local flavor="$1"
88
+	python <<-PYEOF
89
+	from fuelmenu.fuelmenu import Settings
90
+	conf = Settings().read("$ASTUTE_YAML").get('BOOTSTRAP', {})
91
+	conf['flavor'] = "$flavor"
92
+	Settings().write({'BOOTSTRAP': conf}, outfn="$ASTUTE_YAML", defaultsfile=None)
93
+	PYEOF
94
+}
95
+
96
+switch_bootstrap () {
97
+	local flavor="$1"
98
+	verify_bootstrap_flavor "$flavor"
99
+	if [ "$flavor" = "ubuntu" ]; then
100
+		maybe_build_ubuntu_bootstrap
101
+	fi
102
+	write_astute_yaml "$flavor"
103
+	run_puppet cobbler "$cobbler_manifest"
104
+	# XXX: sometimes dnsmasq stops after cobbler sync
105
+	maybe_restart_dnsmasq
106
+	run_puppet astute "$astute_manifest"
107
+	# XXX: astute puppet manifest should take care to restart astuted on its own
108
+	dockerctl shell astute killall -sHUP supervisord
109
+}
110
+
111
+switch_bootstrap $1

+ 0
- 1
deployment_scripts/fuel-bootstrap-image-builder/share/fuel-bootstrap-image/ubuntu/files/root/.ssh/authorized_keys View File

@@ -1 +0,0 @@
1
-ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtrVTSM8tGd4E8khJn2gfN/2fymnX/0YKAGSVZTWDNIcYL5zXTlSwrccn/8EgmnNsJNxucJRT+oWqrDGaFaehuwlY/IBqm50KJVaUr5QYzOUpqVpFIpoX3UwETCxcSB1LiQYbCvrJcqOPQ4Zu9fMhMGKaAX1ohzOumn4czuLDYIvCnPnoU5RDWt7g1GaFFlzGU3JFooj7/aWFJMqJLinvay3vr2vFpBvO1y29nKu+zgpZkzzJCc0ndoVqvB+W9DY6QtgTSWfd3ZE/8vg4h8QV8H+xxqL/uWCxDkv2Y3rviAHivR/V+1YCSQH0NBJrNSkRjd+1roLhcEGT7/YEnbgVV nailgun@bootstrap

Loading…
Cancel
Save