123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- # 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: <BROADCAST,MULTICAST,UP,LOWER_UP>" {} 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
- }
-
|