Skip to content

Commit

Permalink
Merge pull request #4710 from miha-plesko/retire-request-show-vms
Browse files Browse the repository at this point in the history
Show correct VMs upon Service retirement
  • Loading branch information
mzazrivec authored Oct 8, 2018
2 parents 80770b9 + 80d3684 commit c0c060d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller/miq_request_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ def prov_set_show_vars
end
@options[:wf] = options[:wf]
end
elsif @miq_request.resource_type == 'ServiceRetireRequest'
@view, @pages = nil
if (service_id = @miq_request.options[:src_ids].first) && (service = Service.find_by(:id => service_id)) && Rbac.filtered_object(service)
@view, @pages = get_view(Vm, :parent => service, :view_suffix => 'OrchestrationStackRetireRequest')
end
else
@options = @miq_request.options
@options[:memory], @options[:mem_typ] = reconfigure_calculations(@options[:vm_memory][0]) if @options[:vm_memory]
Expand Down
2 changes: 2 additions & 0 deletions app/views/miq_request/_request.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
= render :partial => "st_prov_show"
- elsif @miq_request.type == 'ServiceReconfigureRequest'
= render :partial => "service_reconfigure_show"
- elsif @miq_request.type == "ServiceRetireRequest"
= render :partial => "service_retire_show"
- elsif @miq_request.type == "AutomationRequest"
= render :partial => "ae_prov_show"
- else
Expand Down
7 changes: 7 additions & 0 deletions app/views/miq_request/_service_retire_show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#main_div
%h3
= _("Affected VMs")
- if @view
- @embedded = true
- @gtl_type = "list"
= render :partial => "layouts/gtl", :locals => {:view => @view, :no_flash_div => true}
55 changes: 55 additions & 0 deletions spec/controllers/miq_request_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,61 @@
end
end

context 'showing details of a retirement task' do
before do
@user = stub_admin
EvmSpecHelper.create_guid_miq_server_zone
end

let(:vm1) { FactoryGirl.create(:vm_cloud) }
let(:vm2) { FactoryGirl.create(:vm_cloud) } # not part of the stack
let(:stack) { FactoryGirl.create(:orchestration_stack).tap { |stack| stack.direct_vms = [vm1] } }
let(:service) { FactoryGirl.create(:service_orchestration).tap { |service| service.add_resource!(stack) } }
let(:request) do
FactoryGirl.create(:service_retire_request,
:type => 'ServiceRetireRequest',
:requester => @user,
:options => {:src_ids => [service.id]})
end
# let(:request) { FactoryGirl.create(:miq_service_retirement_request, :options => {:src_ids => [service.id]}) }

let(:payload) { { :model_name => 'Vm', :parent_id => service.id.to_s, additional_key => additional_val } }
let(:additional_val) do
{
:model => 'Vm',
:parent_id => service.id.to_s,
:parent_class_name => 'ServiceOrchestration',
:view_suffix => 'OrchestrationStackRetireRequest',
:display => 'main',
:gtl_type => 'list'
}
end

context 'angular for grid with affected VMs is properly initialized' do
let(:additional_key) { :report_data_additional_options }
it do
expect(controller).to receive(:prov_set_show_vars).once.and_call_original

# Verify Rails correctly initializes Angular which will then perform POST /report_data to fetch the VMs.
expect_any_instance_of(GtlHelper).to receive(:render_gtl).with match_gtl_options(**payload)

get :show, :params => {:id => request.id}
expect(response.status).to eq(200)
end
end

context 'angular for grid with affected VMs gets the correct VMs with XHR call' do
let(:additional_key) { :additional_options }
it do
post :report_data, :params => payload
expect(response.status).to eq(200)

# Verify Angular got correct VMs when sending the payload as set by previous test.
expect(JSON.parse(response.body).dig('data', 'rows').map { |row| row['id'] }).to eq([vm1.id.to_s])
end
end
end

context "#edit_button" do
before do
stub_user(:features => :all)
Expand Down

0 comments on commit c0c060d

Please sign in to comment.