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

watch_in does not match on the name parameter as documented #9061

Closed
gthb opened this issue Dec 5, 2013 · 5 comments · Fixed by #9329
Closed

watch_in does not match on the name parameter as documented #9061

gthb opened this issue Dec 5, 2013 · 5 comments · Fixed by #9329
Labels
Bug broken, incorrect, or confusing behavior Regression The issue is a bug that breaks functionality known to work in previous releases. severity-low 4th level, cosemtic problems, work around exists

Comments

@gthb
Copy link
Contributor

gthb commented Dec 5, 2013

With this in nginx/init.sls:

nginx-systemwide:
  pkg:
    - name: nginx
    - installed
  service:
    - running
    - name: nginx
    - reload: true

... and this in webapp/deploy.sls:

include:
  - nginx

{% for sitename, site in pillar.get('sites', {}).iteritems() %}
/etc/nginx/sites-available/{{ sitename }}:
  file.managed:
    - source: salt://webapp/site-nginx.jinja
    - context:
        site: {{ site }}
    - template: jinja
    - watch_in:
      - service: nginx
{% endfor %}

... an error is raised:

local:
    Data failed to compile:
----------
    Cannot extend ID nginx in "base:datamarket.webapp.deploy". It is not part of the high state.

But if I change the nginx declaration to have that exact ID:

nginx:
  pkg:
    - installed
  service:
    - running
    - reload: true

then it works. This is inconsistent with Requisites documentation which states “Requisites match on both the ID Declaration and the name parameter.” The requisite is not matching on the name parameter.

Worse (because it was harder to troubleshoot), the watch_in on service: nginx did not raise an error when I had that original nginx-systemwide state declaration and this other one:

{% for user, args in pillar['users'].iteritems() %}
{{ user }}:
  user:
    - present
    - name: {{ user }}
    - home: /home/{{ user }}
    - shell: {{ pillar.get('unprivileged_shell', '/bin/bash') }}
    - fullname: {{ args.get('fullname', user) }}
{% endfor %}

where, you guessed it, one of the users was named nginx. Of course this nginx didn't have any service state, so watch_in on service: nginx should have raised a clear error, something like “Can't apply watch_in to service: nginx because nginx has no service state”. But it didn't raise any error; it just silently failed to reload my nginx service when changing the file.

@basepi
Copy link
Contributor

basepi commented Dec 6, 2013

Thanks for the report. As far as I know, your first example should definitely be working.

Additionally, it definitely looks to me like we should not be silently failing on watch_in -- there may be a use case to explain why that silently fails, but offhand, we should fix that as well.

@basepi
Copy link
Contributor

basepi commented Dec 6, 2013

Can you please post your version info? salt --versions-report

@gthb
Copy link
Contributor Author

gthb commented Dec 7, 2013

$ salt --versions-report
           Salt: 0.17.2
         Python: 2.7.3 (default, Jan  2 2013, 13:56:14)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.10
          PyZMQ: 13.1.0
            ZMQ: 3.2.3

@ghost
Copy link

ghost commented Dec 12, 2013

FWIW, I'm seeing this exact same issue.

$ salt --versions-report
Salt: 0.17.2
Python: 2.7.3 (default, Sep 26 2013, 20:03:06)
Jinja2: 2.6
M2Crypto: 0.21.1
msgpack-python: 0.1.10
msgpack-pure: Not Installed
pycrypto: 2.4.1
PyYAML: 3.10
PyZMQ: 13.0.0
ZMQ: 3.2.2

@terminalmage
Copy link
Contributor

I'm able to reproduce this, and not just on watch_in, but require_in as well. All *_in requisites are disambiguated and turned into require/watch/etc. requisites when the state data is being compiled, so I have a good idea where this might be happening.

terminalmage added a commit to terminalmage/salt that referenced this issue Dec 17, 2013
Under the hood, all '_in' requisites are changed to extends of their
corresponding type. For example, a require_in for a given state extends
the target of the require_in with a 'require' requisite, pointing back
at the state where the require_in was located.

When these extends are reconciled, only the ID declarations are examined
to see if there is a state matching the requisite's target, meaning that
these '_in' requisites cannot point to a 'name' override in the same way
as their counterparts are able to. For more info, see
saltstack#9061.

This commit modifies the extend reconciliation behavior. If there is no
ID declaration matching the requisite's target, then
salt.state.find_name() is used to search the high data for an ID
declaration with a 'name' param matching the requisite target. If a
match is found, then the extend is reconciled against that matching ID.
If no match is found, then the requisite is not found the appropriate
error is returned.
terminalmage added a commit that referenced this issue Jan 9, 2014
Under the hood, all '_in' requisites are changed to extends of their
corresponding type. For example, a require_in for a given state extends
the target of the require_in with a 'require' requisite, pointing back
at the state where the require_in was located.

When these extends are reconciled, only the ID declarations are examined
to see if there is a state matching the requisite's target, meaning that
these '_in' requisites cannot point to a 'name' override in the same way
as their counterparts are able to. For more info, see
#9061.

This commit modifies the extend reconciliation behavior. If there is no
ID declaration matching the requisite's target, then
salt.state.find_name() is used to search the high data for an ID
declaration with a 'name' param matching the requisite target. If a
match is found, then the extend is reconciled against that matching ID.
If no match is found, then the requisite is not found the appropriate
error is returned.
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 Regression The issue is a bug that breaks functionality known to work in previous releases. severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@gthb @terminalmage @basepi and others