Skip to content

Commit

Permalink
Fix events for instance create/update
Browse files Browse the repository at this point in the history
- only one instance action is shown
- when instance is recreated the action is `recreate` instead of start or update
- az is shown for instance creation case

[#115793643](https://www.pivotaltracker.com/story/show/115793643)

Signed-off-by: Konstantin Maksimov <kmaksimov@ru.ibm.com>
  • Loading branch information
Yulia Gaponenko committed Apr 25, 2016
1 parent 71adadb commit f9e05f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
28 changes: 11 additions & 17 deletions bosh-director/lib/bosh/director/instance_updater.rb
Expand Up @@ -75,17 +75,10 @@ def update(instance_plan, options = {})

recreated = false
if needs_recreate?(instance_plan)
begin
recreate_parent_id = add_event(instance.deployment_model.name, 'recreate', instance.model.name, nil) if action == 'update'
@logger.debug('Failed to update in place. Recreating VM')
@disk_manager.unmount_disk_for(instance_plan)
@vm_recreator.recreate_vm(instance_plan, nil)
recreated = true
rescue Exception => e
raise e
ensure
add_event(instance.deployment_model.name, 'recreate', instance.model.name, nil, recreate_parent_id, e) if recreate_parent_id
end
@logger.debug('Failed to update in place. Recreating VM')
@disk_manager.unmount_disk_for(instance_plan)
@vm_recreator.recreate_vm(instance_plan, nil)
recreated = true
end

release_obsolete_ips(instance_plan)
Expand Down Expand Up @@ -137,7 +130,8 @@ def add_event(deployment_name, action, instance_name = nil, context = nil, paren

def get_action_and_context(instance_plan)
changes = instance_plan.changes
if changes.size == 1 && [:state,:recreate,:restart].include?(changes.first)
context = {}
if changes.size == 1 && [:state, :restart].include?(changes.first)
action = case instance_plan.instance.virtual_state
when 'started'
'start'
Expand All @@ -148,16 +142,16 @@ def get_action_and_context(instance_plan)
else
instance_plan.instance.virtual_state
end
return action , {}
else
context['az'] = instance_plan.desired_az_name if instance_plan.desired_az_name
if instance_plan.new?
return 'create', {}
action = 'create'
else
context = {changes: changes.to_a}
context['az'] = instance_plan.desired_az_name if instance_plan.desired_az_name
return 'update', context
context['changes'] = changes.to_a unless changes.size == 1 && changes.first == :recreate
action = needs_recreate?(instance_plan) ? 'recreate' : 'update'
end
end
return action, context
end

def release_obsolete_ips(instance_plan)
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/template_evaluation_spec.rb
Expand Up @@ -55,6 +55,15 @@
expect(new_id).to match /[a-f0-9\-]/

expect(new_id).to eq(original_id)

output = bosh_runner.run('events')
parser = Support::TableHelpers::Parser.new(scrub_event_time(scrub_random_cids(scrub_random_ids(output))))
expect(parser.data).to include(
{'ID' => /[0-9]{1,3} <- [0-9]{1,3}/, 'Time' => 'xxx xxx xx xx:xx:xx UTC xxxx', 'User' => 'test', 'Action' => 'update', 'Object type' => 'deployment', 'Task' => /[0-9]{1,3}/, 'Object ID' => 'simple', 'Dep' => 'simple', 'Inst' => '-', 'Context' => '-'},
{'ID' => /[0-9]{1,3} <- [0-9]{1,3}/, 'Time' => 'xxx xxx xx xx:xx:xx UTC xxxx', 'User' => 'test', 'Action' => 'recreate', 'Object type' => 'instance', 'Task' => /[0-9]{1,3}/, 'Object ID' => 'id_job/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Dep' => 'simple', 'Inst' => 'id_job/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Context' => '-'},
{'ID' => /[0-9]{1,3}/, 'Time' => 'xxx xxx xx xx:xx:xx UTC xxxx', 'User' => 'test', 'Action' => 'recreate', 'Object type' => 'instance', 'Task' => /[0-9]{1,3}/, 'Object ID' => 'id_job/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Dep' => 'simple', 'Inst' => 'id_job/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Context' => '-'},
{'ID' => /[0-9]{1,3}/, 'Time' => 'xxx xxx xx xx:xx:xx UTC xxxx', 'User' => 'test', 'Action' => 'update', 'Object type' => 'deployment', 'Task' => /[0-9]{1,3}/, 'Object ID' => 'simple', 'Dep' => 'simple', 'Inst' => '-', 'Context' => '-'},
)
end

it 'prints all template evaluation errors when there are errors in multiple release template files' do
Expand Down
2 changes: 1 addition & 1 deletion spec/shared/support/table_helpers.rb
Expand Up @@ -28,7 +28,7 @@ def clean(content)
end

def parse(content)
CSV.parse(clean(content), { col_sep: "|" }).map(&:compact)
CSV.parse(clean(content), { col_sep: "|", quote_char: "\x00" }).map(&:compact)
end
end
end
Expand Down

0 comments on commit f9e05f4

Please sign in to comment.