bstinson / centos / t_functional

Forked from centos/t_functional 4 years ago
Clone

Blame tests/p_python/20-python-mysql-test.sh

Christoph Galuschka 518959
#!/bin/sh
Christoph Galuschka 518959
# Author: Athmane Madjoudj <athmanem@gmail.com>
Christoph Galuschka 518959
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka 518959
Christoph Galuschka 518959
t_Log "Running $0 - python can retrieve mysql-server version information."
Christoph Galuschka 518959
Pablo Greco aee784
if [ "$centos_ver" -ge 8 ] ; then
Pablo Greco aee784
PYTHON=python3
Pablo Greco aee784
else
Pablo Greco aee784
PYTHON=python
Pablo Greco aee784
fi
Christoph Galuschka 518959
# we need a working and running mysql server
Christoph Galuschka 269271
# starting with 5.10, we have to differ between mysql55 and mysql
e848a7
Pablo Greco aee784
if [ "$centos_ver" -ge 7 ] ; then
e848a7
  my_packages="mariadb mariadb-server nc"
e848a7
  mysql_service="mariadb"
e848a7
elif [ "$centos_ver" = "5" ] ;then
e848a7
  my_packages="mysql mysql-server nc mysql55-mysql-server"
e848a7
  mysql_service="mysqld"
Christoph Galuschka 269271
else
e848a7
  my_packages="mysql mysql-server nc"
e848a7
  mysql_service="mysqld"
Christoph Galuschka 269271
fi
e848a7
e848a7
t_ServiceControl ${mysql_service} start >/dev/null 2>&1
Christoph Galuschka 518959
Christoph Galuschka 518959
# Installing additional python/mysql module
Pablo Greco aee784
if [ "$centos_ver" -ge 8 ] ; then
Pablo Greco aee784
t_InstallPackage python3-PyMySQL
Pablo Greco aee784
importcomponent="pymysql"
Pablo Greco aee784
else
Christoph Galuschka 518959
t_InstallPackage MySQL-python
Pablo Greco aee784
importcomponent="MySQLdb"
Pablo Greco aee784
fi
Christoph Galuschka 518959
Christoph Galuschka 518959
# create python Scrip
Christoph Galuschka 518959
SCRIPT='/var/tmp/test.py'
Christoph Galuschka 518959
Christoph Galuschka 518959
cat >$SCRIPT <
Pablo Greco aee784
import $importcomponent
Christoph Galuschka 518959
Pablo Greco aee784
conn = $importcomponent.connect (host = "localhost",
Christoph Galuschka 518959
                           user = "",
Christoph Galuschka 518959
                           passwd = "",
Pablo Greco aee784
                           db = "")
Christoph Galuschka 518959
cursor = conn.cursor ()
Christoph Galuschka 518959
cursor.execute ("SELECT VERSION()")
Christoph Galuschka 518959
row = cursor.fetchone ()
Pablo Greco aee784
print ("server version:", row[0])
Christoph Galuschka 518959
cursor.close ()
Christoph Galuschka 518959
conn.close ()
Christoph Galuschka 518959
EOF
Christoph Galuschka 518959
Christoph Galuschka 518959
# If we execute the script and get the version it works
Pablo Greco aee784
$PYTHON $SCRIPT |grep -q 'server version'
Christoph Galuschka 518959
Christoph Galuschka 518959
t_CheckExitStatus $?
Christoph Galuschka 518959
Christoph Galuschka 518959
# cleaning up
Christoph Galuschka 518959
/bin/rm $SCRIPT