From 35bb4addbc04e8a8dea26aa2099d852ce084ec14 Mon Sep 17 00:00:00 2001
From: Tomas Jelinek <tojeline@redhat.com>
Date: Wed, 21 Oct 2015 10:46:17 +0200
Subject: [PATCH] fix setting cluster properties in web UI
- set the properties correctly even if it is not possible to load the
properties' current values
- do not depend on cluster being imported in pcsd when loading the
properties
- fix loading default values of cluster properties
---
pcsd/pcsd.rb | 39 +++++++++++++++-----------------
pcsd/remote.rb | 11 ++++++---
pcsd/settings.rb | 1 +
pcsd/settings.rb.i386-linux-gnu.debian | 1 +
pcsd/settings.rb.x86_64-linux-gnu.debian | 1 +
5 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/pcsd/pcsd.rb b/pcsd/pcsd.rb
index b7c2a49..c42abb8 100644
--- a/pcsd/pcsd.rb
+++ b/pcsd/pcsd.rb
@@ -573,7 +573,7 @@ if not DISABLE_GUI
end
@resource_agents = get_resource_agents_avail(session)
@stonith_agents = get_stonith_agents_avail(session)
- @config_options = getConfigOptions2(session, @cluster_name)
+ @config_options = getConfigOptions2(session, @nodes)
erb :nodes, :layout => :main
end
@@ -895,7 +895,7 @@ def getLocationDeps(session, cur_node)
[deps_allow, deps_disallow]
end
-def getConfigOptions2(session, cluster_name)
+def getConfigOptions2(session, cluster_nodes)
config_options = {}
general_page = []
# general_page << ConfigOption.new("Cluster Delay Time", "cluster-delay", "int", 4, "Seconds")
@@ -933,7 +933,7 @@ If checked, the cluster will refuse to start resources unless one or more STONIT
allconfigoptions = []
config_options.each { |i,k| k.each { |j| allconfigoptions << j } }
ConfigOption.getDefaultValues(allconfigoptions)
- ConfigOption.loadValues(session, allconfigoptions, cluster_name)
+ ConfigOption.loadValues(session, allconfigoptions, cluster_nodes)
return config_options
end
@@ -1005,16 +1005,8 @@ class ConfigOption
@desc = desc
end
- def self.loadValues(session, cos, cluster_name, node_list=nil)
- if node_list
- code, output = send_nodes_request_with_token(
- session, node_list, "get_cib"
- )
- else
- code, output = send_cluster_request_with_token(
- session, cluster_name, "get_cib"
- )
- end
+ def self.loadValues(session, cos, node_list)
+ code, output = send_nodes_request_with_token(session, node_list, "get_cib")
$logger.info(code)
if code != 200
$logger.info "Error: unable to load cib"
@@ -1037,14 +1029,19 @@ class ConfigOption
end
def self.getDefaultValues(cos)
- metadata = `#{PENGINE} metadata`
- doc = REXML::Document.new(metadata)
-
- cos.each { |co|
- doc.elements.each("resource-agent/parameters/parameter[@name='#{co.configname}']/content") { |e|
- co.default = e.attributes["default"]
- break
- }
+ [PENGINE, CIB_BINARY].each { |command|
+ metadata = `#{command} metadata`
+ begin
+ doc = REXML::Document.new(metadata)
+ cos.each { |co|
+ doc.elements.each("resource-agent/parameters/parameter[@name='#{co.configname}']/content") { |e|
+ co.default = e.attributes["default"]
+ break
+ }
+ }
+ rescue
+ $logger.error("Failed to parse #{command} metadata")
+ end
}
end
diff --git a/pcsd/remote.rb b/pcsd/remote.rb
index e65c8ac..dc90fc9 100644
--- a/pcsd/remote.rb
+++ b/pcsd/remote.rb
@@ -1921,9 +1921,13 @@ def update_cluster_settings(params, request, session)
binary_settings = []
changed_settings = []
old_settings = {}
- getConfigOptions2(PCSAuth.getSuperuserSession(), $cluster_name).values().flatten().each { |opt|
+ getConfigOptions2(
+ PCSAuth.getSuperuserSession(), get_nodes().flatten()
+ ).values().flatten().each { |opt|
+ binary_settings << opt.configname if "check" == opt.type
+ # if we don't know current value of an option, consider it changed
+ next if opt.value.nil?
if "check" == opt.type
- binary_settings << opt.configname
old_settings[opt.configname] = is_cib_true(opt.value)
else
old_settings[opt.configname] = opt.value
@@ -1931,6 +1935,7 @@ def update_cluster_settings(params, request, session)
}
settings.each { |key, val|
new_val = binary_settings.include?(key) ? is_cib_true(val) : val
+ # if we don't know current value of an option, consider it changed
if (not old_settings.key?(key)) or (old_settings[key] != new_val)
changed_settings << key.downcase()
end
@@ -1940,7 +1945,7 @@ def update_cluster_settings(params, request, session)
return 403, 'Permission denied'
end
end
- if changed_settings.count { |x| x != 'enable-acl'} > 0
+ if changed_settings.count { |x| x != 'enable-acl' } > 0
if not allowed_for_local_cluster(session, Permissions::WRITE)
return 403, 'Permission denied'
end
diff --git a/pcsd/settings.rb b/pcsd/settings.rb
index 4cea800..ff056a4 100644
--- a/pcsd/settings.rb
+++ b/pcsd/settings.rb
@@ -10,6 +10,7 @@ HEARTBEAT_AGENTS_DIR = "/usr/lib/ocf/resource.d/heartbeat/"
PACEMAKER_AGENTS_DIR = "/usr/lib/ocf/resource.d/pacemaker/"
NAGIOS_METADATA_DIR = '/usr/share/pacemaker/nagios/plugins-metadata/'
PENGINE = "/usr/libexec/pacemaker/pengine"
+CIB_BINARY = '/usr/libexec/pacemaker/cib'
CRM_MON = "/usr/sbin/crm_mon"
CRM_NODE = "/usr/sbin/crm_node"
CRM_ATTRIBUTE = "/usr/sbin/crm_attribute"
diff --git a/pcsd/settings.rb.i386-linux-gnu.debian b/pcsd/settings.rb.i386-linux-gnu.debian
index 6366651..4db23e4 100644
--- a/pcsd/settings.rb.i386-linux-gnu.debian
+++ b/pcsd/settings.rb.i386-linux-gnu.debian
@@ -7,6 +7,7 @@ OCF_ROOT = "/usr/lib/ocf"
HEARTBEAT_AGENTS_DIR = "/usr/lib/ocf/resource.d/heartbeat/"
PACEMAKER_AGENTS_DIR = "/usr/lib/ocf/resource.d/pacemaker/"
PENGINE = "/usr/lib/i386-linux-gnu/pacemaker/pengine"
+CIB_BINARY = '/usr/lib/i386-linux-gnu/pacemaker/cib'
CRM_NODE = "/usr/sbin/crm_node"
CRM_ATTRIBUTE = "/usr/sbin/crm_attribute"
COROSYNC_BINARIES = "/usr/sbin/"
diff --git a/pcsd/settings.rb.x86_64-linux-gnu.debian b/pcsd/settings.rb.x86_64-linux-gnu.debian
index 23a71ab..3f6d5c0 100644
--- a/pcsd/settings.rb.x86_64-linux-gnu.debian
+++ b/pcsd/settings.rb.x86_64-linux-gnu.debian
@@ -7,6 +7,7 @@ OCF_ROOT = "/usr/lib/ocf"
HEARTBEAT_AGENTS_DIR = "/usr/lib/ocf/resource.d/heartbeat/"
PACEMAKER_AGENTS_DIR = "/usr/lib/ocf/resource.d/pacemaker/"
PENGINE = "/usr/lib/x86_64-linux-gnu/pacemaker/pengine"
+CIB_BINARY = '/usr/lib/x86_64-linux-gnu/pacemaker/cib'
CRM_NODE = "/usr/sbin/crm_node"
CRM_ATTRIBUTE = "/usr/sbin/crm_attribute"
COROSYNC_BINARIES = "/usr/sbin/"
--
1.9.1