Skip to content
Open
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
6 changes: 0 additions & 6 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ jobs:
timeout: 2h
privileged: true
params:
COVERAGE: false
DB: mysql
RAKE_TASK: spec:unit:director

Expand All @@ -221,7 +220,6 @@ jobs:
timeout: 2h
privileged: true
params:
COVERAGE: false
DB: postgresql
RAKE_TASK: spec:unit:director

Expand All @@ -244,7 +242,6 @@ jobs:
timeout: 2h
privileged: true
params:
COVERAGE: false
DB: postgresql
RAKE_TASK: spec:unit:director

Expand Down Expand Up @@ -309,7 +306,6 @@ jobs:
image: integration-postgres-15-image
privileged: true
params:
COVERAGE: false
DB: postgresql
RAKE_TASK: spec:integration
PARALLEL_TEST_MULTIPLY_PROCESSES: "0.5"
Expand Down Expand Up @@ -368,7 +364,6 @@ jobs:
image: integration-mysql-8-0-image
privileged: true
params:
COVERAGE: false
DB: mysql
RAKE_TASK: spec:integration

Expand Down Expand Up @@ -1389,7 +1384,6 @@ jobs:
input_mapping:
bosh: bosh-out
params:
COVERAGE: false
DB: sqlite
RAKE_TASK: spec:unit:parallel
- put: bosh
Expand Down
2 changes: 1 addition & 1 deletion ci/tasks/test-rake-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ run:
path: bosh-ci/ci/tasks/test-rake-task.sh

params:
COVERAGE: true
COVERAGE: false
DB:
RAKE_TASK:
SPEC_PATH: ~
Expand Down
6 changes: 3 additions & 3 deletions src/bosh-director/lib/bosh/director/cloud_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def get(cpi_name, stemcell_api_version = nil)

begin
info_response = cloud.info || {}
cpi_api_version = info_response.fetch('api_version', 1)
rescue
cpi_api_version = 1
cpi_api_version = info_response.fetch('api_version')
rescue StandardError
raise Bosh::Clouds::NotSupported, 'CPI must report api_version via info'
end
supported_cpi_version = [cpi_api_version, Bosh::Director::Config.preferred_cpi_api_version].min
@logger.debug("Using cpi_version #{supported_cpi_version} for CPI #{cpi_name}")
Expand Down
40 changes: 12 additions & 28 deletions src/bosh-director/lib/clouds/external_cpi_response_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def set_disk_metadata(*arguments); invoke_cpi_method(__method__.to_s, *arguments
def create_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
def has_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
def delete_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
def attach_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
Comment thread
aramprice marked this conversation as resolved.
def detach_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
def snapshot_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
def delete_snapshot(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
Expand All @@ -36,44 +35,29 @@ def invoke_cpi_method(method, *arguments)
end

def create_vm(*args)
cpi_response = @cpi.create_vm(*args)

response = []
if @cpi_api_version >= 2
response = cpi_response
else
response << cpi_response
end

response
@cpi.create_vm(*args)
end


def create_stemcell(*args)
final_args = args.take(2)
if @cpi_api_version >= 3
final_args = args
end
return @cpi.create_stemcell(*final_args)
def create_stemcell(*args)
final_args = @cpi_api_version >= 3 ? args : args.take(2)
@cpi.create_stemcell(*final_args)
end


def attach_disk(*args)
cpi_response = @cpi.attach_disk(*args)

if @cpi_api_version >= 2
raise Bosh::Clouds::AttachDiskResponseError, 'No disk_hint' if cpi_response.nil? || cpi_response.empty?
cpi_response
else
nil
end
raise Bosh::Clouds::AttachDiskResponseError, 'No disk_hint' if cpi_response.nil? || cpi_response.empty?
cpi_response
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
end

private

def check_cpi_api_support
unsupported = @cpi_api_version > Bosh::Director::Config.preferred_cpi_api_version
raise Bosh::Clouds::NotSupported, "CPI API version #{@cpi_api_version} is not supported." if unsupported
if @cpi_api_version < 2
raise Bosh::Clouds::NotSupported, "CPI API version #{@cpi_api_version} is not supported. Minimum required version is 2."
end
if @cpi_api_version > Bosh::Director::Config.preferred_cpi_api_version
raise Bosh::Clouds::NotSupported, "CPI API version #{@cpi_api_version} is not supported."
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ module Bosh::Director

before do
allow(Bosh::Director::Config).to receive(:uuid).and_return('snoopy-uuid')
allow(Bosh::Director::Config).to receive(:preferred_cpi_api_version).and_return(1)
allow(Bosh::Director::Config).to receive(:preferred_cpi_api_version).and_return(2)
allow(Bosh::Director::Config).to receive(:cloud_options).and_return('provider' => { 'path' => '/path/to/default/cpi' })
allow(Bosh::Clouds::ExternalCpi).to receive(:new).with('/path/to/default/cpi',
'snoopy-uuid',
instance_of(Logging::Logger),
stemcell_api_version: nil).and_return(default_cloud)
allow(default_cloud).to receive(:info)
allow(default_cloud).to receive(:info).and_return('api_version' => 2)
allow(default_cloud).to receive(:request_cpi_api_version=)
end

Expand Down Expand Up @@ -126,7 +126,7 @@ module Bosh::Director
before do
expect(az_cloud_factory.uses_cpi_config?).to be_truthy
clouds.each do |cloud|
allow(cloud).to receive(:info)
allow(cloud).to receive(:info).and_return('api_version' => 2)
allow(cloud).to receive(:request_cpi_api_version=)
end
end
Expand Down
15 changes: 7 additions & 8 deletions src/bosh-director/spec/unit/bosh/director/cloud_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Bosh::Director
let(:cloud) { instance_double(Bosh::Clouds::ExternalCpi) }
let(:parsed_cpi_config) { CpiConfig::ParsedCpiConfig.new(cpis) }
let(:cpis) { [] }
let(:cpi_api_version) { 1 }
let(:cpi_api_version) { 2 }
let(:cpi_info) do
{
'stemcell_formats' => 'some-stemcell-support-format',
Expand Down Expand Up @@ -50,14 +50,13 @@ module Bosh::Director
end
end

context 'old CPIs do not return the version from info' do
context 'CPIs that do not report a version from info' do
let(:cpi_info) do
{}
end

it 'creates cloud with CPI API version of 1' do
expect(cloud).to receive(:request_cpi_api_version=).with(1)
cloud_factory.get(nil, stemcell_api_version)
it 'raises NotSupported' do
expect { cloud_factory.get(nil, stemcell_api_version) }.to raise_error(Bosh::Clouds::NotSupported)
end
end
end
Expand Down Expand Up @@ -95,7 +94,7 @@ module Bosh::Director

shared_examples_for 'lookup for clouds' do
before do
allow(cloud).to receive(:info).and_return({})
allow(cloud).to receive(:info).and_return('api_version' => 2)
allow(cloud).to receive(:request_cpi_api_version=)
end

Expand Down Expand Up @@ -205,7 +204,7 @@ module Bosh::Director
stemcell_api_version: nil).and_return(clouds[2])

clouds.each do |cloud|
allow(cloud).to receive(:info)
allow(cloud).to receive(:info).and_return('api_version' => 2)
allow(cloud).to receive(:request_cpi_api_version=)
end
end
Expand All @@ -215,7 +214,7 @@ module Bosh::Director
instance_of(Logging::Logger),
properties_from_cpi_config: cpis[1].properties,
stemcell_api_version: nil).and_return(clouds[1])
allow(clouds[1]).to receive(:info).and_return({})
allow(clouds[1]).to receive(:info).and_return('api_version' => 2)
expect(Bosh::Clouds::ExternalCpiResponseWrapper).to receive(:new).with(clouds[1],
kind_of(Integer)).and_return(cloud_wrapper)
cloud = cloud_factory.get('name2')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Bosh::Director
let(:another_agent_client) { instance_double('Bosh::Director::AgentClient') }
let(:availability_zone) { nil }
let(:cloud) { instance_double(Bosh::Clouds::ExternalCpi) }
let(:cloud_wrapper) { Bosh::Clouds::ExternalCpiResponseWrapper.new(cloud, 1) }
let(:cloud_wrapper) { Bosh::Clouds::ExternalCpiResponseWrapper.new(cloud, 2) }
let(:package) { instance_double(Models::Package, name: 'fake-package') }
let(:package2) { instance_double(Models::Package, name: 'fake-package2') }

Expand Down Expand Up @@ -141,12 +141,12 @@ module Bosh::Director

before do
allow(Config).to receive(:cloud_options).and_return('provider' => { 'path' => '/path/to/default/cpi' })
allow(cloud).to receive(:create_vm)
allow(cloud).to receive(:create_vm).and_return([nil, {}])
allow(cloud).to receive(:set_vm_metadata)
allow(cloud).to receive(:info).and_return({})
allow(cloud).to receive(:request_cpi_api_version=).with(1)
allow(cloud).to receive(:request_cpi_api_version).and_return(1)
allow(Config).to receive(:preferred_cpi_api_version).and_return(1)
allow(cloud).to receive(:info).and_return('api_version' => 2)
allow(cloud).to receive(:request_cpi_api_version=).with(2)
allow(cloud).to receive(:request_cpi_api_version).and_return(2)
allow(Config).to receive(:preferred_cpi_api_version).and_return(2)
allow(Bosh::Clouds::ExternalCpi).to receive(:new).and_return(cloud)
allow(Bosh::Clouds::ExternalCpiResponseWrapper).to receive(:new).with(cloud, anything).and_return(cloud_wrapper)
allow(network).to receive(:network_settings)
Expand Down Expand Up @@ -196,7 +196,7 @@ module Bosh::Director
expected_network_settings,
[],
compilation_env,
)
).and_return([nil, {}])
action
end

Expand Down Expand Up @@ -273,6 +273,7 @@ module Bosh::Director

allow(cloud).to receive(:create_vm) do |_, _, cloud_properties|
expect(cloud_properties['vm_resources']).to eq('foo')
[nil, {}]
end

action
Expand Down Expand Up @@ -462,7 +463,7 @@ module Bosh::Director
anything,
anything,
anything,
)
).and_return([nil, {}])

compilation_instance_pool.with_reused_vm(stemcell, package) {}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module Bosh::Director

allow(plan).to receive(:network).with('default').and_return(network)

allow(Config).to receive(:preferred_cpi_api_version).and_return(1)
allow(Config).to receive(:preferred_cpi_api_version).and_return(2)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

allow(Config).to receive(:current_job).and_return(update_job)
allow(Config).to receive(:name).and_return('fake-director-name')
Expand All @@ -152,7 +152,7 @@ module Bosh::Director
allow(Config).to receive(:nats_client_ca_private_key_path).and_return(director_config['nats']['client_ca_private_key_path'])
allow(Config).to receive(:nats_client_ca_certificate_path).and_return(director_config['nats']['client_ca_certificate_path'])
allow(Bosh::Director::Config).to receive(:event_log).and_return(event_log)
allow(cloud).to receive(:info)
allow(cloud).to receive(:info).and_return({ 'api_version' => 2 })
allow(cloud).to receive(:request_cpi_api_version=)
allow(cloud).to receive(:request_cpi_api_version)
allow(cloud).to receive(:set_vm_metadata)
Expand Down Expand Up @@ -679,7 +679,7 @@ def compile_package_with_url_encrypt_stub(args)

expect(cloud).to receive(:create_vm).once.ordered
.with(instance_of(String), stemcell.models.first.cid, {}, net, [], { 'bosh' => { 'group' => 'fake-director-name-mycloud-compilation-deadbeef', 'groups' => expected_groups } })
.and_return(vm_cid)
.and_return([vm_cid, {}])

allow(AgentClient).to receive(:with_agent_id).and_return(agent)

Expand Down Expand Up @@ -776,7 +776,7 @@ def compile_package_with_url_encrypt_stub(args)

expect(cloud).to receive(:create_vm)
.with(instance_of(String), @stemcell_a.models.first.cid, {}, net, [], { 'bosh' => { 'group' => 'fake-director-name-mycloud-compilation-deadbeef', 'groups' => expected_groups } })
.and_return(vm_cid)
.and_return([vm_cid, {}])

allow(AgentClient).to receive(:with_agent_id).and_return(agent)

Expand Down Expand Up @@ -874,7 +874,7 @@ def compile_package_with_url_encrypt_stub(args)
before do
Bosh::Director::Config.trusted_certs = director_test_certs

allow(cloud).to receive(:create_vm).and_return('new-vm-cid')
allow(cloud).to receive(:create_vm).and_return(['new-vm-cid', {}])
allow(AgentClient).to receive_messages(with_agent_id: client)
allow(cloud).to receive(:delete_vm)
allow(client).to receive(:update_settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ module Bosh::Director::DeploymentPlan::Stages
allow(Bosh::Director::Config).to receive(:event_log).and_return(event_log)
allow(Bosh::Director::Config).to receive(:uuid).and_return('meow-uuid')
allow(Bosh::Director::Config).to receive(:cloud_options).and_return('provider' => { 'path' => '/path/to/default/cpi' })
allow(Bosh::Director::Config).to receive(:preferred_cpi_api_version).and_return(1)
allow(Bosh::Director::Config).to receive(:preferred_cpi_api_version).and_return(2)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
allow(Bosh::Director::Config).to receive(:enable_short_lived_nats_bootstrap_credentials).and_return(true)
director_config = SpecHelper.director_config_hash
allow(Bosh::Director::Config).to receive(:nats_client_ca_private_key_path).and_return(director_config['nats']['client_ca_private_key_path'])
allow(Bosh::Director::Config).to receive(:nats_client_ca_certificate_path).and_return(director_config['nats']['client_ca_certificate_path'])
external_cpi = instance_double(Bosh::Clouds::ExternalCpi)
allow(Bosh::Clouds::ExternalCpi).to receive(:new).and_return(external_cpi)
allow(external_cpi).to receive(:info).and_return('api_version' => 2)
allow(Bosh::Clouds::ExternalCpiResponseWrapper).to receive(:new).with(anything, anything).and_return(cloud)
allow(variables_interpolator).to receive(:interpolate_template_spec_properties).and_return({})
allow(variables_interpolator).to receive(:interpolated_versioned_variables_changed?).and_return(false)
Expand Down Expand Up @@ -116,7 +119,7 @@ module Bosh::Director::DeploymentPlan::Stages
anything,
anything,
)
.and_return(['vm-cid-2'])
.and_return(['vm-cid-2', {}])
.ordered

update_step.perform
Expand Down Expand Up @@ -148,7 +151,7 @@ module Bosh::Director::DeploymentPlan::Stages
allow(agent_client).to receive(:prepare)
allow(agent_client).to receive(:run_script)
allow(agent_client).to receive(:start)
allow(cloud).to receive(:create_vm).and_return(['vm-cid-2'])
allow(cloud).to receive(:create_vm).and_return(['vm-cid-2', {}])
end

it "creates an instance with 'lifecycle' in the spec" do
Expand Down
Loading
Loading