Class: RSpec::Puppet::Adapters::Adapter40

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec-puppet/adapters.rb

Direct Known Subclasses

Adapter4X, Adapter6X

Instance Method Summary collapse

Methods inherited from Base

#get_setting

Instance Method Details

#catalog(node, exported) ⇒ Object



180
181
182
183
184
185
186
187
188
189
# File 'lib/rspec-puppet/adapters.rb', line 180

def catalog(node, exported)
  node.environment = current_environment
  # Override $::environment to workaround PUP-5835, where Puppet otherwise
  # stores a symbol for the parameter
  if node.parameters['environment'] != node.parameters['environment'].to_s
    node.parameters['environment'] =
      current_environment.name.to_s
  end
  super
end

#current_environmentObject



191
192
193
# File 'lib/rspec-puppet/adapters.rb', line 191

def current_environment
  Puppet.lookup(:current_environment)
end

#manifestString?

Puppet 4.0 specially handles environments that don’t have a manifest set, so we check for the no manifest value and return nil when it is set.

Returns:

  • (String, nil)

    The path to the Puppet manifest if it is present and set, nil otherwise.



203
204
205
206
207
208
209
210
# File 'lib/rspec-puppet/adapters.rb', line 203

def manifest
  m = current_environment.manifest
  if m == Puppet::Node::Environment::NO_MANIFEST
    nil
  else
    m
  end
end

#modulepathObject



195
196
197
# File 'lib/rspec-puppet/adapters.rb', line 195

def modulepath
  current_environment.modulepath
end

#set_facter_impl(impl) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the FacterImpl constant to the given Facter implementation or noop if the constant is already set. If a proc is given, it will only be called if FacterImpl is not defined.

Parameters:

  • impl (Object, Proc)

    An object or a proc that implements the Facter API



126
127
128
129
130
131
# File 'lib/rspec-puppet/adapters.rb', line 126

def set_facter_impl(impl)
  return if defined?(FacterImpl)

  impl = impl.call if impl.is_a?(Proc)
  Object.send(:const_set, :FacterImpl, impl)
end

#settings_mapObject



171
172
173
174
175
176
177
178
# File 'lib/rspec-puppet/adapters.rb', line 171

def settings_map
  super.push(
    i[environmentpath environmentpath],
    i[hiera_config hiera_config],
    i[strict_variables strict_variables],
    i[manifest manifest]
  )
end

#setup_puppet(example_group) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/rspec-puppet/adapters.rb', line 133

def setup_puppet(example_group)
  super

  modulepath = if (rspec_modulepath = RSpec.configuration.module_path)
                 rspec_modulepath.split(File::PATH_SEPARATOR)
               else
                 Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
                   File.join(path, 'fixtures', 'modules')
                 end
               end

  if (rspec_manifest = RSpec.configuration.manifest)
    manifest = rspec_manifest
  else
    manifest_paths = Puppet[:environmentpath].split(File::PATH_SEPARATOR).map do |path|
      File.join(path, 'fixtures', 'manifests')
    end

    manifest = manifest_paths.find do |path|
      File.exist?(path)
    end

    manifest ||= Puppet::Node::Environment::NO_MANIFEST
  end

  env = Puppet::Node::Environment.create(@environment_name, modulepath, manifest)
  loader = Puppet::Environments::Static.new(env)

  Puppet.push_context(
    {
      environments: loader,
      current_environment: env,
      loaders: (Puppet::Pops::Loaders.new(env) if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0'))
    },
    'Setup rspec-puppet environments'
  )
end