Implement option for bootstrapping current directory
This commit is contained in:
Родитель
978cabaa23
Коммит
f307fc645a
|
@ -136,6 +136,10 @@ module OctocatalogDiff
|
|||
def self.run_bootstrap(logger, opts)
|
||||
logger.debug("Begin bootstrap with '#{opts[:bootstrap_script]}' in #{opts[:path]}")
|
||||
result = OctocatalogDiff::Bootstrap.bootstrap(opts)
|
||||
if opts[:debug_bootstrap] || result[:status_code] > 0
|
||||
output = result[:output].split(/[\r\n]+/)
|
||||
output.each { |x| logger.debug("Bootstrap: #{x}") }
|
||||
end
|
||||
raise BootstrapError, "bootstrap failed for #{opts[:path]}: #{result[:output]}" unless (result[:status_code]).zero?
|
||||
logger.debug("Success bootstrap in #{opts[:path]}")
|
||||
result[:output]
|
||||
|
|
|
@ -94,7 +94,17 @@ module OctocatalogDiff
|
|||
raise Errno::ENOENT, "Invalid dir #{@opts[:bootstrapped_dir]}" unless File.directory?(@opts[:bootstrapped_dir])
|
||||
tmphash[:basedir] = @opts[:bootstrapped_dir]
|
||||
elsif @opts[:branch] == '.'
|
||||
tmphash[:basedir] = @opts[:basedir]
|
||||
if @opts[:bootstrap_current]
|
||||
tmphash[:basedir] = Dir.mktmpdir
|
||||
at_exit { cleanup_checkout_dir(tmphash[:basedir], logger) }
|
||||
|
||||
FileUtils.cp_r File.join(@opts[:basedir], '.'), tmphash[:basedir]
|
||||
|
||||
o = @opts.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
|
||||
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(o, logger)
|
||||
else
|
||||
tmphash[:basedir] = @opts[:basedir]
|
||||
end
|
||||
else
|
||||
checkout_dir = Dir.mktmpdir
|
||||
at_exit { cleanup_checkout_dir(checkout_dir, logger) }
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
ls -lR > /tmp/foo.$$
|
||||
echo "Hello, stdout"
|
||||
echo "Hello, stderr" 1>&2
|
||||
cp -r external-modules/test modules
|
||||
exit 0
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "Fail, stdout"
|
||||
echo "Fail, stderr" 1>&2
|
||||
exit 1
|
|
@ -0,0 +1,5 @@
|
|||
class test {
|
||||
file { '/tmp/foo':
|
||||
content => template('test/foo.erb'),
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Test 123
|
|
@ -0,0 +1 @@
|
|||
include test
|
|
@ -7,6 +7,43 @@ require OctocatalogDiff::Spec.require_path('/catalog/computed')
|
|||
require OctocatalogDiff::Spec.require_path('/catalog-util/builddir')
|
||||
|
||||
describe OctocatalogDiff::Catalog::Computed do
|
||||
context 'bootstrapping in the current directory' do
|
||||
before(:all) do
|
||||
@repo_dir = Dir.mktmpdir
|
||||
FileUtils.cp_r OctocatalogDiff::Spec.fixture_path('repos/bootstrap'), @repo_dir
|
||||
|
||||
@node = 'rspec-node.github.net'
|
||||
catalog_opts = {
|
||||
node: @node,
|
||||
puppet_binary: OctocatalogDiff::Spec::PUPPET_BINARY,
|
||||
basedir: File.join(@repo_dir, 'bootstrap'),
|
||||
fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'),
|
||||
branch: '.',
|
||||
bootstrap_current: true,
|
||||
debug_bootstrap: true,
|
||||
bootstrap_script: 'config/bootstrap.sh'
|
||||
}
|
||||
@catalog = OctocatalogDiff::Catalog::Computed.new(catalog_opts)
|
||||
logger, @logger_str = OctocatalogDiff::Spec.setup_logger
|
||||
@catalog.build(logger)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
OctocatalogDiff::Spec.clean_up_tmpdir(@repo_dir)
|
||||
end
|
||||
|
||||
describe '#bootstrap' do
|
||||
it 'should result in a successful compilation' do
|
||||
expect(@catalog.catalog).to be_a_kind_of(Hash), @catalog.inspect
|
||||
end
|
||||
|
||||
it 'should log debug messages' do
|
||||
expect(@logger_str.string).to match(/Bootstrap: Hello, stdout/)
|
||||
expect(@logger_str.string).to match(/Bootstrap: Hello, stderr/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'compiling a catalog' do
|
||||
context 'with a working catalog' do
|
||||
before(:all) do
|
||||
|
|
Загрузка…
Ссылка в новой задаче