Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore Salt exit codes #705

Open
tacerus opened this issue Jun 16, 2023 · 0 comments
Open

Ignore Salt exit codes #705

tacerus opened this issue Jun 16, 2023 · 0 comments

Comments

@tacerus
Copy link
Contributor

tacerus commented Jun 16, 2023

Hi,

I wrote a test like the following:

def test_salt_state_apply_test(host):
    result = host.salt('state.apply', ['suse_ha', 'test=True'])
    changed, changes = find_changes(result, True)
    assert changed

The Salt command returns exit code 1 (or 2, with --retcode-passthrough) - this is expected by me, and I further analyze the validity of the result using my custom logic (find_changes, in this example).
However, Pytest does not execute my logic, as it immediately aborts the test after host.salt returns:

    def test_salt_state_apply_test(host):
>       result = host.salt('state.apply', ['suse_ha', 'test=True'])

suse_ha-formula/tests/test_00_salt.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.10/site-packages/testinfra/modules/salt.py:49: in __call__
    return json.loads(self.check_output(cmd, *cmd_args))["local"]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'testinfra.modules.base.Salt'>, args = ('salt-call --out=json %s %s %s', 'state.apply', 'suse_ha', 'test=True'), kwargs = {}

    @classmethod
    def check_output(cls, *args, **kwargs):
>       return cls._host.check_output(*args, **kwargs)

< lots of output from Salt >

FAILED suse_ha-formula/tests/test_00_salt.py::test_salt_state_apply_test[paramiko://test-ha-minion-01] - AssertionError: Unexpected exit code 1 for CommandResult(command=b"sudo /bin/sh -c 'salt-call --out=json state.apply suse_ha test=True'", exit_status=1, stdout=b'{\n    "local"...

Is there a way to ignore or whitelist "bad" exit codes and to continue my test function?
I only found run_expect in the documentation, but would preferably continue using the Salt module.

It seems the issue is with check_output having 0 defined as its only acceptable return code:

assert out.rc == 0, "Unexpected exit code {} for {}".format(out.rc, out)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant