Make static-components.conf.erb more readable, maybe
authorPeter Palfrader <peter@palfrader.org>
Tue, 10 Sep 2019 20:30:31 +0000 (22:30 +0200)
committerPeter Palfrader <peter@palfrader.org>
Tue, 10 Sep 2019 20:30:31 +0000 (22:30 +0200)
modules/roles/misc/static-components.yaml
modules/roles/templates/static-mirroring/static-components.conf.erb

index 78bf031..16aee4f 100644 (file)
@@ -13,6 +13,8 @@
 #       whitelist of mirrors ('limit-mirrors') that they should
 #       be synced to, thus excluding all others.
 #
+# Empty lists do not count.
+#
 # A mirrorrun for a component can only be triggered by its source
 # host and any hosts listed in that components "extra-push" list.
 
index fb89f46..a7234f9 100644 (file)
@@ -14,6 +14,12 @@ lines << "# <master> <service> <source host> <directory> <extra push hosts, comm
 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)
@@ -21,27 +27,33 @@ config['components'].each_pair do |component_name, component_conf|
 
        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