Skip to content

Commit

Permalink
Merge pull request #5128 from hstastna/Power_dropdown_enabled_for_tem…
Browse files Browse the repository at this point in the history
…plate

Fix enabling Power operations for a template
  • Loading branch information
mzazrivec authored Feb 18, 2019
2 parents 77ab087 + 0643df5 commit 8bf2ad4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 47 deletions.
5 changes: 1 addition & 4 deletions app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,7 @@ def generic_button_operation(action, action_name, operation, options = {})
# - false otherwise
def testable_action(action)
controller = params[:controller]
vm_infra_untestable_actions = %w(
reboot_guest stop start check_compliance_queue destroy
refresh_ems vm_miq_request_new suspend reset shutdown_guest
)
vm_infra_untestable_actions = %w(check_compliance_queue destroy refresh_ems vm_miq_request_new)
ems_cluster_untestable_actions = %w(scan)
if controller == "vm_infra"
return vm_infra_untestable_actions.exclude?(action)
Expand Down
42 changes: 29 additions & 13 deletions spec/controllers/application_controller/ci_processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end
end

describe "action_to_feature" do
describe "#action_to_feature" do
let(:record) { FactoryBot.create(:vm_redhat) }

context 'the UI action is also a queryable feature' do
Expand Down Expand Up @@ -681,7 +681,7 @@
end
end

context "#discover" do
describe "#discover" do
it "checks that keys in @to remain set if there is an error after submit is pressed" do
from_first = "1"
from_second = "1"
Expand Down Expand Up @@ -720,7 +720,7 @@
end
end

context "#process_elements" do
describe "#process_elements" do
it "shows passed in display name in flash message" do
pxe = FactoryBot.create(:pxe_server)
controller.send(:process_elements, [pxe.id], PxeServer, 'synchronize_advertised_images_queue', 'Refresh Relationships')
Expand All @@ -735,7 +735,7 @@
end
end

context "#identify_record" do
describe "#identify_record" do
it "Verify flash error message when passed in ID no longer exists in database" do
record = controller.send(:identify_record, "1", ExtManagementSystem)
expect(record).to be_nil
Expand All @@ -749,7 +749,7 @@
end
end

context "#get_record" do
describe "#get_record" do
it "use passed in db to set class for identify_record call" do
host = FactoryBot.create(:host)
controller.instance_variable_set(:@_params, :id => host.id)
Expand Down Expand Up @@ -800,7 +800,7 @@
let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) }
let(:zone) { FactoryBot.create(:zone) }

context "#show_association" do
describe "#show_association" do
before do
stub_user(:features => :all)
EvmSpecHelper.create_guid_miq_server_zone
Expand Down Expand Up @@ -846,7 +846,7 @@
end
end

context "#process_objects" do
describe "#process_objects" do
it "returns array of object ids " do
vm1 = FactoryBot.create(:vm_vmware)
vm2 = FactoryBot.create(:vm_vmware)
Expand All @@ -858,7 +858,7 @@
end
end

context "#process_hosts" do
describe "#process_hosts" do
before do
@host1 = FactoryBot.create(:host)
@host2 = FactoryBot.create(:host)
Expand All @@ -881,7 +881,7 @@
end
end

context "#generic_button_operation" do
describe "#generic_button_operation" do
before do
allow(subject).to receive(:vm_button_action).and_return(subject.method(:process_objects))
allow(controller).to receive(:render)
Expand Down Expand Up @@ -916,7 +916,7 @@
end

describe ServiceController do
context "#vm_button_operation" do
describe "#vm_button_operation" do
let(:user) { FactoryBot.create(:user_admin) }

before do
Expand Down Expand Up @@ -947,7 +947,7 @@
end

describe MiqTemplateController do
context "#vm_button_operation" do
describe "#vm_button_operation" do
before do
_guid, @miq_server, @zone = EvmSpecHelper.remote_guid_miq_server_zone
allow(MiqServer).to receive(:my_zone).and_return("default")
Expand All @@ -973,7 +973,7 @@
end

describe VmOrTemplateController do
context "#vm_button_operation" do
describe "#vm_button_operation" do
let(:user) { FactoryBot.create(:user_admin) }

before do
Expand Down Expand Up @@ -1029,7 +1029,7 @@
end

describe OrchestrationStackController do
context "#orchestration_stack_delete" do
describe "#orchestration_stack_delete" do
let(:orchestration_stack) { FactoryBot.create(:orchestration_stack_cloud) }
let(:orchestration_stack_deleted) { FactoryBot.create(:orchestration_stack_cloud) }

Expand Down Expand Up @@ -1082,3 +1082,19 @@
end
end
end

describe VmInfraController do
describe '#testable_action' do
before do
controller.instance_variable_set(:@_params, :controller => 'vm_infra')
end

context 'power operations and vm infra controller' do
%w(reboot_guest reset shutdown_guest start stop suspend).each do |op|
it "returns true for #{op} operation on a VM" do
expect(controller.send(:testable_action, op)).to be(true)
end
end
end
end
end
79 changes: 49 additions & 30 deletions spec/controllers/vm_infra_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
let(:host_1x1) { FactoryBot.create(:host_vmware_esx, :hardware => FactoryBot.create(:hardware, :cpu1x1, :ram1GB)) }
let(:host_2x2) { FactoryBot.create(:host_vmware_esx, :hardware => FactoryBot.create(:hardware, :cpu2x2, :ram1GB)) }
let(:vm_vmware) { FactoryBot.create(:vm_vmware) }

before do
stub_user(:features => :all)

Expand Down Expand Up @@ -434,46 +435,64 @@
end
end

it 'can Shutdown Guest' do
post :x_button, :params => {:pressed => 'vm_guest_shutdown', :id => vm_vmware.id}
expect(response.status).to eq(200)
context 'power operations' do
let(:ems) { FactoryBot.create(:ems_vmware, :hostname => 'foo.com') }

expect(response.body).to include('Shutdown Guest initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
context 'operations on VMs' do
let(:vm) { FactoryBot.create(:vm_vmware, :host => host_1x1, :raw_power_state => 'poweredOn', :ext_management_system => ems) }

it 'can Restart Guest' do
post :x_button, :params => {:pressed => 'vm_guest_restart', :id => vm_vmware.id}
expect(response.status).to eq(200)

expect(response.body).to include('Restart Guest initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
it 'can Shutdown Guest' do
post :x_button, :params => {:pressed => 'vm_guest_shutdown', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Shutdown Guest initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end

it 'can Power On VM' do
post :x_button, :params => {:pressed => 'vm_start', :id => vm_vmware.id}
expect(response.status).to eq(200)
it 'can Restart Guest' do
post :x_button, :params => {:pressed => 'vm_guest_restart', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Restart Guest initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end

expect(response.body).to include('Start initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
context 'powering on VM' do
let(:vm) { FactoryBot.create(:vm_vmware, :host => host_1x1, :raw_power_state => 'poweredOff', :ext_management_system => ems) }

it 'can Power Off VM' do
post :x_button, :params => {:pressed => 'vm_stop', :id => vm_vmware.id}
expect(response.status).to eq(200)
it 'can Power On VM' do
post :x_button, :params => {:pressed => 'vm_start', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Start initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
end

expect(response.body).to include('Stop initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
it 'can Power Off VM' do
post :x_button, :params => {:pressed => 'vm_stop', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Stop initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end

it 'can Suspend VM' do
post :x_button, :params => {:pressed => 'vm_suspend', :id => vm_vmware.id}
expect(response.status).to eq(200)
it 'can Suspend VM' do
post :x_button, :params => {:pressed => 'vm_suspend', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Suspend initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end

expect(response.body).to include('Suspend initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
it 'can Reset VM' do
post :x_button, :params => {:pressed => 'vm_reset', :id => vm.id}
expect(response.status).to eq(200)
expect(response.body).to include('Reset initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
end
end

it 'can Reset VM' do
post :x_button, :params => {:pressed => 'vm_reset', :id => vm_vmware.id}
expect(response.status).to eq(200)
context 'operations on Templates' do
let(:template) { FactoryBot.create(:template, :ext_management_system => ems) }

expect(response.body).to include('Reset initiated for 1 VM and Instance from the %{product} Database' % {:product => Vmdb::Appliance.PRODUCT_NAME})
%w(vm_guest_shutdown vm_guest_restart vm_start vm_stop vm_suspend vm_reset).zip(['Shutdown Guest', 'Restart Guest', 'Start', 'Stop', 'Suspend', 'Reset']).each do |action, action_name|
it "cannot #{action_name}" do
post :x_button, :params => {:pressed => action, :id => template.id}
expect(response.status).to eq(200)
expect(response.body).to include('%{action_name} action does not apply to selected items' % {:action_name => action_name})
end
end
end
end

it 'can run Utilization' do
Expand Down

0 comments on commit 8bf2ad4

Please sign in to comment.