Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny fixes in mysql checks #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/check_mysql_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ def parse_args():

return parser.parse_args()

def check_config_file(conf_fd):
Copy link
Contributor

@kofrezo kofrezo Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def check_config_file(conf_fd):
def check_config_file(conf_fd):
# Import configparser module on top
config = configparser.ConfigParser()
config.read_file(conf_fd)
return config.has_section('mysqld')

"""Check if the given config file is not empty and has a [mysqld] section"""
found_mysqld = False
for line in conf_fd:
if line.strip() == '[mysqld]':
found_mysqld = True
break
if found_mysqld:
for line in conf_fd:
if line.strip():
return True
return False

def main():
args = parse_args()
Expand All @@ -79,13 +91,9 @@ def main():
check_procs = []
for conf_file in args.conf_files:
with open(conf_file) as conf_fd:
for line in conf_fd:
if line.strip() == '[mysqld]':
break
else:
continue
proc = Popen(command + [conf_file], stdout=PIPE)
check_procs.append(proc)
if check_config_file(conf_fd):
proc = Popen(command + [conf_file], stdout=PIPE)
check_procs.append(proc)

# Wait for all check processes to finish
exit_code = max(p.wait() for p in check_procs)
Expand Down