Skip to content

Commit b549023

Browse files
author
Kevin Paulisse
committed
Implement preserve environments feature
1 parent b5e81c2 commit b549023

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def initialize(options = {}, logger = nil)
4949

5050
create_structure
5151

52-
if options[:preserve_environment]
52+
if options[:preserve_environments]
5353
install_directory_symlink(logger, File.join(options[:basedir], 'environments'), 'environments')
5454
options.fetch(:create_symlinks, %w(modules manifests)).each do |x|
5555
install_directory_symlink(logger, File.join(options[:basedir], x), x)

lib/octocatalog-diff/catalog-util/command.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ def puppet_command
7373
--no-ca
7474
--color=false
7575
--config_version="/bin/echo catalogscript"
76-
--environment=production
7776
)
7877

78+
# Add environment - only make this variable if preserve_environments is used.
79+
# If preserve_environments is not used, the hard-coded 'production' here matches
80+
# up with the symlink created under the temporary directory structure.
81+
environ = @options[:preserve_environments] ? @options.fetch(:environment, 'production') : 'production'
82+
cmdline << "--environment=#{Shellwords.escape(environ)}"
83+
7984
# For people who aren't running hiera, a hiera-config will not be generated when @options[:hiera_config]
8085
# is nil. For everyone else, the hiera config was generated/copied/munged in the 'builddir' class
8186
# and was installed into the compile directory and named hiera.yaml.

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,21 @@ def exec_puppet
181181
}
182182
end
183183

184+
# Private method: Make sure that the Puppet environment directory exists.
185+
def assert_that_puppet_environment_directory_exists
186+
environ = @opts[:preserve_environments] ? @opts.fetch(:environment, 'production') : 'production'
187+
target_dir = File.join(@builddir.tempdir, 'environments', environ)
188+
return if File.directory?(target_dir)
189+
raise Errno::ENOENT, "Environment directory #{target_dir} does not exist"
190+
end
191+
184192
# Private method: Runs puppet on the command line to compile the catalog
185193
# Exit code is 0 if catalog generation was successful, non-zero otherwise.
186194
# @param logger [Logger] Logger object
187195
# @return [Hash] { stdout: <catalog as JSON>, stderr: <error messages>, exitcode: <hopefully 0> }
188196
def run_puppet(logger)
197+
assert_that_puppet_environment_directory_exists
198+
189199
# Run 'cmd' with environment 'env' from directory 'dir'
190200
# First line of a successful result needs to be stripped off. It will look like:
191201
# Notice: Compiled catalog for xxx in environment production in 27.88 seconds

0 commit comments

Comments
 (0)