Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ha-feature-exoscale
- Loading branch information
Showing
5 changed files
with
125 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,7 @@ end | |
group :deis do | ||
gem 'git' | ||
end | ||
|
||
group :opsworks do | ||
gem 'aws-sdk', '>= 2.0.18.pre' | ||
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
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 |
---|---|---|
@@ -1,91 +1,127 @@ | ||
require 'spec_helper' | ||
require 'aws-sdk-v1' | ||
require 'aws-sdk' | ||
require 'dpl/provider' | ||
require 'dpl/provider/ops_works' | ||
|
||
describe DPL::Provider::OpsWorks do | ||
|
||
before (:each) do | ||
AWS.stub! | ||
subject :provider do | ||
described_class.new(DummyContext.new, :access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz') | ||
end | ||
|
||
subject :provider do | ||
described_class.new(DummyContext.new, :access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz', :bucket => 'my-bucket') | ||
describe '#opsworks_options' do | ||
context 'without region' do | ||
example do | ||
options = provider.opsworks_options | ||
expect(options[:region]).to eq('us-east-1') | ||
end | ||
end | ||
|
||
context 'with region' do | ||
example do | ||
region = 'us-west-1' | ||
provider.options.update(:region => region) | ||
options = provider.opsworks_options | ||
expect(options[:region]).to eq(region) | ||
end | ||
end | ||
end | ||
|
||
describe "#check_auth" do | ||
example do | ||
expect(provider).to receive(:setup_auth) | ||
expect(provider).to receive(:log).with('Logging in with Access Key: ****************jklz') | ||
provider.check_auth | ||
end | ||
end | ||
|
||
describe "#setup_auth" do | ||
example do | ||
expect(AWS).to receive(:config).with(:access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz').once.and_call_original | ||
provider.setup_auth | ||
end | ||
end | ||
|
||
describe "#needs_key?" do | ||
example do | ||
expect(provider.needs_key?).to eq(false) | ||
end | ||
end | ||
|
||
describe "#push_app" do | ||
let(:client) { double(:ops_works_client) } | ||
let(:ops_works_app) { {shortname: 'app', stack_id: 'stack-id'} } | ||
before do | ||
expect(provider).to receive(:current_sha).and_return('sha') | ||
expect(provider.api).to receive(:client).and_return(client) | ||
expect(provider.context.env).to receive(:[]).with('TRAVIS_BUILD_NUMBER').and_return('123') | ||
end | ||
describe DPL::Provider::OpsWorks do | ||
access_key_id = 'someaccesskey' | ||
secret_access_key = 'somesecretaccesskey' | ||
region = 'us-east-1' | ||
|
||
let(:custom_json) { "{\"deploy\":{\"app\":{\"migrate\":false,\"scm\":{\"revision\":\"sha\"}}}}" } | ||
example 'without :migrate option' do | ||
provider.options.update(app_id: 'app-id') | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]} | ||
) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json | ||
).and_return({}) | ||
provider.push_app | ||
end | ||
client_options = { | ||
stub_responses: true, | ||
region: region, | ||
credentials: Aws::Credentials.new(access_key_id, secret_access_key) | ||
} | ||
|
||
let(:custom_json_with_migrate) { "{\"deploy\":{\"app\":{\"migrate\":true,\"scm\":{\"revision\":\"sha\"}}}}" } | ||
example 'with :migrate option' do | ||
provider.options.update(app_id: 'app-id', migrate: true) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json_with_migrate | ||
).and_return({}) | ||
provider.push_app | ||
subject :provider do | ||
described_class.new(DummyContext.new, { | ||
access_key_id: access_key_id, | ||
secret_access_key: secret_access_key | ||
}) | ||
end | ||
|
||
example 'with :wait_until_deployed' do | ||
provider.options.update(app_id: 'app-id', wait_until_deployed: true) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).and_return({deployment_id: 'deployment_id'}) | ||
expect(client).to receive(:describe_deployments).with({deployment_ids: ['deployment_id']}).and_return({deployments: [status: 'running']}, {deployments: [status: 'successful']}) | ||
provider.push_app | ||
before :each do | ||
expect(provider).to receive(:opsworks_options).and_return(client_options) | ||
end | ||
|
||
example 'with :instance-ids' do | ||
provider.options.update(app_id: 'app-id', instance_ids: ['instance-id']) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', instance_ids:['instance-id'], command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json | ||
).and_return({}) | ||
provider.push_app | ||
describe '#opsworks' do | ||
example do | ||
expect(Aws::OpsWorks::Client).to receive(:new).with(client_options).once | ||
provider.opsworks | ||
end | ||
end | ||
end | ||
|
||
describe "#api" do | ||
example do | ||
expect(AWS::OpsWorks).to receive(:new) | ||
provider.api | ||
describe "#push_app" do | ||
let(:client) { provider.opsworks } | ||
let(:ops_works_app) { {shortname: 'app', stack_id: 'stack-id'} } | ||
before do | ||
expect(provider).to receive(:current_sha).and_return('sha') | ||
expect(provider.context.env).to receive(:[]).with('TRAVIS_BUILD_NUMBER').and_return('123') | ||
end | ||
|
||
let(:custom_json) { "{\"deploy\":{\"app\":{\"migrate\":false,\"scm\":{\"revision\":\"sha\"}}}}" } | ||
example 'without :migrate option' do | ||
provider.options.update(app_id: 'app-id') | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json | ||
).and_return({}) | ||
provider.push_app | ||
end | ||
|
||
let(:custom_json_with_migrate) { "{\"deploy\":{\"app\":{\"migrate\":true,\"scm\":{\"revision\":\"sha\"}}}}" } | ||
example 'with :migrate option' do | ||
provider.options.update(app_id: 'app-id', migrate: true) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json_with_migrate | ||
).and_return({}) | ||
provider.push_app | ||
end | ||
|
||
example 'with :wait_until_deployed' do | ||
provider.options.update(app_id: 'app-id', wait_until_deployed: true) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).and_return({deployment_id: 'deployment_id'}) | ||
expect(client).to receive(:describe_deployments).with({deployment_ids: ['deployment_id']}).and_return({deployments: [status: 'running']}, {deployments: [status: 'successful']}) | ||
provider.push_app | ||
end | ||
|
||
example 'with :instance-ids' do | ||
provider.options.update(app_id: 'app-id', instance_ids: ['instance-id']) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', instance_ids:['instance-id'], command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json | ||
).and_return({}) | ||
provider.push_app | ||
end | ||
|
||
example 'with :layer-ids' do | ||
provider.options.update(app_id: 'app-id', layer_ids: ['layer-id']) | ||
expect(client).to receive(:describe_apps).with(app_ids: ['app-id']).and_return({apps: [ops_works_app]}) | ||
expect(client).to receive(:create_deployment).with( | ||
stack_id: 'stack-id', app_id: 'app-id', layer_ids:['layer-id'], command: {name: 'deploy'}, comment: 'Deploy build 123 via Travis CI', custom_json: custom_json | ||
).and_return({}) | ||
provider.push_app | ||
end | ||
end | ||
end | ||
end |