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

support instance tags and include relevant specs #2444

Closed
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
10 changes: 10 additions & 0 deletions src/bosh-director/lib/bosh/director/vm_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def get_agenda_for_instance_plan(instance_plan, disks, tags, ip_provider, total,
instance = instance_plan.instance
already_had_active_vm = instance.vm_created?

variables_interpolator = Bosh::Director::ConfigServer::VariablesInterpolator.new
env = variables_interpolator.interpolate_with_versioning(instance.env, instance.desired_variable_set)
env['bosh'] ||= {}
env['bosh'] = Config.agent_env.merge(env['bosh'])
tags = combined_tags(tags, env['bosh']['tags'])

agenda.steps = [
DeploymentPlan::Steps::CreateVmStep.new(
instance_plan,
Expand Down Expand Up @@ -93,5 +99,9 @@ def get_agenda_for_instance_plan(instance_plan, disks, tags, ip_provider, total,
def creating_first_create_swap_delete_vm?(instance_plan, already_had_active_vm)
instance_plan.should_create_swap_delete? && !already_had_active_vm
end

def combined_tags(deployment_tags, instance_tags)
instance_tags.nil? ? deployment_tags : deployment_tags.merge(instance_tags)
end
end
end
21 changes: 20 additions & 1 deletion src/bosh-director/spec/unit/vm_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Director
end
let(:dns_encoder) { instance_double(DnsEncoder) }
let(:ip_provider) { double(:ip_provider) }
let(:variables_interpolator) { instance_double(Bosh::Director::ConfigServer::VariablesInterpolator) }

let(:instance) do
instance_double(DeploymentPlan::Instance, model: instance_model, vm_created?: false)
Expand All @@ -33,6 +34,19 @@ module Director
)
end

let(:agent_env_bosh_hash) do
{
'value_1_key' => 'value_1_value_changed',
'value_6_key' => {
'smurf' => 'i am here',
},
'a' => '12',
'b' => {
'c' => '34',
},
}
end

let(:tags) { { 'mytag' => 'foobar' } }

let(:instance_group) do
Expand Down Expand Up @@ -93,7 +107,9 @@ module Director

before do
fake_app

allow(instance).to receive(:env).and_return({ "bosh": {} })
allow(instance).to receive(:desired_variable_set).and_return({})
allow(variables_interpolator).to receive(:interpolate_with_versioning).and_return({})
allow(instance_model).to receive(:managed_persistent_disk_cid).and_return('fake-disk-cid')
allow(DeploymentPlan::Stages::Report).to receive(:new).and_return(report)

Expand All @@ -120,6 +136,8 @@ module Director
.and_return(commit_networks_step)
allow(DeploymentPlan::Steps::ReleaseObsoleteNetworksStep).to receive(:new)
.with(ip_provider).and_return(release_networks_step)
allow(ConfigServer::VariablesInterpolator).to receive(:new).and_return(variables_interpolator)
allow(Config).to receive(:agent_env).and_return(agent_env_bosh_hash)
end

describe '#create_for_instance_plan' do
Expand Down Expand Up @@ -188,6 +206,7 @@ module Director
context 'when the instance uses create-swap-delete strategy' do
before do
allow(instance_plan).to receive(:should_create_swap_delete?).and_return(true)
allow(instance).to receive(:env).and_return({})
end

context 'when there is already an active vm' do
Expand Down