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

Add Thread ID to all BIH log messages #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
55 changes: 28 additions & 27 deletions src/docserv/bih.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ def __init__(self, build_instruction, config, gitLocks, gitLocksLock, thread_id)
self.cleanup_done = False
self.cleanup_lock = threading.Lock()

if self.validate(build_instruction, config):
if self.validate(build_instruction, config, thread_id):
self.initialized = True
self.build_instruction = build_instruction
if 'deliverables' in build_instruction:
self.deliverables = build_instruction['deliverables']
self.config = config
if not self.read_conf_dir():
if not self.read_conf_dir(thread_id):
self.initialized = False
return
self.git_lock = RepoLock(resource_to_filename(
self.remote_repo), thread_id, gitLocks, gitLocksLock)
self.prepare_repo(thread_id)
self.get_commit_hash()
self.get_commit_hash(thread_id)
else:
self.initialized = False
return
Expand Down Expand Up @@ -189,37 +189,37 @@ def mail(self, command, out, err):
subject = "[docserv²] Failed build preparation"
mail(msg, subject, to)

def read_conf_dir(self):
def read_conf_dir(self, thread_id):
"""
Use the docserv-stitch command to stitch all single XML configuration
files to a big config file. Then parse it and extract required information
for the current build instruction.
"""
target = self.build_instruction['target']
if not self.config['targets'][target]['active'] == "yes":
logger.debug("Target %s not active.", target)
logger.debug("Thread {}: Target {} not active.".format(thread_id, target))
return False
self.stitch_tmp_file = os.path.join(tempfile.mkdtemp(
prefix="docserv_stitch_"), 'docserv_config_full.xml')
logger.debug("Stitching XML config directory to %s",
self.stitch_tmp_file)
logger.debug("Thread {}: Stitching XML config directory to {}".format(
thread_id, self.stitch_tmp_file))
cmd = '%s --make-positive --valid-languages="%s" %s %s' % (
os.path.join(BIN_DIR, 'docserv-stitch'),
self.config['server']['valid_languages'],
self.config['targets'][target]['config_dir'],
self.stitch_tmp_file)
logger.debug("Stitching command: %s", cmd)
logger.debug("Thread {}: Stitching command: {}".format(thread_id, cmd))
cmd = shlex.split(cmd)
s = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
s.communicate()[0]
rc = int(s.returncode)
if rc == 0:
logger.debug("Stitching of %s successful",
self.config['targets'][target]['config_dir'])
logger.debug("Thread {}: Stitching of {} successful".format(
thread_id, self.config['targets'][target]['config_dir']))
else:
logger.warning("Stitching of %s failed!",
self.config['targets'][target]['config_dir'])
logger.warning("Thread {}: Stitching of {} failed!".format(
thread_id, self.config['targets'][target]['config_dir']))
self.initialized = False
return False

Expand All @@ -245,7 +245,8 @@ def read_conf_dir(self):
self.build_instruction['product'], self.build_instruction['docset'])
self.remote_repo = xml_root.find(xpath).text
except AttributeError:
logger.warning("Failed to parse xpath: %s", xpath)
logger.warning("Thread {}: Failed to parse xpath: {}".format(
thread_id, xpath))
return False

try:
Expand Down Expand Up @@ -314,16 +315,16 @@ def prepare_repo(self, thread_id):
out, err = s.communicate()
self.git_lock.release()
if commands[i]['ret_val'] is not None and not commands[i]['ret_val'] == int(s.returncode):
logger.warning("Build failed! Unexpected return value %i for '%s'",
s.returncode, commands[i]['cmd'])
logger.warning("Thread {}: Build failed! Unexpected return value {} for '{}'".format(
thread_id, s.returncode, commands[i]['cmd']))
self.mail(commands[i]['cmd'], out.decode(
'utf-8'), err.decode('utf-8'))
self.initialized = False
return False

return True

def get_commit_hash(self):
def get_commit_hash(self, thread_id):
"""
Extract HEAD commit hash from branch.
"""
Expand All @@ -333,42 +334,42 @@ def get_commit_hash(self):
stderr=subprocess.PIPE)
self.build_instruction['commit'] = s.communicate()[
0].decode('utf-8').rstrip()
logger.debug("Current commit hash: %s",
self.build_instruction['commit'])
logger.debug("Thread {}: Current commit hash: {}".format(
thread_id, self.build_instruction['commit']))

def validate(self, build_instruction, config):
def validate(self, build_instruction, config, thread_id):
"""
Validate completeness of build instruction. Format:
{'docset': '15ga', 'lang': 'en', 'product': 'sles', 'target': 'external'}
"""
#
if not isinstance(build_instruction, dict):
logger.warning("Validation: Is not a dict")
logger.warning("Thread {}: Validation: Is not a dict".format(thread_id))
return False
if not isinstance(build_instruction['docset'], str):
logger.warning("Validation: docset is not a string")
logger.warning("Thread {}: Validation: docset is not a string".format(thread_id))
return False
if not isinstance(build_instruction['lang'], str):
logger.warning("Validation: lang is not a string")
logger.warning("Thread {}: Validation: lang is not a string".format(thread_id))
return False
if not isinstance(build_instruction['product'], str):
logger.warning("Validation: product is not a string")
logger.warning("Thread {}: Validation: product is not a string".format(thread_id))
return False
if not isinstance(build_instruction['target'], str):
logger.warning("Validation: target is not a string")
logger.warning("Thread {}: Validation: target is not a string".format(thread_id))
return False
logger.debug("Valid build instruction: %s", build_instruction['id'])
logger.debug("Thread {}: Valid build instruction: {}".format(thread_id, build_instruction['id']))
return True

def generate_deliverables(self):
def generate_deliverables(self, thread_id):
"""
Iterate through delvierable elements in configuration and create
instances of the Deliverable class for each.
"""
if not self.initialized:
return False
xml_root = self.tree.getroot()
logger.debug("Generating deliverables.")
logger.debug("Thread {}: Generating deliverables.".format(thread_id))
xpath = ".//product[@productid='%s']/docset[@setid='%s']/builddocs/language[@lang='%s']/deliverable" % (
self.build_instruction['product'], self.build_instruction['docset'], self.build_instruction['lang'])
for xml_deliverable in xml_root.findall(xpath):
Expand Down
2 changes: 1 addition & 1 deletion src/docserv/docserv.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def parse_build_instruction(self, thread_id):
if myBIH.initialized == False:
self.abort_build_instruction(build_instruction['id'])
return
myBIH.generate_deliverables()
myBIH.generate_deliverables(thread_id)
self.remove_scheduled_build_instruction(build_instruction['id'])
with self.bih_dict_lock:
self.bih_dict[build_instruction['id']] = myBIH
Expand Down