Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump the bosh_cpi gem #273

Merged
merged 3 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ci/tasks/run-lifecycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@ if [ "${AZURE_USE_MANAGED_DISKS}" == "false" ]; then
bundle exec rspec spec/integration/managed_disks_migration_spec.rb
popd > /dev/null
fi

# The azure_cpi test doesn't care whether managed disks are used. Only run it when AZURE_USE_MANAGED_DISKS is set to true
if [ "${AZURE_USE_MANAGED_DISKS}" == "true" ]; then
export BOSH_AZURE_USE_MANAGED_DISKS=true
pushd bosh-cpi-src/src/bosh_azure_cpi > /dev/null
bundle install
bundle exec rspec spec/integration/azure_cpi_spec.rb
popd > /dev/null
fi
5 changes: 2 additions & 3 deletions src/bosh_azure_cpi/Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
source 'https://rubygems.org'

gem 'bosh_common'
gem 'bosh_cpi'
gem 'bosh_common', '1.3262.24.0'
gem 'bosh_cpi', '2.1.1'
gem 'azure-storage', '0.12.1.preview'
gem 'vhd', '0.0.4'
gem 'httpclient', '2.4.0'

group :development, :test do
gem 'rspec', '~>3.0.0'
Expand Down
13 changes: 6 additions & 7 deletions src/bosh_azure_cpi/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ GEM
faraday_middleware (~> 0.10)
nokogiri (~> 1.7, < 1.8)
bit-struct (0.15.0)
bosh_common (1.3262.4.0)
bosh_common (1.3262.24.0)
logging (~> 1.8.2)
semi_semantic (~> 1.2.0)
bosh_cpi (1.3262.4.0)
bosh_common (~> 1.3262.4.0)
bosh_cpi (2.1.1)
httpclient (~> 2.8.3)
logging (~> 1.8.2)
membrane (~> 1.1.0)
crack (0.4.3)
Expand All @@ -28,7 +28,7 @@ GEM
faraday_middleware (0.11.0.1)
faraday (>= 0.7.4, < 1.0)
hashdiff (0.3.0)
httpclient (2.4.0)
httpclient (2.8.3)
json (1.8.3)
little-plugger (1.1.4)
logging (1.8.2)
Expand Down Expand Up @@ -72,9 +72,8 @@ PLATFORMS

DEPENDENCIES
azure-storage (= 0.12.1.preview)
bosh_common
bosh_cpi
httpclient (= 2.4.0)
bosh_common (= 1.3262.24.0)
bosh_cpi (= 2.1.1)
rake (~> 10.3.2)
rspec (~> 3.0.0)
simplecov
Expand Down
8 changes: 6 additions & 2 deletions src/bosh_azure_cpi/bin/azure_cpi
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ require 'cloud/azure'

cpi_config = YAML.load_file(ARGV.shift)

cloud_config = OpenStruct.new(:logger => Logger.new(STDERR))
cloud_config = OpenStruct.new(:logger => Bosh::Cpi::Logger.new(STDERR))

Bosh::Clouds::Config.configure(cloud_config)

cpi_log = StringIO.new

cpi_lambda = lambda do
cpi_lambda = lambda do |context|
unless cpi_config.has_key?('cloud') && cpi_config['cloud'].has_key?('properties')
raise "Could not find cloud properties in the configuration"
end

cloud_properties = cpi_config['cloud']['properties']
cloud_properties['cpi_log'] = cpi_log

# allow azure config to be overwritten dynamically by context
cloud_properties['azure'].merge!(context)

Bosh::Clouds::Azure.new(cloud_properties)
end

Expand Down
5 changes: 5 additions & 0 deletions src/bosh_azure_cpi/lib/cloud/azure/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def initialize(options)

@logger = Bosh::Clouds::Config.logger

request_id = options['azure']['request_id']
if request_id
@logger.set_request_id(request_id)
end

@use_managed_disks = azure_properties['use_managed_disks']

init_registry
Expand Down
215 changes: 215 additions & 0 deletions src/bosh_azure_cpi/spec/integration/azure_cpi_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
require 'spec_helper'
require 'json'
require 'tempfile'
require 'yaml'

describe 'the azure_cpi executable' do

before(:all) do
@subscription_id = ENV['BOSH_AZURE_SUBSCRIPTION_ID'] || raise("Missing BOSH_AZURE_SUBSCRIPTION_ID")
@resource_group_name = ENV['BOSH_AZURE_RESOURCE_GROUP_NAME_FOR_VMS'] || raise("Missing BOSH_AZURE_RESOURCE_GROUP_NAME_FOR_VMS")
@tenant_id = ENV['BOSH_AZURE_TENANT_ID'] || raise("Missing BOSH_AZURE_TENANT_ID")
@client_id = ENV['BOSH_AZURE_CLIENT_ID'] || raise("Missing BOSH_AZURE_CLIENT_ID")
@client_secret = ENV['BOSH_AZURE_CLIENT_SECRET'] || raise("Missing BOSH_AZURE_CLIENT_SECRET")
@ssh_public_key = ENV['BOSH_AZURE_SSH_PUBLIC_KEY'] || raise("Missing BOSH_AZURE_SSH_PUBLIC_KEY")
@default_security_group = ENV['BOSH_AZURE_DEFAULT_SECURITY_GROUP'] || raise("Missing BOSH_AZURE_DEFAULT_SECURITY_GROUP")
end

let(:azure_environment) { ENV.fetch('BOSH_AZURE_ENVIRONMENT', 'AzureCloud') }

before(:each) do
config_file.write(cloud_properties.to_yaml)
config_file.close
end

let(:config_file) { Tempfile.new('cloud_properties.yml') }

let(:cloud_properties) do
{
'cloud' => {
'properties' => {
'azure' => {
'environment' => azure_environment,
'subscription_id' => @subscription_id,
'resource_group_name' => @resource_group_name,
'tenant_id' => @tenant_id,
'client_id' => @client_id,
'client_secret' => @client_secret,
'ssh_user' => 'vcap',
'ssh_public_key' => @ssh_public_key,
'default_security_group' => @default_security_group,
'parallel_upload_thread_num' => 16,
'use_managed_disks' => true
},
'registry' => {
'endpoint' => 'fake',
'user' => 'fake',
'password' => 'fake'
}
}
}
}
end

context 'when given invalid credentials' do
context 'when client_id is invalid' do
let(:cloud_properties) do
{
'cloud' => {
'properties' => {
'azure' => {
'environment' => azure_environment,
'subscription_id' => @subscription_id,
'resource_group_name' => @resource_group_name,
'tenant_id' => @tenant_id,
'client_id' => 'fake-client-id',
'client_secret' => @client_secret,
'ssh_user' => 'vcap',
'ssh_public_key' => @ssh_public_key,
'default_security_group' => @default_security_group,
'parallel_upload_thread_num' => 16,
'use_managed_disks' => true
},
'registry' => {
'endpoint' => 'fake',
'user' => 'fake',
'password' => 'fake'
}
}
}
}
end

it 'will not evaluate anything that causes an exception and will return the proper message to stdout' do
result = run_cpi({'method'=>'ping', 'arguments'=>[], 'context'=>{'director_uuid' => 'abc123'}})

expect(result.keys).to eq(%w(result error log))

expect(result['result']).to be_nil

expect(result['error']['message']).to match(/http code: 400. Azure authentication failed: Bad request. Please assure no typo in values of tenant id, client id or client secret/)
expect(result['error']['ok_to_retry']).to be(false)
expect(result['error']['type']).to eq("Bosh::Clouds::CloudError")

expect(result['log']).to include('backtrace')
end
end

context 'when client_secret is invalid' do
let(:cloud_properties) do
{
'cloud' => {
'properties' => {
'azure' => {
'environment' => azure_environment,
'subscription_id' => @subscription_id,
'resource_group_name' => @resource_group_name,
'tenant_id' => @tenant_id,
'client_id' => @client_id,
'client_secret' => 'fake-client-secret',
'ssh_user' => 'vcap',
'ssh_public_key' => @ssh_public_key,
'default_security_group' => @default_security_group,
'parallel_upload_thread_num' => 16,
'use_managed_disks' => true
},
'registry' => {
'endpoint' => 'fake',
'user' => 'fake',
'password' => 'fake'
}
}
}
}
end

it 'will not evaluate anything that causes an exception and will return the proper message to stdout' do
result = run_cpi({'method'=>'ping', 'arguments'=>[], 'context'=>{'director_uuid' => 'abc123'}})

expect(result.keys).to eq(%w(result error log))

expect(result['result']).to be_nil

expect(result['error']['message']).to match(/http code: 401. Azure authentication failed: Invalid tenant id, client id or client secret/)
expect(result['error']['ok_to_retry']).to be(false)
expect(result['error']['type']).to eq("Bosh::Clouds::CloudError")

expect(result['log']).to include('backtrace')
end
end
end

context 'when given an empty config file' do
let(:cloud_properties) { {} }

it 'will return an appropriate error message when passed an invalid config file' do
result = run_cpi({'method'=>'ping', 'arguments'=>[], 'context'=>{'director_uuid' => 'abc123'}})

expect(result.keys).to eq(%w(result error log))

expect(result['result']).to be_nil

expect(result['error']).to eq({
'type' => 'Unknown',
'message' => 'Could not find cloud properties in the configuration',
'ok_to_retry' => false
})

expect(result['log']).to include('backtrace')
end
end

context 'when given cpi config in the context' do
let(:cloud_properties) {
{
'cloud' => {
'properties' => {
'azure' => {
},
'registry' => {
'endpoint' => 'fake',
'user' => 'fake',
'password' => 'fake'
}
}
}
}
}
let(:context) {
{
'director_uuid' => 'abc123',
'environment' => azure_environment,
'subscription_id' => @subscription_id,
'resource_group_name' => @resource_group_name,
'tenant_id' => @tenant_id,
'client_id' => @client_id,
'client_secret' => @client_secret,
'ssh_user' => 'vcap',
'ssh_public_key' => @ssh_public_key,
'default_security_group' => @default_security_group,
'parallel_upload_thread_num' => 16,
'use_managed_disks' => true
}
}
it 'merges the context into the cloud_properties' do
result = run_cpi({'method'=>'has_vm', 'arguments'=>['fake-instance-id'], 'context'=> context})

expect(result.keys).to eq(%w(result error log))

expect(result['result']).to be_falsey
expect(result['error']).to be_nil
end
end

def run_cpi(input)
command_file = Tempfile.new('command.json')
command_file.write(input.to_json)
command_file.close

stdoutput = `bin/azure_cpi #{config_file.path} < #{command_file.path} 2> /dev/null`
status = $?.exitstatus

expect(status).to eq(0)
JSON.parse(stdoutput)
end
end
5 changes: 4 additions & 1 deletion src/bosh_azure_cpi/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MOCK_AZURE_CLIENT_SECRET = '0e67d8fc-150e-4cc0-bbf3-087e6c4b9e2a'
MOCK_SSH_PUBLIC_KEY = 'bar'
MOCK_DEFAULT_SECURITY_GROUP = 'fake-default-nsg-name'
MOCK_REQUEST_ID = '47504c59-37af-42f3-a386-22d0c2c73175'

# Let us keep the least API versions here for unit tests.
AZURE_API_VERSION = '2015-06-15'
Expand Down Expand Up @@ -55,7 +56,8 @@ def mock_cloud_options
'parallel_upload_thread_num' => 16,
'default_security_group' => MOCK_DEFAULT_SECURITY_GROUP,
'debug_mode' => false,
'use_managed_disks' => false
'use_managed_disks' => false,
'request_id' => MOCK_REQUEST_ID
},
'registry' => {
'endpoint' => 'localhost:42288',
Expand Down Expand Up @@ -126,5 +128,6 @@ def mock_cloud(options = nil)
config.before do
logger = Logger.new('/dev/null')
allow(Bosh::Clouds::Config).to receive(:logger).and_return(logger)
allow(logger).to receive(:set_request_id).with(MOCK_REQUEST_ID)
end
end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/bosh_azure_cpi/vendor/package/json-1.8.3.gem
Binary file not shown.