mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Set the name of engine processes #60259
This commit is contained in:
parent
5de0386b5d
commit
cbbee775c0
4 changed files with 30 additions and 2 deletions
|
@ -8,7 +8,7 @@ import logging
|
|||
import salt
|
||||
import salt.loader
|
||||
import salt.utils.platform
|
||||
from salt.utils.process import SignalHandlingProcess
|
||||
import salt.utils.process
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -63,7 +63,7 @@ def start_engines(opts, proc_mgr, proxy=None):
|
|||
)
|
||||
|
||||
|
||||
class Engine(SignalHandlingProcess):
|
||||
class Engine(salt.utils.process.SignalHandlingProcess):
|
||||
"""
|
||||
Execute the given engine in a new process
|
||||
"""
|
||||
|
@ -107,10 +107,18 @@ class Engine(SignalHandlingProcess):
|
|||
"log_queue_level": self.log_queue_level,
|
||||
}
|
||||
|
||||
@property
|
||||
def module_name(self):
|
||||
"""
|
||||
The name of the module this engine is targeting.
|
||||
"""
|
||||
return self.fun.split('.')[0]
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run the master service!
|
||||
"""
|
||||
salt.utils.process.appendproctitle("Engine: {}".format(self.module_name))
|
||||
self.utils = salt.loader.utils(self.opts, proxy=self.proxy)
|
||||
if salt.utils.platform.is_windows():
|
||||
# Calculate function references since they can't be pickled.
|
||||
|
|
|
@ -121,6 +121,9 @@ salt/cloud/*:
|
|||
salt/cloud/__init__.py:
|
||||
- pytests.functional.cli.test_salt_cloud
|
||||
|
||||
salt/engines/*:
|
||||
- pytests.unit.engines.test_engines
|
||||
|
||||
salt/grains/*:
|
||||
- integration.grains.test_custom
|
||||
|
||||
|
|
1
tests/pytests/unit/engines/__init__.py
Normal file
1
tests/pytests/unit/engines/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
16
tests/pytests/unit/engines/test_engines.py
Normal file
16
tests/pytests/unit/engines/test_engines.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import salt.engines
|
||||
import pytest
|
||||
from tests.support.mock import patch, MagicMock
|
||||
|
||||
|
||||
def test_engine_module_name():
|
||||
engine = salt.engines.Engine({}, 'foobar.start', {}, {}, {}, {})
|
||||
assert engine.module_name == 'foobar'
|
||||
|
||||
def test_engine_title_set():
|
||||
engine = salt.engines.Engine({}, 'foobar.start', {}, {}, {}, {})
|
||||
with patch('salt.utils.process.appendproctitle', MagicMock()) as mm:
|
||||
with pytest.raises(KeyError):
|
||||
# The method does not exist so a KeyError will be raised.
|
||||
engine.run()
|
||||
mm.assert_called_with('Engine: foobar')
|
Loading…
Add table
Reference in a new issue