summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ilyin <dilyin@mirantis.com>2016-05-05 16:33:02 +0300
committerDmitry Ilyin <dilyin@mirantis.com>2016-05-20 11:55:08 +0300
commitda6ea6109e3ca92c852c4543bb226569c74beb50 (patch)
tree55137fe74c60c9acbf013a2e3d3d3acf4f5f72bf
parent47d20c9c22c799d8b2e303643c450403b5a71776 (diff)
Puppet4 Support: noop fixtures
Notes
Notes (review): Verified+1: Fuel CI <fuel-ci-bot@mirantis.com> Code-Review+1: Ivan Berezovskiy <iberezovskiy@mirantis.com> Code-Review+2: Dmitry Ilyin <dilyin@mirantis.com> Workflow+1: Dmitry Ilyin <dilyin@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 23 May 2016 16:26:23 +0000 Reviewed-on: https://review.openstack.org/312948 Project: openstack/fuel-noop-fixtures Branch: refs/heads/master
-rw-r--r--Gemfile2
-rw-r--r--catalogs/.gitignore1
-rw-r--r--facts/ubuntu.yaml1
-rw-r--r--lib/noop/task/facts.rb1
-rw-r--r--lib/noop/task/helpers.rb37
-rw-r--r--lib/noop/task/overrides.rb22
-rw-r--r--spec/shared-examples.rb2
7 files changed, 53 insertions, 13 deletions
diff --git a/Gemfile b/Gemfile
index d886be3..cb312fa 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3group :development, :test do 3group :development, :test do
4 gem 'puppetlabs_spec_helper' 4 gem 'puppetlabs_spec_helper'
5 gem 'puppet-lint', '~> 0.3.2' 5 gem 'puppet-lint', '~> 0.3.2'
6 gem 'rspec-puppet', '~> 2.2.0' 6 gem 'rspec-puppet', '~> 2.4.0'
7 gem 'rspec-puppet-utils', '~> 2.0.0' 7 gem 'rspec-puppet-utils', '~> 2.0.0'
8 gem 'deep_merge' 8 gem 'deep_merge'
9 gem 'pry' 9 gem 'pry'
diff --git a/catalogs/.gitignore b/catalogs/.gitignore
index e69de29..b8cdaf8 100644
--- a/catalogs/.gitignore
+++ b/catalogs/.gitignore
@@ -0,0 +1 @@
*.pp
diff --git a/facts/ubuntu.yaml b/facts/ubuntu.yaml
index b0c3d85..f842575 100644
--- a/facts/ubuntu.yaml
+++ b/facts/ubuntu.yaml
@@ -18,3 +18,4 @@
18:lsbdistcodename: 'trusty' 18:lsbdistcodename: 'trusty'
19:os_package_type: 'debian' 19:os_package_type: 'debian'
20:os_service_default: '<SERVICE DEFAULT>' 20:os_service_default: '<SERVICE DEFAULT>'
21:libvirt_package_version: '1.2.9'
diff --git a/lib/noop/task/facts.rb b/lib/noop/task/facts.rb
index 8ccef34..7aaf735 100644
--- a/lib/noop/task/facts.rb
+++ b/lib/noop/task/facts.rb
@@ -67,6 +67,7 @@ module Noop
67 facts_data[:hostname] = hostname if hostname 67 facts_data[:hostname] = hostname if hostname
68 facts_data[:l3_fqdn_hostname] = hostname if hostname 68 facts_data[:l3_fqdn_hostname] = hostname if hostname
69 facts_data[:fqdn] = fqdn if fqdn 69 facts_data[:fqdn] = fqdn if fqdn
70 facts_data[:puppetversion] = Puppet.version
70 end 71 end
71 72
72 # @return [Hash] 73 # @return [Hash]
diff --git a/lib/noop/task/helpers.rb b/lib/noop/task/helpers.rb
index d1b2023..796f476 100644
--- a/lib/noop/task/helpers.rb
+++ b/lib/noop/task/helpers.rb
@@ -43,8 +43,12 @@ module Noop
43 def puppet_function(name, *args) 43 def puppet_function(name, *args)
44 name = name.to_sym unless name.is_a? Symbol 44 name = name.to_sym unless name.is_a? Symbol
45 puppet_function_load name 45 puppet_function_load name
46 error "Could not load Puppet function '#{name}'!" unless puppet_scope.respond_to? "function_#{name}".to_sym 46 if puppet4?
47 puppet_scope.send "function_#{name}".to_sym, args 47 puppet_scope.call_function name, args
48 else
49 error "Could not load Puppet function '#{name}'!" unless puppet_scope.respond_to? "function_#{name}".to_sym
50 puppet_scope.send "function_#{name}".to_sym, args
51 end
48 end 52 end
49 53
50 # Take a variable value from the saved puppet scope 54 # Take a variable value from the saved puppet scope
@@ -66,7 +70,7 @@ module Noop
66 def puppet_class_include(class_name) 70 def puppet_class_include(class_name)
67 class_name = class_name.to_s 71 class_name = class_name.to_s
68 unless puppet_scope.catalog.classes.include? class_name 72 unless puppet_scope.catalog.classes.include? class_name
69 debug "Dynamicly loading class: '#{class_name}'" 73 debug "Dynamically loading class: '#{class_name}'"
70 puppet_scope.compiler.evaluate_classes [class_name], puppet_scope, false 74 puppet_scope.compiler.evaluate_classes [class_name], puppet_scope, false
71 end 75 end
72 end 76 end
@@ -113,5 +117,32 @@ module Noop
113 end 117 end
114 end 118 end
115 119
120 # check if we're using Puppet4
121 # @return [true,false]
122 def puppet4?
123 Puppet.version.to_f >= 4.0
124 end
125
126 # convert the values in the nested data structure
127 # from nil to :undef as they are used in Puppet 4
128 # modifies the argument object and returns it
129 # @param data [Array, Hash]
130 # @return [Array, Hash]
131 def nil2undef(data)
132 return :undef if data.nil?
133 if data.is_a? Array
134 data.each_with_index do |value, index|
135 data[index] = nil2undef value
136 end
137 data
138 elsif data.is_a? Hash
139 data.keys.each do |key|
140 data[key] = nil2undef data[key]
141 end
142 data
143 end
144 data
145 end
146
116 end 147 end
117end 148end
diff --git a/lib/noop/task/overrides.rb b/lib/noop/task/overrides.rb
index cd8a354..d650efa 100644
--- a/lib/noop/task/overrides.rb
+++ b/lib/noop/task/overrides.rb
@@ -17,6 +17,10 @@ module Noop
17 RSpec.configuration.manifest = file_path_manifest.to_s 17 RSpec.configuration.manifest = file_path_manifest.to_s
18 RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.to_s 18 RSpec.configuration.module_path = Noop::Config.dir_path_modules_local.to_s
19 RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s 19 RSpec.configuration.manifest_dir = Noop::Config.dir_path_tasks_local.to_s
20
21 # FIXME: kludge to support calling Puppet function outside of the test context
22 Puppet.settings[:modulepath] = RSpec.configuration.module_path
23 Puppet.settings[:manifest] = RSpec.configuration.manifest_dir
20 end 24 end
21 25
22 # Override Hiera configuration in the Puppet objects 26 # Override Hiera configuration in the Puppet objects
@@ -82,15 +86,15 @@ module Noop
82 # This results in an rspec failure so we need to initialize the basic 86 # This results in an rspec failure so we need to initialize the basic
83 # settings up front to prevent issues with test framework. See PUP-5601 87 # settings up front to prevent issues with test framework. See PUP-5601
84 def puppet_default_settings 88 def puppet_default_settings
85 Puppet.settings.initialize_app_defaults( 89 defaults = {
86 { 90 :logdir => '/dev/null',
87 :logdir => '/dev/null', 91 :confdir => '/dev/null',
88 :confdir => '/dev/null', 92 :vardir => '/dev/null',
89 :vardir => '/dev/null', 93 :rundir => '/dev/null',
90 :rundir => '/dev/null', 94 :hiera_config => '/dev/null',
91 :hiera_config => '/dev/null', 95 }
92 } 96 defaults[:codedir] = '/dev/null' if puppet4?
93 ) 97 Puppet.settings.initialize_app_defaults(defaults)
94 end 98 end
95 99
96 def rspec_coverage_add_override 100 def rspec_coverage_add_override
diff --git a/spec/shared-examples.rb b/spec/shared-examples.rb
index c587a47..6b7d3c6 100644
--- a/spec/shared-examples.rb
+++ b/spec/shared-examples.rb
@@ -63,6 +63,8 @@ def run_test(manifest_file, *args)
63 63
64 Noop::Config.log.progname = 'noop_spec' 64 Noop::Config.log.progname = 'noop_spec'
65 Noop::Utils.debug "RSPEC: #{Noop.task.inspect}" 65 Noop::Utils.debug "RSPEC: #{Noop.task.inspect}"
66
67 # FIXME: kludge to support calling Puppet function outside of the test context
66 Noop.setup_overrides 68 Noop.setup_overrides
67 69
68 include FuelRelationshipGraphMatchers 70 include FuelRelationshipGraphMatchers