Module: check_mk
Branch: master
Commit: d9ebe9e05cb58b7f9e4f276de0f88a83f37e016b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d9ebe9e05cb58b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Aug 11 19:24:56 2018 +0200
Moved site_is_autostart() to SiteContext
Change-Id: Id1fba99872c94fb46640b7cb52b70199f823c833
---
omd/packages/omd/omdlib/main.py | 14 ++++++--------
tests/unit/omdlib/test_site_context.py | 19 +++++++++++++++++++
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/omd/packages/omd/omdlib/main.py b/omd/packages/omd/omdlib/main.py
index 2ff0730..1dcdf7d 100644
--- a/omd/packages/omd/omdlib/main.py
+++ b/omd/packages/omd/omdlib/main.py
@@ -579,13 +579,6 @@ def site_is_stopped(sitename):
def site_is_running(sitename):
return check_status(sitename, False) == 0
-# Determines wether a specific site is set to autostart. Note that
-# this needs to be called from a non-site-specific context and
-# can there not use the g_site... variables.
-def site_autostart(sitename):
- config = parse_site_conf(sitename)
- return config.get('AUTOSTART', 'on') == 'on'
-
def start_site(sitename):
site = SiteContext(sitename)
prepare_and_populate_tmpfs(site)
@@ -3312,7 +3305,7 @@ def main_init_action(command, args, options=None):
# Handle non autostart sites
if command in [ "start", "restart", "reload" ] or
\
( "auto" in options and command == "status" ):
- if not opt_force and not site_autostart(site.name):
+ if not opt_force and not site.is_autostart():
if bare:
continue
elif not parallel:
@@ -4165,6 +4158,11 @@ class SiteContext(AbstractSiteContext):
return True
+ def is_autostart(self):
+ """Determines wether a specific site is set to
autostart."""
+ return self.conf.get('AUTOSTART', 'on') == 'on'
+
+
class RootContext(AbstractSiteContext):
diff --git a/tests/unit/omdlib/test_site_context.py
b/tests/unit/omdlib/test_site_context.py
index acf3098..155bfa7 100644
--- a/tests/unit/omdlib/test_site_context.py
+++ b/tests/unit/omdlib/test_site_context.py
@@ -1,4 +1,5 @@
import os
+import pytest
import omdlib.main
@@ -40,3 +41,21 @@ def test_site_context_is_empty(monkeypatch):
site = omdlib.main.SiteContext("dingelang")
assert not site.is_empty()
+
+
+def test_site_context_is_autostart(monkeypatch):
+ site = omdlib.main.SiteContext("dingeling")
+
+ with pytest.raises(Exception) as e:
+ site.is_autostart()
+ assert "not loaded yet" in str(e)
+
+ site._config = {}
+ site._config_loaded = True
+ assert site.is_autostart()
+
+ site._config = {"AUTOSTART": "on"}
+ assert site.is_autostart()
+
+ site._config = {"AUTOSTART": "off"}
+ assert not site.is_autostart()