summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ilyin <dilyin@mirantis.com>2016-05-25 17:53:26 +0300
committerDmitry Ilyin <dilyin@mirantis.com>2016-05-25 17:54:19 +0300
commit41966d861d18cd8d8665cf46f7a1d6690dd1bcaa (patch)
tree764c3ddf07ed36847675ebfb0c90bb4edcdc8d69
parent47d20c9c22c799d8b2e303643c450403b5a71776 (diff)
Improve generate functions handling
Notes
Notes (review): Code-Review+1: Sergii Golovatiuk <sgolovatiuk@mirantis.com> Verified+1: Fuel CI <fuel-ci-bot@mirantis.com> Code-Review+2: Bogdan Dobrelya <bdobrelia@mirantis.com> Workflow+1: Bogdan Dobrelya <bdobrelia@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 27 May 2016 07:38:58 +0000 Reviewed-on: https://review.openstack.org/321043 Project: openstack/fuel-noop-fixtures Branch: refs/heads/master
-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 d1b2023..cce37e5 100644
--- a/lib/noop/task/helpers.rb
+++ b/lib/noop/task/helpers.rb
@@ -77,26 +77,39 @@ module Noop
77 # @param context [RSpec::ExampleGroup] The 'self' of the RSpec example group 77 # @param context [RSpec::ExampleGroup] The 'self' of the RSpec example group
78 # @return <Lambda> 78 # @return <Lambda>
79 def create_ral_catalog(context) 79 def create_ral_catalog(context)
80 catalog = context.subject 80 catalog = context.catalog
81 catalog = catalog.call if catalog.is_a? Proc 81 catalog = catalog.call if catalog.is_a? Proc
82 ral_catalog = catalog.to_ral 82 ral_catalog = catalog.to_ral
83 generate_functions = [:generate, :eval_generate]
84
85 ral_catalog.resources.each do |resource| 83 ral_catalog.resources.each do |resource|
86 generate_functions.each do |function_name| 84 generate_additional_resources ral_catalog, resource
87 next unless resource.respond_to? function_name
88 generated = resource.send function_name
89 next unless generated.is_a? Array
90 generated.each do |generated_resource|
91 next unless generated_resource.is_a? Puppet::Type
92 ral_catalog.add_resource generated_resource
93 end
94 end
95 end 85 end
96
97 lambda { ral_catalog } 86 lambda { ral_catalog }
98 end 87 end
99 88
89 # If the resources has one of the generate function
90 # run it and add the generated resources to the catalog
91 # if they are not there already. Run generate functions
92 # recursively for the generated resources too.
93 # @param catalog [Puppet::Catalog]
94 # @param resource [Puppet::Type]
95 def generate_additional_resources(catalog, resource)
96 generate_functions = [:generate, :eval_generate]
97 generate_functions.each do |function_name|
98 next unless resource.respond_to? function_name
99 debug "Resource: #{resource} run: #{function_name}"
100 generated = resource.send function_name
101 next unless generated.is_a? Array
102 generated.each do |generated_resource|
103 next unless generated_resource.is_a? Puppet::Type
104 next if catalog.resource generated_resource.ref
105 debug "Add resource: #{generated_resource} to the catalog"
106 catalog.add_resource generated_resource
107 generate_additional_resources catalog, generated_resource
108 end
109 end
110 catalog
111 end
112
100 # Check if the currently running spec is the given one 113 # Check if the currently running spec is the given one
101 # or one of the given ones if an array is provided 114 # or one of the given ones if an array is provided
102 # @param spec [String, Array<String>] 115 # @param spec [String, Array<String>]