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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23706 - CV/LE show the right value on Host form #7398

Merged
merged 1 commit into from Jul 13, 2018

Conversation

dLobatog
Copy link
Member

@dLobatog dLobatog commented May 28, 2018

Before this patch, the following situation could happen:

  1. Host A is part of a Host Group 'test'. Host A inherits LE/CV 'test'
    coming from Host Group 'test'

  2. We decide to change the LE/CV of Host A to 'production', either
    through the API or the UI.

  3. The next time we decide to check the UI, the helper was wrong (this
    patch fixes it) and showed the LE/CV from the Host Group 'test'. This is
    very confusing and may even cause you to change the LE/CV to from
    'production' to 'test' by accident.

In my opinion this should be backported to 3.6 at least

馃帴

Before: https://webmshare.com/q5g6Q
After: https://webmshare.com/mPa3D

@theforeman-bot
Copy link

Issues: #23706

@ares
Copy link
Contributor

ares commented May 29, 2018

Makes sense to me, hostgroup already implements both methods (via hostgroup extensions), reporter confirms it fixes the issue, 馃憤 from me

@ares
Copy link
Contributor

ares commented May 29, 2018

@dLobatog the test failure is related

Failure:

HostAndHostGroupsHelperLifecycleEnvironmentTests#test_accessible_lifecycle_environments_limited [/var/lib/workspace/workspace/katello-pr-test/test/helpers/hosts_and_hostgroups_helper_test.rb:31]:

--- expected

+++ actual

@@ -1 +1 @@

-[#<Katello::KTEnvironment id: 562075838, name: "Library", description: "This is the Library", library: true, organization_id: 114267492, created_at: "2018-05-28 12:33:33", updated_at: "2018-05-28 12:33:33", label: "library_label", registry_name_pattern: nil>]

+#<ActiveRecord::AssociationRelation []>

Copy link
Member Author

@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.

@ares Updated, had to jump through some hoops to get the test passing, just some differences between working with FactoryBot vs real models saved in the db.

@@ -26,6 +29,8 @@ def test_accessible_lifecycle_environments
end

def test_accessible_lifecycle_environments_limited
@host.save
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to do this so I could call @host.lifecycle_environment later..
On the test environment with FactoryBot.build it doesn't work as the association needs to be saved in the database to work: https://github.com/Katello/katello/blob/master/app/models/katello/concerns/content_facet_host_extensions.rb#L29

@ares
Copy link
Contributor

ares commented Jun 4, 2018

could some committer take a look and merge if ACKed?

@ehelms
Copy link
Member

ehelms commented Jun 7, 2018

@parthaa Can you take a look?

@jlsherrill
Copy link
Member

@dLobatog this doesn't seem to fix the issue? at least i can reproduce it as described:

  1. change the LE/CV or content-source from WebUI and save it
  2. click on edit host again and LE/CV changed to the default one in the hostgroup

recorded

@@ -77,20 +61,19 @@ def kickstart_repository_id(host, options = {})
end

def fetch_lifecycle_environment(host, options = {})
return host.lifecycle_environment if host.lifecycle_environment.present?
selected_host_group = options.fetch(:selected_host_group, nil)
return lifecycle_environment(selected_host_group) if selected_host_group.present?
Copy link
Member

Choose a reason for hiding this comment

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

looks like you deleted the lifecycle_environment method above:

undefined method `lifecycle_environment' for #<#Class:0x0000000bb7e3e0:0x0000000bb8ed58>

Copy link
Member

Choose a reason for hiding this comment

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

this seems to happen if you create a host, select the host group, but don't select a CV or LCE. Then go to the host edit page.

It does seem to solve the original issue thou gh.

end

def fetch_content_view(host, options = {})
return host.content_view if host.content_view.present?
selected_host_group = options.fetch(:selected_host_group, nil)
return content_view(selected_host_group) if selected_host_group.present?
Copy link
Contributor

Choose a reason for hiding this comment

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

This method has been deleted as well. This line needs to change too

Copy link
Member Author

@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.

@parthaa @jlsherrill Updated to fix the calls to the removed method

Before this patch, the following situation could happen:

1. Host A is part of a Host Group 'test'. Host A inherits LE/CV 'test'
coming from Host Group 'test'

2. We decide to change the LE/CV of Host A to 'production', either
through the API or the UI.

3. The next time we decide to check the UI, the helper was wrong (this
patch fixes it) and showed the LE/CV from the Host Group 'test'. This is
very confusing and may even cause you to change the LE/CV to from
'production' to 'test' by accident.
Copy link
Member Author

@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.

@jlsherrill @parthaa Green tests 馃槃

If you could take a look again it'd be great, it's really bothering the people who opened the BZ (it has several cases attached as you may see).

Copy link
Member

@akofink akofink left a comment

Choose a reason for hiding this comment

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

It works as expected, though I noticed this scenario:

  1. create a host
  2. assign a CV/LE and save, leaving hostgroup empty
  3. edit the host, select a host group

At this point, I can't clear the CV or LE without incurring validation errors. There doesn't seem to be a way to tell Foreman to use the CV/LE associated with the host group. This is kind of a contrived scenario, but users may encounter it. What do you think? @jlsherrill had mentioned to me that we might think about something like the inherit button we use for the puppet fields.

@jlsherrill
Copy link
Member

@akofink i agree, but i think we might should open a 2nd issue for that? This would be a better change for the near term and less risky to backport to older releases. Thoughts?

@akofink
Copy link
Member

akofink commented Jul 13, 2018

I'm good with that. I'll file an issue for it.

https://projects.theforeman.org/issues/24253

Copy link
Member

@akofink akofink left a comment

Choose a reason for hiding this comment

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

ACK from me! Thanks @dLobatog!

@jlsherrill
Copy link
Member

Thanks @dLobatog and @akofink !

@jlsherrill jlsherrill merged commit 81ecd36 into Katello:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants