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 #35215 - Handle cloned hostgroups in hosts_and_hostgroups_helper #10894

Merged

Conversation

jeremylenz
Copy link
Member

@jeremylenz jeremylenz commented Feb 16, 2024

Requires theforeman/foreman#10055

What are the changes introduced in this pull request?

When cloning a hostgroup, all existing hostgroup attributes should be pre-filled on the new form. However, some fields were not being pre-populated, including

  • Content source
  • Lifecycle environment
  • Content view

There were two reasons for this.

First, I discovered that when a hostgroup is cloned, its content facet was not also being cloned. Because of this, only the "main" attributes were being copied over, and not the content facet attributes above. That should be addressed for all facets, not just content, so that fix is in theforeman/foreman#10055.

Second, host_and_hostgroups_helper has a few methods to fetch the existing values:

  • fetch_lifecycle_environment
  • fetch_content_view
  • fetch_content_source

These methods were returning nil for the newly-cloned hostgroup. I think this is because they relied on Rails associations which assume all the records are already saved in the database. The problem with cloned hostgroups is that the record is a new record, and is not yet saved in the database. For example, when calling host_or_hostgroup.lifecycle_environment (assuming host_or_hostgroup is a ::Hostgroup), Rails normally looks at its associations:

# app/models/katello/concerns/hostgroup_extensions.rb

has_one :lifecycle_environment, :through => :content_facet

Rails is probably trying to look up the content facet via its ID, so that it can then retrieve the lifecycle environment. But since the content facet is a new record and does not have an ID, it would not be able to do this. I got around this by calling host_or_hostgroup.content_facet.lifecycle_environment directly, which seems to work.

I also made similar changes for content view and content source.

Considerations taken when implementing this change?

What are the testing steps for this pull request?

Clone a hostgroup and verify that content source, lifecycle environment, and content view values are properly cloned
Save the cloned hostgroup and verify everything works as expected

@jeremylenz
Copy link
Member Author

[test katello]

@jeremylenz jeremylenz force-pushed the 35215-hostgroup-clone-handling-katello branch from 7ef5448 to c611daf Compare February 28, 2024 17:10
@jeremylenz
Copy link
Member Author

rebased

Copy link
Contributor

@parthaa parthaa left a comment

Choose a reason for hiding this comment

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

Works well!

@jeremylenz
Copy link
Member Author

In my testing this is still needed even after the changes to theforeman/foreman#10055.

@jeremylenz jeremylenz merged commit e3d46c6 into Katello:master Mar 10, 2024
14 of 16 checks passed
qcjames53 pushed a commit to qcjames53/katello that referenced this pull request Mar 19, 2024
qcjames53 added a commit that referenced this pull request Mar 19, 2024
* Refs #37148 - Remove removed_widgets override (#10927)

(cherry picked from commit 40a70ce)

* Fixes #35215 - Handle cloned hostgroups in hosts_and_hostgroups_helper (#10894)

(cherry picked from commit e3d46c6)

* Fixes #36979 - Remove cdn_ssl_version setting

This was originally added to allow downgrading the CDN connection
SSL version for compatibility with much older proxy servers. That
should be less of a concern now.

We do still set a value of TLS v1.2 for the min_version, but only
because ruby/openssl#709 prevents using
the system-wide crypto policy for now. In the future, that can be
removed as well, restoring control to the user at the OS level.

(cherry picked from commit 78fcba9)

* Fixes #37277 - Fix ACS randomly failing VCR tests (#10941)

(cherry picked from commit 6d93801)

* Fixes #37240 - Fix CCV duplicate repo warning (#10928)

(cherry picked from commit 02fc313)

---------

Co-authored-by: Jeremy Lenz <jlenz@redhat.com>
Co-authored-by: William Bradford Clark <wclark@redhat.com>
Co-authored-by: Ian Ballou <ianballou67@gmail.com>
Co-authored-by: Markus Bucher <bucher@atix.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants