Skip to content

Commit

Permalink
Use /usr/bin/test command instead of shell evaluation
Browse files Browse the repository at this point in the history
Replace direct shell evaluation with `/usr/bin/test` command to bypass
confusing output in logs:

shell evaluation output:
```
  Executed command '[ -f /etc/bluechi/controller.conf.d/ctrl.conf ] && echo 'exists'' with result '2' and output '[: missing ']''
```

/usr/bin/test command output:
```
  Executed command '/usr/bin/test -f /etc/bluechi/controller.conf.d/ctrl.conf' with result '1' and output 'b'''
```

Signed-off-by: Martin Perina <mperina@redhat.com>
  • Loading branch information
mwperina committed Aug 12, 2024
1 parent 2e8d273 commit dae822d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/bluechi_test/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(self, name: str, client: Client) -> None:
def create_file(self, target_dir: str, file_name: str, content: str) -> None:
target_file = os.path.join(target_dir, file_name)
try:
_, output = self.client.exec_run(f"[ -f {target_file} ] && echo 'exists'")
if output == "exists":
res, _ = self.client.exec_run(f"/usr/bin/test -f {target_file}")
if res == 0:
self._track_changed_file(target_dir, file_name)
else:
self.created_files.append(os.path.join(target_dir, file_name))
Expand Down Expand Up @@ -173,8 +173,8 @@ def copy_machine_lib(self):
return

machine_lib_dir = "/tmp/bluechi_machine_lib"
_, output = self.client.exec_run(f"[ -d {machine_lib_dir} ] && echo 'exists'")
if output != "exists":
res, _ = self.client.exec_run(f"/usr/bin/test -d {machine_lib_dir}")
if res != 0:
self.exec_run(f"mkdir {machine_lib_dir}")
for filename in os.listdir(source_dir):
source_path = os.path.join(source_dir, filename)
Expand Down

0 comments on commit dae822d

Please sign in to comment.