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

[BUG] __opts__["test"] is not True in cross called state module when custom state is prereq target #63414

Closed
4 tasks
bdrx312 opened this issue Jan 4, 2023 · 2 comments
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@bdrx312
Copy link
Contributor

bdrx312 commented Jan 4, 2023

Description

When cross calling a state module from custom state module as documented here https://docs.saltproject.io/en/latest/ref/states/writing.html#cross-calling-state-modules, if the custom module is set as target of a prereq the opts["test"] value is not correctly also set on the cross called state.

Setup

  • ec2 instance running rhel 7.9

  • classic packaging (yum install salt-minion)

  • create a minimum custom state to cross call another state /srv/salt/_states/custom_state.py:

    def wrap(*args, **kwargs):
        return __states__["file.managed"](*args, **kwargs)
  • create /srv/salt/test.sls:

    "/tmp/trash_dir/trash_file":
      custom_state.wrap:
        - contents: "\n"
     
    "/tmp/trash_dir":
      file.directory:
        - prereq:
          - "/tmp/trash_dir/trash_file"

Steps to Reproduce the behavior

salt-call -l info --local saltutil.sync_all
salt-call -l info --local state.apply test

Output:

----------
ID: /tmp/trash_dir
Function: file.directory
Result: False
Comment: One or more requisite failed: test./tmp/trash_dir/trash_file
Started: ...
Duration: 4ms
Changes:
----------
ID: /tmp/trash_dir/trash_file
Function: custom_state.wrap
Result: False
Comment: Parent directory not present
Changes:

Summary for local
------------
Failed: 2
------------

Expected behavior

"/tmp/trash_dir" and "/tmp/trash_dir/trash_file" should be created; the "/tmp/trash_dir/trash_file" state should be detected as needing changes and the required state which has the prereq "/tmp/trash_dir" should be created. The __opts__['test'] variable should be set to True in the states["file.managed"] state call from the custom_state.wrap state so that the prereq condition behaves correctly.

Versions Report

salt-call --versions-report
Salt Version:
        Salt: 3004.1

Dependency Versions:
    Jinja2: 2.11.1
    Python: 3.6.8 (default, Aug 13 2020, 07:46:32)
    PyYAML: 3.13

System Versions:
      dist: rhel 7.9 Maipo
    locale: UTF-8
   release: 3.10.0-1160.15.2.el7.x86_64
   system: Linux
@bdrx312 bdrx312 added Bug broken, incorrect, or confusing behavior needs-triage labels Jan 4, 2023
@lkubb
Copy link
Contributor

lkubb commented Jan 4, 2023

I think this is a duplicate: #62590

For a workaround, see

salt/salt/states/x509_v2.py

Lines 1576 to 1582 in a3a69cf

def _file_managed(name, test=None, **kwargs):
if test not in [None, True]:
raise SaltInvocationError("test param can only be None or True")
# work around https://github.com/saltstack/salt/issues/62590
test = test or __opts__["test"]
res = __salt__["state.single"]("file.managed", name, test=test, **kwargs)
return res[next(iter(res))]

@bdrx312
Copy link
Contributor Author

bdrx312 commented Jan 4, 2023

I think this is a duplicate: #62590

Yeah this looks like a duplicate of that issue. I should have done a better job of searching the existing issues.

@bdrx312 bdrx312 closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants