From: Tomas Sedovic <tsedovic(a)redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=711294
A deployable can be deleted only when all of its instances are
stopped or in the "create_failed" state.
This also removes UI for deleting instances directly.
---
src/app/controllers/deployments_controller.rb | 2 +-
src/app/controllers/instances_controller.rb | 22
---------------------- src/app/models/deployment.rb
| 2 +- src/app/views/deployments/_header_show.haml | 2 ++
src/app/views/instances/_list.haml | 1 -
src/features/deployment.feature | 7 +++++++
src/features/instance.feature | 8 --------
src/spec/models/deployment_spec.rb | 18
++++++++++++++++++ 8 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/app/controllers/deployments_controller.rb
b/src/app/controllers/deployments_controller.rb index
4140620..6fadb88 100644 ---
a/src/app/controllers/deployments_controller.rb +++
b/src/app/controllers/deployments_controller.rb @@ -163,7 +163,7 @@
class DeploymentsController < ApplicationController load_deployments
render :partial => 'list'
end
- format.html { redirect_to deployments_url }
+ format.html { redirect_to pools_url }
format.json { render :json => {:success => destroyed, :errors
=> failed} } end
end
diff --git a/src/app/controllers/instances_controller.rb
b/src/app/controllers/instances_controller.rb index fa60438..004da1f
100644 --- a/src/app/controllers/instances_controller.rb
+++ b/src/app/controllers/instances_controller.rb
@@ -151,28 +151,6 @@ class InstancesController < ApplicationController
end
end
- def remove_failed
- notices = ""
- errors = ""
- Instance.find(params[:instance_selected]).each do |instance|
- begin
- require_privilege(Privilege::USE,instance)
- raise ActionError.new("remove failed cannot be performed on
this instance.") unless
- instance.state == Instance::STATE_ERROR
- condormatic_instance_reset_error(instance)
- notices << "#{instance.name}: remove failed action was
successfully queued."
- rescue Exception => err
- errors << "#{instance.name}: " + err + "<br/>"
- end
- end
- flash[:notice] = notices unless notices.blank?
- flash[:error] = errors unless errors.blank?
- respond_to do |format|
- format.html { redirect_to instances_path }
- format.json { render :json => {:success => notices, :errors =>
errors}, :status => :unprocessable_entity }
- end
- end
-
def can_create
respond_to do |format|
begin
diff --git a/src/app/models/deployment.rb
b/src/app/models/deployment.rb index ea78cd8..dae2f65 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -47,7 +47,7 @@ class Deployment < ActiveRecord::Base
belongs_to :pool
- has_many :instances
+ has_many :instances, :dependent => :destroy
belongs_to :realm
belongs_to :frontend_realm
diff --git a/src/app/views/deployments/_header_show.haml
b/src/app/views/deployments/_header_show.haml index a6ecc9c..511917c
100644 --- a/src/app/views/deployments/_header_show.haml
+++ b/src/app/views/deployments/_header_show.haml
@@ -4,4 +4,6 @@
#obj_actions.button-container
.button-group
= pretty_filter_toggle(deployment_path(@deployment, :view =>
'pretty'), deployment_path(@deployment, :view => 'filter'))
+ .button-group
+ = button_to 'Delete', deployment_path(@deployment), :method
=> :delete, :confirm => "Are you sure you vant to delete this
deployment?", :class => "button pill danger" .corner diff
--git a/src/app/views/instances/_list.haml
b/src/app/views/instances/_list.haml index a80606f..fe34ed6 100644
--- a/src/app/views/instances/_list.haml +++
b/src/app/views/instances/_list.haml @@ -1,6 +1,5 @@
- form_tag do
= restful_submit_tag 'Stop', 'stop', multi_stop_instances_path,
'GET', :class => 'button'
- = restful_submit_tag 'Remove failed', 'remove_failed',
remove_failed_instances_path, 'GET', :class => 'button'
= render :partial => 'layouts/select_all_none'
diff --git a/src/features/deployment.feature
b/src/features/deployment.feature index 257fedc..9c72262 100644
--- a/src/features/deployment.feature
+++ b/src/features/deployment.feature
@@ -166,3 +166,10 @@ Feature: Manage Deployments
When I follow "Instances"
Then I should see "testdeployment"
+
+ Scenario: Delete a deployment
+ Given there is a deployment named "testdeployment" belonging to
"testdeployable" owned by "testuser"
+ And I am on the pools page
+ When I follow "testdeployment"
+ And I press "Delete"
+ Then I should see "The deployment testdeployment was
successfully deleted" diff --git a/src/features/instance.feature
b/src/features/instance.feature index 4ae087a..4b1bed4 100644
--- a/src/features/instance.feature
+++ b/src/features/instance.feature
@@ -65,14 +65,6 @@ Feature: Manage Instances
Then I should get back a partial
And I should see "Name"
- Scenario: Remove failed instances
- Given there is a "mock1" failed instance
- And I am on the instances page
- When I check "mock1" instance
- And I press "Remove failed"
- Then I should be on the instances page
- And I should see "mock1: remove failed action was successfully
queued" -
Scenario: Stop instance
Given there is a "mock1" running instance
And I am on the instances page
diff --git a/src/spec/models/deployment_spec.rb
b/src/spec/models/deployment_spec.rb index bde2358..b7d9883 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -70,4 +70,22 @@ describe Deployment do
@deployment.properties.should be_a_kind_of(Hash)
@deployment.properties.should ==
{:created=>nil, :pool=>@deployment.pool.name, :owner=>"John
Smith", :name=>@deployment.name} end +
+ it "should be removable under with stopped or create_failed
instances" do
+ @deployment.save!
+ inst1 = Factory.create :mock_running_instance, :deployment_id =>
@deployment.id
+ inst2 = Factory.create :mock_running_instance, :deployment_id =>
@deployment.id +
+ @deployment.should_not be_destroyable
+ @deployment.destroy.should == false
+
+ inst1.state = Instance::STATE_CREATE_FAILED
+ inst1.save!
+ inst2.state = Instance::STATE_STOPPED
+ inst2.save!
+
+ @deployment = Deployment.find((a)deployment.id)
+ @deployment.should be_destroyable
+ expect { @deployment.destroy }.to
change(Deployment, :count).by(-1)
+ end
end
ACK. Maybe you can add cucumber for unsuccessful remove