1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-28 14:50:08 +03:00

F #2645: Fix bug when there aren't defaults in config file (#2949)

This commit is contained in:
Alejandro Huertas Herrero 2019-02-14 17:45:32 +01:00 committed by Tino Vázquez
parent 9445bb7a7a
commit 4f2e6857cb
2 changed files with 38 additions and 14 deletions

View File

@ -270,7 +270,10 @@ module OneProvision
cfg[r].each do |x|
begin
driver = cfg['defaults']['provision']['driver']
if cfg['defaults'] && cfg['defaults']['driver']
driver = cfg['defaults']['provision']['driver']
end
r_name = "#{r}: #{x['name']}"
Driver.retry_loop "Failed to create #{r_name}" do

View File

@ -79,7 +79,6 @@ module OneProvision
def check_config(config)
name = config['name']
version = config['version']
defaults = config['defaults']['provision']
if !version.nil? && version != 1
Utils.fail('There is an error in your configuration ' \
@ -91,11 +90,6 @@ module OneProvision
'file: no name given')
end
if defaults.nil?
Utils.fail('There is an error in your configuration' \
'file: defaults provision is missing')
end
if config['hosts']
config['hosts'].each_with_index do |h, i|
im = h['im_mad']
@ -105,7 +99,7 @@ module OneProvision
if im.nil?
Utils.fail('There is an error in your ' \
'configuration file: there is ' \
"no im_mad in host #{i + 1}")
"no im_mad in host #{i + 1}")
end
if vm.nil?
@ -124,13 +118,25 @@ module OneProvision
end
end
return unless config['datastores']
if config['datastores']
config['datastores'].each_with_index do |d, i|
if d['tm_mad'].nil?
Utils.fail('There is an error in your ' \
'configuration file: there is '\
"no tm_mad in datastore #{i + 1}")
end
config['datastores'].each_with_index do |d, i|
if d['tm_mad'].nil?
next
end
end
return unless config['networks']
config['networks'].each_with_index do |n, i|
if n['vn_mad'].nil?
Utils.fail('There is an error in your ' \
'configuration file: there is '\
"no tm_mad in datastore #{i + 1}")
"no vn_mad in newtork #{i + 1}")
end
next
@ -150,6 +156,8 @@ module OneProvision
yaml['cluster'] = { 'name' => yaml['name'] } if cluster.nil?
defaults = yaml['defaults']
# TODO: schema check
if yaml['hosts']
yaml['hosts'] = yaml['hosts'].map do |host|
@ -174,12 +182,25 @@ module OneProvision
next unless yaml[r]
yaml[r] = yaml[r].map do |x|
x['provision'] = yaml['defaults']['provision']
if defaults && x['provision']
x['provision'].merge!(defaults['provision'])
else
x['provision'] = {} unless x['provision']
end
x
end
end
yaml['cluster']['provision'] = yaml['defaults']['provision']
cluster_p = yaml['cluster']['provision']
if defaults && cluster_p
yaml['cluster']['provision']
.merge!(defaults['provision'])
else
yaml['cluster']['provision'] = {} unless cluster_p
end
rescue StandardError => e
Utils.fail("Failed to read configuration: #{e}")
end