salt icon indicating copy to clipboard operation
salt copied to clipboard

rabbitmq module functions are not available immediately (requires minion restart) after installing rabbitmq package

Open rvora opened this issue 11 years ago • 5 comments

After installing rabbitmq-server, use of rabbitmq.add_vhost or other module functions fails with "Module function rabbitmq.add_vhost is not available" error.

rabbitmq-server:
  pkg.installed: []

# use rabbitmq module
rabbitmq_add_vhost:
  module.run:
    - name: rabbitmq.add_vhost
    - vhost: '/sensu'

# use rabbitmq_vhost state
rabbitmq_vhost.present:
  - vhost: '/sensu'

Both module and state functions fail unless salt-minion is restated after installing rtabbitmq-server.

This can be verified by running "salt-call sys.list_functions | grep rebbitmq" which comes up empty. Once salt-minion is restarted, you can use all the rabbitmq functions.

I believe this bug might be introduced by this commit by @s0undt3ch if I am not mistaken: https://github.com/saltstack/salt/commit/7d114ac4ecb397d641ad4e68975a5f44303d1192

Since rabbitmq-server is not installed on the salt-minion initially, salt.utils.which('rabbitmqctl') will obviously return None thus rabbitmq.py:virtual() returning False and preventing rabbitmq.py module from being loaded. A minion restart after installing rabbitmq-server will obviously fix this problem.

What is the harm in loading rabbitmq module when Rabbitmq is not installed?

rvora avatar May 12 '15 23:05 rvora

Its easy to reproduce and confirms that you can not install rabbitmq and manage rabbitmq all in one go without restarting salt-minion. Or is there something I am missing.

Create a new instance on AWS/OpenStack with a standard image.

SSH into the instance, Install salt-minion, then run:

# should return no output
salt-call --local sys.list_modules | grep rabbit
salt-call --local sys.list_state_modules | grep rabbit

Create another instance with following Startup script (passed as User-data)

#!/bin/bash
touch /usr/local/bin/rabbitmqctl
chmod 755 /usr/local/bin/rabbitmqctl

Now, SSH into the instance, Install salt-minion, then run:

# should return all the rabbitmq modules
salt-call --local sys.list_modules | grep rabbit
salt-call --local sys.list_state_modules | grep rabbit

rvora avatar May 13 '15 17:05 rvora

@rvora, thanks for the report. Something you could try as a workaround is to reload the salt modules.

rabbitmq-server:
  pkg.installed:
    - name: rabbitmq-server
    - reload_modules: True

# use rabbitmq module
rabbitmq_add_vhost:
  module.run:
    - name: rabbitmq.add_vhost
    - vhost: '/sensu'

# use rabbitmq_vhost state
rabbitmq_vhost.present:
  - vhost: '/sensu'

jfindlay avatar May 13 '15 19:05 jfindlay

Thanks @jfindlay. That workaround seems to work.

rvora avatar May 13 '15 22:05 rvora

@rvora I believe this has been fixed since this issue was reported. I am not able to reproduce this error. I used the state you provided above, with a couple of modifications, because when using it "as-is" I had some state compilation errors.

Before I ran the state, I ran the following commands to make sure rabbitmq wasn't installed:

root@rallytime:~# salt rally-1 sys.list_modules | grep rabbit
root@rallytime:~# salt rally-1 sys.list_state_modules | grep rabbit

Here's the state, a run of state.show_sls to make sure I knew what order the states would run in, the state run itself, and a versions report:

root@rallytime:~# cat /srv/salt/rabbitmq.sls
rabbitmq-server:
  pkg.installed

# use rabbitmq module
rabbitmq_add_vhost:
  module.run:
    - name: rabbitmq.add_vhost
    - vhost: '/sensu'

# use rabbitmq_vhost state
rabbitmq_vhost:
  rabbitmq_vhost.present
root@rallytime:~# salt rally-1 state.show_sls rabbitmq
rally-1:
    ----------
    rabbitmq-server:
        ----------
        __env__:
            base
        __sls__:
            rabbitmq
        pkg:
            - installed
            |_
              ----------
              order:
                  10000
    rabbitmq_add_vhost:
        ----------
        __env__:
            base
        __sls__:
            rabbitmq
        module:
            |_
              ----------
              name:
                  rabbitmq.add_vhost
            |_
              ----------
              vhost:
                  /sensu
            - run
            |_
              ----------
              order:
                  10001
    rabbitmq_vhost:
        ----------
        __env__:
            base
        __sls__:
            rabbitmq
        rabbitmq_vhost:
            |_
              ----------
              vhost:
                  /sensu
            - present
            |_
              ----------
              order:
                  10002
root@rallytime:~# salt rally-1 state.sls rabbitmq
rally-1:
----------
          ID: rabbitmq-server
    Function: pkg.installed
      Result: True
     Comment: The following packages were installed/updated: rabbitmq-server
     Started: 19:35:51.760217
    Duration: 378007.122 ms
     Changes:
              ----------
              erlang-abi-15.b:
                  ----------
                  new:
                      1
                  old:
              erlang-asn1:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-base:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-corba:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-crypto:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-diameter:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-edoc:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-eldap:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-erl-docgen:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-eunit:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-ic:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-inets:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-mnesia:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-nox:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-odbc:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-os-mon:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-parsetools:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-percept:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-public-key:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-runtime-tools:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-snmp:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-ssh:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-ssl:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-syntax-tools:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-tools:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-webtool:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              erlang-xmerl:
                  ----------
                  new:
                      1:16.b.3-dfsg-1ubuntu2.1
                  old:
              libltdl7:
                  ----------
                  new:
                      2.4.2-1.7ubuntu1
                  old:
              libodbc1:
                  ----------
                  new:
                      2.2.14p2-5ubuntu5
                  old:
              libsctp1:
                  ----------
                  new:
                      1.0.15+dfsg-1
                  old:
              lksctp-tools:
                  ----------
                  new:
                      1.0.15+dfsg-1
                  old:
              rabbitmq-server:
                  ----------
                  new:
                      3.2.4-1
                  old:
----------
          ID: rabbitmq_add_vhost
    Function: module.run
        Name: rabbitmq.add_vhost
      Result: True
     Comment: Module function rabbitmq.add_vhost executed
     Started: 19:42:09.771514
    Duration: 280.382 ms
     Changes:
              ----------
              ret:
                  ----------
                  Added:
                      Creating vhost "/sensu" ...
                      ...done.
----------
          ID: rabbitmq_vhost
    Function: rabbitmq_vhost.present
      Result: True
     Comment: Creating vhost "rabbitmq_vhost" ...
              ...done.
     Started: 19:42:10.054160
    Duration: 620.503 ms
     Changes:
              ----------
              new:
                  rabbitmq_vhost
              old:

Summary for rally-1
------------
Succeeded: 3 (changed=3)
Failed:    0
Warnings:  1
------------
Total states run:     3
root@rallytime:~# salt --versions
Salt Version:
           Salt: 2015.8.3-267-g7d307e2

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
           Mako: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.5.0
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: 0.8.6
       cherrypy: Not Installed
       dateutil: 2.4.2
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.10
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: 0.9.0
        timelib: Not Installed

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 4.4.0-x86_64-linode63
         system: Ubuntu 14.04 trusty

I did not have to restart the salt minion at any time:

root@rallytime:~# salt rally-1 sys.list_modules | grep rabbit
    - rabbitmq
root@rallytime:~# salt rally-1 sys.list_state_modules | grep rabbit
    - rabbitmq_cluster
    - rabbitmq_plugin
    - rabbitmq_policy
    - rabbitmq_user
    - rabbitmq_vhost
root@rallytime:~# salt rally-1 rabbitmq.list_vhosts
rally-1:
    - /
    - /sensu
    - rabbitmq_vhost

The code in the rabbitmq module has changed a bit since the original breaking commit, 7d114ac4ecb397d641ad4e68975a5f44303d1192, and all seems to be well again on the 2015.8 branch. Given this information, as well as the work-around provided above, can we close this issue?

rallytime avatar Jan 26 '16 20:01 rallytime

I'm going to go ahead and close this, since we haven't heard back. Please do let us know if this pops up again.

rallytime avatar Feb 11 '16 22:02 rallytime