# Common VZ5 kernel test procedures # This file is designed to be sourced from expect script namespace eval VZ5 { variable rows [stty rows] variable cols [stty columns] } # Procedure called on timeout # The expect main script must define VZ5::abort ordering the VM to stop proc abort {} { VZ5::abort } # Procedure called when abort fails to stop the VM # The expect main script must define VZ5::destroy proc destroy {} { VZ5::destroy } #  proc debug_interact {} { expect "[prompt]" { send " echo H4sIAAAAAAACA+OSjjY2zFXGB7iUFaSjc/mlo01zXVydQt0VPP1CXIMcnUM8w1wVgl2Dgz39/aAqQEZxETbM2Cg3oCi1uFghuaQoRztRIb9IIS5WoSRfITUvRQFmCkRdSUaqQjFQaWZ+HlhCARUQsA3kKi4uALzdLXnkAAAA|base64 -d|gzip -d\r" } interact { \001 { abort; } \x1d { abort; } } } proc vm_stty {} { expect "[prompt]" {send "stty -brkint -imaxbel iutf8 rows $::VZ5::rows cols $::VZ5::cols\r"} timeout destroy } proc termconfig {} { send_tty "\033\[?7h\033\[?4h" } #################### # Tests procedures # #################### # Wait for login prompt, and login as root without password # Calls stty to inform VM of terminal size proc login {} { send_log "\nPID : '[exp_pid]'\n" if { [exp_pid] == 0 } { destroy } set timeout 15 expect "Console: " { termconfig } timeout destroy expect { "$::VZ5::HOSTNAME login:" {} "FAIL" { expect "\r" expect "\r" { sleep 2; expect "login:" { send "root\r"; vm_stty; debug_interact; } timeout destroy } timeout destroy } timeout destroy } set timeout 5 if {[catch {send "root\r"} err]} { destroy } vm_stty } # Basics tests # - Checks date & time # - Check uname status code # - Checks /proc/cpuinfo # - Checks kernel clocksource kvm-clock support proc test_base {} { set timeout 2 expect "[prompt]" { send "date -Im\r" } timeout abort expect [system date -Im] {} timeout abort expect "[prompt]" { send "date\r" } timeout abort check_ret expect "[prompt]" { send "uname -a\r" } timeout abort check_ret expect { "[prompt]" { send "cat /proc/cpuinfo\r" } timeout abort "processor " {} timeout abort } expect "[prompt]" { send "cat /sys/devices/system/clocksource/clocksource0/current_clocksource\r" } timeout abort expect "kvm-clock" {} timeout abort } # Tests uname kernel version # Arguments : # - version : expected kernel version proc test_kernel_version {version} { set timeout 3 expect "[prompt]" { send "uname -r\r" } timeout abort expect "$version-kvmguest" {} timeout abort } # Testing swap support proc test_swap {} { set timeout 3 expect "[prompt]" { send "cat /proc/swaps | grep partition\r" } timeout abort expect "/dev/vd*" {} timeout abort expect { "[prompt]" { send "free -h\r" } timeout abort "Mem: " {} timeout abort "Swap: " {} timeout abort } } # Testing ssh daemon is running proc test_ssh {} { set timeout 3 expect { "[prompt]" { send "ps aux|grep sshd\r" } expect "*/usr/sbin/sshd -D \[listener\] *" timeout abort } } # Check for vz5 network address configuration proc test_vz5_netconfig {} { set timeout 3 expect { "[prompt]" { send "ip a\r" } "2: enp1s0: " {} timeout abort "inet 192.168.242." {} timeout abort "inet6 2001:41d0:203:10ae:1312::" {} timeout abort } } # Testing that apt runs proc test_apt {} { set timeout 30 expect "[prompt]" { send "apt update\r" } timeout abort check_ret expect "[prompt]" { send "apt -y dist-upgrade\r" } timeout abort check_ret } # Testing ping proc test_ping {} { set timeout 10 expect "[prompt]" { send "ping -c2 gnu.org\r" } timeout abort check_ret expect "[prompt]" { send "ping -4 -c2 gnu.org\r" } timeout abort check_ret } # Testing that vda is mounted rw proc test_vda_rw {} { set timeout 3 expect { "[prompt]" { send "grep '^rw' /proc/fs/ext4/vda/options\r" } timeout abort "rw" {} timeout abort } } # Reboot using systemctl and reboot proc test_reboot {} { expect "[prompt]" { send "# Rebooting in 2 seconds\r" } set timeout 30 expect "[prompt]" { sleep 2; send "systemctl reboot\r" } login expect "[prompt]" { send "reboot\r" } login } proc test_virsh_reboot {} { system virsh reboot test login } proc shutdown {} { set timeout 2 expect "[prompt]" { send "shutdown -h now\r" } set timeout 15 expect eof {} timeout destroy } # Return the expected prompt in order to expect it proc prompt {} { return "root@${::VZ5::HOSTNAME}:~#" } # Check that a command return a 0 status code proc check_ret {} { expect "[prompt]" { send "echo \"ret='$?'\"\r"; expect -timeout 1 "ret='0'" {} timeout abort } timeout abort }