Module: check_mk
Branch: master
Commit: 14fa966f91b1b83db565afc75101c5b603feca61
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=14fa966f91b1b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 8 16:48:11 2016 +0100
Fixed user profile sync and call sync only for login+replication sites
---
web/htdocs/wato.py | 23 ++++++------
web/htdocs/watolib.py | 97 +++++++++++++++++++++++++++------------------------
2 files changed, 61 insertions(+), 59 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index acc1f87..086024a 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -9645,6 +9645,8 @@ def automation_push_profile():
if not profile:
raise MKGeneralException(_('Invalid call: The profile is missing.'))
+ init_wato_datastructures()
+
users = userdb.load_users(lock = True)
profile = mk_eval(profile)
users[user_id] = profile
@@ -13950,8 +13952,6 @@ def user_profile_async_replication_page():
def user_profile_async_replication_dialog():
- slave_sites = wato_slave_sites()
- sort_sites(slave_sites)
repstatus = load_replication_status()
html.message(_('In order to activate your changes available on all remote sites,
your user profile needs '
@@ -13962,13 +13962,9 @@ def user_profile_async_replication_dialog():
html.h3(_('Replication States'))
html.open_div(id_="profile_repl")
num_replsites = 0
- for site_id, site in slave_sites:
- is_local = config.site_is_local(site_id)
-
- if is_local or (not is_local and not site.get("replication")):
- continue # Skip non replication slaves
-
- srs = repstatus.get(site_id, {})
+ for site_id in get_login_sites():
+ site = config.sites[site_id]
+ srs = repstatus.get(site_id, {})
if not "secret" in site:
status_txt = _('Not logged in.')
@@ -13983,7 +13979,7 @@ def user_profile_async_replication_dialog():
html.icon(status_txt, icon)
if start_sync:
- estimated_duration = srs.get("times",
{}).get(ACTIVATION_TIME_PROFILE_SYNC, 2.0)
+ estimated_duration = ActivateChanges().get_activation_time(site_id,
ACTIVATION_TIME_PROFILE_SYNC, 2.0)
html.javascript('wato_do_profile_replication(\'%s\', %d,
\'%s\');' %
(site_id, int(estimated_duration * 1000.0), _('Replication in
progress')))
num_replsites += 1
@@ -14092,9 +14088,10 @@ def page_user_profile(change_pw=False):
password_changed = True
- # Now, if in distributed environment, set the trigger for pushing the new
- # auth information to the slave sites asynchronous
- if has_wato_slave_sites():
+ # Now, if in distributed environment where users can login to remote sites,
+ # set the trigger for pushing the new auth information to the slave sites
+ # asynchronous
+ if get_login_sites():
start_async_replication = True
userdb.save_users(users)
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index aa86416..7b5aedf 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -3524,6 +3524,26 @@ def wato_slave_sites():
if site.get("replication") ]
+# Returns a list of site ids which are WATO slave sites and users can login
+def get_login_sites():
+ sites = []
+ for site_id, site in wato_slave_sites():
+ if site.get('user_login', True) and not config.site_is_local(site_id):
+ sites.append(site_id)
+ return sites
+
+
+# Returns a list of site ids which gets the Event Console configuration replicated
+def get_event_console_sync_sites():
+ sites = []
+ for site_id, site in config.sites.items():
+ if config.site_is_local(site_id) or site.get("replicate_ec"):
+ sites.append(site_id)
+ return sites
+
+
+
+
def declare_site_attribute():
undeclare_host_attribute("site")
declare_host_attribute(SiteAttribute(), show_in_table = True, show_in_folder = True)
@@ -3604,24 +3624,6 @@ def update_replication_status(site_id, vars, changes=None):
save_replication_status(repstatus)
-# Returns a list of site ids where users can login
-def get_login_sites():
- sites = []
- for site_id, site in config.sites.items():
- if site.get('user_login', True) and not config.site_is_local(site_id):
- sites.append(site_id)
- return sites
-
-
-# Returns a list of site ids which gets the Event Console configuration replicated
-def get_event_console_sync_sites():
- sites = []
- for site_id, site in config.sites.items():
- if config.site_is_local(site_id) or site.get("replicate_ec"):
- sites.append(site_id)
- return sites
-
-
def automation_push_snapshot():
site_id = html.var("siteid")
@@ -3725,7 +3727,7 @@ def push_user_profile_to_site(site, user_id, profile):
return response
-def synchronize_profile(site, user_id):
+def synchronize_profile(site_id, site, user_id):
users = userdb.load_users(lock = False)
if not user_id in users:
raise MKUserError(None, _('The requested user does not exist'))
@@ -3733,8 +3735,7 @@ def synchronize_profile(site, user_id):
start = time.time()
result = push_user_profile_to_site(site, user_id, users[user_id])
duration = time.time() - start
- # TODO: Auf neue Funktionen umbauen
- update_replication_status(site["id"], {}, {ACTIVATION_TIME_PROFILE_SYNC:
duration})
+ ActivateChanges().update_activation_time(site_id, ACTIVATION_TIME_PROFILE_SYNC,
duration)
return result
@@ -3749,9 +3750,10 @@ def ajax_profile_repl():
else:
site = config.site(site_id)
try:
- result = synchronize_profile(site, config.user.id)
+ result = synchronize_profile(site_id, site, config.user.id)
except Exception, e:
- result = str(e)
+ log_exception()
+ result = "%s" % e
if result == True:
answer = "0 %s" % _("Replication completed successfully.");
@@ -3908,6 +3910,29 @@ class ActivateChanges(object):
return len(change["affected_sites"]) == len(config.sitenames())
+ def update_activation_time(self, site_id, ty, duration):
+ repstatus = load_replication_status(lock=True)
+ try:
+ repstatus.setdefault(site_id, {})
+ times = repstatus[site_id].setdefault("times", {})
+
+ if ty not in times:
+ times[ty] = duration
+ else:
+ times[ty] = 0.8 * times[ty] + 0.2 * duration
+ finally:
+ save_replication_status(repstatus)
+
+
+ def get_activation_times(self, site_id):
+ repstatus = load_replication_status()
+ return repstatus.get(site_id, {}).get("times", {})
+
+
+ def get_activation_time(self, site_id, ty, deflt=None):
+ return self.get_activation_times(site_id).get(ty, deflt)
+
+
class ActivateChangesManager(ActivateChanges):
activation_base_dir = cmk.paths.tmp_dir + "/wato/activation"
@@ -4252,7 +4277,6 @@ class ActivateChangesManager(ActivateChanges):
-
PHASE_INITIALIZED = "initialized" # Thread object has been initialized (not in
thread yet)
PHASE_STARTED = "started" # Thread just started, nothing happened yet
PHASE_SYNC = "sync" # About to sync
@@ -4438,7 +4462,7 @@ class ActivateChangesSite(multiprocessing.Process,
ActivateChanges):
result = self._push_snapshot_to_site()
duration = time.time() - start
- self._update_activation_time(ACTIVATION_TIME_SYNC, duration)
+ self.update_activation_time(self._site_id, ACTIVATION_TIME_SYNC, duration)
# Pre 1.2.7i3 and sites return True on success and a string on error.
# 1.2.7i3 and later return a list of warning messages on success.
@@ -4492,7 +4516,7 @@ class ActivateChangesSite(multiprocessing.Process,
ActivateChanges):
configuration_warnings = self._call_activate_changes_automation()
duration = time.time() - start
- self._update_activation_time(ACTIVATION_TIME_RESTART, duration)
+ self.update_activation_time(self._site_id, ACTIVATION_TIME_RESTART, duration)
return configuration_warnings
@@ -4551,25 +4575,6 @@ class ActivateChangesSite(multiprocessing.Process,
ActivateChanges):
return sorted(list(domains))
- def _update_activation_time(self, ty, duration):
- repstatus = load_replication_status(lock=True)
- try:
- repstatus.setdefault(self._site_id, {})
- times = repstatus[self._site_id].setdefault("times", {})
-
- if ty not in times:
- times[ty] = duration
- else:
- times[ty] = 0.8 * times[ty] + 0.2 * duration
- finally:
- save_replication_status(repstatus)
-
-
- def _get_activation_times(self):
- repstatus = load_replication_status()
- return repstatus.get(self._site_id, {}).get("times", {})
-
-
def _confirm_activated_changes(self):
repstatus = load_replication_status(lock=True)
try:
@@ -4643,7 +4648,7 @@ class ActivateChangesSite(multiprocessing.Process,
ActivateChanges):
def _get_expected_duration(self):
- times = self._get_activation_times()
+ times = self.get_activation_times(self._site_id)
duration = 0.0
if self.is_sync_needed(self._site_id):