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 #6952 - Set hostgroup after provisioning from pxe #4112

Closed
wants to merge 1 commit into from

Conversation

amirfefer
Copy link
Member

After hostgroup provisioning, when the machine has registered
with foreman, it should be in the same hostgroup.
to achieve this behavier, the referenced snippet should be added
to hostgroup provisioning template.

@mention-bot
Copy link

@amirfefer, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ares, @GregSutcliffe and @isratrade to be potential reviewers.

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.

It's nearly done. Just call set_hostgroup_defaults and please add something to theforeman.org documenting what this does, as foreman_hostgroup isn't provided by Ansible, Puppet etc...

Thanks @amirfefer

@@ -120,6 +120,7 @@ def import_facts(facts)

facts[:domain].try(:downcase!)

hostgroup_title = facts.delete(:foreman_hostgroup)
Copy link
Member

Choose a reason for hiding this comment

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

This fact isn't standard, from what I read on the issue description it's a custom fact. I think the functionality is neat, but please add docs to this after it's merged

@@ -209,6 +211,10 @@ def ==(comparison_object)
comparison_object.id == id
end

def set_hostgroup(title)
self.hostgroup = Hostgroup.find_by_title(title)
Copy link
Member

Choose a reason for hiding this comment

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

Call set_hostgroup_defaults after, so that the attributes from the host group are applied

facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}
assert_response :success
assert_equal hostgroup.root_pass, Host.find_by_name(hostname).root_pass

Choose a reason for hiding this comment

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

Use find_by instead of dynamic find_by_name.

hostname = fact_json['name']
facts = fact_json['facts']
facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}

Choose a reason for hiding this comment

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

Use keyword arguments instead of positional arguments for http call: post.

facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}
assert_response :success
assert_equal hostgroup, Host.find_by_name(hostname).hostgroup

Choose a reason for hiding this comment

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

Use find_by instead of dynamic find_by_name.

hostname = fact_json['name']
facts = fact_json['facts']
facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}

Choose a reason for hiding this comment

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

Use keyword arguments instead of positional arguments for http call: post.

@@ -209,6 +211,11 @@ def ==(comparison_object)
comparison_object.id == id
end

def set_hostgroup(title)
self.hostgroup = Hostgroup.find_by_title(title)

Choose a reason for hiding this comment

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

Use find_by instead of dynamic find_by_title.

After hostgroup provisioning, when the machine has registered
with foreman, it should be in the same hostgroup.
to achieve this behavier, the referenced snippet should be added
to hostgroup provisioning template
@amirfefer
Copy link
Member Author

Thanks for your review @dLobatog, I've added set_hostgroup_defaults call, and a related test.

@dLobatog
Copy link
Member

@amirfefer I'll fix the HoundCI qualms on merge, remember to write some docs for this on https://github.com/theforeman/theforeman.org/ please. Thanks!

@dLobatog
Copy link
Member

Merged as 9883149 , thanks @amirfefer !

@dLobatog dLobatog closed this Jan 11, 2017
@domcleal
Copy link
Contributor

9883149 looks significantly different to the reviewed commit 604a651, adding hostgroup to attributes_to_import_from_facts and removing the set_hostgroup method + calls. Why isn't it the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants