説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

testlib.expect 4.5KB

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