Skip to content

Commit

Permalink
clean up after automated deploy
Browse files Browse the repository at this point in the history
Signed-off-by: dmitriy kalinin <dmitriy@pivotallabs.com>
  • Loading branch information
caleb miles authored and dmitriy kalinin committed Apr 15, 2014
1 parent 4bff724 commit 25c3d6b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
2 changes: 2 additions & 0 deletions bosh-dev/lib/bosh/dev/automated_deploy.rb
Expand Up @@ -49,6 +49,8 @@ def deploy

manifest_path = @deployment_account.manifest_path
director_client.deploy(manifest_path)

director_client.clean_up
end

private
Expand Down
18 changes: 11 additions & 7 deletions bosh-dev/lib/bosh/dev/director_client.rb
Expand Up @@ -5,18 +5,17 @@
module Bosh::Dev
class DirectorClient
def initialize(options = {})
@uri = options.fetch(:uri)
@username = options.fetch(:username)
@password = options.fetch(:password)
@cli = BoshCliSession.new
@director_handle = Bosh::Cli::Client::Director.new(uri, username, password)
@uri = options.fetch(:uri)
@username = options.fetch(:username)
@password = options.fetch(:password)
@cli = BoshCliSession.new
@director_handle = Bosh::Cli::Client::Director.new(uri, username, password)
end

def upload_stemcell(stemcell_archive)
target_and_login!
unless has_stemcell?(stemcell_archive.name, stemcell_archive.version)
cmd = "upload stemcell #{stemcell_archive.path}"
cli.run_bosh(cmd, debug_on_fail: true)
cli.run_bosh("upload stemcell #{stemcell_archive.path}", debug_on_fail: true)
end
end

Expand All @@ -32,6 +31,11 @@ def deploy(manifest_path)
cli.run_bosh('deploy', debug_on_fail: true)
end

def clean_up
target_and_login!
cli.run_bosh('cleanup', debug_on_fail: true)
end

private

attr_reader :uri, :username, :password, :cli, :director_handle
Expand Down
16 changes: 11 additions & 5 deletions bosh-dev/spec/bosh/dev/automated_deploy_spec.rb
Expand Up @@ -106,10 +106,15 @@ module Bosh::Dev
end

let(:director_client) do
instance_double('Bosh::Dev::DirectorClient', upload_stemcell: nil, upload_release: nil, deploy: nil)
instance_double('Bosh::Dev::DirectorClient', {
upload_stemcell: nil,
upload_release: nil,
deploy: nil,
clean_up: nil,
})
end

it 'prepare deployment account and then follows the normal deploy procedure' do
it 'prepare deployment account and then follows the normal deploy procedure and then cleans up old resources' do
expect(deployment_account).to receive(:prepare).with(no_args)

artifacts_downloader
Expand All @@ -125,9 +130,10 @@ module Bosh::Dev
stemcell_archive = instance_double('Bosh::Stemcell::Archive')
Bosh::Stemcell::Archive.should_receive(:new).with('/tmp/stemcell.tgz').and_return(stemcell_archive)

director_client.should_receive(:upload_stemcell).with(stemcell_archive)
director_client.should_receive(:upload_release).with('/tmp/release.tgz')
director_client.should_receive(:deploy).with('/path/to/manifest.yml')
director_client.should_receive(:upload_stemcell).with(stemcell_archive).ordered
director_client.should_receive(:upload_release).with('/tmp/release.tgz').ordered
director_client.should_receive(:deploy).with('/path/to/manifest.yml').ordered
director_client.should_receive(:clean_up).with(no_args).ordered

deployer.deploy
end
Expand Down
20 changes: 18 additions & 2 deletions bosh-dev/spec/bosh/dev/director_client_spec.rb
Expand Up @@ -58,7 +58,6 @@ module Bosh::Dev

it 'does not re-upload it' do
cli.should_not_receive(:run_bosh).with(/upload stemcell/, debug_on_fail: true)

director_client.upload_stemcell(stemcell_archive)
end
end
Expand All @@ -67,7 +66,6 @@ module Bosh::Dev
describe '#upload_release' do
it 'uploads the release using the cli, skipping if the release already exists' do
cli.should_receive(:run_bosh).with('upload release /path/to/fake-release.tgz --skip-if-exists', debug_on_fail: true)

director_client.upload_release('/path/to/fake-release.tgz')
end

Expand Down Expand Up @@ -144,5 +142,23 @@ module Bosh::Dev
director_client.deploy(manifest_path)
end
end

describe '#clean_up' do
it 'cleans up resources on the director' do
cli.should_receive(:run_bosh).with('cleanup', debug_on_fail: true)
director_client.clean_up
end

it 'always re-targets and logs in first' do
target_retryable = double('target-retryable')
Bosh::Retryable.stub(:new).with(tries: 3, on: [RuntimeError]).and_return(target_retryable)

cli.should_receive(:run_bosh).with('target bosh.example.com', retryable: target_retryable).ordered
cli.should_receive(:run_bosh).with('login fake_username fake_password').ordered
cli.should_receive(:run_bosh).with(/cleanup/, debug_on_fail: true).ordered

director_client.clean_up
end
end
end
end

0 comments on commit 25c3d6b

Please sign in to comment.