Module: check_mk
Branch: master
Commit: bd224c085ad3d1705db085bbdf2d782a34d88d7a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bd224c085ad3d1…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Jun 8 16:48:18 2018 +0200
Avoid dangerous hierarchical import in the middle of a function.
This shadows the upper names of the hierarchy in the code before the import.
o_O
Change-Id: Id41d00656b800492104253ca8dde01020ae86bfc
---
cmk_base/automations/check_mk.py | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index f61f97e..355bede 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -37,14 +37,7 @@ import cmk_base.utils
import cmk_base.console as console
import cmk_base.config as config
import cmk_base.rulesets as rulesets
-# TODO: For some extremely obscure reason we can't simply import the module and
-# use it in a qualified way in AutomationRestart.execute: It results in:
-#
-# UnboundLocalError: local variable 'cmk_base' referenced before assignment
-#
-# Doing exactly the same thing in e.g. AutomationDiscovery.execute works. o_O
-# Leaving a funny identifier as an urgent reminder to figure out what's going on
here...
-import cmk_base.core as maxGNARK
+import cmk_base.core
import cmk_base.core_config as core_config
import cmk_base.snmp as snmp
import cmk_base.checks as checks
@@ -231,7 +224,7 @@ class AutomationRenameHosts(Automation):
# it now.
core_was_running = self._core_is_running()
if core_was_running:
- maxGNARK.do_core_action("stop", quiet=True)
+ cmk_base.core.do_core_action("stop", quiet=True)
try:
for oldname, newname in renamings:
@@ -729,7 +722,7 @@ class AutomationRestart(Automation):
return "restart"
- # TODO: Cleanup duplicate code with maxGNARK.do_restart()
+ # TODO: Cleanup duplicate code with cmk_base.core.do_restart()
def execute(self, args):
# make sure, Nagios does not inherit any open
# filedescriptors. This really happens, e.g. if
@@ -760,7 +753,7 @@ class AutomationRestart(Automation):
try:
backup_path = None
- if maxGNARK.try_get_activation_lock():
+ if cmk_base.core.try_get_activation_lock():
raise MKAutomationError("Cannot activate changes. "
"Another activation process is currently in progresss")
@@ -779,8 +772,8 @@ class AutomationRestart(Automation):
configuration_warnings =
core_config.create_core_config(create_config_hook)
try:
- import cmk_base.cee.agent_bakery
- cmk_base.cee.agent_bakery.bake_on_restart()
+ from cmk_base.cee.agent_bakery import bake_on_restart
+ bake_on_restart()
except ImportError:
pass
@@ -801,7 +794,7 @@ class AutomationRestart(Automation):
from cmk_base.core_nagios import precompile_hook
precompile_hook()
- maxGNARK.do_core_action(self._mode())
+ cmk_base.core.do_core_action(self._mode())
else:
broken_config_path = "%s/check_mk_objects.cfg.broken" %
cmk.paths.tmp_dir
file(broken_config_path,
"w").write(file(cmk.paths.nagios_objects_file).read())