Skip to content

SystemdService.exists fails with an error due to a malformed command #757

@mcdonnnj

Description

@mcdonnnj

The command being run by SystemdService.exists:

cmd = self.run_test('systemctl list-unit-files | grep -q"^%s"', self.name)

does not run successfully as it appears to be malformed. When attempting to use it in a molecule test configuration the following error is seen:

E       AssertionError: Unexpected exit code 2 for CommandResult(backend=<testinfra.backend.docker.DockerBackend object at 0x7f792dec0a70>, exit_status=2, command=b'systemctl list-unit-files | grep -q"^systemd-binfmt"', _stdout=b'', _stderr=b"grep: invalid option -- '^'\nUsage: grep [OPTION]... PATTERNS [FILE]...\nTry 'grep --help' for more information.\n")
E       assert 2 in [0, 1]
E        +  where 2 = CommandResult(backend=<testinfra.backend.docker.DockerBackend object at 0x7f792dec0a70>, exit_status=2, command=b'syst...=b"grep: invalid option -- '^'\nUsage: grep [OPTION]... PATTERNS [FILE]...\nTry 'grep --help' for more information.\n").rc

I verified that I receive the same error if I login to a running test container:

root@debian12-systemd:/# systemctl list-unit-files | grep -q"^systemd-binfmt"
grep: invalid option -- '^'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
root@debian12-systemd:/# systemctl list-unit-files | grep -q "^systemd-binfmt"
root@debian12-systemd:/# echo $?
0

It appears that #754 fixes this issue in addition to adding testing as verified by both the tests in that PR and my own double-check in the same molecule container:

root@debian12-systemd:/# systemctl list-units --all | grep -q "^[[:space:]]*systemd-binfmt"
root@debian12-systemd:/# echo $?
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions