salt icon indicating copy to clipboard operation
salt copied to clipboard

"service.running" returns True on an non existing service

Open r0main opened this issue 9 years ago • 4 comments

Hi,

I found that the state function "service.running" is returning True on a non existing service name. I would expect it to return False in this case.

Description of Issue/Question

Setup

Saltstack : 2017.7.1 OS : Centos 7.3

Steps to Reproduce Issue

Create a state "service.running" with a service name that does not exist :

test_service_running:
  service.running:
    - name: aaaa
    - enable: True

Execute this state and the output will give you :

            ID: test_service_running
                  Function: service.running
                      Name: aaaa
                    Result: True
                   Comment: Running scope as unit run-19948.scope.
                            Failed to start aaaa.service: Unit not found.
                   Started: 13:38:01.413388
                  Duration: 63.058 ms
                   Changes:

The result is True with a comment that indicates the service was not found. The expected behavior would be that Result = False.

Versions Report

No difference between master and minion :

Salt Version:
           Salt: 2017.7.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov  6 2016, 00:28:07)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.3.1611 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-514.2.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.3.1611 Core

r0main avatar Oct 20 '17 14:10 r0main

I can not reproduce it on fresh Centos 7.3 system.

2017.7.1 - can not reproduce 2017.7.2 - can not reproduce

# cat /srv/salt/issue.sls 
test_service_running:
  service.running:
    - name: aaaa
    - enable: True
# salt lab-co7-cloud04 state.apply issue
lab-co7-cloud04:
----------
          ID: test_service_running
    Function: service.running
        Name: aaaa
      Result: False
     Comment: The named service aaaa is not available
     Started: 20:35:36.002852
    Duration: 13.226 ms
     Changes:   

Summary for lab-co7-cloud04
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:  13.226 ms


-------------------------------------------
Summary
-------------------------------------------
# of minions targeted: 1
# of minions returned: 1
# of minions that did not return: 0
# of minions with errors: 1
-------------------------------------------
ERROR: Minions returned with non-zero exit code

samodid avatar Jan 28 '18 18:01 samodid

I just had this same issue happen in my environment. My minion is a "Red Hat Enterprise Linux Server release 7.4 (Maipo)" and my master is a "CentOS Linux release 7.3.1611".

Both my master and minion are running 2017.7.0 version of SaltStack.

I ran a state.apply against my minion and during the state run it failed to install the docker packages, so the unit file that gets installed with the packages were not present. The rest of my state ran and I noticed that the service.running gave a result of True when it failed:

----------
          ID: docker-service
    Function: service.running
        Name: docker
      Result: True
     Comment: Running scope as unit run-2183.scope.
              Failed to start docker.service: Unit not found.
     Started: 17:10:58.375006
    Duration: 88.456 ms
     Changes:   

Taking a look at the v2017.7.0 branch, I believe it should be exiting on this private method call https://github.com/saltstack/salt/blob/v2017.7.0/salt/states/service.py#L402. If I make the execution module calls on the command line that are in that private method, they both come back as false:

[root@saltmaster ~]# salt nexus service.available docker
nexus:
    False
[root@saltmaster ~]# salt nexus service.get_all | grep -i docker
[root@saltmaster ~]#

If it wouldn't fail on the _available method, then I think it should either fail or be caught in the section starting on line https://github.com/saltstack/salt/blob/v2017.7.0/salt/states/service.py#L442 or https://github.com/saltstack/salt/blob/v2017.7.0/salt/states/service.py#L449. All I know is that the state comment has the output of the service.start execution module return?

[root@saltmaster ~]# salt nexus service.start docker
nexus:
    ERROR: Running scope as unit run-2305.scope.
    Failed to start docker.service: Unit not found.

Now, I'm not sure why you are unable to reproduce the issue @samodid, but my minion is fresh (this was the first state.apply running against it after creation). It could be server configuration, which would effect which module gets loaded as the 'service' module. I am assuming that it's using the systemd.py module in my environment based on my grains. Which would mean that the issue would be solved in the execution module.

[root@saltmaster ~]# salt nexus grains.item init
nexus:
    ----------
    init:
        systemd

However, I would love for this issue to be found and fixed.

robertpenberthy avatar Feb 12 '18 18:02 robertpenberthy

An update, I just reran my state apply and on the second run it came back with:

----------
          ID: docker-service
    Function: service.running
        Name: docker
      Result: False
     Comment: The named service docker is not available
     Started: 18:36:24.116400
    Duration: 14.878 ms
     Changes:   

It may be related to the service.systemctl_reload module that ran right before the service.running.

Output from the first run:

----------
          ID: docker-service-reload-daemon
    Function: module.wait
        Name: service.systemctl_reload
      Result: True
     Comment: Module function service.systemctl_reload executed
     Started: 17:10:57.846542
    Duration: 506.132 ms
     Changes:   
              ----------
              ret:
                  True
----------
          ID: docker-service
    Function: service.running
        Name: docker
      Result: True
     Comment: Running scope as unit run-2183.scope.
              Failed to start docker.service: Unit not found.
     Started: 17:10:58.375006
    Duration: 88.456 ms
     Changes:   

Output from the second run:

----------
          ID: docker-service-reload-daemon
    Function: module.wait
        Name: service.systemctl_reload
      Result: True
     Comment: 
     Started: 18:36:23.710505
    Duration: 0.67 ms
     Changes:   
----------
          ID: docker-service
    Function: service.running
        Name: docker
      Result: False
     Comment: The named service docker is not available
     Started: 18:36:24.116400
    Duration: 14.878 ms
     Changes:   

robertpenberthy avatar Feb 12 '18 18:02 robertpenberthy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar May 28 '19 18:05 stale[bot]