Commit e56706de authored by Maria Shaldibina's avatar Maria Shaldibina

Ignore disk pool cloud properties if size is still 0

Signed-off-by: default avatarLuke Woydziak <luke.woydziak@emc.com>
parent 46bdbc6b
......@@ -335,7 +335,9 @@ module Bosh::Director
def persistent_disk_changed?
new_disk_size = @job.persistent_disk_pool ? @job.persistent_disk_pool.disk_size : 0
new_disk_cloud_properties = @job.persistent_disk_pool ? @job.persistent_disk_pool.cloud_properties : {}
new_disk_size != disk_size || new_disk_cloud_properties != disk_cloud_properties
return true if new_disk_size != disk_size
new_disk_size != 0 && new_disk_cloud_properties != disk_cloud_properties
end
##
......
......@@ -17,12 +17,21 @@ module Bosh::Director::DeploymentPlan
network: net,
})
end
let(:job) { instance_double('Bosh::Director::DeploymentPlan::Job', resource_pool: resource_pool, deployment: plan, name: 'fake-job') }
let(:resource_pool) { instance_double('Bosh::Director::DeploymentPlan::ResourcePool', network: net) }
let(:job) do
instance_double('Bosh::Director::DeploymentPlan::Job',
resource_pool: resource_pool,
deployment: plan,
name: 'fake-job',
persistent_disk_pool: disk_pool,
)
end
let(:resource_pool) { instance_double('Bosh::Director::DeploymentPlan::ResourcePool', network: net, name: 'fake-resource-pool') }
let(:disk_pool) { nil }
let(:net) { instance_double('Bosh::Director::DeploymentPlan::Network', name: 'net_a') }
let(:vm) { Vm.new(resource_pool) }
before do
allow(resource_pool).to receive(:allocate_vm).and_return(vm)
allow(resource_pool).to receive(:add_allocated_vm).and_return(vm)
allow(job).to receive(:instance_state).with(0).and_return('started')
end
......@@ -72,7 +81,6 @@ module Bosh::Director::DeploymentPlan
network: network,
})
end
before { allow(resource_pool).to receive(:add_allocated_vm).and_return(vm) }
let(:vm) do
instance_double('Bosh::Director::DeploymentPlan::Vm', {
......@@ -796,6 +804,28 @@ module Bosh::Director::DeploymentPlan
end
end
describe 'persistent_disk_changed?' do
context 'when disk pool with size 0 is used' do
let(:disk_pool) do
Bosh::Director::DeploymentPlan::DiskPool.parse(
{
'name' => 'fake-name',
'disk_size' => 0,
'cloud_properties' => {'type' => 'fake-type'},
}
)
end
before { instance.bind_existing_instance(instance_model, {}, {}) }
context 'when disk_size is still 0' do
it 'returns false' do
expect(instance.persistent_disk_changed?).to be(false)
end
end
end
end
describe '#spec' do
let(:job_spec) { {name: 'job', release: 'release', templates: []} }
let(:release_spec) { {name: 'release', version: '1.1-dev'} }
......
......@@ -3,12 +3,13 @@ require 'spec_helper'
describe 'disk pools', type: :integration do
with_reset_sandbox_before_each
it 'allows specifying a disk_pool' do
def deploy_with_disk_pool(disk_size, cloud_properties={})
cloud_config_hash = Bosh::Spec::Deployments.simple_cloud_config
cloud_config_hash['disk_pools'] = [
{
'name' => 'fast_disks',
'disk_size' => 3000,
'disk_size' => disk_size,
'cloud_properties' => cloud_properties
}
]
......@@ -16,6 +17,10 @@ describe 'disk pools', type: :integration do
manifest_hash['jobs'].first['persistent_disk_pool'] = 'fast_disks'
deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash)
end
it 'allows specifying a disk_pool' do
deploy_with_disk_pool(3000)
director.vms.each do |vm|
expect(vm.get_state['persistent_disk']).to eq(3000)
......@@ -42,4 +47,59 @@ describe 'disk pools', type: :integration do
expect(vm.get_state['persistent_disk']).to eq(0)
end
end
context 'with existing disk pool with cloud_properties' do
let(:cloud_properties) { {'type' => 'gp2'} }
before { deploy_with_disk_pool(disk_size, cloud_properties) }
context 'when disk size is 0' do
let(:disk_size) { 0 }
context 'when cloud_properties were not changed' do
it 'does not update the job' do
expect(deploy_with_disk_pool(disk_size, cloud_properties)).to_not include('Started updating job foobar')
director.vms.each do |vm|
expect(vm.get_state['persistent_disk']).to eq(disk_size)
end
end
end
context 'when cloud_properties were changed' do
let(:cloud_properties) { {'type' => 'ssd'} }
it 'does not update the job' do
expect(deploy_with_disk_pool(disk_size, cloud_properties)).to_not include('Started updating job foobar')
director.vms.each do |vm|
expect(vm.get_state['persistent_disk']).to eq(disk_size)
end
end
end
end
context 'when disk size is greater than 0' do
let(:disk_size) { 1 }
context 'when cloud_properties were not changed' do
it 'does not update the job' do
expect(deploy_with_disk_pool(disk_size, cloud_properties)).to_not include('Started updating job foobar')
director.vms.each do |vm|
expect(vm.get_state['persistent_disk']).to eq(disk_size)
end
end
end
context 'when cloud_properties were changed' do
it 'does update the job' do
expect(deploy_with_disk_pool(disk_size, {'type' => 'ssd'})).to include('Started updating job foobar')
director.vms.each do |vm|
expect(vm.get_state['persistent_disk']).to eq(disk_size)
end
end
end
end
end
end
......@@ -69,7 +69,7 @@ module IntegrationExampleGroup
end
def upload_stemcell
bosh_runner.run("upload stemcell #{spec_asset('valid_stemcell.tgz')}")
bosh_runner.run("upload stemcell #{spec_asset('valid_stemcell.tgz')} --skip-if-exists")
end
def set_deployment(options)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment