Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show correct VMs upon Service retirement #4710

Merged
merged 1 commit into from
Oct 8, 2018

Conversation

miha-plesko
Copy link
Contributor

With this commit we make sure correct VMs are shown as part of service retirement request. Talking about "Affected VMs" section that now looks like:

image

Prior to this commit there was always only a single VM displayed in there, and it was not the right one. Happened to see AWS EC2 VM on a vCloud vApp retirement request details!

image

The reason for all this was that

@miq_request.options[:src_ids]

was treated as it's a list of VM ids whereas it infact was a list of Service ids. If we were lucky enough, some Service id collided with random VM id and BUUUM, wrong VM was shown.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1632239

Related PRs:

@miq-bot assign @mzazrivec
@miq-bot add_label enhancement,gaprindashvili/yes,hammer/yes

/cc @tinaafitz @d-m-u

@JPrause
Copy link
Member

JPrause commented Sep 28, 2018

@miq-bot add_label blocker

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 => "VmReconfigureRequest")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is a bug, I am however unsure of why VmReconfigureRequests would come into play here, as @tinaafitz pointed out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK it's only a matter of what columns are displayed for each Vm. Here I reused the reconfigure view which shows CPU and memory resources consumed by each Vm.

But let me double check on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-m-u just realized view_suffix has to do with Rbac view, not the haml views. I do apologize for screwing this up, did it right this time. Thanks for pointing out!

@mzazrivec
Copy link
Contributor

@d-m-u Do you approve the current fix?

@miha-plesko
Copy link
Contributor Author

@mzazrivec think I should try to come up with some specs? I think there are non currently, but should you find it valuable, I can give it a try.

@mzazrivec
Copy link
Contributor

@miha-plesko specs are always appreciated.

@miha-plesko miha-plesko changed the title Show correct VMs upon Service retirement [WIP] Show correct VMs upon Service retirement Oct 1, 2018
@miq-bot miq-bot added the wip label Oct 1, 2018
@miha-plesko miha-plesko changed the title [WIP] Show correct VMs upon Service retirement Show correct VMs upon Service retirement Oct 2, 2018
@miq-bot miq-bot removed the wip label Oct 2, 2018
@miha-plesko
Copy link
Contributor Author

@mzazrivec pulled half of my hair implementing the spec, but here it is ;) Problem is that list of affected VMs is in fact loaded by Angular not Rails and Rails doesn't even know what VMs will be listed. The rspec we have now is a two-step: first it asserts payload sent from Rails to Angular, then it simulates XHR request with this same payload as Angular would do it, and asserts that we get correct VMs.

Is there a better way? It really got me curious after the hard time I had to implement it at least this way.

@mzazrivec
Copy link
Contributor

@skateman Could you please look at the spec and / or give advice? Thanks.

@@ -0,0 +1,5 @@
FactoryGirl.define do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factories should live in the core repo to avoid conflicts. But you probably won't need it anyway, there's some ✨ magic ✨ around them that creates them on-the-fly if they're missing. Just pass these arguments to the .create.

expect(response.status).to eq(200)

# Verify Angular got correct VMs when sending the payload as set by previous test.
obtained = JSON.parse(response.body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAGNI -> response.parsed_body

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno, .parsed_body is string for me no matter what headers I set. Even

post :report_data, :params => payload, :format => :json

won't help.. I see other people also need workaround to get this working rails-api/active_model_serializers#1437 (comment)

end

it 'angular for grid with affected VMs is properly initialized' do
payload = angular_payload.update(:report_data_additional_options => angular_additional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather extract this into contexts and then you don't have to call the update:

let(payload) { {:model => blah, additional_key => additional_val} }
let(:additional_val) { ... }

context 'first' do
  let(:additional_key) { :report_data_additional_options }
  it ...
end

context 'second' do
  let(:additional_key) { :additional_options }
  it ...
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really smart 👍

@miha-plesko
Copy link
Contributor Author

Thanks @skateman, appreciate your feedback. Is there perhaps a way I could let the Angular to be actually executed on the page returned by the first test, so I wouldn't need to simulate the second test at all (the POST request is actually performed by Angular and I need to be sure that correct list is returned)?

I suppose I want it on too high level so it's a matter of integration tests, but at least I have to ask :)

@skateman
Copy link
Member

skateman commented Oct 2, 2018

@miha-plesko no, the only thing you can test is the request/response for the GTL data.

With this commit we make sure correct VMs are shown as part
of service retirement request. Talking about "Affected VMs"
section.

Prior to this commit there was always only a single VM displayed
in there, and it was not the right one. Happened to see AWS EC2 VM
on a vCloud vApp retirement request details!

The reason for all this was that

```
@miq_request.options[:src_ids]
```

were treated as it's a list of VM ids whereas it infact was a
list of Service ids. If we were lucky enough, some Service id
collided with random VM id and BUUUM, wrong VM was shown.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1632239

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
Copy link
Contributor Author

@miha-plesko miha-plesko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so specs are updated, looking forward to any other suggestion.

end

it 'angular for grid with affected VMs is properly initialized' do
payload = angular_payload.update(:report_data_additional_options => angular_additional)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really smart 👍

expect(response.status).to eq(200)

# Verify Angular got correct VMs when sending the payload as set by previous test.
obtained = JSON.parse(response.body)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno, .parsed_body is string for me no matter what headers I set. Even

post :report_data, :params => payload, :format => :json

won't help.. I see other people also need workaround to get this working rails-api/active_model_serializers#1437 (comment)

@miq-bot
Copy link
Member

miq-bot commented Oct 2, 2018

Some comments on commit miha-plesko@80d3684

spec/controllers/miq_request_controller_spec.rb

  • ⚠️ - 305 - Detected expect_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented Oct 2, 2018

Checked commit miha-plesko@80d3684 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@h-kataria
Copy link
Contributor

@skateman @mzazrivec is this ready for merge?

@mzazrivec
Copy link
Contributor

@skateman Are you OK with the current specs?

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Seal of Approval

@mzazrivec mzazrivec added this to the Sprint 96 Ending Oct 8, 2018 milestone Oct 8, 2018
@mzazrivec mzazrivec merged commit c0c060d into ManageIQ:master Oct 8, 2018
simaishi pushed a commit that referenced this pull request Oct 8, 2018
@simaishi
Copy link
Contributor

simaishi commented Oct 8, 2018

Hammer backport details:

$ git log -1
commit b6a3763e1a5d5382ccc4e9fdf15f8dc492691855
Author: Milan Zázrivec <mzazrivec@redhat.com>
Date:   Mon Oct 8 08:58:32 2018 +0200

    Merge pull request #4710 from miha-plesko/retire-request-show-vms
    
    Show correct VMs upon Service retirement
    
    (cherry picked from commit c0c060d2d8bfdb303f54f45a849afc94a21d9fe1)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1632239

simaishi pushed a commit that referenced this pull request Oct 11, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 2e85ec094ec9fbd6cc55bdaffba5727e972da371
Author: Milan Zázrivec <mzazrivec@redhat.com>
Date:   Mon Oct 8 08:58:32 2018 +0200

    Merge pull request #4710 from miha-plesko/retire-request-show-vms
    
    Show correct VMs upon Service retirement
    
    (cherry picked from commit c0c060d2d8bfdb303f54f45a849afc94a21d9fe1)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1636494

@simaishi
Copy link
Contributor

@miha-plesko Please take a look at Travis failure for Gaprindashvili branch:

https://travis-ci.org/ManageIQ/manageiq-ui-classic/jobs/440166352

  1) MiqRequestController showing details of a retirement task angular for grid with affected VMs gets the correct VMs with XHR call 
     Failure/Error: @user = stub_admin
     NameError:
       undefined local variable or method `stub_admin' for #<RSpec::ExampleGroups::MiqRequestController_2::ShowingDetailsOfARetirementTask::AngularForGridWithAffectedVMsGetsTheCorrectVMsWithXHRCall:0x00000039c863b8>
     # ./spec/controllers/miq_request_controller_spec.rb:262:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:73:in `block (3 levels) in <top (required)>'
     # ./spec/manageiq/spec/support/evm_spec_helper.rb:35:in `clear_caches'
     # ./spec/spec_helper.rb:73:in `block (2 levels) in <top (required)>'

  2) MiqRequestController showing details of a retirement task angular for grid with affected VMs is properly initialized 
     Failure/Error: @user = stub_admin
     NameError:
       undefined local variable or method `stub_admin' for #<RSpec::ExampleGroups::MiqRequestController_2::ShowingDetailsOfARetirementTask::AngularForGridWithAffectedVMsIsProperlyInitialized:0x0000003c7d52d0>
     # ./spec/controllers/miq_request_controller_spec.rb:262:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:73:in `block (3 levels) in <top (required)>'
     # ./spec/manageiq/spec/support/evm_spec_helper.rb:35:in `clear_caches'
     # ./spec/spec_helper.rb:73:in `block (2 levels) in <top (required)>'

@d-m-u
Copy link
Contributor

d-m-u commented Oct 11, 2018

I also think this shouldn't be in G at all...

@d-m-u
Copy link
Contributor

d-m-u commented Oct 11, 2018

But it'll probably be a valid bug on 5.9, just not anything to do with requests.

@d-m-u
Copy link
Contributor

d-m-u commented Oct 11, 2018

I think we should recheck what this looks like on 5.9.

@simaishi
Copy link
Contributor

Reverted the G backport.

commit 2b18e5a19bdfdd52f16924f953c1628565e2e99b
Author: Satoe Imaishi <simaishi@redhat.com>
Date:   Thu Oct 11 13:21:42 2018 -0400

    Revert "Merge pull request #4710 from miha-plesko/retire-request-show-vms"
    
    This reverts commit 2e85ec094ec9fbd6cc55bdaffba5727e972da371.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1636494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants