Class: RSpec::Puppet::Adapters::Adapter4X

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

Instance Method Summary collapse

Methods inherited from Base

#set_setting

Instance Method Details

#catalog(node, exported) ⇒ Object



146
147
148
149
# File 'lib/rspec-puppet/adapters.rb', line 146

def catalog(node, exported)
  node.environment = current_environment
  super
end

#current_environmentObject



151
152
153
# File 'lib/rspec-puppet/adapters.rb', line 151

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.



163
164
165
166
167
168
169
170
# File 'lib/rspec-puppet/adapters.rb', line 163

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

#modulepathObject



155
156
157
# File 'lib/rspec-puppet/adapters.rb', line 155

def modulepath
  current_environment.modulepath
end

#settings_mapObject



138
139
140
141
142
143
144
# File 'lib/rspec-puppet/adapters.rb', line 138

def settings_map
  super.concat([
    [:environmentpath, :environmentpath],
    [:hiera_config, :hiera_config],
    [:strict_variables, :strict_variables],
  ])
end

#setup_puppet(example_group) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rspec-puppet/adapters.rb', line 101

def setup_puppet(example_group)
  super

  if rspec_modulepath = RSpec.configuration.module_path
    modulepath = rspec_modulepath.split(File::PATH_SEPARATOR)
  else
    modulepath = 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
    },
    "Setup rspec-puppet environments"
  )
end