Skip to content

Commit 8e14bd2

Browse files
committed
Fix py move-results to use ConfigParser
The Python 3 based "move-results" code was using the old `configtools` module instead of just using `ConfigParser` directly. This would end up causing failures in the unit tests because it was calling the `parse_args` method of `configtools` to first parse the command line arguments. But in principle, we never want to access the command line arguments while running unit tests. The unit test should provide them for the method under test to properly ensure the correct behavior is tested. We simply replace the use of `configtools` with `ConfigParser` directly, which ends up simplifying the code as well. Further, using configtools just for the result directory `metadata.log` is over kill, because `configtools` was there to support multiple configuration files, and there is only one `metadata.log` file. We remove the `SETUP` and `TEARDOWN` messages since they are really debugging statements and have no business being there for normal test operation.
1 parent 28cb5b1 commit 8e14bd2

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

lib/pbench/agent/results.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import sys
66
import tarfile
77

8+
from configparser import ConfigParser
89
from pathlib import Path
10+
911
from werkzeug.utils import secure_filename
1012

11-
from pbench.cli.agent.commands.log import add_metalog_option
12-
from pbench.common import configtools
1313
from pbench.common.utils import md5sum
1414

1515

@@ -62,18 +62,17 @@ def make_result_tb(self):
6262
)
6363
sys.exit(0)
6464

65+
mdlog_name = self.result_dir / "metadata.log"
66+
mdlog = ConfigParser()
6567
try:
66-
md_log = (self.result_dir / "metadata.log").resolve(strict=True)
68+
with mdlog_name.open("r") as fp:
69+
mdlog.read_file(fp)
6770
except FileNotFoundError:
6871
self.logger.debug(
6972
"The {}/metadata.log file seems to be missing", pbench_run_name
7073
)
7174
sys.exit(0)
72-
73-
opts, _ = configtools.parse_args()
74-
opts.filename = md_log
75-
conf_md, _ = configtools.init(opts, None)
76-
md_config = conf_md["pbench"]
75+
md_config = mdlog["pbench"]
7776
res_name = md_config.get("name")
7877
if res_name != pbench_run_name:
7978
self.logger.warning(
@@ -85,22 +84,23 @@ def make_result_tb(self):
8584
sys.exit(1)
8685

8786
if self.user:
88-
add_metalog_option(md_log, "run", "user", self.user)
87+
mdlog.set("run", "user", self.user)
8988

9089
if self.prefix:
91-
add_metalog_option(md_log, "run", "prefix", self.prefix)
90+
mdlog.set("run", "prefix", self.prefix)
9291

9392
# FIXME: subprocess "du" command
9493
result_size = sum(f.stat().st_size for f in self.result_dir.rglob("*"))
9594
self.logger.debug(
9695
"preparing to tar up {} bytes of data from {}", result_size, self.result_dir
9796
)
98-
add_metalog_option(md_log, "run", "raw_size", f"{result_size}")
97+
mdlog.set("run", "raw_size", f"{result_size}")
9998

10099
timestamp = datetime.datetime.isoformat(datetime.datetime.now())
101-
add_metalog_option(
102-
md_log, "pbench", "tar-ball-creation-timestamp", f"{timestamp}"
103-
)
100+
mdlog.set("pbench", "tar-ball-creation-timestamp", f"{timestamp}")
101+
102+
with mdlog_name.open("w") as fp:
103+
mdlog.write(fp)
104104

105105
# FIXME: subprocess "tar" command
106106
tarball = self.target_dir / f"{pbench_run_name}.tar.xz"

lib/pbench/test/unit/agent/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
def base_setup(request, pytestconfig):
99
"""Test package setup for pbench-agent"""
10-
print("Test SETUP for pbench-agent")
1110

1211
# Create a single temporary directory for the "/opt/pbench-agent" and
1312
# "/var/lib/pbench-agent" directories.
@@ -32,7 +31,6 @@ def base_setup(request, pytestconfig):
3231

3332
def teardown():
3433
"""Test package teardown for pbench-agent"""
35-
print("Test TEARDOWN for pbench-agent")
3634
TMP.cleanup()
3735

3836
request.addfinalizer(teardown)

lib/pbench/test/unit/server/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
@pytest.fixture(scope="session", autouse=True)
3838
def setup(request, pytestconfig):
3939
"""Test package setup for pbench-server"""
40-
print("\nTest SETUP for pbench-server")
4140

4241
# Create a single temporary directory for the "/srv/pbench" and
4342
# "/opt/pbench-server" directories.
@@ -75,7 +74,6 @@ def setup(request, pytestconfig):
7574

7675
def teardown():
7776
"""Test package teardown for pbench-server"""
78-
print("\nTest TEARDOWN for pbench-server")
7977
TMP.cleanup()
8078

8179
request.addfinalizer(teardown)

0 commit comments

Comments
 (0)