From: Jiri Tomasek jtomasek@redhat.com
Redmine #1229
Launch new and stop button functions has been implemented --- .../resources/deployments_controller.rb | 37 +++++++++++++++ src/app/views/resources/deployments/_list.haml | 47 ++++++++++---------- .../views/resources/deployments/launch_new.haml | 6 +++ src/config/routes.rb | 2 +- src/features/deployment.feature | 21 +++++++++ src/features/step_definitions/assembly_steps.rb | 11 +++++ src/features/step_definitions/deployment_steps.rb | 5 ++ src/features/support/paths.rb | 3 + 8 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 src/app/views/resources/deployments/launch_new.haml
diff --git a/src/app/controllers/resources/deployments_controller.rb b/src/app/controllers/resources/deployments_controller.rb index a35bbe5..81378f8 100644 --- a/src/app/controllers/resources/deployments_controller.rb +++ b/src/app/controllers/resources/deployments_controller.rb @@ -5,6 +5,13 @@ class Resources::DeploymentsController < ApplicationController def index end
+ def launch_new + @launchable_deployables = [] + Deployable.all.each do |deployable| + @launchable_deployables << deployable if deployable.launchable? + end + end + def new require_privilege(Privilege::CREATE, Deployment) @deployment = Deployment.new(:deployable_id => params[:deployable_id]) @@ -54,6 +61,35 @@ class Resources::DeploymentsController < ApplicationController end end
+ def multi_stop + notices = "" + errors = "" + Deployment.find(params[:deployments_selected]).each do |deployment| + deployment.instances.each do |instance| + begin + require_privilege(Privilege::USE,instance) + unless instance.valid_action?('stop') + raise ActionError.new("stop is an invalid action.") + end + + # not sure if task is used as everything goes through condor + #permissons check here + @task = instance.queue_action(@current_user, 'stop') + unless @task + raise ActionError.new("stop cannot be performed on this instance.") + end + condormatic_instance_stop(@task) + notices << "Deployment: #{instance.deployment.name}, Instance: #{instance.name}: stop action was successfully queued.<br/>" + rescue Exception => err + errors << "Deployment: #{instance.deployment.name}, Instance: #{instance.name}: " + err + "<br/>" + end + end + end + flash[:notice] = notices unless notices.blank? + flash[:error] = errors unless errors.blank? + redirect_to resources_deployments_path + end + private def load_deployments @url_params = params @@ -62,6 +98,7 @@ class Resources::DeploymentsController < ApplicationController :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] || 'asc') ) @header = [ + { :name => "", :sort_attr => :name }, { :name => "Deployment name", :sort_attr => :name }, { :name => "Deployable", :sortable => false }, { :name => "Owner", :sort_attr => "owner.login"}, diff --git a/src/app/views/resources/deployments/_list.haml b/src/app/views/resources/deployments/_list.haml index a87f1d6..7b80677 100644 --- a/src/app/views/resources/deployments/_list.haml +++ b/src/app/views/resources/deployments/_list.haml @@ -1,7 +1,8 @@ - form_tag do #object-actions = restful_submit_tag "Start", "start", resources_deployments_path, "PUT" - = restful_submit_tag "Stop", "stop", resources_deployments_path, "PUT" + = restful_submit_tag "Stop", "stop", multi_stop_resources_deployments_path, "GET" + = restful_submit_tag "Launch new", "launch_new", launch_new_resources_deployments_path, "GET" = restful_submit_tag "Delete", "delete", resources_deployments_path, "DELETE"
#search-actions @@ -9,26 +10,26 @@ = restful_submit_tag "Save Selection", "save_selection", resources_deployments_path, "PUT" = restful_submit_tag "Export to File", "export", resources_deployments_path, "PUT"
- #selections - %p - Select: - = link_to "All", @url_params.merge(:select => 'all') - %span> , - = link_to "None", @url_params.merge(:select => 'none') + %p + Select: + = link_to "All", @url_params.merge(:select => 'all') + %span> , + = link_to "None", @url_params.merge(:select => 'none')
-%table#deployments_table - = sortable_table_header @header - - @deployments.each do |deployment| - %tr - %td - - selected = @url_params[:select] == 'all' - %input{:name => "deployments_selected[]", :type => "checkbox", :value => deployment.id, :id => "deployment_checkbox_#{deployment.id}", :checked => selected } - = link_to deployment.name, resources_deployment_path(deployment) - %td - = link_to deployment.deployable.name, image_factory_deployable_path(deployment.deployable) - %td - = deployment.owner.login - %td - = deployment.created_at - %td - = link_to deployment.pool.name, resources_pool_path(deployment.pool) + %table#deployments_table + = sortable_table_header @header + - @deployments.each do |deployment| + %tr + %td + - selected = @url_params[:select] == 'all' + %input{:name => "deployments_selected[]", :type => "checkbox", :value => deployment.id, :id => "deployment_checkbox_#{deployment.id}", :checked => selected } + %td + = link_to deployment.name, resources_deployment_path(deployment) + %td + = link_to deployment.deployable.name, image_factory_deployable_path(deployment.deployable) + %td + = deployment.owner.login + %td + = deployment.created_at + %td + = link_to deployment.pool.name, resources_pool_path(deployment.pool) diff --git a/src/app/views/resources/deployments/launch_new.haml b/src/app/views/resources/deployments/launch_new.haml new file mode 100644 index 0000000..86cf47f --- /dev/null +++ b/src/app/views/resources/deployments/launch_new.haml @@ -0,0 +1,6 @@ +%h2 Launch new deployment via +- form_tag new_resources_deployment_path, :method => :get do + = label_tag "Deployable:" + = select_tag :deployable_id, options_from_collection_for_select(@launchable_deployables, "id", "name") + = submit_tag "Launch" + = link_to "Cancel", resources_deployments_path, :class => "button" diff --git a/src/config/routes.rb b/src/config/routes.rb index c02f864..ab23347 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -34,7 +34,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace 'resources' do |r| r.resources :pools, :collection => { :multi_destroy => :delete } - r.resources :deployments + r.resources :deployments, :collection => { :multi_stop => :get, :launch_new => :get } r.resources :instances, :collection => {:start => :get, :multi_stop => :get, :select_template => :get, :remove_failed => :get, :can_start => :get, :can_create => :get }, :member => {:key => :get} end
diff --git a/src/features/deployment.feature b/src/features/deployment.feature index 3f96e64..4b26097 100644 --- a/src/features/deployment.feature +++ b/src/features/deployment.feature @@ -13,3 +13,24 @@ Feature: Manage Deployments When I go to the resources deployments page Then I should see "MySQL Cluster" And I should see "bob" + + Scenario: Launch new deployment + Given there is a deployable named "testdeployable" + And There is a mock pulp repository + And there is a "testtemplate" template + And there is an assembly named "testassembly" belonging to "testdeployable" + And there is an assembly named "testassembly" belonging to "testtemplate" template + When I go to the resources deployments page + And I press "Launch new" + Then I should see "Launch new deployment via" + When I select "testdeployable" from "deployable_id" + When I press "Launch" + Then I should see "Launch deployable" + + Scenario: Stop deployments + Given there is a deployment named "testdeployment" belonging to "testdeployable" owned by "testuser" + When I go to the resources deployments page + Then I should see "testdeployment" + When I check "testdeployment" deployment + And I press "Stop" + Then I should see "testdeployment" diff --git a/src/features/step_definitions/assembly_steps.rb b/src/features/step_definitions/assembly_steps.rb index 383114d..bb50b85 100644 --- a/src/features/step_definitions/assembly_steps.rb +++ b/src/features/step_definitions/assembly_steps.rb @@ -8,6 +8,17 @@ Given /^there is an assembly named "([^"]*)" belonging to "([^"]*)"$/ do |assemb # Assembly.create!(:name => assembly, :architecture => 'x86_64', :deployable => Deployable.find_by_name(deployable)) end
+Given /^there is an assembly named "([^"]*)" belonging to "([^"]*)" template$/ do |assembly_name, template_name| + template = Template.find_by_name(template_name) + assembly = Assembly.find_by_name(assembly_name) + unless assembly.nil? + template.assemblies << assembly + else + template.assemblies.create!(:name => assembly_name, :architecture => 'x86_64') + end +# Assembly.create!(:name => assembly, :architecture => 'x86_64', :deployable => Deployable.find_by_name(deployable)) +end + When /^I check the "([^"]*)" assembly$/ do |name| assembly = Assembly.find_by_name(name) check("assembly_checkbox_#{assembly.id}") diff --git a/src/features/step_definitions/deployment_steps.rb b/src/features/step_definitions/deployment_steps.rb index 7af353c..ef187c8 100644 --- a/src/features/step_definitions/deployment_steps.rb +++ b/src/features/step_definitions/deployment_steps.rb @@ -3,3 +3,8 @@ Given /^there is a deployment named "([^"]*)" belonging to "([^"]*)" owned by "( deployable = Deployable.create!(:name => deployable_name, :owner => user) deployable.deployments.create!({:name => deployment_name, :pool => Pool.first, :owner => user}) end + +When /^I check "([^"]*)" deployment/ do |name| + deployment = Deployment.find_by_name(name) + check("deployment_checkbox_#{deployment.id}") +end diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb index b8e6e74..04c589a 100644 --- a/src/features/support/paths.rb +++ b/src/features/support/paths.rb @@ -59,6 +59,9 @@ module NavigationHelpers when /the pool realms page/ pool_realms_path
+ when /the deployments page/ + resources_deployments_path + when /the instances page/ resources_instances_path