From fb6f9b67ca4bf82b22fc9ec469b9b6beeb08c0a2 Mon Sep 17 00:00:00 2001 From: Nicolas Vigier Date: Thu, 23 May 2013 15:06:02 +0000 Subject: buildsystem: remove use of .each on hashes Remove use of "each" methods on hashes in template files. With ruby 1.8, the order in which the hash is enumerated is random. When using the each method to scan all hash keys and elements in template files, puppet will do unnecessary changes in files installed on the server, making it more difficult to see the real changes. In order to avoid this, we stop using the "each" method on hashes and instead use the "keys" method to get an array of all keys and sort it alphabetically. With ruby 1.9 the hashes enumerate their values in the order that the corresponding keys were inserted, but we are still using ruby 1.8 with Mageia 2. --- modules/buildsystem/templates/iurt.conf | 5 +++-- modules/buildsystem/templates/media.cfg | 15 ++++++++++----- modules/buildsystem/templates/mgarepo.conf | 12 ++++++++---- modules/buildsystem/templates/vhost_repository.conf | 3 ++- 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'modules/buildsystem') diff --git a/modules/buildsystem/templates/iurt.conf b/modules/buildsystem/templates/iurt.conf index ef67e567..b0ed5879 100644 --- a/modules/buildsystem/templates/iurt.conf +++ b/modules/buildsystem/templates/iurt.conf @@ -2,8 +2,9 @@ { supported_arch => [ '<%= distro['arch'].join("', '") %>' ], all_media =>{ -<%- distro['medias'].each{|media, m| -%> - '<%= media %>' => [ '<%= m['repos'].keys.join("', '") %>' ], +<%- distro['medias'].keys.sort.each{|media| -%> + '<%= media %>' => [ '<%= + distro['medias'][media]['repos'].keys.sort.join("', '") %>' ], <%- } -%> }, diff --git a/modules/buildsystem/templates/media.cfg b/modules/buildsystem/templates/media.cfg index 3ac06bce..bdd5d813 100644 --- a/modules/buildsystem/templates/media.cfg +++ b/modules/buildsystem/templates/media.cfg @@ -15,7 +15,8 @@ end def media_out(name, media_hash) media_out = "[%s]\n" % name - media_hash.each{|key, value| + media_hash.keys.sort.each{|key| + value = media_hash[key] if value != nil media_out += "%s=%s\n" % [ key, value ] end @@ -32,8 +33,10 @@ arch=<%= @arch %> xml-info=1 <%- -distro['medias'].each{|medianame, media| - media['repos'].each{|reponame, repo| +distro['medias'].keys.sort.each{|medianame| + media = distro['medias'][medianame] + media['repos'].keys.sort.each{|reponame| + repo = media['repos'][reponame] media_types = [] if media['media_types'] != nil media_types += media['media_types'] @@ -100,8 +103,10 @@ distro['medias'].each{|medianame, media| } } if distro['based_on'] != nil - distro['based_on'].each{|bdistroname, bdistro| - bdistro.each{|medianame, media| + distro['based_on'].keys.sort.each{|bdistroname| + bdistro = distro['based_on'][bdistroname] + bdistro.keys.sort.each{|medianame| + media = bdistro[medianame] for reponame in media -%><%= media_out [ bdistroname, medianame, reponame ].join('/'), diff --git a/modules/buildsystem/templates/mgarepo.conf b/modules/buildsystem/templates/mgarepo.conf index d92c6cd1..cecec703 100644 --- a/modules/buildsystem/templates/mgarepo.conf +++ b/modules/buildsystem/templates/mgarepo.conf @@ -11,7 +11,8 @@ trunk-dir = <%= default_distro %> <%- conf = scope.lookupvar('buildsystem::var::mgarepo::conf') if conf['global'] != nil - conf['global'].each{|key,value| + conf['global'].keys.sort.each{|key| + value = conf['global'][key] -%><%= key %> = <%= value %> <%- } @@ -39,7 +40,8 @@ default = <%= default_distro %> host = <%= scope.lookupvar('buildsystem::var::mgarepo::submit_host') %> <%- - distros.each{|d, distro| + distros.keys.sort.each{|d| + distro = distros[d] -%> [submit <%= d %>] target = <%= sched_home_dir %>/repsys/srpms @@ -55,12 +57,14 @@ rpm-macros = global <%= d %> mkrel(c:) = %{-c: 0.%{-c*}.}%{1}%{?subrel:.%subrel}%{?distsuffix:%distsuffix}%{?!distsuffix:.mga}%{?distro_release:%distro_release} <%- - distros.each{|d, distro| + distros.keys.sort.each{|d| + distro = distros[d] -%> [macros <%= d %>] distro_release = <%= distro['version'] %> <%- - distro['macros'].each{|macro, value| + distro['macros'].keys.sort.each{|macro| + value = distro['macros'][macro] -%><%= macro %> = <%= value %> <%- } %> <%- } diff --git a/modules/buildsystem/templates/vhost_repository.conf b/modules/buildsystem/templates/vhost_repository.conf index 167c026e..6b5b67e5 100644 --- a/modules/buildsystem/templates/vhost_repository.conf +++ b/modules/buildsystem/templates/vhost_repository.conf @@ -8,7 +8,8 @@ distros = scope.lookupvar('buildsystem::var::distros::distros') ServerName <%= scope.lookupvar('buildsystem::var::repository::hostname') %> DocumentRoot <%= mirror_root %> <%- - distros.each{|distroname,distro| + distros.keys.sort.each{|distroname| + distro = distros[distroname] allow_from = distro['repo_allow_from'] != nil ? distro['repo_allow_from'] : [ 'all' ] %> Alias /bootstrap/<%= distroname %>/ "<%= bootstrap_reporoot %>/<%= distroname %>/" -- cgit v1.2.1