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

Fixes #20564 - ignore locking in migration #370

Merged
merged 1 commit into from Aug 30, 2017

Conversation

lzap
Copy link
Member

@lzap lzap commented Aug 11, 2017

Until there is a way for plugin API to do this for us, we need to ignore locking to prevent this error:

Validation failed: Filters.role is locked for user modifications

@theforeman-bot
Copy link
Member

Issues: #20564

@lzap
Copy link
Member Author

lzap commented Aug 17, 2017

Random failures hmmm [test]

@lzap
Copy link
Member Author

lzap commented Aug 22, 2017

Test [test]

@lzap
Copy link
Member Author

lzap commented Aug 23, 2017

So previous [test] failed with:

Test Result (3 failures / +3)

HostTest::location or organizations are not enabled.test_0081_non-admin user with edit_hosts permission can update interface
HostsControllerTest.test_0077_select multiple action with not exists host_ids should redirect to hosts page
HostIntegrationTest::edit page.test_0002_user without edit_params permission can save host with params

Trying again.

@lzap
Copy link
Member Author

lzap commented Aug 24, 2017

One [test] failed, a different one of course.

Test Result (1 failure / +1)
HostJSTest::edit page.test_0002_choosing a hostgroup does not override other host attributes

@lzap
Copy link
Member Author

lzap commented Aug 24, 2017

If this turns out to be random failure again, let's merge this one then? We have couple of others that would need to be in 10.0.0 @dLobatog @ares ...

@lzap lzap added the Important label Aug 24, 2017
@ares
Copy link
Member

ares commented Aug 24, 2017

LGTM, not tested yet. Note that this won't benecessary soon, plugin DSL will always update role permissions according to what's defined in engine.rb.

@lzap
Copy link
Member Author

lzap commented Aug 30, 2017

@dLobatog mind quick merge here? this only adds Role.ignore_locking to prevent "Template is locked" errors during migration. Foreman 1.16 is no longer affected, but we need this for 1.15 which I will be cherry picking into, thanks!

default_permissions[role_name].each do |permission|
role.add_permissions!(permission) unless role.permission_names.include?(permission.to_sym)
end
role.ignore_locking do |r|
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to ignore locking twice - if you do it at the class level it will be ignored for all instances.

Copy link
Member

@dLobatog dLobatog left a comment

Choose a reason for hiding this comment

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

@lzap Check out the few comments inline that are easy to fix, 👍 if tests pass.

default_permissions[role_name].each do |permission|
role.add_permissions!(permission) unless role.permission_names.include?(permission.to_sym)
Role.ignore_locking do
role = Role.find_by_name(role_name) || next
Copy link
Member

Choose a reason for hiding this comment

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

Role.unscoped. no user is set here so I think Role.find_by_name will be scoped to not show everything in all orgs/locs

Role.ignore_locking do
role = Role.find_by_name(role_name) || next
default_permissions[role_name].each do |permission|
role.add_permissions!(permission) unless role.permission_names.include?(permission.to_sym)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, since it's calling .save! on line 12, use add_permissions(permission) here - add_permissions! will save it once, then twice at the end of the loop.

@@ -1,12 +1,14 @@
default_permissions = Foreman::Plugin.find("foreman_discovery").default_roles
Copy link
Member

Choose a reason for hiding this comment

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

nitpick, all strings in here can safely be frozen, you can add

# frozen_string_literal: true

at the beginning of the file for better performance & thread safety (I know it's a little ridiculous for a loop with 2 objects but it's easy enough)

@lzap
Copy link
Member Author

lzap commented Aug 30, 2017

Ok amended all remarks thanks for such a triple review that's nice :-)

default_permissions[role_name].each do |permission|
role.add_permissions(permission) unless role.permission_names.include?(permission.to_sym)
end
role.update_attributes :origin => "discovery", :description => "Discovery plugin built-in role"
Copy link
Member

@dLobatog dLobatog Aug 30, 2017

Choose a reason for hiding this comment

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

update_attributes already saves the role, no need to call .save! after. Set all attributes then save to ensure it's saved only once:

role.add_permissions(permission)
role.origin = 'discovery'
role.description = 'discovery plugin builtin'
role.save

(sorry GitHub saved the comment but didn't publish it with the review)

@lzap
Copy link
Member Author

lzap commented Aug 30, 2017

@dLobatog just like that?

@timogoebel timogoebel merged commit 24ec75a into theforeman:develop Aug 30, 2017
@timogoebel
Copy link
Member

Merged, thanks @lzap, @dLobatog and @tbrisker.

@lzap lzap deleted the ignore-locking-20564 branch September 4, 2017 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants