Skip to content

Commit

Permalink
Merge pull request #164 from vuntz/no-require-pacemaker-chef-run
Browse files Browse the repository at this point in the history
Do not require crowbar-pacemaker cookbook to run when we configure HA in openstack
  • Loading branch information
vuntz authored Jan 6, 2017
2 parents 0479f48 + 52d11b7 commit b5cb68d
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 93 deletions.
28 changes: 28 additions & 0 deletions chef/cookbooks/crowbar-pacemaker/recipes/attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Author:: Vincent Untz
# Cookbook Name:: crowbar-pacemaker
# Recipe:: attributes
#
# Copyright 2016, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

node[:pacemaker][:attributes].each do |attr, value|
execute %(set pacemaker attribute "#{attr}" to "#{value}") do
command %(crm node attribute #{node[:hostname]} set "#{attr}" "#{value}")
# The cluster only does a transition if the attribute value changes,
# so checking the value before setting would only slow things down
# for no benefit.
end
end
31 changes: 6 additions & 25 deletions chef/cookbooks/crowbar-pacemaker/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,12 @@
revision node[:pacemaker]["crowbar-revision"]
end

# if we ever want to not have a hard dependency on openstack here, we can have
# Crowbar set a node[:pacemaker][:resource_agents] attribute based on available
# barclamps, and do:
# node[:pacemaker][:resource_agents].each do |resource_agent|
# node[:pacemaker][:platform][:resource_packages][resource_agent].each do |pkg|
# package pkg
# end
# end
node[:pacemaker][:platform][:resource_packages][:openstack].each do |pkg|
package pkg
end
include_recipe "crowbar-pacemaker::attributes"
include_recipe "crowbar-pacemaker::maintenance-mode"
include_recipe "crowbar-pacemaker::mutual_ssh"

if node[:pacemaker][:drbd][:enabled]
include_recipe "crowbar-pacemaker::drbd"
end
include_recipe "crowbar-pacemaker::openstack"

node[:pacemaker][:attributes].each do |attr, value|
execute %(set pacemaker attribute "#{attr}" to "#{value}") do
command %(crm node attribute #{node[:hostname]} set "#{attr}" "#{value}")
# The cluster only does a transition if the attribute value changes,
# so checking the value before setting would only slow things down
# for no benefit.
end
if node[:pacemaker][:drbd][:enabled]
include_recipe "crowbar-pacemaker::drbd_setup"
end

include_recipe "crowbar-pacemaker::haproxy"
include_recipe "crowbar-pacemaker::maintenance-mode"
include_recipe "crowbar-pacemaker::mutual_ssh"
46 changes: 0 additions & 46 deletions chef/cookbooks/crowbar-pacemaker/recipes/drbd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,8 @@
# limitations under the License.
#

claim_string = "LVM_DRBD"
lvm_group = "drbd"
lvm_disk = nil

unclaimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.unclaimed(node).sort
claimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.claimed(node, claim_string).sort

if claimed_disks.empty? and not unclaimed_disks.empty?
unclaimed_disks.each do |disk|
if disk.claim(claim_string)
Chef::Log.info("#{claim_string}: Claimed #{disk.name}")
lvm_disk = disk
break
else
Chef::Log.info("#{claim_string}: Ignoring #{disk.name}")
end
end
else
lvm_disk = claimed_disks.first
end

if lvm_disk.nil?
message = "There is no suitable disk for LVM for DRBD!"
Chef::Log.fatal(message)
raise message
end

# SLE11 only
if node[:platform] == "suse" && node[:platform_version].to_f < 12.0
# Make sure that LVM is setup on boot
service "boot.lvm" do
action [:enable]
end
end

include_recipe "lvm::default"

lvm_physical_volume lvm_disk.name

lvm_volume_group lvm_group do
physical_volumes [lvm_disk.name]
end

include_recipe "drbd::install"
include_recipe "drbd::config"

crowbar_pacemaker_drbd_create_internal "create drbd resources" do
lvm_group lvm_group
end

include_recipe "drbd::default"
71 changes: 71 additions & 0 deletions chef/cookbooks/crowbar-pacemaker/recipes/drbd_setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Cookbook Name:: crowbar-pacemaker
# Recipe:: drbd
#
# Copyright 2014, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

claim_string = "LVM_DRBD"
lvm_group = "drbd"
lvm_disk = nil

unclaimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.unclaimed(node).sort
claimed_disks = BarclampLibrary::Barclamp::Inventory::Disk.claimed(node, claim_string).sort

if claimed_disks.empty? && !unclaimed_disks.empty?
unclaimed_disks.each do |disk|
if disk.claim(claim_string)
Chef::Log.info("#{claim_string}: Claimed #{disk.name}")
lvm_disk = disk
break
else
Chef::Log.info("#{claim_string}: Ignoring #{disk.name}")
end
end
else
lvm_disk = claimed_disks.first
end

if lvm_disk.nil?
message = "There is no suitable disk for LVM for DRBD!"
Chef::Log.fatal(message)
raise message
end

# SLE11 only
if node[:platform] == "suse" && node[:platform_version].to_f < 12.0
# Make sure that LVM is setup on boot
service "boot.lvm" do
action [:enable]
end
end

include_recipe "lvm::default"

lvm_physical_volume lvm_disk.name

lvm_volume_group lvm_group do
physical_volumes [lvm_disk.name]
end

include_recipe "drbd::install"
include_recipe "drbd::config"

# Disable drbd as it should never be started on boot (pacemaker should do it)
# However, start it because on initial setup, we currently require drbd to be
# running.
service "drbd" do
action [:disable, :start]
end
31 changes: 31 additions & 0 deletions chef/cookbooks/crowbar-pacemaker/recipes/openstack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Author:: Vincent Untz
# Cookbook Name:: crowbar-pacemaker
# Recipe:: openstack
#
# Copyright 2016, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# if we ever want to not have a hard dependency on openstack here, we can have
# Crowbar set a node[:pacemaker][:resource_agents] attribute based on available
# barclamps, and do:
# node[:pacemaker][:resource_agents].each do |resource_agent|
# node[:pacemaker][:platform][:resource_packages][resource_agent].each do |pkg|
# package pkg
# end
# end
node[:pacemaker][:platform][:resource_packages][:openstack].each do |pkg|
package pkg
end
14 changes: 2 additions & 12 deletions chef/cookbooks/crowbar-pacemaker/recipes/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,11 @@
include_recipe "crowbar-pacemaker::pacemaker_authkey"
include_recipe "pacemaker::remote"

# if we ever want to not have a hard dependency on openstack here, we can have
# Crowbar set a node[:pacemaker][:resource_agents] attribute based on available
# barclamps, and do:
# node[:pacemaker][:resource_agents].each do |resource_agent|
# node[:pacemaker][:platform][:resource_packages][resource_agent].each do |pkg|
# package pkg
# end
# end
node[:pacemaker][:platform][:resource_packages][:openstack].each do |pkg|
package pkg
end

ruby_block "mark node as ready for pacemaker_remote" do
block do
node[:pacemaker][:remote_setup] = true
node.save
end
end

include_recipe "crowbar-pacemaker::openstack"
31 changes: 31 additions & 0 deletions chef/cookbooks/crowbar-pacemaker/recipes/remote_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Author:: Vincent Untz
# Cookbook Name:: crowbar-pacemaker
# Recipe:: attributes
#
# Copyright 2016, SUSE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CrowbarPacemakerHelper.remote_nodes(node).each do |remote|
remote[:pacemaker][:attributes].each do |attr, value|
execute %(set pacemaker attribute "#{attr}" to "#{value}" on remote #{remote[:hostname]}) do
command %(crm node attribute remote-#{remote[:hostname]} set "#{attr}" "#{value}")
# The cluster only does a transition if the attribute value changes,
# so checking the value before setting would only slow things down
# for no benefit.
only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
end
end
12 changes: 2 additions & 10 deletions chef/cookbooks/crowbar-pacemaker/recipes/remote_delegator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@
action :commit_new
only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) }
end

remote[:pacemaker][:attributes].each do |attr, value|
execute %(set pacemaker attribute "#{attr}" to "#{value}" on remote #{remote[:hostname]}) do
command %(crm node attribute remote-#{remote[:hostname]} set "#{attr}" "#{value}")
# The cluster only does a transition if the attribute value changes,
# so checking the value before setting would only slow things down
# for no benefit.
only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) }
end
end
end

include_recipe "crowbar-pacemaker::remote_attributes"

0 comments on commit b5cb68d

Please sign in to comment.