config = YAML.load(File.open('/etc/puppet/modules/roles/misc/static-components.yaml').read)
mirrors = scope.lookupvar('site::roles')['static_mirror']
+config['mirrors'].each do |mirror, mc|
+ if not mirrors.include?(mirror)
+ fail("static-components.yaml defines mirror #{mirror} but we do not know of it")
+ end
+end
+
config['components'].each_pair do |component_name, component_conf|
%w{exclude-mirrors extra-push limit-mirrors}.each do |key|
component_conf[key] = [] unless component_conf.has_key?(key)
srchost, srcpath = component_conf['source'].split(':', 2)
- config['mirrors'].each do |mirror, mc|
- next unless mirrors.include?(mirror)
+ if not component_conf['exclude-mirrors'].empty? and \
+ not component_conf['limit-mirrors'].empty? then
+ fail("Component #{component_name} specifies both exclude-mirrors and limit-mirrors.")
+ end
- if mc.has_key?('components-include') and not mc['components-include'].include?(component_name)
- component_conf['exclude-mirrors'] << mirror
+ # In the end, we care about an exclude list, so let's invert limit-mirror and turn it into an exclude list
+ if not component_conf['limit-mirrors'].empty? then
+ component_conf['exclude-mirrors'] = mirrors.select do |m|
+ not component_conf['limit-mirrors'].include?(m)
end
end
- if component_conf['limit-mirrors'].size > 0
- mirrors.each do |mirror|
- if not component_conf['limit-mirrors'].include?(mirror)
- next if component_conf['exclude-mirrors'].include?(mirror) # if it's already excluded, do not add it again
- component_conf['exclude-mirrors'] << mirror
- end
+
+ # mirrors may also specify limits as components-include (thus excluding all others). Apply this
+ config['mirrors'].each do |mirror, mc|
+ mirror_components_include = mc.fetch('components-include', [])
+ next if mirror_components_include.empty?
+
+ if not mirror_components_include.include?(component_name)
+ next if component_conf['exclude-mirrors'].include?(mirror) # do not exclude twice
+ component_conf['exclude-mirrors'] << mirror
end
end
-
exclude = component_conf['exclude-mirrors'].sort().join(',')
- exclude = '-' unless exclude != ""
+ exclude = '-' if exclude == ""
extrapush = component_conf['extra-push'].sort().join(',')
- extrapush = '-' unless extrapush != ""
+ extrapush = '-' if extrapush == ""
lines << "#{component_conf['master']} #{component_name} #{srchost} #{srcpath} #{extrapush} #{exclude}"
end