Skip to content

Commit 05b710c

Browse files
committed
Refactor code
1 parent 92280bb commit 05b710c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2526
-4403
lines changed

.idea/misc.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/pxc-qa.iml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 0 additions & 158 deletions
This file was deleted.

base_test.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import argparse
2+
3+
from config import WORKDIR, NODE, PT_BASEDIR, BASEDIR, SERVER, PXC_LOWER_BASE, PXC_UPPER_BASE
4+
from util import pxc_startup, ps_startup
5+
from util.utility import *
6+
7+
workdir = WORKDIR
8+
pt_basedir = PT_BASEDIR
9+
server = SERVER
10+
11+
# Read argument
12+
parser = argparse.ArgumentParser(prog='PXC test', usage='%(prog)s [options]')
13+
parser.add_argument('-e', '--encryption-run', action='store_true',
14+
help='This option will enable encryption options')
15+
parser.add_argument('-d', '--debug', action='store_true',
16+
help='This option will enable debug logging')
17+
18+
args = parser.parse_args()
19+
encryption = 'NO'
20+
if args.encryption_run is True:
21+
encryption = 'YES'
22+
23+
debug = 'NO'
24+
if args.debug is True:
25+
debug = 'YES'
26+
27+
utility_cmd = Utility(debug)
28+
utility_cmd.check_python_version()
29+
version = utility_cmd.version_check(BASEDIR)
30+
lower_version = get_mysql_version(PXC_LOWER_BASE)
31+
upper_version = get_mysql_version(PXC_UPPER_BASE)
32+
low_version_num = utility_cmd.version_check(PXC_LOWER_BASE)
33+
high_version_num = utility_cmd.version_check(PXC_UPPER_BASE)
34+
db = "test"
35+
36+
37+
class BaseTest:
38+
def __init__(self, number_of_nodes: int = int(NODE),
39+
wsrep_provider_options=None,
40+
my_extra=None,
41+
extra_config_file=None,
42+
init_extra=None,
43+
vers: Version = None,
44+
encrypt: bool = False,
45+
ssl: bool = False):
46+
self.__number_of_nodes = number_of_nodes
47+
self.__my_extra = my_extra
48+
self.__wsrep_provider_options = wsrep_provider_options
49+
self.__extra_config_file = extra_config_file
50+
self.__init_extra = init_extra
51+
self.__version = vers
52+
self.encrypt = encrypt
53+
self.ssl = ssl
54+
self.pxc_nodes: list[DbConnection] = None
55+
self.node1: DbConnection = None
56+
self.node2: DbConnection = None
57+
self.node3: DbConnection = None
58+
self.ps_nodes: list[DbConnection] = None
59+
60+
def start_pxc(self, my_extra: str = None, custom_conf_settings: dict = None,
61+
terminate_on_startup_failure: bool = True):
62+
if my_extra is not None:
63+
my_extra_options = my_extra
64+
else:
65+
my_extra_options = self.__my_extra
66+
67+
# Start PXC cluster for ChaosMonkey test
68+
server_startup = pxc_startup.StartCluster(self.__number_of_nodes, debug, self.__version)
69+
server_startup.sanity_check()
70+
if encryption == 'YES' or self.encrypt:
71+
server_startup.create_config('encryption', self.__wsrep_provider_options,
72+
custom_conf_settings=custom_conf_settings)
73+
elif self.ssl:
74+
server_startup.create_config('ssl', self.__wsrep_provider_options,
75+
custom_conf_settings=custom_conf_settings)
76+
else:
77+
server_startup.create_config('none', self.__wsrep_provider_options,
78+
custom_conf_settings=custom_conf_settings)
79+
server_startup.initialize_cluster()
80+
if self.__extra_config_file is not None:
81+
server_startup.add_myextra_configuration(self.__extra_config_file)
82+
self.pxc_nodes = server_startup.start_cluster(my_extra_options, terminate_on_startup_failure)
83+
if len(self.pxc_nodes) == self.__number_of_nodes:
84+
self.node1 = self.pxc_nodes[0]
85+
self.node2 = self.pxc_nodes[1]
86+
self.node3 = self.pxc_nodes[2]
87+
self.node1.test_connection_check()
88+
else:
89+
print("Some problem while setting up cluster nodes. Not all nodes seems in healthy state")
90+
print("Number of nodes: " + str(len(self.pxc_nodes)))
91+
if terminate_on_startup_failure:
92+
exit(1)
93+
if debug == 'YES':
94+
for node in self.pxc_nodes:
95+
print("node is " + node.get_socket())
96+
# atexit.register(shutdown_nodes(self.node))
97+
98+
def start_ps(self, my_extra=None):
99+
""" Start Percona Server. This method will
100+
perform sanity checks for PS startup
101+
"""
102+
# Start PXC cluster for replication test
103+
if my_extra is not None:
104+
my_extra_options = my_extra
105+
else:
106+
my_extra_options = self.__my_extra
107+
server_startup = ps_startup.StartPerconaServer(self.__number_of_nodes, debug, self.__version)
108+
server_startup.test_sanity_check()
109+
if encryption == 'YES':
110+
server_startup.create_config('encryption')
111+
else:
112+
server_startup.create_config()
113+
server_startup.initialize_server()
114+
if self.__extra_config_file is not None:
115+
server_startup.add_myextra_configuration(self.__extra_config_file)
116+
self.ps_nodes = server_startup.start_server(my_extra_options)
117+
118+
def shutdown_nodes(self, nodes=None):
119+
if nodes is None:
120+
nodes = self.pxc_nodes
121+
for node in nodes:
122+
node.shutdown()
123+
124+
def set_extra_conf_file(self, conf_file):
125+
self.__extra_config_file = conf_file
126+
127+
def set_wsrep_provider_options(self, options):
128+
self.__wsrep_provider_options = options
129+
130+
def set_number_of_nodes(self, number_of_nodes: int):
131+
self.__number_of_nodes = number_of_nodes
132+
133+
def get_number_of_nodes(self):
134+
return self.__number_of_nodes

config.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ basedir = /dev/shm/qa/PXC_tarball
44
server=pxc
55
node = 3
66
user = root
7-
ps1_socket = /tmp/psnode1.sock
8-
ps2_socket = /tmp/psnode2.sock
9-
ps3_socket = /tmp/psnode3.sock
107
pt_basedir = /dev/shm/qa/percona-toolkit-3.0.10
118
pstress_bin = /dev/shm/qa/pstress/src/pstress-pxc
129
pstress_grammar_file = /dev/shm/qa/pstress/src/grammar.sql

config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
SERVER = config['config']['server']
1010
NODE = config['config']['node']
1111
USER = config['config']['user']
12-
PS1_SOCKET = config['config']['ps1_socket']
13-
PS2_SOCKET = config['config']['ps2_socket']
14-
PS3_SOCKET = config['config']['ps3_socket']
1512
PT_BASEDIR = config['config']['pt_basedir']
1613
PSTRESS_BIN = config['config']['pstress_bin']
1714
PSTRESS_GRAMMAR_FILE = config['config']['pstress_grammar_file']

0 commit comments

Comments
 (0)