summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-05-27 07:38:58 +0000
committerGerrit Code Review <review@openstack.org>2016-05-27 07:38:58 +0000
commit4db6b799b508176053db6c93480406809cbe2ece (patch)
treee0475d56991a1ae149211be2f8ea36d66d9bb815
parenta89fd17fb3377cdccef0507b1150e2849928fcf3 (diff)
parent41966d861d18cd8d8665cf46f7a1d6690dd1bcaa (diff)
Merge "Improve generate functions handling"
-rw-r--r--lib/noop/task/helpers.rb39
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/noop/task/helpers.rb b/lib/noop/task/helpers.rb
index 796f476..fcb945d 100644
--- a/lib/noop/task/helpers.rb
+++ b/lib/noop/task/helpers.rb
@@ -81,26 +81,39 @@ module Noop
81 # @param context [RSpec::ExampleGroup] The 'self' of the RSpec example group 81 # @param context [RSpec::ExampleGroup] The 'self' of the RSpec example group
82 # @return <Lambda> 82 # @return <Lambda>
83 def create_ral_catalog(context) 83 def create_ral_catalog(context)
84 catalog = context.subject 84 catalog = context.catalog
85 catalog = catalog.call if catalog.is_a? Proc 85 catalog = catalog.call if catalog.is_a? Proc
86 ral_catalog = catalog.to_ral 86 ral_catalog = catalog.to_ral
87 generate_functions = [:generate, :eval_generate]
88
89 ral_catalog.resources.each do |resource| 87 ral_catalog.resources.each do |resource|
90 generate_functions.each do |function_name| 88 generate_additional_resources ral_catalog, resource
91 next unless resource.respond_to? function_name
92 generated = resource.send function_name
93 next unless generated.is_a? Array
94 generated.each do |generated_resource|
95 next unless generated_resource.is_a? Puppet::Type
96 ral_catalog.add_resource generated_resource
97 end
98 end
99 end 89 end
100
101 lambda { ral_catalog } 90 lambda { ral_catalog }
102 end 91 end
103 92
93 # If the resources has one of the generate function
94 # run it and add the generated resources to the catalog
95 # if they are not there already. Run generate functions
96 # recursively for the generated resources too.
97 # @param catalog [Puppet::Catalog]
98 # @param resource [Puppet::Type]
99 def generate_additional_resources(catalog, resource)
100 generate_functions = [:generate, :eval_generate]
101 generate_functions.each do |function_name|
102 next unless resource.respond_to? function_name
103 debug "Resource: #{resource} run: #{function_name}"
104 generated = resource.send function_name
105 next unless generated.is_a? Array
106 generated.each do |generated_resource|
107 next unless generated_resource.is_a? Puppet::Type
108 next if catalog.resource generated_resource.ref
109 debug "Add resource: #{generated_resource} to the catalog"
110 catalog.add_resource generated_resource
111 generate_additional_resources catalog, generated_resource
112 end
113 end
114 catalog
115 end
116
104 # Check if the currently running spec is the given one 117 # Check if the currently running spec is the given one
105 # or one of the given ones if an array is provided 118 # or one of the given ones if an array is provided
106 # @param spec [String, Array<String>] 119 # @param spec [String, Array<String>]