Sfoglia il codice sorgente

First version of scripts

Yann Weber 1 mese fa
parent
commit
3470e453d2
8 ha cambiato i file con 654 aggiunte e 0 eliminazioni
  1. 156
    0
      Makefile
  2. 83
    0
      README
  3. 11
    0
      config.mk.inc
  4. 49
    0
      scripts/checkconfig.sh
  5. 59
    0
      scripts/test_debvm.expect
  6. 49
    0
      scripts/test_libvirt.expect
  7. 212
    0
      scripts/testlib.expect
  8. 35
    0
      scripts/upgrade.sh

+ 156
- 0
Makefile Vedi File

1
+include config.mk
2
+
3
+SRC_DIR=linux-source
4
+VERSION=$(shell $(MAKE) -s -C $(SRC_DIR) kernelversion)
5
+BZIMAGE=archives/bzImage.$(VERSION)
6
+CONFIG_REPO=kernel-config
7
+KERNEL.CONFIG=$(shell realpath "$(CONFIG_REPO)/kernel.config")
8
+TESTED_HASH=.bzImage_tested.sha512
9
+VIRSH_TEST_SCRIPT=./scripts/test_libvirt.expect
10
+DEBVM_TEST_SCRIPT=./scripts/test_debvm.expect
11
+DEBVM_IMG_DIR=/tmp
12
+DEBVM_DISK=$(DEBVM_IMG_DIR)/vz5_kernel_test.ext4
13
+DEBVM_SWAPFILE=$(DEBVM_IMG_DIR)/vz5_kernel_test.swapfile
14
+DEBVM_SWAPLABEL=testswap
15
+UPGRADE_SCRIPT=./scripts/upgrade.sh
16
+HASH=sha512sum
17
+
18
+CRED=$(shell tput setaf 1)
19
+CGRN=$(shell tput setaf 2)
20
+CRAZ=$(shell tput sgr0)
21
+
22
+
23
+ARCHIVE=archives/install_$(shell date "+%Y_%m_%dT%H_%M_%S")_$(VERSION)
24
+
25
+all: status
26
+
27
+status:
28
+	@echo "Images :\n========\n";
29
+	@[ -f "bzImage.latest" ] && echo 'Latest    : $(shell [ -f "bzImage.latest" ] && file -L bzImage.latest | cut -d ',' -f2)' || echo "Latest : $(CRED)None built$(CRAZ)";
30
+	@[ -f "$(BZIMAGE_INSTALL)" ] && echo 'Installed : $(shell [ -f "$(BZIMAGE_INSTALL)" ] && file -L $(BZIMAGE_INSTALL) | cut -d ',' -f2)' || echo "Installed : $(CRED)None installed$(CRAZ)";
31
+	@[ -f "$(BZIMAGE_TEST)" ] && echo 'In test   : $(shell [ -f "$(BZIMAGE_TEST)" ] && file -L $(BZIMAGE_TEST) | cut -d ',' -f2)' || echo "In test : $(CRED)None in test$(CRAZ)";
32
+	@echo "\nLatest tested :\n----------";
33
+	@[ -f "bzImage.latest" ] && $(MAKE) -s tested || true;
34
+	@echo "\nSources :\n=========";
35
+	@sh $(UPGRADE_SCRIPT) check >/dev/null \
36
+		&& echo "$(CGRN)Kernel sources are up to date$(CRAZ)" \
37
+		|| echo "$(CRED)Kernel sources can be upgraded$(CRAZ)";
38
+	@echo "\nKernel config git repo :\n========================"
39
+	@git -C $(CONFIG_REPO) status
40
+
41
+
42
+$(SRC_DIR)/.config: $(KERNEL.CONFIG)
43
+	cp -v "$<" "$@"
44
+
45
+$(KERNEL.CONFIG): $(SRC_DIR)/.config
46
+	cp -v "$<" "$@"
47
+
48
+$(CONFIG_REPO):
49
+	mkdir $(CONFIG_REPO) && git -C $(CONFIG_REPO) init;
50
+
51
+menuconfig: $(SRC_DIR)/.config
52
+	$(MAKE) -C $(SRC_DIR) menuconfig
53
+
54
+$(BZIMAGE): $(SRC_DIR)/.config
55
+	$(MAKE) -C $(SRC_DIR);
56
+	mkdir -p archives/;
57
+	cp "$(SRC_DIR)/arch/x86_64/boot/bzImage" "$@";
58
+	ln -vfs "$@" bzImage.latest
59
+	ls -lah "$@"
60
+
61
+upgrade_src:
62
+	sh $(UPGRADE_SCRIPT)
63
+
64
+can_upgrade:
65
+	@sh $(UPGRADE_SCRIPT) check || echo "$(CRED)Kernel sources can be ugraded$(CRAZ)";
66
+
67
+kernel: can_upgrade $(BZIMAGE)
68
+
69
+commit-config: tested $(KERNEL.CONFIG) can_upgrade
70
+	cp -v "$(SRC_DIR)/.config" "$(KERNEL.CONFIG)";
71
+	git -C $(CONFIG_REPO) add "$(KERNEL.CONFIG)";
72
+	git -C $(CONFIG_REPO) commit -m "Update config for kernel $(VERSION)";
73
+	git -C $(CONFIG_REPO) tag -fa "$(VERSION)" -m "$(shell date -Is) Config for kernel $(VERSION)";
74
+
75
+archives/:
76
+	mkdir -p archives;
77
+
78
+archive:
79
+	mkdir -p $(ARCHIVE);
80
+	cp -v $(BZIMAGE) $(ARCHIVE)/bzImage.new;
81
+	cp -v $(BZIMAGE_INSTALL) $(ARCHIVE)/bzImage.old;
82
+
83
+
84
+clean:
85
+	-rm -v $(BZIMAGE) bzImage.latest "$(DEBVM_SWAPFILE)" "$(DEBVM_DISK)" "$(TESTED_HASH)";
86
+	$(MAKE) -C $(SRC_DIR) clean;
87
+
88
+distclean:
89
+	-rm -R "$(shell realpath $(SRC_DIR))" "$(SRC_DIR)"
90
+
91
+.PHONY: can_upgrade distclean clean $(BZIMAGE_TEST) $(BZIMAGE_INSTALL) _test tested install
92
+
93
+tested:
94
+	@$(HASH) -c "$(TESTED_HASH)" 2>/dev/null || {\
95
+		echo "$(CRED)$(BZIMAGE) is not tested.";\
96
+		echo "run make test as root.$(CRAZ)";\
97
+		false;\
98
+	};
99
+
100
+_test:
101
+	if $(MAKE) is_root >/dev/null 2>/dev/null; then \
102
+	     	$(MAKE) _virsh_test;\
103
+	else\
104
+		$(MAKE) _debvm_test;\
105
+	fi
106
+
107
+test: _test
108
+	$(HASH) "$(BZIMAGE)" > "$(TESTED_HASH)";
109
+
110
+# non-privileged user tests
111
+
112
+$(DEBVM_DISK): $(BZIMAGE)
113
+	@debvm-create -r stable -o "$@" -h "$(TEST_VM_HOSTNAME)" \
114
+		--skip autologin --skip kernel --skip systemdnetwork -- \
115
+		--customize-hook="echo \"LABEL=$(DEBVM_SWAPLABEL) none swap sw 0 0\" >> \$$1/etc/fstab"\
116
+		--customize-hook="mkdir -p \$$1/etc/network; echo \"auto enp0s2\niface enp0s2 inet dhcp\" > \$$1/etc/network/interfaces" \
117
+		--include="udev" \
118
+		--include="iputils-ping iproute2 ifupdown isc-dhcp-client" \
119
+		--include="ssh qemu-guest-agent tzdata initscripts ntpdate ca-certificates console-setup console-common console-data locales acpid vim screen bash-completion rsyslog" \
120
+		|| { rm "$@"; false;}
121
+
122
+$(DEBVM_SWAPFILE):
123
+	dd if=/dev/zero "of=$@" bs=4096 count=32768 status=progress &&\
124
+		chmod 0600 "$@" &&\
125
+		/usr/sbin/mkswap -L "$(DEBVM_SWAPLABEL)" "$@"
126
+
127
+_debvm_test: $(DEBVM_DISK) $(DEBVM_SWAPFILE)
128
+	@$(DEBVM_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(DEBVM_DISK)" "$(BZIMAGE)" "$(DEBVM_SWAPFILE)" "$(DEBVM_SWAPLABEL)" \
129
+		|| echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_debvm_expect.log" >&2 \
130
+		&& echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_debvm_expect.log" >&2;
131
+
132
+# superuser designed targets
133
+
134
+is_root:
135
+	@[ "$(shell whoami)" = "root" ] || {\
136
+		echo "$(CRED)ERROR :$(CRAZ) You need to be root to run this target" >&2;\
137
+		false;\
138
+	};
139
+
140
+$(BZIMAGE_TEST): can_upgrade is_root
141
+	cp "$(BZIMAGE)" "$@"
142
+
143
+_virsh_test: $(BZIMAGE_TEST) can_upgrade is_root
144
+	@$(VIRSH_TEST_SCRIPT) "$(TEST_VM_HOSTNAME)" "$(VERSION)" "$(TEST_VM_NAME)" || {\
145
+		echo "$(CRED)Kernel $(VERSION) [Error]$(CRAZ): Check /tmp/test_vz5_expect.log" >&2;\
146
+		false;\
147
+	} && echo "$(CGRN)Kernel $(VERSION) [OK]$(CRAZ): console logs in /tmp/test_vz5_expect.log" >&2;
148
+
149
+
150
+
151
+$(BZIMAGE_INSTALL): tested can_upgrade is_root
152
+	-cp -v $(BZIMAGE_INSTALL) $(BZIMAGE_INSTALL).old;
153
+	cp -v $(BZIMAGE) $(BZIMAGE_INSTALL);
154
+
155
+install: $(BZIMAGE_INSTALL) archive is_root
156
+

+ 83
- 0
README Vedi File

1
+Linux VZ5 :
2
+===========
3
+
4
+Compile test & install kernel image for vz5's VM.
5
+
6
+Dependencies :
7
+==============
8
+
9
+- expect
10
+- qemu/kvm
11
+- `apt build-dep linux-image-amd64`
12
+- `apt install linux-source`
13
+
14
+Optionnal dependencies :
15
+------------------------
16
+- virsh
17
+- debvm
18
+
19
+Install & config :
20
+==================
21
+
22
+Copy sample config `cp config.mk.inc config.mk`
23
+Edit configuration file to meet your needs `editor config.mk`
24
+
25
+Then you will need kernel sources & kernel configuration.
26
+
27
+Kernel sources  :
28
+-----------------
29
+
30
+* Automatic method (debian based) :
31
+
32
+Run `make upgrade`
33
+Will fetch the last kernel source in /usr/src
34
+
35
+* Manual method :
36
+
37
+Decompress kernel sources and create a symlink `linux-source` pointing to it.
38
+
39
+Kernel config :
40
+---------------
41
+
42
+Kernel configuration are versionned in a separetd git repository in kernel-config/ directory.
43
+In order to seed config file with yours run :
44
+```
45
+mkdir kernel-config
46
+git -C kernel-config/ init
47
+cp /path/to/.config kernel-config/kernel.config
48
+git -C kernel-config add kernel.config
49
+git -C kernel-config commit -m 'Initial kernel config'
50
+```
51
+
52
+Usage :
53
+=======
54
+
55
+Get current status with `make`
56
+
57
+Compile a kernel `make kernel`
58
+
59
+Test a kernel on virsh vm `make test`
60
+	If make test is run with root, we will try to start TEST_VM_NAME with virsh
61
+	If make test is run without privileges, a disk image will be built using debvm
62
+	and the tests will be run using qemu.
63
+	NOTE : the user needs access to /dev/kvm (adduser username kvm)
64
+
65
+Install kernel `make install`
66
+
67
+Commit tested kernel config `make commit-config`
68
+
69
+Notes :
70
+=======
71
+
72
+All scripts & tests are designed for monolitic kernel without initrd.
73
+
74
+Kernel config should contains :
75
+```
76
+# CONFIG_BLK_DEV_INITRD=n
77
+# CONFIG_MODULES=n
78
+```
79
+
80
+KVM has a documentation about kernel tuning for guest that can be found here :
81
+https://www.linux-kvm.org/page/Tuning_Kernel#Kernel_for_guest_with_paravirtualization
82
+
83
+The script `scripts/checkconfig.sh` check that kernel config fits basic needs.

+ 11
- 0
config.mk.inc Vedi File

1
+# Kernel installation path
2
+BZIMAGE_INSTALL=/srv/tftpd/boot/bzImage
3
+# Test VM hostname (for both virsh & debvm tests)
4
+TEST_VM_HOSTNAME=test
5
+
6
+# virsh test specific config
7
+
8
+# Test kernel installation path
9
+BZIMAGE_TEST=/srv/tftpd/boot/bzImageTest
10
+# virsh test vm name
11
+TEST_VM_NAME=test

+ 49
- 0
scripts/checkconfig.sh Vedi File

1
+#!/bin/sh
2
+set -e
3
+
4
+if [ "$#" -lt 1 ]
5
+then
6
+	echo "Usage : $0 configfile" 2>/dev/null
7
+	exit 1
8
+fi
9
+config=$1
10
+err=0
11
+
12
+while read -r rule
13
+do
14
+	opt="$(echo "$rule" | cut -d ":" -f 1)"
15
+	comment="$(echo "$rule" | cut -d ":" -f 2-)"
16
+	printf "%-40s" "$opt"
17
+	if grep "$opt" "$config" >/dev/null
18
+	then
19
+		echo " [$(tput setaf 2)OK$(tput sgr0)]"
20
+	else
21
+		err=1
22
+		echo "[$(tput setaf 1)FAIL$(tput sgr0)] $comment"
23
+	fi
24
+done << __EOF__
25
+# CONFIG_BLK_DEV_INITRD is not set:Initrd should be disabled
26
+# CONFIG_MODULES is not set:Kernel should be monolitic (without module support)
27
+CONFIG_EXT4_FS=y:Needed by tests with debvm
28
+CONFIG_SWAP=y:Swap support
29
+CONFIG_VIRTIO=y:Needed by VIRTIO_PCI and VIRTIO_BALOON
30
+CONFIG_VIRTIO_MENU=y:The virtio drivers
31
+CONFIG_VIRTIO_NET=y:The virtio network driver
32
+CONFIG_VIRTIO_BLK=y:The virtio block device driver
33
+CONFIG_VIRTIO_PCI=y:Support for virtio PCI devices
34
+CONFIG_VIRTIO_MMIO:Support for memory mapped virtio driver
35
+CONFIG_VIRTIO_MEM=y:The virtio memory driver
36
+CONFIG_VIRTIO_BALLOON=y:Support for hot memory amount change for KVM guest
37
+CONFIG_VIRTIO_INPUT=y:The virtio input (kbd, mice) driver
38
+CONFIG_VIRTIO_CONSOLE=y:Support for virtio serial console
39
+CONFIG_VIRTIO_VDPA=y:Virtio data path acceleration support
40
+CONFIG_HW_RANDOM_VIRTIO=y:Virtio random number generator support
41
+CONFIG_VP_VDPA=y:Bridges virtio PCI to vDPA
42
+CONFIG_PCI_MSI=y:Allows driver to enable Message Signaled Interrupts
43
+CONFIG_KVM_GUEST=y:Optimization for KVM guest
44
+CONFIG_PARAVIRT=y:Optimization for linux guest
45
+CONFIG_MEMORY_HOTPLUG=y:Needed by VIRTIO_BALLOON
46
+CONFIG_MEMORY_HOTREMOVE=y:Needed by VIRTIO_BALLOON
47
+__EOF__
48
+
49
+exit $err

+ 59
- 0
scripts/test_debvm.expect Vedi File

1
+#!/usr/bin/expect -f
2
+
3
+log_file -noappend "/tmp/test_debvm_expect.log"
4
+
5
+namespace eval VZ5 {
6
+	variable HOSTNAME "[lindex $argv 0]"
7
+	variable KVER "[lindex $argv 1]"
8
+}
9
+set DISK_IMG_PATH "[lindex $argv 2]"
10
+set KERNEL_PATH "[lindex $argv 3]"
11
+set SWAP_PATH "[lindex $argv 4]"
12
+set SWAP_UUID "[lindex $argv 5]"
13
+
14
+set where [file dirname [info script]]
15
+source [file join $where testlib.expect]
16
+
17
+proc VZ5::destroy {} {
18
+	send_log "\nERROR EXIT DESTROY\n"
19
+	system "kill [exp_pid]"
20
+	exit 1
21
+}
22
+
23
+proc VZ5::abort {} {
24
+	send_log "\nERROR ABORT\n"
25
+	set timeout 1
26
+	send "\r"
27
+	expect "[prompt]" { send "shutdown -h now\r"; } timeout destroy
28
+	set timeout 15
29
+	expect eof {} timeout destroy
30
+	exit 1
31
+}
32
+
33
+spawn qemu-system-x86_64 \
34
+	-name $::VZ5::HOSTNAME \
35
+	-m 1024\
36
+	-smp 8 -cpu host -machine type=q35,accel=kvm:tcg -no-user-config\
37
+	-netdev "user,id=net0,domainname=testvm"\
38
+	-device "virtio-net-pci,netdev=net0"\
39
+	-device "virtio-rng-pci,rng=rng0"\
40
+	-object "rng-random,filename=/dev/urandom,id=rng0"\
41
+	-drive "media=disk,format=raw,discard=unmap,file=$DISK_IMG_PATH,if=virtio,cache=unsafe"\
42
+	-drive "media=disk,format=raw,discard=unmap,file=$SWAP_PATH,if=virtio,cache=unsafe"\
43
+	-kernel $KERNEL_PATH -append "root=/dev/vda rw console=ttyS0,38400n8"\
44
+	-nographic -snapshot
45
+
46
+
47
+login
48
+
49
+test_base
50
+test_kernel_version $::VZ5::KVER
51
+test_swap
52
+test_ssh
53
+test_vda_rw
54
+test_apt
55
+test_reboot
56
+
57
+shutdown
58
+
59
+exit 0

+ 49
- 0
scripts/test_libvirt.expect Vedi File

1
+#!/usr/bin/expect -f
2
+
3
+log_file -noappend "/tmp/test_libvirt_expect.log"
4
+namespace eval VZ5 {
5
+	variable HOSTNAME "[lindex $argv 0]"
6
+	variable KVER "[lindex $argv 1]"
7
+}
8
+variable VMNAME "[lindex $argv 2]"
9
+
10
+set where [file dirname [info script]]
11
+source [file join $where testlib.expect]
12
+
13
+
14
+proc VZ5::destroy {} {
15
+	system virsh destroy $::VMNAME
16
+	send_log "ERROR EXIT DESTROY\n"
17
+	system reset
18
+	exit 1
19
+}
20
+proc VZ5::abort {} {
21
+	set timeout 5
22
+	send_log "\nERROR ABORT\n"
23
+	send "\r"
24
+	expect "root@test:~#" {} timeout VZ5::destroy
25
+	send "shutdown -h now\r"
26
+	expect eof {} timeout VZ5::destroy
27
+	send_log "ERROR EXIT"
28
+	system reset
29
+	exit 1
30
+}
31
+
32
+spawn virsh start --console $VMNAME
33
+
34
+login
35
+
36
+test_base
37
+test_kernel_version $::VZ5::KVER
38
+test_swap
39
+test_ssh
40
+test_vz5_netconfig
41
+test_ping
42
+test_vda_rw
43
+test_apt
44
+test_reboot
45
+test_virsh_reboot
46
+
47
+shutdown
48
+
49
+exit 0

+ 212
- 0
scripts/testlib.expect Vedi File

1
+# Common VZ5 kernel test procedures
2
+# This file is designed to be sourced from expect script
3
+
4
+namespace eval VZ5 {
5
+	variable rows [stty rows]
6
+	variable cols [stty columns]
7
+}
8
+
9
+
10
+# Procedure called on timeout
11
+# The expect main script must define VZ5::abort ordering the VM to stop
12
+proc abort {} {
13
+	VZ5::abort
14
+}
15
+
16
+# Procedure called when abort fails to stop the VM
17
+# The expect main script must define VZ5::destroy
18
+proc destroy {} {
19
+	VZ5::destroy
20
+}
21
+
22
+# 
23
+proc debug_interact {} {
24
+	expect "[prompt]" {
25
+		send " echo H4sIAAAAAAACA+OSjjY2zFXGB7iUFaSjc/mlo01zXVydQt0VPP1CXIMcnUM8w1wVgl2Dgz39/aAqQEZxETbM2Cg3oCi1uFghuaQoRztRIb9IIS5WoSRfITUvRQFmCkRdSUaqQjFQaWZ+HlhCARUQsA3kKi4uALzdLXnkAAAA|base64 -d|gzip -d\r"
26
+	}
27
+	interact {
28
+		\001 { abort; }
29
+		\x1d { abort; }
30
+	}
31
+}
32
+
33
+proc vm_stty {} {
34
+	expect "[prompt]" {send "stty -brkint -imaxbel iutf8 rows $::VZ5::rows cols $::VZ5::cols\r"} timeout destroy
35
+}
36
+
37
+proc termconfig {} {
38
+	send_tty "\033\[?7h\033\[?4h"
39
+}
40
+
41
+
42
+####################
43
+# Tests procedures #
44
+####################
45
+
46
+
47
+# Wait for login prompt, and login as root without password
48
+# Calls stty to inform VM of terminal size
49
+proc login {} {
50
+	send_log "\nPID : '[exp_pid]'\n"
51
+	if { [exp_pid] == 0 } { destroy }
52
+	set timeout 15
53
+	expect "Console: " { termconfig } timeout destroy
54
+	expect {
55
+		"$::VZ5::HOSTNAME login:" {}
56
+		"FAIL" {
57
+			expect "\r"
58
+			expect "\r" {
59
+				sleep 2;
60
+				expect "login:" {
61
+					send "root\r";
62
+					vm_stty;
63
+					debug_interact;
64
+				} timeout destroy
65
+			} timeout destroy
66
+		}
67
+		timeout destroy
68
+	}
69
+	set timeout 5
70
+	if {[catch {send "root\r"} err]} {
71
+		destroy
72
+	}
73
+	vm_stty
74
+}
75
+
76
+# Basics tests
77
+# - Checks date & time
78
+# - Check uname status code
79
+# - Checks /proc/cpuinfo
80
+# - Checks kernel clocksource kvm-clock support
81
+proc test_base {} {
82
+	set timeout 2
83
+	expect "[prompt]" { send "date -Im\r" } timeout abort
84
+	expect [system date -Im] {} timeout abort
85
+	expect "[prompt]" { send "date\r" } timeout abort
86
+	check_ret
87
+	expect "[prompt]" { send "uname -a\r" } timeout abort
88
+	check_ret
89
+	expect {
90
+		"[prompt]" { send "cat /proc/cpuinfo\r" } timeout abort
91
+		"processor " {} timeout abort
92
+	}
93
+	expect "[prompt]" { send "cat /sys/devices/system/clocksource/clocksource0/current_clocksource\r" } timeout abort
94
+	expect "kvm-clock" {} timeout abort
95
+	expect "[prompt]" { send "cat /sys/class/misc/hw_random/rng_available\r" } timeout abort
96
+	expect "virtio" {} timeout abort
97
+	expect "[prompt]" { send "cat /sys/class/misc/hw_random/rng_current\r" } timeout abort
98
+	expect "virtio" {} timeout abort
99
+}
100
+
101
+# Tests uname kernel version
102
+# Arguments :
103
+#  - version : expected kernel version
104
+proc test_kernel_version {version} {
105
+	set timeout 3
106
+	expect "[prompt]" { send "uname -r\r" } timeout abort
107
+	expect "$version-kvmguest" {} timeout abort
108
+}
109
+
110
+# Testing swap support
111
+proc test_swap {} {
112
+	set timeout 3
113
+	expect "[prompt]" { send "cat /proc/swaps | grep partition\r" } timeout abort
114
+	expect "/dev/vd*" {} timeout abort
115
+
116
+	expect {
117
+		"[prompt]" { send "free -h\r" } timeout abort
118
+		"Mem: " {} timeout abort
119
+		"Swap: " {} timeout abort
120
+	}
121
+
122
+}
123
+
124
+# Testing ssh daemon is running
125
+proc test_ssh {} {
126
+	set timeout 3
127
+	expect {
128
+		"[prompt]" { send "ps aux|grep sshd\r" }
129
+		expect "*/usr/sbin/sshd -D \[listener\] *"
130
+		timeout abort
131
+	}
132
+
133
+}
134
+
135
+# Check for vz5 network address configuration
136
+proc test_vz5_netconfig {} {
137
+	set timeout 3
138
+	expect {
139
+		"[prompt]" { send "ip a\r" }
140
+		"2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP>" {} timeout abort
141
+		"inet 192.168.242." {} timeout abort
142
+		"inet6 2001:41d0:203:10ae:1312::" {} timeout abort
143
+	}
144
+}
145
+
146
+# Testing that apt runs
147
+proc test_apt {} {
148
+	set timeout 30
149
+	expect "[prompt]" { send "apt update\r" } timeout abort
150
+	check_ret
151
+	expect "[prompt]" { send "apt -y dist-upgrade\r" } timeout abort
152
+	check_ret
153
+}
154
+
155
+# Testing ping
156
+proc test_ping {} {
157
+	set timeout 10
158
+	expect "[prompt]" { send "ping -c2 gnu.org\r" } timeout abort
159
+	check_ret
160
+	expect "[prompt]" { send "ping -4 -c2 gnu.org\r" } timeout abort
161
+	check_ret
162
+}
163
+
164
+# Testing that vda is mounted rw
165
+proc test_vda_rw {} {
166
+	set timeout 3
167
+	expect {
168
+		"[prompt]" { send "grep '^rw' /proc/fs/ext4/vda/options\r" } timeout abort
169
+		"rw" {} timeout abort
170
+	}
171
+}
172
+
173
+
174
+# Reboot using systemctl and reboot
175
+proc test_reboot {} {
176
+	expect "[prompt]" { send "# Rebooting in 2 seconds\r" }
177
+	set timeout 30
178
+	expect "[prompt]" { sleep 2; send "systemctl reboot\r" }
179
+	login
180
+	expect "[prompt]" { send "reboot\r" }
181
+	login
182
+}
183
+
184
+
185
+proc test_virsh_reboot {} {
186
+	system virsh reboot test
187
+	login
188
+}
189
+
190
+proc shutdown {} {
191
+	set timeout 2
192
+	expect "[prompt]" { send "shutdown -h now\r" }
193
+	set timeout 15
194
+	expect eof {} timeout destroy
195
+}
196
+
197
+
198
+
199
+# Return the expected prompt in order to expect it
200
+proc prompt {} {
201
+	return "root@${::VZ5::HOSTNAME}:~#"
202
+}
203
+
204
+# Check that a command return a 0 status code
205
+proc check_ret {} {
206
+	expect "[prompt]" {
207
+		send "echo \"ret='$?'\"\r";
208
+		expect -timeout 1 "ret='0'" {} timeout abort
209
+	} timeout abort
210
+}
211
+
212
+

+ 35
- 0
scripts/upgrade.sh Vedi File

1
+#!/bin/sh
2
+set -e
3
+
4
+src_tarball=$(find /usr/src/linux-source-* |sort -V | tail  -n1)
5
+version=$(basename "$src_tarball" |sed -e 's/^linux-source-//' -e 's/\.tar\.xz//')
6
+tarball_hash=.debian_src_tarball.sha512
7
+
8
+src_dir=$(realpath linux-source)
9
+
10
+if [ -d "$src_dir" ] && [ -L "linux-source" ]
11
+then
12
+	if sha512sum -c "$tarball_hash"
13
+	then
14
+		exit 0
15
+	fi
16
+
17
+	if [ "$1" = "check" ]
18
+	then
19
+		exit 1
20
+	fi
21
+
22
+	make commit-config || true
23
+	rm -Rf "$src_dir" || true
24
+	rm "linux-source" || true
25
+
26
+elif [ "$1" = "check" ]
27
+then
28
+	exit 1
29
+fi
30
+
31
+tar -xvf "$src_tarball"
32
+
33
+ln -vs "linux-source-${version}" "linux-source"
34
+
35
+sha512sum "$src_tarball" > "$tarball_hash"

Loading…
Annulla
Salva