Без опису
Ви не можете вибрати більше 25 тем Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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