diff options
author | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-12-01 12:19:33 +0100 |
---|---|---|
committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-12-01 12:19:33 +0100 |
commit | 3f990beb97c2f72a6af28dd24f70b016606acc61 (patch) | |
tree | 8354ac8ba8203d0807199f5c89a393835a9c1132 /ironic/common | |
parent | 04c45f88a58f92c12cbade0ea761f535849b3bb8 (diff) | |
download | ironic-3f990beb97c2f72a6af28dd24f70b016606acc61.tar.gz |
Refactor common configuration bits from service commands
The prepare_service call from ironic.common.service is changed to also
configure guru meditation and profiler. A new call prepare_command is
provided for the cases it's not required.
Change-Id: I5b9b7b7bc827c8bcda06e9a967deae8577ad87f4
Diffstat (limited to 'ironic/common')
-rw-r--r-- | ironic/common/service.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/ironic/common/service.py b/ironic/common/service.py index e0a8f1852..db83c147a 100644 --- a/ironic/common/service.py +++ b/ironic/common/service.py @@ -15,15 +15,29 @@ # under the License. from oslo_log import log +try: + from oslo_reports import guru_meditation_report as gmr + from oslo_reports import opts as gmr_opts +except ImportError: + gmr = None from oslo_service import service from ironic.common import config +from ironic.common import profiler from ironic.conf import CONF from ironic.conf import opts from ironic import objects +from ironic import version -def prepare_service(argv=None): +LOG = log.getLogger(__name__) + + +def prepare_command(argv=None): + """Prepare any Ironic command for execution. + + Sets up configuration and logging, registers objects. + """ argv = [] if argv is None else argv log.register_options(CONF) opts.update_opt_defaults() @@ -35,5 +49,23 @@ def prepare_service(argv=None): objects.register_all() +def prepare_service(name, argv=None, conf=CONF): + """Prepare an Ironic service executable. + + In addition to what `prepare_command` does, set up guru meditation + reporting and profiling. + """ + prepare_command(argv) + + if gmr is not None: + gmr_opts.set_defaults(CONF) + gmr.TextGuruMeditation.setup_autorun(version, conf=CONF) + else: + LOG.debug('Guru meditation reporting is disabled ' + 'because oslo.reports is not installed') + + profiler.setup(name, CONF.host) + + def process_launcher(): return service.ProcessLauncher(CONF, restart_method='mutate') |