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

Provide message when tag assignment failed #20216

Merged

Conversation

yrudman
Copy link
Contributor

@yrudman yrudman commented May 27, 2020

ISSUE:
if tag category or tag name misspelled when executing API call to assign tag than return message did not indicate what went wrong.

with ManageIQ/manageiq-api#843 fixes BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1792106

Example:
curl --user admin:smartvm -i -X POST -d '{"action":"assign","resources":[{"category":"team","name":"it_pnp"}]}' http://localhost:3000/api/vms/54/tags
BEFORE:
{"results":[{"success":false,"message":"Assigning Tag: category:'team' name:'it_pnp'", ...}
AFTER:
{"results":[{"success":false,"message":"Assigning Tag: category:'team' name:'it_pnp' - FAILED. Tag category 'team' not found in region 0", ...}

cross-repo: ManageIQ/manageiq-cross_repo-tests#133

@miq-bot miq-bot added the wip label May 27, 2020
@yrudman yrudman force-pushed the provide-message-when-tag-assignment-failed branch from 1674419 to f70884f Compare May 27, 2020 18:27
@yrudman yrudman force-pushed the provide-message-when-tag-assignment-failed branch from f70884f to d9df6b4 Compare May 27, 2020 18:30
@miq-bot
Copy link
Member

miq-bot commented May 27, 2020

Checked commits yrudman/manageiq@76c59d2~...d9df6b4 with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. 👍

@yrudman yrudman changed the title [WIP]Provide message when tag assignment failed Provide message when tag assignment failed May 27, 2020
@miq-bot miq-bot removed the wip label May 27, 2020
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

this fixes the bz and it doesn't adversely effect the other code

ent = cat.find_entry_by_name(entry_name, obj.region_id)
ent.assign_entry_to(obj, is_request) unless ent.nil? || obj.is_tagged_with?(ent.to_tag, :ns => "none")
end
cat = Classification.find_by_name(category_name, obj.region_id)
Copy link
Member

Choose a reason for hiding this comment

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

this does feel like ui code.

also programmatically, it is difficult to know if this succeeded or failed without string compare.

nice thing about this code is that it doesn't blow up our other classes that assume this method will not throw an exception.

@@ -61,6 +61,35 @@
FactoryBot.create(:classification_tag, :name => "multi_entry_2", :parent => parent)
end

describe ".classify" do
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the tests.

makes understanding the goals that much easier

ent.assign_entry_to(obj, is_request) unless ent.nil? || obj.is_tagged_with?(ent.to_tag, :ns => "none")
end
cat = Classification.find_by_name(category_name, obj.region_id)
return " - FAILED. Tag category '#{category_name}' not found in region #{obj.region_id}" if cat.nil?
Copy link
Member

@Fryguy Fryguy May 27, 2020

Choose a reason for hiding this comment

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

Are these going to make their way to the UI? If so they need to be I18N'd properly.


Separately, I think it's weird that this method returns failure strings.

I think better interfaces would be

  • an Exception with the error and the caller catches that and presents it
  • on success return true; on failure return [false, message] where message is the actual failure message without the leading - FAILURE. The caller does success, message = Classification.classify(...) and is then responsible for checking the success value, and then presenting the message with whatever prefix it needs. This is actually a pattern we follow elsewhere in the code.

Copy link
Member

Choose a reason for hiding this comment

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

@Fryguy a number of places including automate rely upon the fact that exceptions are not thrown.

Do you propose we update automate to handle a thrown exception here?

We could add these rescues in the various places and then merge the change here.

going the way you proposed is how Yuri originally did it. But we reverted because so much stuff seemed to break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an Exception with the error and the caller catches that and presents it

this PR #20197 was reverted since it affect automation

Are these going to make their way to the UI? If so they need to be I18N'd properly.

return of method was not checked previously and made use of in ManageIQ/manageiq-api#843. In that place returned message was not go over I18N' before.
If it should be I18N'd properly may be it should go to another PR ?

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about creating an Errors object and returning that? It a hack because you don't have an actual object to add it to but, at least it would be more model like

Something like -

e=ActiveModel::Errors.new(Classification.new)
e.add(:category, "'#{category_name}' not found in region #{obj.region_id")

Copy link
Contributor Author

@yrudman yrudman May 29, 2020

Choose a reason for hiding this comment

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

it looks slightly over-designed - create new object only to use as wrapper for error string and on consumer side check if that object returned (and not nil) and extract that string from object

I agree that returned string "- FAILED..." does looks strange,
But, it accomplished request; I think that in order to make required improvement better - too many changes / refactoring needed, which may introduce more harm than added value from improvement

@gtanzillo gtanzillo merged commit 7cebd4e into ManageIQ:master Jun 17, 2020
@yrudman yrudman deleted the provide-message-when-tag-assignment-failed branch June 17, 2020 18:01
@yrudman
Copy link
Contributor Author

yrudman commented Jun 19, 2020

@miq-bot add-label jansa/yes?

simaishi pushed a commit that referenced this pull request Jun 25, 2020
…nment-failed

Provide message when tag assignment failed

(cherry picked from commit 7cebd4e)
@simaishi
Copy link
Contributor

Jansa backport details:

$ git log -1
commit cf1cad141f82bee36e344ed2baf889f7f5963086
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Wed Jun 17 13:41:55 2020 -0400

    Merge pull request #20216 from yrudman/provide-message-when-tag-assignment-failed

    Provide message when tag assignment failed

    (cherry picked from commit 7cebd4e2a5ec5dbfc96d8e02fd2c754cb40ca3ca)

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.

6 participants