Set the name of engine processes #60259

This commit is contained in:
Daniel A. Wozniak 2021-05-26 15:25:24 -07:00 committed by Megan Wilhite
parent 5de0386b5d
commit cbbee775c0
4 changed files with 30 additions and 2 deletions

View file

@ -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.

View file

@ -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

View file

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

View 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')