Ver código fonte

First version of scripts

Yann Weber 4 semanas atrás
pai
commit
257a8fb5e0
8 arquivos alterados com 644 adições e 0 exclusões
  1. 156
    0
      Makefile
  2. 83
    0
      README
  3. 4
    0
      config.mk.inc
  4. 50
    0
      scripts/checkconfig.sh
  5. 59
    0
      scripts/test_debvm.expect
  6. 49
    0
      scripts/test_libvirt.expect
  7. 208
    0
      scripts/testlib.expect
  8. 35
    0
      scripts/upgrade.sh

+ 156
- 0
Makefile Ver arquivo

@@ -0,0 +1,156 @@
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 Ver arquivo

@@ -0,0 +1,83 @@
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.

+ 4
- 0
config.mk.inc Ver arquivo

@@ -0,0 +1,4 @@
1
+BZIMAGE_TEST=/srv/tftpd/boot/bzImageTest
2
+BZIMAGE_INSTALL=/srv/tftpd/boot/bzImage
3
+TEST_VM_NAME=test
4
+TEST_VM_HOSTNAME=test

+ 50
- 0
scripts/checkconfig.sh Ver arquivo

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

+ 59
- 0
scripts/test_debvm.expect Ver arquivo

@@ -0,0 +1,59 @@
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 Ver arquivo

@@ -0,0 +1,49 @@
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

+ 208
- 0
scripts/testlib.expect Ver arquivo

@@ -0,0 +1,208 @@
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
+}
96
+
97
+# Tests uname kernel version
98
+# Arguments :
99
+#  - version : expected kernel version
100
+proc test_kernel_version {version} {
101
+	set timeout 3
102
+	expect "[prompt]" { send "uname -r\r" } timeout abort
103
+	expect "$version-kvmguest" {} timeout abort
104
+}
105
+
106
+# Testing swap support
107
+proc test_swap {} {
108
+	set timeout 3
109
+	expect "[prompt]" { send "cat /proc/swaps | grep partition\r" } timeout abort
110
+	expect "/dev/vd*" {} timeout abort
111
+
112
+	expect {
113
+		"[prompt]" { send "free -h\r" } timeout abort
114
+		"Mem: " {} timeout abort
115
+		"Swap: " {} timeout abort
116
+	}
117
+
118
+}
119
+
120
+# Testing ssh daemon is running
121
+proc test_ssh {} {
122
+	set timeout 3
123
+	expect {
124
+		"[prompt]" { send "ps aux|grep sshd\r" }
125
+		expect "*/usr/sbin/sshd -D \[listener\] *"
126
+		timeout abort
127
+	}
128
+
129
+}
130
+
131
+# Check for vz5 network address configuration
132
+proc test_vz5_netconfig {} {
133
+	set timeout 3
134
+	expect {
135
+		"[prompt]" { send "ip a\r" }
136
+		"2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP>" {} timeout abort
137
+		"inet 192.168.242." {} timeout abort
138
+		"inet6 2001:41d0:203:10ae:1312::" {} timeout abort
139
+	}
140
+}
141
+
142
+# Testing that apt runs
143
+proc test_apt {} {
144
+	set timeout 30
145
+	expect "[prompt]" { send "apt update\r" } timeout abort
146
+	check_ret
147
+	expect "[prompt]" { send "apt -y dist-upgrade\r" } timeout abort
148
+	check_ret
149
+}
150
+
151
+# Testing ping
152
+proc test_ping {} {
153
+	set timeout 10
154
+	expect "[prompt]" { send "ping -c2 gnu.org\r" } timeout abort
155
+	check_ret
156
+	expect "[prompt]" { send "ping -4 -c2 gnu.org\r" } timeout abort
157
+	check_ret
158
+}
159
+
160
+# Testing that vda is mounted rw
161
+proc test_vda_rw {} {
162
+	set timeout 3
163
+	expect {
164
+		"[prompt]" { send "grep '^rw' /proc/fs/ext4/vda/options\r" } timeout abort
165
+		"rw" {} timeout abort
166
+	}
167
+}
168
+
169
+
170
+# Reboot using systemctl and reboot
171
+proc test_reboot {} {
172
+	expect "[prompt]" { send "# Rebooting in 2 seconds\r" }
173
+	set timeout 30
174
+	expect "[prompt]" { sleep 2; send "systemctl reboot\r" }
175
+	login
176
+	expect "[prompt]" { send "reboot\r" }
177
+	login
178
+}
179
+
180
+
181
+proc test_virsh_reboot {} {
182
+	system virsh reboot test
183
+	login
184
+}
185
+
186
+proc shutdown {} {
187
+	set timeout 2
188
+	expect "[prompt]" { send "shutdown -h now\r" }
189
+	set timeout 15
190
+	expect eof {} timeout destroy
191
+}
192
+
193
+
194
+
195
+# Return the expected prompt in order to expect it
196
+proc prompt {} {
197
+	return "root@${::VZ5::HOSTNAME}:~#"
198
+}
199
+
200
+# Check that a command return a 0 status code
201
+proc check_ret {} {
202
+	expect "[prompt]" {
203
+		send "echo \"ret='$?'\"\r";
204
+		expect -timeout 1 "ret='0'" {} timeout abort
205
+	} timeout abort
206
+}
207
+
208
+

+ 35
- 0
scripts/upgrade.sh Ver arquivo

@@ -0,0 +1,35 @@
1
+#!/bin/sh
2
+set -e
3
+
4
+src_tarball=$(ls /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" -a -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"

Carregando…
Cancelar
Salvar