test_actions.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. # Define some variables
  3. source /etc/profile.d/vesta.sh
  4. V_BIN="$VESTA/bin"
  5. V_TEST="$VESTA/test"
  6. # Define functions
  7. random() {
  8. MATRIX='0123456789'
  9. LENGTH=$1
  10. while [ ${n:=1} -le $LENGTH ]; do
  11. rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  12. let n+=1
  13. done
  14. echo "$rand"
  15. }
  16. echo_result() {
  17. echo -en "$1"
  18. echo -en '\033[60G'
  19. echo -n '['
  20. if [ "$2" -ne 0 ]; then
  21. echo -n 'FAILED'
  22. echo -n ']'
  23. echo -ne '\r\n'
  24. echo ">>> $4"
  25. echo ">>> RETURN VALUE $2"
  26. cat $3
  27. else
  28. echo -n ' OK '
  29. echo -n ']'
  30. fi
  31. echo -ne '\r\n'
  32. }
  33. # Create random username
  34. user="tmp_$(random 4)"
  35. while [ ! -z "$(grep "^$user:" /etc/passwd)" ]; do
  36. user="tmp_$(random 4)"
  37. done
  38. # Create random tmpfile
  39. tmpfile=$(mktemp -p /tmp )
  40. # Add new user
  41. cmd="v_add_user $user $user $user@vestacp.com default Super Test"
  42. $cmd > $tmpfile 2>> $tmpfile
  43. echo_result "Adding new user $user" "$?" "$tmpfile" "$cmd"
  44. # Change system shell
  45. cmd="v_change_user_shell $user bash"
  46. $cmd > $tmpfile 2>> $tmpfile
  47. echo_result "Changing system shell to /bin/bash" "$?" "$tmpfile" "$cmd"
  48. # Change name servers
  49. cmd="v_change_user_ns $user ns0.com ns1.com ns2.com ns3.com"
  50. $cmd > $tmpfile 2>> $tmpfile
  51. echo_result "Changing nameservers" "$?" "$tmpfile" "$cmd"
  52. # Add cron job
  53. cmd="v_add_cron_job $user 1 1 1 1 1 echo"
  54. $cmd > $tmpfile 2>> $tmpfile
  55. echo_result "Adding cron job" "$?" "$tmpfile" "$cmd"
  56. # Suspend cron job
  57. cmd="v_suspend_cron_job $user 1"
  58. $cmd > $tmpfile 2>> $tmpfile
  59. echo_result "Suspending cron job" "$?" "$tmpfile" "$cmd"
  60. # Unsuspend cron job
  61. cmd="v_unsuspend_cron_job $user 1"
  62. $cmd > $tmpfile 2>> $tmpfile
  63. echo_result "Unsuspending cron job" "$?" "$tmpfile" "$cmd"
  64. # Delete cron job
  65. cmd="v_delete_cron_job $user 1"
  66. $cmd > $tmpfile 2>> $tmpfile
  67. echo_result "Deleting cron job" "$?" "$tmpfile" "$cmd"
  68. # Add cron job
  69. cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
  70. $cmd > $tmpfile 2>> $tmpfile
  71. echo_result "Adding cron job" "$?" "$tmpfile" "$cmd"
  72. # Add cron job
  73. cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
  74. $cmd > $tmpfile 2>> $tmpfile
  75. if [ "$?" -eq 4 ]; then
  76. retval=0
  77. else
  78. retval=1
  79. fi
  80. echo_result "Dublicate cron job check" "$retval" "$tmpfile" "$cmd"
  81. # List network interfaces
  82. cmd="v_list_sys_interfaces plain"
  83. interface=$($cmd 2> $tmpfile | head -n 1)
  84. if [ -z "$interface" ]; then
  85. echo_result "Listing network interfaces" "1" "$tmpfile" "$cmd"
  86. else
  87. echo_result "Listing network interfaces" "0" "$tmpfile" "$cmd"
  88. fi
  89. # Add new ip address
  90. cmd="v_add_sys_ip 198.18.0.123 255.255.255.255 $interface $user"
  91. $cmd > $tmpfile 2>> $tmpfile
  92. echo_result "Adding ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  93. # Delete ip address
  94. cmd="v_delete_sys_ip 198.18.0.123"
  95. $cmd > $tmpfile 2>> $tmpfile
  96. echo_result "Deleting ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  97. # Delete new user
  98. cmd="v_delete_user $user"
  99. $cmd > $tmpfile 2>> $tmpfile
  100. echo_result "Deleting user $user" "$?" "$tmpfile" "$cmd"