Skip to content

Commit 90c1cb5

Browse files
authored
Merge pull request #1841 from cmurphy/fix-restore-with-ssl
crowbar: Move crowbarrc mgmt into crowbar cookbook (SCRD-8330)
2 parents 660dd52 + b2c8be4 commit 90c1cb5

File tree

3 files changed

+65
-72
lines changed

3 files changed

+65
-72
lines changed

chef/cookbooks/crowbar/recipes/default.rb

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
chef_solr_data = "/var/cache/chef/solr/data"
254254
end
255255

256-
if node["crowbar"] && node["crowbar"]["realm"]
256+
if node["crowbar"]
257257
# After installation of a gem, we have a new path for the new gem, so we
258258
# need to reset the paths if we can't load the gem
259259
begin
@@ -262,9 +262,6 @@
262262
Gem.clear_paths
263263
end
264264

265-
realm = node["crowbar"]["realm"]
266-
users = {}
267-
268265
begin
269266
crowbarrc = IniFile.load("/etc/crowbarrc") || {}
270267
rescue IniFile::Error
@@ -275,38 +272,74 @@
275272
Chef::Log.warn("Could not parse config file /etc/crowbarrc")
276273
else
277274
crowbarrc_config = crowbarrc["default"]
275+
# On admin server, only make sure the address and verify_ssl options are
276+
# correct; the admin is the one controlling the username & password.
277+
# During initial install, server and ssl settings may not be there yet,
278+
# don't worry about it
279+
if node[:crowbar][:network].key?(:admin) && node[:crowbar].key?(:apache)
280+
address = node[:crowbar][:network][:admin][:address]
281+
protocol = node[:crowbar][:apache][:ssl] ? "https" : "http"
282+
server = "#{protocol}://#{address}"
283+
verify_ssl = !node[:crowbar][:apache][:insecure]
284+
else
285+
server = nil
286+
verify_ssl = nil
287+
end
288+
if server != crowbarrc_config["server"]
289+
crowbarrc_config["server"] = server
290+
Chef::Log.info("Will update \"server\" option in /etc/crowbarrc to \"#{server}\"")
291+
do_save = true
292+
end
293+
crowbarrc_verify_ssl = crowbarrc_config["verify_ssl"].nil? ||
294+
![false, 0, "0", "f", "F", "false", "FALSE"].include?(crowbarrc_config["verify_ssl"])
295+
296+
if protocol == "http" && crowbarrc_config.key?("verify_ssl")
297+
crowbarrc_config.delete("verify_ssl")
298+
Chef::Log.info("Will remove \"verify_ssl\" option in /etc/crowbarrc")
299+
do_save = true
300+
elsif protocol == "https" && verify_ssl != crowbarrc_verify_ssl
301+
crowbarrc_config["verify_ssl"] = verify_ssl ? 1 : 0
302+
Chef::Log.info("Will update \"verify_ssl\" option in /etc/crowbarrc to " \
303+
"\"#{crowbarrc_config["verify_ssl"]}\"")
304+
do_save = true
305+
end
306+
crowbarrc.save if do_save
307+
end
308+
309+
if node["crowbar"]["realm"]
310+
realm = node["crowbar"]["realm"]
311+
users = {}
278312
admin_username = crowbarrc_config["username"]
279313
admin_password = crowbarrc_config["password"]
280314
unless admin_username.nil? || admin_password.nil?
281315
admin_digest = Digest::MD5.hexdigest("#{admin_username}:#{realm}:#{admin_password}")
282316
users[admin_username] = { "digest" => admin_digest }
283317
end
284-
end
285-
286-
template "/opt/dell/crowbar_framework/htdigest" do
287-
source "htdigest.erb"
288-
variables(users: users, realm: realm)
289-
owner "root"
290-
group node[:apache][:group]
291-
mode "0640"
292-
not_if { users.empty? }
293-
end
318+
template "/opt/dell/crowbar_framework/htdigest" do
319+
source "htdigest.erb"
320+
variables(users: users, realm: realm)
321+
owner "root"
322+
group node[:apache][:group]
323+
mode "0640"
324+
not_if { users.empty? }
325+
end
294326

295-
client_users = users.dup
296-
client_username = node["crowbar"]["client_user"]["username"]
297-
# Fix passwords into digests.
298-
client_password = node["crowbar"]["client_user"]["password"]
299-
client_digest = Digest::MD5.hexdigest("#{client_username}:#{realm}:#{client_password}")
300-
client_users[client_username] = { "digest" => client_digest }
301-
template "/opt/dell/crowbar_framework/htdigest-clients" do
302-
source "htdigest.erb"
303-
variables(users: client_users, realm: realm)
304-
owner "root"
305-
group node[:apache][:group]
306-
mode "0640"
327+
client_users = users.dup
328+
client_username = node["crowbar"]["client_user"]["username"]
329+
# Fix passwords into digests.
330+
client_password = node["crowbar"]["client_user"]["password"]
331+
client_digest = Digest::MD5.hexdigest("#{client_username}:#{realm}:#{client_password}")
332+
client_users[client_username] = { "digest" => client_digest }
333+
template "/opt/dell/crowbar_framework/htdigest-clients" do
334+
source "htdigest.erb"
335+
variables(users: client_users, realm: realm)
336+
owner "root"
337+
group node[:apache][:group]
338+
mode "0640"
339+
end
340+
else
341+
realm = nil
307342
end
308-
else
309-
realm = nil
310343
end
311344

312345
# Remove rainbows configuration, dating from before the switch to puma

chef/cookbooks/provisioner/recipes/base.rb

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -355,48 +355,7 @@
355355

356356
package "ruby2.1-rubygem-crowbar-client"
357357

358-
if is_admin && ::File.exist?("/etc/crowbarrc")
359-
# On admin server, only make sure the address and verify_ssl options are
360-
# correct; the admin is the one controlling the username & password
361-
362-
# After installation of a gem, we have a new path for the new gem, so we
363-
# need to reset the paths if we can't load the gem
364-
begin
365-
require "inifile"
366-
rescue LoadError
367-
Gem.clear_paths
368-
end
369-
370-
begin
371-
crowbarrc = IniFile.load("/etc/crowbarrc")
372-
373-
crowbarrc_config = crowbarrc["default"]
374-
375-
if server != crowbarrc_config["server"]
376-
crowbarrc_config["server"] = server
377-
Chef::Log.info("Will update \"server\" option in /etc/crowbarrc to \"#{server}\"")
378-
do_save = true
379-
end
380-
381-
crowbarrc_verify_ssl = crowbarrc_config["verify_ssl"].nil? ||
382-
![false, 0, "0", "f", "F", "false", "FALSE"].include?(crowbarrc_config["verify_ssl"])
383-
384-
if protocol == "http" && crowbarrc_config.key?("verify_ssl")
385-
crowbarrc_config.delete("verify_ssl")
386-
Chef::Log.info("Will remove \"verify_ssl\" option in /etc/crowbarrc")
387-
do_save = true
388-
elsif protocol == "https" && verify_ssl != crowbarrc_verify_ssl
389-
crowbarrc_config["verify_ssl"] = verify_ssl ? 1 : 0
390-
Chef::Log.info("Will update \"verify_ssl\" option in /etc/crowbarrc to " \
391-
"\"#{crowbarrc_config["verify_ssl"]}\"")
392-
do_save = true
393-
end
394-
395-
crowbarrc.save if do_save
396-
rescue IniFile::Error
397-
Chef::Log.warn("Could not parse/update config file /etc/crowbarrc")
398-
end
399-
elsif !is_admin
358+
unless is_admin
400359
# On non-admin nodes, setup /etc/crowbarrc with the restricted client
401360
username = crowbar_node["crowbar"]["client_user"]["username"]
402361
password = crowbar_node["crowbar"]["client_user"]["password"]

crowbar_framework/lib/crowbar/backup/restore.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def restore_chef
187187

188188
begin
189189
[:nodes, :roles, :clients, :databags].each do |type|
190+
Rails.logger.debug("Restoring #{type}")
190191
Dir.glob(@data.join("knife", type.to_s, "**", "*")).each do |file|
191192
file = Pathname.new(file)
192193
next unless file.extname == ".json"
@@ -207,8 +208,8 @@ def restore_chef
207208
@status[:restore_chef] ||= { status: :ok, msg: "" }
208209
rescue Errno::ECONNREFUSED
209210
raise Crowbar::Error::ChefOffline.new
210-
rescue Net::HTTPServerException
211-
raise "Restore failed"
211+
rescue Net::HTTPServerException => exception
212+
raise "Restore failed: #{exception.message}"
212213
end
213214

214215
# now that restore is done, dns server can answer requests from other nodes.

0 commit comments

Comments
 (0)