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

Add Ansible Repository refresh output page #3762

Merged

Conversation

Glutexo
Copy link
Member

@Glutexo Glutexo commented Apr 12, 2018

Create a custom display mode for Ansible Repository show page with last refresh output capture. If an Ansible Tower Repository has this capture from its last failed refresh, the Status row becomes a link to this subpage.

Presenting this information is a workaround for cloning repositories from HTTPS servers with untrusted SSL certificates. Tower API does not offer an option to disable SSL check, so with the stdout user can at least see, why the cloning actually failed.

Along with RSpec examples for this feature, refactor a bit other tests related to the page refresh button:

  • Increase test coverage of the AJAX content replacement used
  • Test Playbooks nested list subpage
  • Rename examples with rather misleading titles

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

Prior merging this PR, following PRs are required to be merged:

/cc @ZitaNemeckova, @hstastna for review

@hstastna
Copy link

@Glutexo Could you please add some screenshots if there is some change in the UI? I'm not sure if I understand your change. Thanks!

@hstastna
Copy link

And in specs, I would better use

is_expected.to have_http_status(200)

instead of is_expected.to have_http_status 200
but that's just a detail.

@@ -97,6 +111,12 @@ def new
@in_a_form = true
end

def show_output
drop_breadcrumb(:name => "Refresh output", :url => show_output_link)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing gettext.

@Glutexo
Copy link
Member Author

Glutexo commented Apr 23, 2018

@hstastna

Here there the screenshots requested. They show the Repository show page and its new output subpage. Before this PR, all Repositories looked the same. This adds a subpage (display mode) for the failed ones. The Status: failed row turns into a link.

For the non-failed repo’s too, the Status row is not clickable, she subpage can be accessed directly by the url though. The Refresh button in the toolbar should reload the subpage contents via AJAX, not returning to the Summary. The back-arrow button should return to the Summary.

@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from 436dfea to c6beb47 Compare April 23, 2018 13:40
@Glutexo
Copy link
Member Author

Glutexo commented Apr 23, 2018

I fixed the missing gettext spotted by @mzazrivec, squashed it and rebased onto current upstream master.

@hstastna As for the parentheses in the have_http_status method call: I agree with you, however I mimicked the style of the calls that is already there. So I leave it as it is, re-styling can be done in bulk if necessary.

Technically, the expect(…).to is a method call too, so it should be expect(response).to(have_http_status(200))

end

it 'calls show_output method' do
controller.params[:display] = 'output'

Choose a reason for hiding this comment

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

I see that you set controller.params[:display] in more it blocks exactly like this. You can use context blocks and set params[:display] in them by using let for lazy evaluation and it blocks then. For example like this:

context 'calling show_output method' do
  let(:display) { 'output' }

   it 'calls show_output method' do
     receives_init_show
     expect(controller).to receive(:show_output)
     renders
     controller.send(:button)
  end
end

If you do so, you may also want to change line 125 https://github.com/ManageIQ/manageiq-ui-classic/pull/3762/files#diff-62ca34af6656484e37abce1fb2fe1461R125 like this, to set params[:display] for the spec properly:

      let(:params) { {:action => "button", :pressed => "ansible_repository_reload", :display => display} }

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool! I didn’t know that more nested lets can be used from outside context too. Thanks!

@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from c6beb47 to ce87ef5 Compare April 25, 2018 13:17
@Glutexo
Copy link
Member Author

Glutexo commented Apr 25, 2018

In reaction to a review comment by @hstastna, I grouped the “refreshing an actual repository page” specs into contexts based on the display param they use. Squashed and rebased onto the current master.

Just a note: We decided to store the output capture for all repositories, not only for the failed ones. This requires no code change in the UI, it is just not a bug when the “Status: successful” row becomes clickable. Capturing stdout makes sense for non-failed repositories as well, since there might be warnings or other useful information.

@miq-bot
Copy link
Member

miq-bot commented May 23, 2018

This pull request is not mergeable. Please rebase and repush.

@Glutexo
Copy link
Member Author

Glutexo commented Jun 6, 2018

When I created this PR, there was a refresh button on subpages (custom display modes) as it was on main show page. When I now want to test it after rebasing, I don’t see the refresh button anymore.

Main show toolbar:
Main show toolbar

Custom display mode (subpage) toolbar:
Custom display mode toolbar

Is it possible that toolbar behavior changed? I added a custom display mode in this PR and along with that a piece of code handling the refresh button. If the button is really no longer there, I can remove this newly introduced code and thus reduce complexity. Also in such case the refresh button handling could be simplified, not in this PR though.

Maybe @mzazrivec or @himdel could know?

@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from ce87ef5 to 31f9f59 Compare June 6, 2018 09:39
@Glutexo
Copy link
Member Author

Glutexo commented Jun 7, 2018

@miq-bot add_label pending core


template = 'show'
if self.class.display_methods.include?(params[:display])
display_nested_list(params[:display])
Copy link
Contributor

@himdel himdel Jun 8, 2018

Choose a reason for hiding this comment

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

how is display_nested_list relevant here? Are you introducing any nested lists?

(or is this just reimplementing the parts of show that were already needed?)

Copy link
Member Author

Choose a reason for hiding this comment

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

@himdel This is a piece taken from the show method in a not very DRY way.

The show method doesn’t reach the custom_display_call at all, so at least this one would have to remain here. Because of that and some other struggles I decided to leave only what’s necessary here from the show method.

That is: init_show and those two ifs. The first is for playbooks subpage, which is a nested list, the second is for the new output subpage. I am however not sure whether it decreases complexity – the whole show method is not called here – or increases it – there are two decision points introduced.

However, since the Refresh button disappeared, this might not be actually needed at all. Moreover, the existing code there could be safely removed.

end
end

def receives_init_show
Copy link
Contributor

@himdel himdel Jun 8, 2018

Choose a reason for hiding this comment

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

Cc @skateman , I think you may have some comments here..

(Methods in a spec.)

Copy link
Member

Choose a reason for hiding this comment

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

@Glutexo methods in a spec are evil, can you rewrite them using shared examples and shared contexts?

Copy link
Member Author

Choose a reason for hiding this comment

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

@himdel @skateman No problem, I’ll rewrite it. Would you please provide me with a link to some resource explaining the evilness of methods in specs?

Copy link
Member

@skateman skateman Jun 8, 2018

Choose a reason for hiding this comment

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

TL;DR: mixing two patterns that do the same thing (rspec ruby vs pure ruby) is never a good idea
If you want a longer explanation, I can try next week if that's okay for you 😉

@himdel
Copy link
Contributor

himdel commented Jun 8, 2018

@Glutexo you may need to explicitly set @center_toolbar = 'ansible_repository_center', so that the right toolbar gets picked up for the new screen.

@Glutexo
Copy link
Member Author

Glutexo commented Jun 11, 2018

I bisected the state before rebase and after that. The refresh button disappeared with the commit 3c7f204 by @hstastna. From my first glimpse at the PR that contains it (#3721) it looks like the refresh button should not have been there in the first place. I’ll investigate it a bit more.

@Glutexo
Copy link
Member Author

Glutexo commented Jun 15, 2018

I get it now. The playbooks subpage used the same toolbar as its parent repository page. Because of that the Policy › Add Tags button added tags to the repository and not to the playbooks. That was addressed and fixed by #3721.

However at the same time the repository toolbar contained a refresh button. This button appeared on the playbooks subpage too. There is a piece of code that handles the button press. Thanks to the magic in the generic show mixin it works for the playbooks subpage correctly too.

Still there is some rather obscure manipulation with the @display and params[:display] values:

params[:display] = @display if @display
followed directly by
@display = params[:display] || default_display
. This still doesn’t work too great.

For a mix of reasons, this piece of code didn’t work automatically for the new stdout subpage I introduced. Because of that I made some controversial modifications to the refresh button handling. But since the button is no longer there, although not necessary intentionally, this piece of code is not necessary and can be removed from this PR.

@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from 31f9f59 to 51dfdbf Compare June 19, 2018 07:08
@Glutexo
Copy link
Member Author

Glutexo commented Jun 19, 2018

So, the refresh button is gone for subpages (be in intentional or not). Thanks to that I could simplify this PR. Removed changes to the refresh button handling making it work for the new subpage as well as the related tests. Those can be added in case the refresh button would return.

Still this is not mergeable, because of dependencies on other PRs. It is however hopefully at least simple enough to be reviewed.

cc @himdel @hstastna

@hstastna
Copy link

hstastna commented Jun 19, 2018

@Glutexo It looks good (except the specs). Maybe you could divide the code into more commits to make your changes more clear to anyone. At least 2 commits: commit for the changes + commit for specs ;)
Question:
"If an Ansible Tower Repository has this capture from its last failed refresh, the Status row becomes a link to this subpage." - how can I achieve this (failed refresh) to test Refresh output page in the UI? Thank you!

@hstastna
Copy link

@Glutexo Travis is failing here and it looks like it is related to your changes. Specs are failing for me locally, too, with your changes (they pass without your changes). Could you check it, please? Thank you! 👍

@Glutexo
Copy link
Member Author

Glutexo commented Jun 19, 2018

Okay, I’ll check more deeply.

@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from 51dfdbf to 1338d45 Compare June 20, 2018 08:01
@Glutexo
Copy link
Member Author

Glutexo commented Jun 20, 2018

@hstastna

Failing specs

Oh, of course the specs are failing! It’s because these changes depend on a model/schema update: Please checkout https://github.com/Glutexo/manageiq/tree/add_configuration_script_source_last_update_stdout and https://github.com/Glutexo/manageiq-schema/tree/add_configuration_script_source_last_update_stdout to update the database schema and the Rails model.

Unfortunately I am currently not able to quickly test it locally, because Bundler and updates fail for me for some unknown reason. But that above is necessary to test both by rspec and manually.

How to test the UI behavior

Prerequisities

  • You have to have some Ansible Repositories in your database. I assume you already have those.
  • You have to have your database schema updated, so you have the last_update_stdout column in the configuration_script_source table.

Steps

  • Fill in something into the last_update_stdout column of some Ansible repository.
  • Find this repository in the list (Automate › Ansible › Repositories) and click it to open its show page.
  • See the Status row containing success/failed and check it is a link.
  • Click the row to open a separate page with the output.
  • Check that there is the column contents displayed.
  • Set the column value to NULL.
  • Refresh the page.
  • Check that no error (500) is raised and there is a friendly notice on the page.
  • Go back to the main repository show page and refresh it.
  • See the Status row again and check it is not a link.

@hstastna
Copy link

Of course I've updated the db schema. And specs are still failing.

@Glutexo
Copy link
Member Author

Glutexo commented Jun 20, 2018

@hstastna I know you said you updated the schema, but still I’d like to verify you don’t have the same problem as I did.

I double- (triple-) checked and got failing specs too. This was really because of the missing column, at least on my machine, in the vmdb_test database. After a few moments of despair I realized that I have to overload the manageiq-schema gem in my custom bundler.d Gemfile. This made the Rake task to pick my branch with the additional migration. When I fixed this and ran rake test:vmdb:setup the tests magically turned green.

@hstastna
Copy link

hstastna commented Jun 20, 2018

@Glutexo Thank you very much for your detailed explanation. Yes, sometimes we can forget about some specific things which we should do.. But.. I did the same and it didn't help 😅 Maybe I'm doing something wrong. Anyway, @skateman is better expert for specs ;)

@skateman
Copy link
Member

Try from the manageiq core repo:

RAILS_ENV=test bin/rake db:migrate

Might help, but just a guess 😉

@Glutexo
Copy link
Member Author

Glutexo commented Jun 20, 2018

@hstastna Just to be sure. When you run the ansible_repository_controller.spec and it fails, take a look into test.log please. What does that say? Just to be sure it‘s not method_missing like this:

[----] F, [2018-06-20T14:49:47.574607 #50762:3fd99e43f7bc] FATAL -- : Error caught: [ActionView::Template::Error] undefined method `last_update_stdout' for #<ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource:0x00007fb347c30418>
Did you mean?  last_updated_on

which would mean that the schema is bad. If it’s something different, then I am wrong with all those schema-rants for the whole time.

Create a custom display mode for Ansible Repository show page with last
refresh output capture. If an Ansible Tower Repository has this capture
from its last failed refresh, the Status row becomes a link to this
subpage.
@Glutexo Glutexo force-pushed the add_ansible_repository_refresh_output_page branch from 1338d45 to c847860 Compare June 21, 2018 09:19
@Glutexo
Copy link
Member Author

Glutexo commented Jun 21, 2018

@Fryguy requested a different name for the new column. I changed it in the schema and in the model as well as here.

@Glutexo
Copy link
Member Author

Glutexo commented Jun 21, 2018

@hstastna I’d prefer not to split the commit to have executive code in a different one than tests. I like that the commit is atomic and tested by itself. Moreover, the spec changes are so little that it doesn't make much sense to extract those. Sorry. 😔

May I ask you to check running the specs with the new column name?

@miq-bot
Copy link
Member

miq-bot commented Jun 21, 2018

Checked commit Glutexo@c847860 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🍰

@hstastna
Copy link

hstastna commented Jun 22, 2018

@Glutexo Finally, the specs passed 👍 for me, locally.

@tumido
Copy link
Member

tumido commented Jul 27, 2018

All related PRs merged now.

@miq-bot remove_label pending core

@himdel himdel merged commit ba8da96 into ManageIQ:master Jul 27, 2018
@himdel himdel self-assigned this Jul 27, 2018
@himdel
Copy link
Contributor

himdel commented Jul 27, 2018

Tested, looks good 👍 :)

The only thing:

Fill in something into the last_update_stdout column of some Ansible repository.

this is called last_update_error now.

@himdel himdel added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 27, 2018
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.

7 participants