ACK and pushed. Mainn
----- Original Message ----- > From: [email protected] > To: [email protected] > Cc: "Jan Provaznik" <[email protected]> > Sent: Thursday, September 20, 2012 10:41:20 AM > Subject: [PATCH conductor] BZ 857542 - updated check of "stopped after > create" state > > From: Jan Provaznik <[email protected]> > > Older dc-core (0.5.x version in RHEL) returns 'pending' state when an > instances > is shutting down. Conductor compared last_pending time with > last_running time > to distinguish newely created instances. But this comparison doesn't > work properly > with the bug in dc-core. > > Instead of last_pending time conductor now checks if 'create' was > last queued > instance's task. > > https://bugzilla.redhat.com/show_bug.cgi?id=857542 > --- > src/app/models/instance.rb | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb > index 544c891..8579379 100644 > --- a/src/app/models/instance.rb > +++ b/src/app/models/instance.rb > @@ -512,8 +512,20 @@ class Instance < ActiveRecord::Base > end > > def stopped_after_creation? > + last_task = tasks.last > state == Instance::STATE_STOPPED && > - time_last_pending.to_i > time_last_running.to_i && > + # TODO: to keep backward compatibility with dc-core 0.5 > + # time_last_pending can't be used, because pending > + # state was used instead of shutting_down in older dc-api > version. > + # https://bugzilla.redhat.com/show_bug.cgi?id=857542 > + #time_last_pending.to_i > time_last_running.to_i && > + last_task && > + [InstanceTask::ACTION_CREATE, > InstanceTask::ACTION_START].include?(last_task.action) && > + last_task.created_at.to_i > time_last_running.to_i && > + # also make sure that the 'create' task was created after > + # last deployment launch request - instance can be stopped > + # since previous rollback+retry request > + last_task.created_at.to_i > last_launch_time.to_i && > provider_account && > provider_account.provider.provider_type.goes_to_stop_after_creation? > end > @@ -628,4 +640,10 @@ class Instance < ActiveRecord::Base > Time.now - task.created_at < 120 > false > end > + > + def last_launch_time > + return nil if deployment.nil? > + event = deployment.events.find_last_by_status_code(:pending) > + event.nil? ? nil : event.created_at > + end > end > -- > 1.7.11.4 > >
