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

multi CPI support #52

Merged
merged 18 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
98683de
multi cpi: allowing openstack properties to by overwritten by context…
MatthiasWinzeler Aug 10, 2016
1efd1db
multi-cpi: supporting ca_cert for context properties
MatthiasWinzeler Aug 17, 2016
7304e30
multi-cpi: separating writing ca file to disk from setting it in options
MatthiasWinzeler Aug 17, 2016
a80a313
multi-cpi: next try to make cert handling cleaner
MatthiasWinzeler Aug 17, 2016
9cef60d
Merge remote-tracking branch 'upstream/master' into multi-cpi
MatthiasWinzeler Aug 26, 2016
1fd522d
multi-cpi: bosh_cpi now merges cpi properties in context so we can us…
MatthiasWinzeler Aug 26, 2016
3041dfe
Merge branch 'master' into multi-cpi
MatthiasWinzeler Oct 12, 2016
04ad815
multi-cpi: don't just overwrite openstack properties but merge, so th…
MatthiasWinzeler Oct 12, 2016
7797037
multi-cpi: no need to check for context.nil? since it's always provid…
MatthiasWinzeler Nov 1, 2016
f702450
Merge branch 'master' into multi-cpi
MatthiasWinzeler Nov 16, 2016
3af0c10
multi-cpi: updating upstream bosh gems to contain context passing
MatthiasWinzeler Nov 17, 2016
8316304
multi-cpi: vendored updated upstream bosh gems
MatthiasWinzeler Nov 21, 2016
affaf07
Merge branch 'master' into multi-cpi
MatthiasWinzeler Nov 21, 2016
57f980b
multi-cpi: cpi properties are no longer in openstack subkey of contex…
MatthiasWinzeler Nov 23, 2016
377bf6f
Merge branch 'master' into multi-cpi
MatthiasWinzeler Dec 2, 2016
71d4c06
Merge remote-tracking branch 'origin/master' into swisscom-multi-cpi
friegger Dec 9, 2016
b774c50
Merge remote-tracking branch 'origin/master' into swisscom-multi-cpi
mauromorales Dec 13, 2016
7f24b4f
Fix context cacert handling
friegger Dec 20, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/bosh_openstack_cpi/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
bosh_common (1.3215.3.0)
bosh_common (1.3262.24.0)
logging (~> 1.8.2)
semi_semantic (~> 1.1.0)
bosh_cpi (1.3215.3.1)
semi_semantic (~> 1.2.0)
bosh_cpi (2.0.1)
bosh_common (~> 1.3262.24.0)
logging (~> 1.8.2)
membrane (~> 1.1.0)
builder (3.2.2)
Expand Down Expand Up @@ -53,7 +54,7 @@ GEM
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
safe_yaml (1.0.4)
semi_semantic (1.1.0)
semi_semantic (1.2.0)
timecop (0.7.4)
webmock (2.1.0)
addressable (>= 2.3.6)
Expand Down
24 changes: 5 additions & 19 deletions src/bosh_openstack_cpi/bin/openstack_cpi
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,9 @@ cloud_config = OpenStruct.new(:logger => Logger.new(STDERR))
Bosh::Clouds::Config.configure(cloud_config)

cpi_log = StringIO.new
Dir.mktmpdir do |dir|
cpi_lambda = Bosh::OpenStackCloud::CpiLambda.create(cpi_config, cpi_log, ssl_ca_file, File.join(dir, 'cacert_context.pem'))
cli = Bosh::Cpi::Cli.new(cpi_lambda, cpi_log, STDOUT)

cpi_lambda = lambda do
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
connection_options = cloud_properties['openstack']['connection_options']
# If 'ca_cert' is set we render non-empty `config/openstack.crt`
if connection_options && connection_options['ca_cert']
connection_options['ssl_ca_file'] = ssl_ca_file
connection_options.delete('ca_cert')
end
Bosh::Clouds::Openstack.new(cloud_properties)
end

cli = Bosh::Cpi::Cli.new(cpi_lambda, cpi_log, STDOUT)

cli.run(ARGF.read)
cli.run(ARGF.read)
end
1 change: 1 addition & 0 deletions src/bosh_openstack_cpi/lib/cloud/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module OpenStackCloud; end
require "cloud"
require "cloud/openstack/helpers"
require "cloud/openstack/cloud"
require "cloud/openstack/cpi_lambda"
require "cloud/openstack/openstack"
require "cloud/openstack/tag_manager"

Expand Down
32 changes: 32 additions & 0 deletions src/bosh_openstack_cpi/lib/cloud/openstack/cpi_lambda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Bosh::OpenStackCloud
class CpiLambda
def self.create(cpi_config, cpi_log, ca_cert_from_config, ca_cert_from_context)
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

# If 'ca_cert' is set in job config we render non-empty `config/openstack.crt` (excon needs it as a file)
connection_options = cloud_properties['openstack']['connection_options']
if connection_options && connection_options.delete('ca_cert')
connection_options['ssl_ca_file'] = ca_cert_from_config
end

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

# write ca cert to disk if given in context
connection_options = cloud_properties['openstack']['connection_options']
if connection_options && (ca_cert = connection_options.delete('ca_cert'))
File.write(ca_cert_from_context, ca_cert)
connection_options['ssl_ca_file'] = ca_cert_from_context
end

Bosh::Clouds::Openstack.new(cloud_properties)
end
end
end
end
90 changes: 90 additions & 0 deletions src/bosh_openstack_cpi/spec/unit/cpi_lambda_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require "spec_helper"

describe Bosh::OpenStackCloud::CpiLambda do
subject { described_class.create(cpi_config, cpi_log, ssl_ca_file, ca_cert_from_context) }
let(:cpi_config) {
{
'cloud' => {
'properties' => {
'openstack' => {
'key1' => 'value1',
'key2' => 'value2'
}
}
}
}
}
let(:ssl_ca_file) { 'feel-free-to-change' }
let(:cpi_log) { StringIO.new }
let(:ca_cert_from_context) { Tempfile.new('ca_cert').path }

describe 'when creating a cloud' do
it 'passes parts of the cpi config to openstack' do
expect(Bosh::Clouds::Openstack).to receive(:new).with({'openstack' => cpi_config['cloud']['properties']['openstack'],
'cpi_log' => cpi_log})
subject.call({})
end

context 'if invalid cpi config is given' do
let(:cpi_config) {{'empty' => 'config'}}

it 'raises an error' do
expect {
subject.call({})
}.to raise_error /Could not find cloud properties in the configuration/
end
end

context 'if using ca_certs in config' do
let(:cpi_config) {{ 'cloud' => {'properties' => { 'openstack' => {'connection_options' => {'ca_cert' => 'xyz'}}}}}}

it 'sets ssl_ca_file that is passed and removes ca_certs' do
expect(Bosh::Clouds::Openstack).to receive(:new).with({'openstack' => {'connection_options' => {'ssl_ca_file' => ssl_ca_file}},
'cpi_log' => cpi_log})
subject.call({})
end
end

context 'if openstack properties are provided in the context' do
it 'merges the openstack properties' do
context = {
'newkey' => 'newvalue',
'newkey2' => 'newvalue2',
}

expect(Bosh::Clouds::Openstack).to receive(:new).with({'openstack' => { 'key1' => 'value1',
'key2' => 'value2',
'newkey' => 'newvalue',
'newkey2' => 'newvalue2'},
'cpi_log' => cpi_log})
subject.call(context)
end

it 'writes the given ca_cert to the disk and sets ssl_ca_file to its path' do
context = {
'newkey' => 'newvalue',
'connection_options' => {'ca_cert' => 'xyz'}
}

expect(Bosh::Clouds::Openstack).to receive(:new).with({'openstack' => { 'newkey' => 'newvalue',
'key1' => 'value1',
'key2' => 'value2',
'connection_options' => {'ssl_ca_file' => ca_cert_from_context}},
'cpi_log' => cpi_log})

subject.call(context)
expect(File.read(ca_cert_from_context)).to eq('xyz')
end

context 'when the context does not include a ca_cert' do
it 'does not write into the file' do
allow(Bosh::Clouds::Openstack).to receive(:new)

subject.call({})

expect(File.read(ca_cert_from_context)).to eq('')
end
end
end
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.