Skip to content

Commit 5edbeda

Browse files
author
Sumit Jamgade
committed
hound fixess
1 parent ff2229f commit 5edbeda

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

chef/cookbooks/barclamp/libraries/barclamp_library.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,12 @@ def self.size_to_bytes(s)
420420
class DependsOn
421421
class << self
422422
def add(dependency)
423-
@recipe_depedancies ||= Mash.new
424-
@recipe_depedancies.merge!(dependency)
423+
@recipe_depedencies ||= Mash.new
424+
@recipe_depedencies.merge!(dependency)
425425
end
426+
426427
def get(recipe)
427-
@recipe_depedancies.fetch(recipe, [])
428+
@recipe_depedencies.fetch(recipe, [])
428429
end
429430
end
430431
end
@@ -440,28 +441,26 @@ def last_two_configs(group, barclamp, instance)
440441
end
441442

442443
def loadattr(hash, attrlist)
443-
i=0
444+
i = 0
445+
return hash unless attlist.length > 0
444446
while hash.is_a?(Hash)
445-
if hash.key?(attrlist[i])
446-
hash = hash[attrlist[i]]
447-
Chef::Log.debug("smart loadattr #{attrlist[i]}, #{hash}")
448-
i+=1
449-
return hash if attrlist.length == i
450-
else
451-
return nil
452-
end
447+
return nil unless hash.key?(attrlist[i])
448+
hash = hash[attrlist[i]]
449+
Chef::Log.debug("smart loadattr #{attrlist[i]}, #{hash}")
450+
i += 1
451+
return hash if attrlist.length == i
453452
end
454453
end
455454

456-
def has_changes_to_apply(depedency, group="openstack" ,instance = nil)
455+
def changes_to_apply?(depedency, group = "openstack", instance = nil)
457456
barclamp = depedency.shift
458457
prev_cfg, curr_cfg = Barclamp::Config.last_two_configs(group, barclamp, instance)
459458
old = loadattr(prev_cfg, depedency)
460459
new = loadattr(curr_cfg, depedency)
461460
Chef::Log.debug("smart loadattr prev #{depedency}, #{prev_cfg}")
462461
Chef::Log.debug("smart loadattr curr #{depedency}, #{curr_cfg.inspect}")
463462
Chef::Log.debug("smart comparisoin #{old}, #{new}")
464-
return old != new
463+
old != new
465464
end
466465

467466
def load(group, barclamp, instance = nil)
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
require 'chef/mixin/language_include_recipe'
1+
require "chef/mixin/language_include_recipe"
22

33
class Chef
44
module Mixin
55
module LanguageIncludeRecipe
66
def include_recipe_smartly(*list_of_recipes)
7-
for recipe in list_of_recipes
8-
included=false
9-
for dependency in BarclampLibrary::Barclamp::DependsOn.get(recipe)
10-
if BarclampLibrary::Barclamp::Config.has_changes_to_apply(dependency)
11-
Chef::Log.info("smart including recipe: #{recipe}")
12-
Chef::Log.debug("due to change in: #{dependency}")
13-
include_recipe recipe
14-
included=true
15-
break
16-
end # if
17-
end # for
7+
list_of_recipes.each do |recipe|
8+
included = false
9+
BarclampLibrary::Barclamp::DependsOn.get(recipe).each do |dependency|
10+
next unless BarclampLibrary::Barclamp::Config.changes_to_apply?(dependency)
11+
Chef::Log.info("smart including recipe: #{recipe}")
12+
Chef::Log.debug("due to change in: #{dependency}")
13+
include_recipe recipe
14+
included = true
15+
break
16+
end # each
1817
Chef::Log.info("recipe excluded: #{recipe}") unless included
19-
end # for
18+
end # each
2019
end # def include_recipe_smartly
2120
end
2221
end
2322
end
24-

0 commit comments

Comments
 (0)