kitchen-salt icon indicating copy to clipboard operation
kitchen-salt copied to clipboard

The state_top attribute doesn't work as expected

Open onionka opened this issue 5 years ago • 1 comments

Hello,

I have a strange problem with my small project, where I am learning how to use SaltStack + Kitchen-Salt. I've forked someones else's SaltStack simple demo: https://github.com/onionka/salt-vagrant-demo and used it to implement Apache, Oh-My-ZSH, and Microservices (unfinished) states.

I am trying to set up custom state top.sls, by using state_top attribute (sorry if I misunderstood its semantics). My kitchen.yaml looks like this:

---
driver:
  name: vagrant

platforms:
  - name: ubuntu-18.04
  - name: centos-7

verifier:
  name: shell
  remote_exec: false
  command: pytest -v test/integration/test_$KITCHEN_SUITE.py

suites:
  - name: apache
    provisioner:
      name: salt_solo
      salt_install: bootstrap
      salt_version: latest
      salt_bootstrap_url: https://bootstrap.saltstack.com
      salt_bootstrap_options: -X -p git -p curl -p sudo
      salt_copy_filter:
        - .git
        - .kitchen
        - .vagrant
        - .pytest_cache
      is_file_root: True
      local_salt_root: '.'
      require_chef: false
      pillars_from_files:
        default.sls: pillar/default.sls
        users.sls: pillar/users.sls
        apache_demo.sls: pillar/apache_demo.sls
      #state_top_from_file: True
      state_top:
        base:
          'default':
            - apache_demo
      pillars:
        top.sls:
          base:
            '*':
              - default
              - users
            'minion2':
              - apache_demo

This will fail with the following error:

       You asked for latest and you have 3000.3 installed, sweet!
       Transferring files to <apache-ubuntu-1804>
       Install External Dependencies
       Content of /tmp/kitchen//srv/salt :
       total 32
       drwxr-xr-x 5 vagrant vagrant 4096 May 20 09:46 .
       drwxr-xr-x 4 vagrant vagrant 4096 May 20 09:46 ..
       drwxr-xr-x 4 vagrant vagrant 4096 May 20 09:46 apache_demo
       -rw-r--r-- 1 vagrant vagrant   83 May 20 09:46 common.sls
       drwxr-xr-x 4 vagrant vagrant 4096 May 20 09:46 microservices_demo
       drwxr-xr-x 2 vagrant vagrant 4096 May 20 09:46 oh-my-zsh
       -rw-r--r-- 1 vagrant vagrant   37 May 20 09:46 top.sls
       -rw-r--r-- 1 vagrant vagrant  503 May 20 09:46 users.sls
       local:
       ----------
                 ID: states
           Function: no.None
             Result: False
            Comment: No Top file or master_tops data matches found. Please see master log for details.
            Changes:   
       
       Summary for local
       ------------
       Succeeded: 0
       Failed:    1
       ------------
       Total states run:     1
       Total run time:   0.000 ms
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Converge failed on instance <apache-ubuntu-1804>.  Please see .kitchen/logs/apache-ubuntu-1804.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

When I set state_top_from_file to True and comment the state_top attribute in suites[0].provisoner it will spin up everything just OK. But tests are failing and saying that the Apache is missing.

I searched through a lot of logs lines from Salt and found out that only the minion1 settings from salt/top.sls were applied. Then I tried to test if zsh is there and it worked. It means that the test set up is working correctly and Apache is indeed missing. It seems that the Kitchen is just using minion1 states and ignores minion2.

Could anyone help me with this, please? It is probably an error in my side but I am currently clueless.

onionka avatar May 20 '20 10:05 onionka

The state_top_from_file works well, we use it everywhere in github.com/saltstack-formulas :)

      state_top:
        base:
          'default':
            - apache_demo

Try changing 'default' by '*' so that all minions will be targetted by this top.sls. (or you need to tell kitchen to set hostname to 'default')

daks avatar Jun 08 '20 12:06 daks