-
Notifications
You must be signed in to change notification settings - Fork 358
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
Conversation
cb03822
to
1cc880d
Compare
@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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
1cc880d
to
b7355f7
Compare
@d-m-u Do you approve the current fix? |
@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. |
@miha-plesko specs are always appreciated. |
b7355f7
to
800be06
Compare
@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. |
@skateman Could you please look at the spec and / or give advice? Thanks. |
spec/factories/miq_request.rb
Outdated
@@ -0,0 +1,5 @@ | |||
FactoryGirl.define do |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAGNI -> response.parsed_body
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really smart 👍
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 :) |
@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>
800be06
to
80d3684
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
Some comments on commit miha-plesko@80d3684 spec/controllers/miq_request_controller_spec.rb
|
Checked commit miha-plesko@80d3684 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@skateman @mzazrivec is this ready for merge? |
@skateman Are you OK with the current specs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show correct VMs upon Service retirement (cherry picked from commit c0c060d) https://bugzilla.redhat.com/show_bug.cgi?id=1632239
Hammer backport details:
|
Show correct VMs upon Service retirement (cherry picked from commit c0c060d) https://bugzilla.redhat.com/show_bug.cgi?id=1636494
Gaprindashvili backport details:
|
@miha-plesko Please take a look at Travis failure for Gaprindashvili branch: https://travis-ci.org/ManageIQ/manageiq-ui-classic/jobs/440166352
|
I also think this shouldn't be in G at all... |
But it'll probably be a valid bug on 5.9, just not anything to do with requests. |
I think we should recheck what this looks like on 5.9. |
Reverted the G backport.
|
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:
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
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