Skip to content

Commit

Permalink
removed method read_job_pr_metadata
Browse files Browse the repository at this point in the history
- call read_job_metadata_from_file from tools/job_metadata.py
- moved one test from tests for EESSIBotSoftwareLayerJobManager to
  tests for tools/job_metadata.py
  • Loading branch information
truib committed Feb 10, 2024
1 parent 4f743a2 commit 7ed3d8d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
19 changes: 3 additions & 16 deletions eessi_bot_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,6 @@ def determine_finished_jobs(self, known_jobs, current_jobs):

return finished_jobs

def read_job_pr_metadata(self, job_metadata_path):
"""
Determine metadata od a job
Args:
job_metadata_path (string): path to job metadata file
Returns:
(ConfigParser): instance of ConfigParser corresponding to the 'PR'
section or None
"""
return read_job_metadata_from_file(job_metadata_path, self.logfile)

def read_job_result(self, job_result_file_path):
"""
Read job result file and return the contents of the 'RESULT' section.
Expand Down Expand Up @@ -345,7 +332,7 @@ def process_new_job(self, new_job):

# assuming that a bot job's working directory contains a metadata
# file, its existence is used to check if the job belongs to the bot
metadata_pr = self.read_job_pr_metadata(job_metadata_path)
metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile)

if metadata_pr is None:
log(f"No metadata file found at {job_metadata_path} for job {job_id}, so skipping it",
Expand Down Expand Up @@ -441,7 +428,7 @@ def process_running_jobs(self, running_job):
job_metadata_path = os.path.join(job_dir, metadata_file)

# check if metadata file exist
metadata_pr = self.read_job_pr_metadata(job_metadata_path)
metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile)
if metadata_pr is None:
raise Exception("Unable to find metadata file")

Expand Down Expand Up @@ -586,7 +573,7 @@ def process_finished_job(self, finished_job):
# obtain id of PR comment to be updated (from file '_bot_jobID.metadata')
metadata_file = f"_bot_job{job_id}.metadata"
job_metadata_path = os.path.join(new_symlink, metadata_file)
metadata_pr = self.read_job_pr_metadata(job_metadata_path)
metadata_pr = read_job_metadata_from_file(job_metadata_path, self.logfile)
if metadata_pr is None:
raise Exception("Unable to find metadata file ... skip updating PR comment")

Expand Down
24 changes: 0 additions & 24 deletions tests/test_eessi_bot_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,10 @@
#
# license: GPLv2
#
import os
import shutil

from eessi_bot_job_manager import EESSIBotSoftwareLayerJobManager


def test_read_job_pr_metadata(tmpdir):
# copy needed app.cfg from tests directory
shutil.copyfile("tests/test_app.cfg", "app.cfg")

# if metadata file does not exist, we should get None as return value
job_manager = EESSIBotSoftwareLayerJobManager()
path = os.path.join(tmpdir, 'test.metadata')
assert job_manager.read_job_pr_metadata(path) is None

with open(path, 'w') as fp:
fp.write('''[PR]
repo=test
pr_number=12345''')

metadata_pr = job_manager.read_job_pr_metadata(path)
expected = {
"repo": "test",
"pr_number": "12345",
}
assert metadata_pr == expected


def test_determine_running_jobs():
job_manager = EESSIBotSoftwareLayerJobManager()

Expand Down
34 changes: 34 additions & 0 deletions tests/test_tools_job_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Tests for 'tools/job_metadata.py' of the EESSI build-and-deploy bot,
# see https://github.com/EESSI/eessi-bot-software-layer
#
# The bot helps with requests to add software installations to the
# EESSI software layer, see https://github.com/EESSI/software-layer
#
# author: Thomas Roeblitz (@trz42)
#
# license: GPLv2
#

import os
import shutil

from tools.job_metadata import read_job_metadata_from_file


def test_read_job_metadata_from_file(tmpdir):
logfile = os.path.join(tmpdir, 'test_read_job_metadata_from_file.log')
# if metadata file does not exist, we should get None as return value
path = os.path.join(tmpdir, 'test.metadata')
assert read_job_metadata_from_file(path, logfile) is None

with open(path, 'w') as fp:
fp.write('''[PR]
repo=test
pr_number=12345''')

metadata_pr = read_job_metadata_from_file(path, logfile)
expected = {
"repo": "test",
"pr_number": "12345",
}
assert metadata_pr == expected

0 comments on commit 7ed3d8d

Please sign in to comment.