This project consists of a number of Python files that contain common function libraries and classes for connecting to and operating in a MySQL database and Mysql replication set.
- Prerequisites
- Installation
- Pip Installation
- Testing
- Unit
- Integration
-
List of Linux packages that need to be installed on the server via git.
- git
- python-pip
-
Local class/library dependencies within the program structure.
- lib/machine
- lib/gen_libs
- From here on out, any reference to {Python_Project} or PYTHON_PROJECT replace with the baseline path of the python program.
- Replace {Other_Python_Project} with the baseline path of another python program.
Create requirements-mysql-lib.txt file and requirements-python-lib.txt files:
cd {Python_Project}
cp requirements-mysql-lib.txt > {Other_Python_Project}/requirements-mysql-lib.txt
cp requirements-python-lib.txt > {Other_Python_Project}/requirements-python-lib.txt
Modify the other program's README.md file to add the pip commands under the "Install supporting classes and libraries" section.
Modify the {Other_Python_Project}/README.md file:
pip install -r requirements-mysql-lib.txt --target mysql_lib --system
pip install -r requirements-python-lib.txt --target mysql_lib/lib --system
Add the general Mysql-Lib requirements to the other program's requirements.txt file. Remove any duplicates.
Add/modify the following lines to the {Other_Python_Project}/requirements.txt file:
mysql-connector-python==8.0.16
simplejson==2.0.9
Install the project using git.
umask 022
cd {Python_Project}
git clone git@github.com:deepcoder42/mysql-lib.git
Install/upgrade system modules.
cd mysql-lib
sudo bash
umask 022
pip install -r requirements.txt --upgrade --system
exit
cd {Python_Project}/mysql-lib
test/unit/mysql_libs/unit_test_run.sh
test/unit/mysql_class/unit_test_run.sh
cd {Python_Project}/mysql-lib
test/unit/mysql_libs/code_coverage.sh
test/unit/mysql_class/code_coverage.sh
NOTE: Integration testing will require access to a MySQL database server.
Install the project using the procedures in the Unit Testing - Installation section.
Create MySQL configuration file.
Make the appropriate change to the environment.
-
Change these entries in the MySQL setup:
- user = "USER"
- japd = "PSWORD"
- host = "HOST_IP"
- name = "HOST_NAME"
- sid = SERVER_ID
- extra_def_file = "PYTHON_PROJECT/config/mysql.cfg"
- cfg_file = "DIRECTORY_PATH/my.cnf"
- ssl_disabled = True
- ssl_verify_id = True
- ssl_verify_cert = True
-
Change these entries only if required:
- serv_os = "Linux"
- port = 3306
cd test/integration/config
cp mysql_cfg.py.TEMPLATE mysql_cfg.py
vim mysql_cfg.py
chmod 600 mysql_cfg.py
Create MySQL definition file.
Make the appropriate change to the environment.
- Change these entries in the MySQL definition file:
- password="PASSWORD"
- socket=DIRECTORY_PATH/mysql.sock
cp mysql.cfg.TEMPLATE mysql.cfg
vim mysql.cfg
chmod 600 mysql.cfg
cd {Python_Project}/mysql-lib
test/integration/mysql_libs/integration_test_run.sh
test/integration/mysql_class/integration_test_run.sh
cd {Python_Project}/mysql-lib
test/integration/mysql_libs/code_coverage.sh
test/integration/mysql_class/code_coverage.sh
This section requires the database being tested to be a master database in a MySQL replica set. Will include all previous testing units.
Create MySQL configuration file.
Make the appropriate change to the environment.
-
Change these entries in the MySQL setup:
- user = "USER"
- japd = "PSWORD"
- rep_user = "REP_USER"
- rep_japd = "REP_PSWORD"
- host = "HOST_IP"
- name = "HOST_NAME"
- sid = SERVER_ID
- extra_def_file = "PYTHON_PROJECT/config/mysql.cfg"
- cfg_file = "DIRECTORY_PATH/my.cnf"
-
Change these entries only if required:
- serv_os = "Linux"
- port = 3306
cd test/integration/config
cp mysql_cfg.py.TEMPLATE master_mysql_cfg.py
vim master_mysql_cfg.py
chmod 600 master_mysql_cfg.py
Create MySQL definition file.
Make the appropriate change to the environment.
- Change these entries in the MySQL definition file:
- password="PASSWORD"
- socket=DIRECTORY_PATH/mysql.sock
cp mysql.cfg.TEMPLATE mysql.cfg
vim mysql.cfg
chmod 600 mysql.cfg
cd {Python_Project}/mysql-lib
test/integration/mysql_class/rep_integration_test_run.sh
cd {Python_Project}/mysql-lib
test/integration/mysql_class/rep_code_coverage.sh
This section requires the database being tested to be a slave database in a MySQL replica set.
Testing will also require a master_mysql_cfg.py file to be present in the config directory. See above for details on creating one.
Create MySQL configuration file.
Make the appropriate change to the environment.
-
Change these entries in the MySQL setup:
- user = "USER"
- japd = "PSWORD"
- rep_user = "REP_USER"
- rep_japd = "REP_PSWORD"
- host = "HOST_IP"
- name = "HOST_NAME"
- sid = SERVER_ID
- extra_def_file = "PYTHON_PROJECT/config/mysql.cfg"
- cfg_file = "DIRECTORY_PATH/my.cnf"
-
Change these entries only if required:
- serv_os = "Linux"
- port = 3306
cd test/integration/config
cp mysql_cfg.py.TEMPLATE slave_mysql_cfg.py
vim slave_mysql_cfg.py
chmod 600 slave_mysql_cfg.py
Create MySQL definition file.
Make the appropriate change to the environment.
- Change these entries in the MySQL definition file:
- password="PASSWORD"
- socket=DIRECTORY_PATH/mysql.sock
cp mysql.cfg.TEMPLATE mysql.cfg
vim mysql.cfg
chmod 600 mysql.cfg
Create a MySQL slave configuration file.
Make the appropriate change to the environment.
-
Change these entries in the MySQL slave setup:
- user = USER
- japd = PSWORD
- rep_user = REP_USER
- rep_japd = REP_PSWORD
- host = HOST_IP
- name = HOSTNAME
- sid = SERVER_ID
-
Change these entries only if required:
- cfg_file = None
- serv_os = Linux
- port = 3306
-
NOTE: Create a new set of entries for each slave in the MySQL replica set.
cp slave.txt.TEMPLATE slave.txt
vim slave.txt
chmod 600 slave.txt
cd {Python_Project}/mysql-lib
test/integration/mysql_class/slaverep_integration_test_run.sh
cd {Python_Project}/mysql-lib
test/integration/mysql_class/slaverep_code_coverage.sh