Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ParveezBaig committed Oct 30, 2024
1 parent 92280bb commit 05b710c
Show file tree
Hide file tree
Showing 49 changed files with 2,526 additions and 4,403 deletions.
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/pxc-qa.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 0 additions & 158 deletions .idea/workspace.xml

This file was deleted.

134 changes: 134 additions & 0 deletions base_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import argparse

from config import WORKDIR, NODE, PT_BASEDIR, BASEDIR, SERVER, PXC_LOWER_BASE, PXC_UPPER_BASE
from util import pxc_startup, ps_startup
from util.utility import *

workdir = WORKDIR
pt_basedir = PT_BASEDIR
server = SERVER

# Read argument
parser = argparse.ArgumentParser(prog='PXC test', usage='%(prog)s [options]')
parser.add_argument('-e', '--encryption-run', action='store_true',
help='This option will enable encryption options')
parser.add_argument('-d', '--debug', action='store_true',
help='This option will enable debug logging')

args = parser.parse_args()
encryption = 'NO'
if args.encryption_run is True:
encryption = 'YES'

debug = 'NO'
if args.debug is True:
debug = 'YES'

utility_cmd = Utility(debug)
utility_cmd.check_python_version()
version = utility_cmd.version_check(BASEDIR)
lower_version = get_mysql_version(PXC_LOWER_BASE)
upper_version = get_mysql_version(PXC_UPPER_BASE)
low_version_num = utility_cmd.version_check(PXC_LOWER_BASE)
high_version_num = utility_cmd.version_check(PXC_UPPER_BASE)
db = "test"


class BaseTest:
def __init__(self, number_of_nodes: int = int(NODE),
wsrep_provider_options=None,
my_extra=None,
extra_config_file=None,
init_extra=None,
vers: Version = None,
encrypt: bool = False,
ssl: bool = False):
self.__number_of_nodes = number_of_nodes
self.__my_extra = my_extra
self.__wsrep_provider_options = wsrep_provider_options
self.__extra_config_file = extra_config_file
self.__init_extra = init_extra
self.__version = vers
self.encrypt = encrypt
self.ssl = ssl
self.pxc_nodes: list[DbConnection] = None
self.node1: DbConnection = None
self.node2: DbConnection = None
self.node3: DbConnection = None
self.ps_nodes: list[DbConnection] = None

def start_pxc(self, my_extra: str = None, custom_conf_settings: dict = None,
terminate_on_startup_failure: bool = True):
if my_extra is not None:
my_extra_options = my_extra
else:
my_extra_options = self.__my_extra

# Start PXC cluster for ChaosMonkey test
server_startup = pxc_startup.StartCluster(self.__number_of_nodes, debug, self.__version)
server_startup.sanity_check()
if encryption == 'YES' or self.encrypt:
server_startup.create_config('encryption', self.__wsrep_provider_options,
custom_conf_settings=custom_conf_settings)
elif self.ssl:
server_startup.create_config('ssl', self.__wsrep_provider_options,
custom_conf_settings=custom_conf_settings)
else:
server_startup.create_config('none', self.__wsrep_provider_options,
custom_conf_settings=custom_conf_settings)
server_startup.initialize_cluster()
if self.__extra_config_file is not None:
server_startup.add_myextra_configuration(self.__extra_config_file)
self.pxc_nodes = server_startup.start_cluster(my_extra_options, terminate_on_startup_failure)
if len(self.pxc_nodes) == self.__number_of_nodes:
self.node1 = self.pxc_nodes[0]
self.node2 = self.pxc_nodes[1]
self.node3 = self.pxc_nodes[2]
self.node1.test_connection_check()
else:
print("Some problem while setting up cluster nodes. Not all nodes seems in healthy state")
print("Number of nodes: " + str(len(self.pxc_nodes)))
if terminate_on_startup_failure:
exit(1)
if debug == 'YES':
for node in self.pxc_nodes:
print("node is " + node.get_socket())
# atexit.register(shutdown_nodes(self.node))

def start_ps(self, my_extra=None):
""" Start Percona Server. This method will
perform sanity checks for PS startup
"""
# Start PXC cluster for replication test
if my_extra is not None:
my_extra_options = my_extra
else:
my_extra_options = self.__my_extra
server_startup = ps_startup.StartPerconaServer(self.__number_of_nodes, debug, self.__version)
server_startup.test_sanity_check()
if encryption == 'YES':
server_startup.create_config('encryption')
else:
server_startup.create_config()
server_startup.initialize_server()
if self.__extra_config_file is not None:
server_startup.add_myextra_configuration(self.__extra_config_file)
self.ps_nodes = server_startup.start_server(my_extra_options)

def shutdown_nodes(self, nodes=None):
if nodes is None:
nodes = self.pxc_nodes
for node in nodes:
node.shutdown()

def set_extra_conf_file(self, conf_file):
self.__extra_config_file = conf_file

def set_wsrep_provider_options(self, options):
self.__wsrep_provider_options = options

def set_number_of_nodes(self, number_of_nodes: int):
self.__number_of_nodes = number_of_nodes

def get_number_of_nodes(self):
return self.__number_of_nodes
3 changes: 0 additions & 3 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ basedir = /dev/shm/qa/PXC_tarball
server=pxc
node = 3
user = root
ps1_socket = /tmp/psnode1.sock
ps2_socket = /tmp/psnode2.sock
ps3_socket = /tmp/psnode3.sock
pt_basedir = /dev/shm/qa/percona-toolkit-3.0.10
pstress_bin = /dev/shm/qa/pstress/src/pstress-pxc
pstress_grammar_file = /dev/shm/qa/pstress/src/grammar.sql
Expand Down
3 changes: 0 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
SERVER = config['config']['server']
NODE = config['config']['node']
USER = config['config']['user']
PS1_SOCKET = config['config']['ps1_socket']
PS2_SOCKET = config['config']['ps2_socket']
PS3_SOCKET = config['config']['ps3_socket']
PT_BASEDIR = config['config']['pt_basedir']
PSTRESS_BIN = config['config']['pstress_bin']
PSTRESS_GRAMMAR_FILE = config['config']['pstress_grammar_file']
Expand Down
Loading

0 comments on commit 05b710c

Please sign in to comment.