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 #36440 - Redefine #attributes= to hijack old content facet attributes #10600

Merged
merged 2 commits into from
Jun 16, 2023

Conversation

jeremylenz
Copy link
Member

@jeremylenz jeremylenz commented Jun 12, 2023

What are the changes introduced in this pull request?

When updating a host using the Api::V2::HostController, Foreman doesn't call @host.update - instead, it does

@host.attributes = host_attributes(host_params, @host)
...
@host.save

The consequence of this is that the host's update method redefined in host_managed_extensions was never getting called. This is what removed the old deprecated content facet attributes content_view_id and lifecycle_environment_id, so as a consequence, those attributes were still present when Foreman called @host.attributes=. Turns out the #attributes= method checks and validates all the nested attributes, so when we try to include imaginary ones like content_view_id, it would throw an error:

Backtrace for 'Action failed' error (ActiveModel::UnknownAttributeError): unknown attribute 'content_view_id' for Katello::Host::ContentFacet.

With this change, the attributes= method of Host::Managed gets the same enhancement that update already had. This will hopefully prevent this problem until we can properly finish the multi-CV related work.

Considerations taken when implementing this change?

Just like #10595, this issue should go away completely when we update Hostgroup::ContentFacet to truly handle multiple content views.

What are the testing steps for this pull request?

Create a hostgroup and assign both CV and LCE
Assign a host to it
Update the host via hammer (this is important because hammer will use the API hosts controller, not the regular one) and include a hostgroup update:

hammer host update --id 5 --lifecycle-environment-id 1 --content-view-id 2 --hostgroup "My hostgroup"

Before: you should get the error above in the Rails log, and Hammer will complain:

Could not update the host:
  Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs.

After:

Host updated.

@theforeman-bot
Copy link

Issues: #36440

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

Working great. Maybe add a quick test that runs attributes= on a host?

@jeremylenz
Copy link
Member Author

@ianballou Updated 👍

@jeremylenz jeremylenz merged commit 0a20051 into Katello:master Jun 16, 2023
4 of 5 checks passed
lfu pushed a commit to lfu/katello that referenced this pull request Jun 21, 2023
…ibutes (Katello#10600)

* Fixes #36440 - Redefine #attributes= to hijack old content facet attributes

* Refs #36440 - add tests

(cherry picked from commit 0a20051)
lfu pushed a commit that referenced this pull request Jun 21, 2023
…ibutes (#10600)

* Fixes #36440 - Redefine #attributes= to hijack old content facet attributes

* Refs #36440 - add tests

(cherry picked from commit 0a20051)
wbclark pushed a commit to wbclark/katello that referenced this pull request Sep 7, 2023
…ibutes (Katello#10600)

* Fixes #36440 - Redefine #attributes= to hijack old content facet attributes

* Refs #36440 - add tests

(cherry picked from commit 0a20051)
wbclark pushed a commit that referenced this pull request Sep 27, 2023
…ibutes (#10600)

* Fixes #36440 - Redefine #attributes= to hijack old content facet attributes

* Refs #36440 - add tests

(cherry picked from commit 0a20051)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants