forked from cloudfoundry/bosh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted job template rendering into bosh-director-core gem
Signed-off-by: Mike Stallard <[email protected]>
- Loading branch information
Jeffrey Peckham
committed
Jan 25, 2014
1 parent
425839a
commit a3f9159
Showing
43 changed files
with
398 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--color | ||
--profile | ||
--require rspec/instafail | ||
--format RSpec::Instafail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# coding: utf-8 | ||
require File.expand_path('../lib/bosh/director/core/version', __FILE__) | ||
|
||
version = Bosh::Director::Core::VERSION | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'bosh-director-core' | ||
spec.version = version | ||
spec.authors = 'Pivotal' | ||
spec.email = '[email protected]' | ||
spec.description = 'Bosh::Director::Core provides common Director code for Director and Microbosh Deployer' | ||
spec.summary = 'Bosh::Director::Core provides common Director code for Director and Microbosh Deployer' | ||
spec.homepage = 'https://github.com/cloudfoundry/bosh' | ||
spec.license = 'Apache 2.0' | ||
|
||
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3') | ||
|
||
spec.files = `git ls-files -- lib/*`.split($/) | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = %w[lib] | ||
|
||
spec.add_dependency 'bosh_common', "~>#{version}" | ||
|
||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rspec' | ||
spec.add_development_dependency 'fakefs' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Bosh | ||
module Director | ||
module Core | ||
end | ||
end | ||
end |
19 changes: 7 additions & 12 deletions
19
...director/lib/bosh/director/tar_gzipper.rb → ...ore/lib/bosh/director/core/tar_gzipper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'bosh/director/core' | ||
|
||
module Bosh::Director::Core | ||
module Templates | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...ib/bosh/director/job_instance_renderer.rb → ...r/core/templates/job_instance_renderer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
.../lib/bosh/director/job_template_loader.rb → ...tor/core/templates/job_template_loader.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
bosh-director-core/lib/bosh/director/core/templates/rendered_file_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bosh/director/core/templates' | ||
|
||
module Bosh::Director::Core::Templates | ||
RenderedFileTemplate = Struct.new(:src_name, :dest_name, :contents) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ib/bosh/director/rendered_job_template.rb → ...r/core/templates/rendered_job_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...oyment_plan/rendered_templates_archive.rb → ...e/templates/rendered_templates_archive.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...osh/director/rendered_templates_writer.rb → ...re/templates/rendered_templates_writer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
bosh-director-core/lib/bosh/director/core/templates/src_file_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bosh/director/core/templates' | ||
|
||
module Bosh::Director::Core::Templates | ||
SrcFileTemplate = Struct.new(:src_name, :dest_name, :erb_file) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Bosh | ||
module Director | ||
module Core | ||
VERSION = '1.1840.0' | ||
end | ||
end | ||
end |
88 changes: 88 additions & 0 deletions
88
bosh-director-core/spec/bosh/director/core/tar_gzipper_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require 'spec_helper' | ||
|
||
require 'tmpdir' | ||
require 'fileutils' | ||
require 'bosh/director/core/tar_gzipper' | ||
|
||
module Bosh::Director::Core | ||
describe TarGzipper do | ||
let(:base_dir) { Dir.mktmpdir } | ||
let(:sources) { %w(1 one) } | ||
let(:dest) { Tempfile.new('logs') } # must keep tempfile reference lest it rm | ||
let(:errored_retval) { ['stdout string', 'a stderr message', double('Status', success?: false, exitstatus: 5)] } | ||
let(:success_retval) { ['', '', double('Status', success?: true)] } | ||
|
||
before do | ||
path = File.join(base_dir, '1', '2') | ||
FileUtils.mkdir_p(path) | ||
File.write(File.join(path, 'hello.log'), 'hello') | ||
|
||
path = File.join(base_dir, 'one', 'two') | ||
FileUtils.mkdir_p(path) | ||
File.write(File.join(path, 'goodbye.log'), 'goodbye') | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf(base_dir) | ||
FileUtils.rm_rf(dest.path) | ||
end | ||
|
||
context 'when copy first feature is enabled' do | ||
it 'copies the files to a temp directory before archiving' do | ||
Dir.stub(:mktmpdir).and_yield('/tempthing') | ||
FileUtils.should_receive(:cp_r).with(%w(/foo/baz /foo/bar), '/tempthing/') | ||
Pathname.stub(:new).and_return(instance_double('Pathname', exist?: true, absolute?: true)) | ||
|
||
Open3.should_receive(:capture3) | ||
.with(*%w(tar -C /tempthing -czf /tmp/backup.tgz baz bar)) | ||
.and_return(success_retval) | ||
|
||
subject.compress('/foo', %w(baz bar), '/tmp/backup.tgz', copy_first: true) | ||
end | ||
end | ||
|
||
it 'raises when a source has a path depth greater than 1' do # sources that contain a '/' | ||
expect { | ||
subject.compress('/var/vcap/foo', %w(foo/bar), '/tmp/backup.tgz') | ||
}.to raise_error("Sources must have a path depth of 1 and contain no '/'") | ||
end | ||
|
||
context 'if the source directory does not exist' do | ||
let(:base_dir) { '/tmp/this/is/not/here' } | ||
|
||
it 'raises an error' do | ||
FileUtils.rm_rf(base_dir) | ||
|
||
expect { | ||
subject.compress(base_dir, sources, dest.path) | ||
}.to raise_error("The base directory #{base_dir} could not be found.") | ||
end | ||
end | ||
|
||
context 'if the base_dir is not absolute' do | ||
let(:base_dir) { 'tmp' } | ||
|
||
it 'raises an error' do | ||
expect { | ||
subject.compress(base_dir, sources, dest.path) | ||
}.to raise_error("The base directory #{base_dir} is not an absolute path.") | ||
end | ||
end | ||
|
||
it 'packages the sources into the destination tarball' do | ||
subject.compress(base_dir, sources, dest.path) | ||
|
||
output = `tar tzvf #{dest.path}` | ||
expect(output).to include(' 1/2/hello.log') | ||
expect(output).to include(' one/two/goodbye.log') | ||
end | ||
|
||
it 'raises if it fails to tar' do | ||
Open3.stub(:capture3).and_return(errored_retval) | ||
expect { | ||
subject.compress(base_dir, sources, dest) | ||
}.to raise_error(RuntimeError, | ||
"tar exited 5, output: 'stdout string', error: 'a stderr message'") | ||
end | ||
end | ||
end |
Oops, something went wrong.