Skip to content

Commit

Permalink
Refactor: cts: Get rid of apply_substitutions.
Browse files Browse the repository at this point in the history
This is no longer useful since all our substitutions are now being done
by f-strings.
  • Loading branch information
clumens committed Feb 5, 2025
1 parent 8264aaa commit fdf3cc0
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions cts/cts-cli.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ class PluralFormatter(Formatter):
return super().format_field(value, format_spec)


def apply_substitutions(s, extra=None):
"""Apply text substitutions to an input string and return it."""
substitutions = {
"cts_cli_data": "%s/cli" % test_home,
"shadow": SHADOW_NAME,
}

if extra is not None:
substitutions.update(extra)

return s.format(**substitutions)


def cleanup_shadow_dir():
"""Remove any previously created shadow CIB directory."""
subprocess.run(["crm_shadow", "--force", "--delete", SHADOW_NAME],
Expand All @@ -119,7 +106,7 @@ def copy_existing_cib(existing):
"""
(fp, new) = mkstemp(prefix="cts-cli.cib.xml.")
os.close(fp)
copyfile(apply_substitutions(existing), new)
copyfile(existing, new)
return new


Expand Down Expand Up @@ -209,7 +196,7 @@ def run_cmd_list(cmds):
if isinstance(c, types.FunctionType):
c()
else:
subprocess.run(apply_substitutions(c), stdout=subprocess.PIPE, stderr=subprocess.PIPE,
subprocess.run(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, universal_newlines=True, check=True)


Expand Down Expand Up @@ -316,9 +303,6 @@ def environ(env):
default, or given with a nested call to this context) by passing None for the
value. Additionally, this context manager accepts None for the env parameter,
in which case nothing will be done.
Finally, note that values in env will be passed to apply_substitutions before
being set in the environment.
"""
if env is None:
env = {}
Expand All @@ -330,7 +314,7 @@ def environ(env):
if v is None:
os.environ.pop(k)
else:
os.environ[k] = apply_substitutions(v)
os.environ[k] = v

try:
yield
Expand Down Expand Up @@ -358,15 +342,14 @@ class StdinCmd:
"""Create a new StdinCmd instance.
Arguments:
cmd -- The command string to run later. This string will be passed
to apply_substitutions before being executed.
cmd -- The command string to run later.
"""
self._cmd = cmd

def run(self):
"""Run this command, returning a subprocess.Popen object."""
return subprocess.Popen(apply_substitutions(self._cmd), shell=True,
encoding="utf-8", stdout=subprocess.PIPE)
return subprocess.Popen(self._cmd, shell=True, encoding="utf-8",
stdout=subprocess.PIPE)


class Test:
Expand All @@ -379,8 +362,7 @@ class Test:
Arguments:
desc -- A short human-readable description of this test
cmd -- The command to run for this test, as a string. This string
will be passed to apply_substitutions before being executed.
cmd -- The command to run for this test, as a string.
Keyword arguments:
expected_rc -- The expected return value of cmd
Expand Down Expand Up @@ -486,7 +468,7 @@ class Test:
"""
self._output = []

cmd = apply_substitutions(self.cmd)
cmd = self.cmd
app = cmd.split(" ")[0]

test_id = "%s(%s)" % (app, group)
Expand Down Expand Up @@ -581,7 +563,7 @@ class AclTest(Test):
"""
self._output = []

cmd = apply_substitutions(self.cmd)
cmd = self.cmd
app = cmd.split(" ")[0]

test_id = "%s(%s)" % (app, group)
Expand Down Expand Up @@ -2833,7 +2815,7 @@ class CrmMonRegressionTest(RegressionTest):
env={"CIB_file": f"{cts_cli_data}/crm_mon.xml"}),
Test("Check that CIB_file=\"-\" works", "crm_mon -1",
env={"CIB_file": "-"},
stdin=pathlib.Path(apply_substitutions(f"{cts_cli_data}/crm_mon.xml"))),
stdin=pathlib.Path(f"{cts_cli_data}/crm_mon.xml")),
TestGroup(partial_tests,
env={"CIB_file": f"{cts_cli_data}/crm_mon-partial.xml"}),
TestGroup(unmanaged_tests,
Expand Down

0 comments on commit fdf3cc0

Please sign in to comment.