Part of the state tree seems to be being pruned #964

Closed
blast-hardcheese opened this Issue Mar 19, 2012 · 12 comments

Comments

Projects
None yet
4 participants
Member

blast-hardcheese commented Mar 19, 2012

sensu:
    gem:
        - installed

sensu-dashboard:
    gem:
        - installed

This produces the following error:

Comment:   The following requisites were not found:
           require: {'gem': 'sensu-dashboard'}

However, if I move sensu-dashboard into a - names: element, I get no requirement errors, everything is green

sensu-gems:
    gem:
        - installed
        - names:
            - sensu
            - sensu-dashboard
Member

blast-hardcheese commented Mar 19, 2012

Tracked it down, the following will reliably reproduce the error:

gem.sls:

include:
    - sensu.initscripts
    - sensu.services

sensu:
    gem:
        - installed

sensu-dashboard:
    gem:
        - installed

initscripts.sls:

/etc/init.d/sensu-dashboard:
    file:
        - managed
        - source: salt://sensu/etc/init.d/init-template
        - require:
            - gem: sensu
            - gem: sensu-dashboard

services.sls:

sensu:
    service:
        - running

sensu-dashboard:
    service:
        - running

This state tree produces the following error:


sensu02:
----------
    State: - file
    Name:      /etc/init.d/sensu-dashboard
    Function:  managed
        Result:    False
        Comment:   The following requisites were not found:
                   require: {'gem': 'sensu'}
                   require: {'gem': 'sensu-dashboard'}

        Changes:   

Now, the fun part comes when you remove the sensu service from services.sls, leaving:

sensu-dashboard:
    service:
        - running

the error is reduced to

sensu02:
----------
    State: - file
    Name:      /etc/init.d/sensu-dashboard
    Function:  managed
        Result:    False
        Comment:   The following requisites were not found:
                   require: {'gem': 'sensu-dashboard'}

        Changes:   

Does the problem still occur if you have an include statement in initscripts.sls?

i.e.
include:

  • sensu.gem

You're ultimately including everything, but maybe the order matters?

Member

blast-hardcheese commented Mar 19, 2012

I think circular includes like that cause more problems than just what I'm experiencing here, but I'm not 100% sure

Member

SEJeff commented Mar 19, 2012

Is this with the latest git?

Owner

thatch45 commented Mar 19, 2012

yes, you need to include the sls modules that are required in initscripts.sls

Member

blast-hardcheese commented Mar 19, 2012

So, sensu/gem.sls includes sensu/initscripts.sls, which then includes sensu/gem.sls?

I thought includes just brought in pre-rendered parts of the state tree... oh.

Member

blast-hardcheese commented Mar 19, 2012

Is there some kind of test or something that can be done to catch this kind of mistake? Maybe "The following symbols couldn't be resolved, it might be helpful to import xxx"

Also, why wouldn't this get stuck in an include loop? I understand in theory, not in practice

Owner

thatch45 commented Mar 19, 2012

yes, the includes are backwards, the things that require need to include what they require, you are including something that requires.

like import foo in a python module that module foo needs, it no worky

Owner

thatch45 commented Mar 19, 2012

Included sls data is passed into a set so that recursive includes can be checked against, otherwise there would eb some crazy issues with recursive includes

I think of it like an inheritance model, so file B includes file A if it (inherits) has a requirement on something in A. The logic breaks if file A includes file B but B has the requirement on A.

If you want to stick with your current includes, i.e. you're loading sensu.gems in your top file and want to keep that, you'd be better off moving the "require" to the gems.sls file and making the gems install require the initscripts.

gems.sls

include:
    - sensu.initscripts
    - sensu.services

sensu:
    gem:
        - installed

sensu-dashboard:
    gem:
        - installed
        - require:
          - file: sensu-dashboard-init

initscript.sls

sensu-dashboard-init:
    file:
        - managed
        - name: /etc/init.d/sensu-dashboard
        - source: salt://sensu/etc/init.d/init-template
Member

blast-hardcheese commented Mar 19, 2012

funky... I don't know why I expected this to work, maybe virtual objects that are resolved when the whole tree has been compiled?

Owner

thatch45 commented Mar 19, 2012

The trippy thing is, that this could appear to work sometimes, since the requisites are evaluated in a complete set, so if you have stuff in the top file then you don't need to always include it, but since states should be standalone they should always explicitly include

@thatch45 thatch45 closed this Oct 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment