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 #16063 - content facet builds when not present #6401

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

lzap
Copy link
Contributor

@lzap lzap commented Oct 18, 2016

Katello as well as the facet framework assumes that the only entrypoint for
host objects are our UI and API controllers (host#create). Facet framework
hooks into there and it just works.

Except there is more. Discovered hosts can be provisioned either via edit host
form (which works with facets) but also via autoprovisioning which is an
alternative path which is missed by Facet framework.

Until Shim comes up with a nicer solution, I propose this "dirty" patch that
explicitly builds the facet object when it's not present. This fixes the issue
in Foreman 1.13, 1.12 and Satellite 6.2 and 6.3. The symptoms are that all
auto-provisioned hosts are completely missing all content flags (source, view,
environment, kickstart repo) and fails provisioning.

I also created and tested downstream version against Satellite 6.2 because
there is opened ticket for 6.2 errata (there were several changes in the
codebase already), so the patch looks like this:

      def set_hostgroup_defaults_with_katello_attributes
        if hostgroup.present?
          if content_facet.present?
            self.content_facet.kickstart_repository_id ||= hostgroup.inherited_kickstart_repository_id
          else
            if hostgroup.inherited_content_view_id && hostgroup.inherited_lifecycle_environment_id
              build_content_facet(
                :kickstart_repository_id => hostgroup.inherited_kickstart_repository_id,
                :content_source_id => hostgroup.inherited_content_source_id,
                :content_view_id => hostgroup.inherited_content_view_id,
                :lifecycle_environment_id => hostgroup.inherited_lifecycle_environment_id)
            end
          end
          assign_hostgroup_attributes(%w(content_source_id content_view_id lifecycle_environment_id environment_id))
        end
        set_hostgroup_defaults_without_katello_attributes
      end

References:

Original issue I need to fix in Foreman and Satellite:

http://projects.theforeman.org/issues/16063

Planned change in Facet framework:

http://projects.theforeman.org/issues/16987

BZ for 6.2:

https://bugzilla.redhat.com/show_bug.cgi?id=1364544

@mention-bot
Copy link

@lzap, thanks for your PR! By analyzing the history of the files in this pull request, we identified @xprazak2, @jlsherrill and @bbuckingham to be potential reviewers.

@lzap
Copy link
Contributor Author

lzap commented Oct 18, 2016

Fixed hound comment. Also CCing @ehelms as I am providing backported version already (it's tested on 6.2.2). Reproducer:

Create a rule "always" with "cpu_count > 1" and associate with any hostgroup that has some Content (View, Environment, Source, Repo) associated. Discover a fake host (*) and AUTO provision it. Check the host if it has all the content flags set. Without the patch, all the fields are empty, thus provisioning would fail.

(*) https://github.com/lzap/bin-public/blob/master/discover-host - script that creates "fake" discovery hosts

@@ -75,7 +75,18 @@ def content_and_puppet_match?
end

def inherited_attributes_with_katello
self.content_facet.kickstart_repository_id ||= hostgroup.inherited_kickstart_repository_id if content_facet.present?
if hostgroup.present?
if content_facet.present?
Copy link
Member

@jlsherrill jlsherrill Oct 18, 2016

Choose a reason for hiding this comment

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

We should probably check to see if the hostgroup has a content_view and lifecycle_env first. Content facets aren't valid if both of those are not present.

Err, this should really have been tagged at the build_content_facet part below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, plus as per IRC discussion, I should use "inherited_" flags everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@theforeman-bot
Copy link

@lzap, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:

  • Move ticket #16063 to the Discovery project
  • File a new ticket in the Discovery project, update the PR title and the commit message (using git commit --amend).

This message was auto-generated by Foreman's prprocessor

@theforeman-bot
Copy link

@lzap, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:

  • Move ticket #16063 to the Discovery project
  • File a new ticket in the Discovery project, update the PR title and the commit message (using git commit --amend).

This message was auto-generated by Foreman's prprocessor

@lzap
Copy link
Contributor Author

lzap commented Oct 18, 2016

Amended the change, also updated the backport code bit in the description.

Please test the version against develop Katello before merging, I was testing with older version.

Moved the Issue to Katello project. Thanks.

@lzap
Copy link
Contributor Author

lzap commented Oct 21, 2016

Ping - see my instructions above how to test this. It's not complex, don't worry :-)

@jlsherrill jlsherrill self-assigned this Oct 26, 2016
if hostgroup.inherited_content_view_id && hostgroup.inherited_lifecycle_environment_id
build_content_facet(
:kickstart_repository_id => hostgroup.inherited_kickstart_repository_id,
:content_source_id => hostgroup.inherited_content_source_id,
Copy link
Member

Choose a reason for hiding this comment

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

getting an error because of this line:

unknown attribute 'content_source_id' for Katello::Host::ContentFacet.

content_source_id is actually on the host object.

Copy link
Member

Choose a reason for hiding this comment

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

Deleting this line, and removing 'content_view_id' and 'lifecycle_environment_id' from the line below:

inherited_attributes_without_katello.concat(%w(content_source_id content_view_id lifecycle_environment_id))

Seems to make it all work.

Copy link
Member

Choose a reason for hiding this comment

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

I'll work on reviewing it quickly after a turnaround :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many thanks, let me fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, did you mean this?

diff --git a/app/models/katello/concerns/host_managed_extensions.rb b/app/models/katello/concerns/host_managed_extensions.rb
index 23fc0f1..202ed53 100644
--- a/app/models/katello/concerns/host_managed_extensions.rb
+++ b/app/models/katello/concerns/host_managed_extensions.rb
@@ -83,13 +83,12 @@ module Katello
             if hostgroup.inherited_content_view_id && hostgroup.inherited_lifecycle_environment_id
               build_content_facet(
                 :kickstart_repository_id => hostgroup.inherited_kickstart_repository_id,
-                :content_source_id => hostgroup.inherited_content_source_id,
                 :content_view_id => hostgroup.inherited_content_view_id,
                 :lifecycle_environment_id => hostgroup.inherited_lifecycle_environment_id)
             end
           end
         end
-        inherited_attributes_without_katello.concat(%w(content_source_id content_view_id lifecycle_environment_id))
+        inherited_attributes_without_katello.concat(%w(content_source_id))
       end

       def import_package_profile(simple_packages)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed! Thanks for help with this one.

Copy link
Member

Choose a reason for hiding this comment

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

Yep exactly, thanks! will re-test

@jlsherrill
Copy link
Member

APJ

@lzap
Copy link
Contributor Author

lzap commented Oct 26, 2016

Sorry, what's that?

@jlsherrill
Copy link
Member

ACK Pending Jenkins :)

@jlsherrill
Copy link
Member

[test]

@jlsherrill
Copy link
Member

thanks @lzap! merging 🍖

@jlsherrill jlsherrill merged commit 0d1d7c1 into Katello:master Nov 1, 2016
@lzap
Copy link
Contributor Author

lzap commented Nov 1, 2016

Thank you so much @jlsherrill !

Is there any chance of getting this into latest stable Katello? Because provisioning is basically blocked for upstream stable users.

@lzap lzap deleted the explicit-facet-build-16063 branch November 1, 2016 13:24
@jlsherrill
Copy link
Member

@lzap yep it'll be cherrypicked for 3.2 GA

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.

4 participants