Do not change mcollective config
The idea is to stop changing mcollective config and restarting it from nailgun agent. This causes a lot of problems related to mcollective service restarted at wrong time. From now at the bootstrap stage mcollective is expected to be configured and started by startup scripts while in bootstrap and by cloud-init at first boot into provisioned node. Change-Id: Ic8e31d6381d8ffb8f7fdfd1aa8ebc655bb4535ec Partial-Bug: #1585671 Depends-On: Ia2f984570b38642b1090f6483ed3fa78958550c5
This commit is contained in:
parent
dd36db6e06
commit
b2d45830c0
66
agent
66
agent
|
@ -79,59 +79,6 @@ def createsig(body)
|
|||
Digest::SHA1.hexdigest( digest body )
|
||||
end
|
||||
|
||||
class McollectiveConfig
|
||||
def initialize(logger)
|
||||
@logger = logger
|
||||
@configfile = '/etc/mcollective/server.cfg'
|
||||
end
|
||||
|
||||
def get_config_by_key(find_key)
|
||||
found_key = nil
|
||||
found_value = nil
|
||||
# This code is from mcollective's sources
|
||||
File.open(@configfile, "r").each do |line|
|
||||
# strip blank spaces, tabs etc off the end of all lines
|
||||
line.gsub!(/\s*$/, "")
|
||||
unless line =~ /^#|^$/
|
||||
if line =~ /(.+?)\s*=\s*(.+)/
|
||||
key = $1
|
||||
val = $2
|
||||
if key == find_key
|
||||
found_key = key
|
||||
found_value = val
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
found_value if found_key
|
||||
end
|
||||
|
||||
def replace_identity(new_id)
|
||||
# check if id complies reqs
|
||||
raise 'Identities can only match /\w\.\-/' unless new_id.to_s.match(/^[\w\.\-]+$/)
|
||||
|
||||
value_from_config = get_config_by_key('identity')
|
||||
|
||||
if value_from_config == new_id.to_s
|
||||
@logger.info "MCollective is up to date with identity = #{new_id}"
|
||||
else
|
||||
config = File.open(@configfile, "rb").read
|
||||
if value_from_config
|
||||
# Key found, but it has other value
|
||||
@logger.info "Replacing identity in mcollective server.cfg to new value = '#{new_id}'"
|
||||
config.gsub!(/^identity[ =].*$/, "identity = #{new_id}")
|
||||
File.open(@configfile, "w") { |f| f.write(config) }
|
||||
else # if key was not found
|
||||
config += "\nidentity = #{new_id}\n"
|
||||
@logger.info "Identity in mcollective server.cfg has not been found. Setting to '#{new_id}'"
|
||||
File.open(@configfile, "w") { |f| f.write(config) }
|
||||
end
|
||||
puts `service mcollective restart`
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Offloading
|
||||
def initialize(name, sub)
|
||||
@name, @sub = name, sub
|
||||
|
@ -1389,10 +1336,6 @@ def write_data_to_file(logger, filename, data)
|
|||
end
|
||||
end
|
||||
|
||||
def provisioned?
|
||||
Socket.gethostname != 'bootstrap'
|
||||
end
|
||||
|
||||
dry_run = false
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: nailgun-agent [options]"
|
||||
|
@ -1418,11 +1361,6 @@ unless dry_run
|
|||
sleep(sleep_time)
|
||||
end
|
||||
|
||||
if File.exist?('/etc/nailgun-agent/nodiscover')
|
||||
logger.info("Discover prevented by /etc/nailgun-agent/nodiscover presence.")
|
||||
exit 1
|
||||
end
|
||||
|
||||
agent = NodeAgent.new(logger, dry_run)
|
||||
agent.update_state
|
||||
|
||||
|
@ -1451,10 +1389,6 @@ begin
|
|||
exit 1
|
||||
end
|
||||
new_id = JSON.parse(resp.body)['id']
|
||||
mc_config = McollectiveConfig.new(logger)
|
||||
unless provisioned?
|
||||
mc_config.replace_identity(new_id)
|
||||
end
|
||||
write_data_to_file(logger, '/etc/nailgun_uid', new_id.to_s)
|
||||
rescue => ex
|
||||
# NOTE(mihgen): There is no need to retry - cron will do it for us
|
||||
|
|
Loading…
Reference in New Issue