Skip to content

Commit

Permalink
Fixes #16197 - Host#smart_proxies returns only the host proxies
Browse files Browse the repository at this point in the history
Doing the following:
- Create 2 smart proxies, one for dhcp/dns/tft/puppetca/puppet, another
for realms. Let's keep the realms proxy off, so it's unreachable.
- Create a hostgroup A that sets domain, subnet, realm, puppet_proxy,
puppet_ca_proxy
- Create a host that uses hostgroup A, but uncheck 'inherit' and
remove the 'realm' attribute. The host is created just fine with no
realm
- When I try to rebuild the host, `HostBuildStatus#check_all_statuses`
is called. This checks the host_status (OK), templates_status(OK), and
smart_proxies_status(FAIL). The host cannot be rebuilt.

The reason `smart_proxies_status` fails is that `smart_proxy_ids`
tries to find whether Realm is set.
- If it's set, it adds the proxy to 'Host#smart_proxies`
- If it's not set, it looks in the hostgroup to see if it's set there.
However, I have overridden the option, because I don't want to set a
Realm since I don't want to boot the Realm proxy I have.

Host#smart_proxies should not look in the host.hostgroup object to
retrieve values for the proxy, but instead retrieve those from itself
  • Loading branch information
dLobatog authored and tbrisker committed Aug 23, 2016
1 parent 8563088 commit 15f2f29
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
22 changes: 22 additions & 0 deletions app/models/concerns/hostext/smart_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Hostext
module SmartProxy
extend ActiveSupport::Concern

def smart_proxies
::SmartProxy.where(:id => smart_proxy_ids)
end

def smart_proxy_ids
ids = []
[subnet, subnet6].compact.each do |s|
ids << s.dhcp_id
ids << s.tftp_id
ids << s.dns_id
end
ids << domain.dns_id if domain.present?
ids << realm.realm_proxy_id if realm.present?
ids += [puppet_proxy_id, puppet_ca_proxy_id]
ids.uniq.compact
end
end
end
27 changes: 1 addition & 26 deletions app/models/host/managed.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Host::Managed < Host::Base
include Hostext::PowerInterface
include Hostext::Search
include Hostext::SmartProxy
include Hostext::Token
include SelectiveClone
include HostParams
Expand Down Expand Up @@ -741,32 +742,6 @@ def vm_compute_attributes
compute_resource ? compute_resource.vm_compute_attributes_for(uuid) : nil
end

def smart_proxies
SmartProxy.where(:id => smart_proxy_ids)
end

def smart_proxy_ids
ids = []
[subnet, hostgroup.try(:subnet), subnet6, hostgroup.try(:subnet6)].compact.each do |s|
ids << s.dhcp_id
ids << s.tftp_id
ids << s.dns_id
end

[domain, hostgroup.try(:domain)].compact.each do |d|
ids << d.dns_id
end

[realm, hostgroup.try(:realm)].compact.each do |r|
ids << r.realm_proxy_id
end

[puppet_proxy_id, puppet_ca_proxy_id, hostgroup.try(:puppet_proxy_id), hostgroup.try(:puppet_ca_proxy_id)].compact.each do |p|
ids << p
end
ids.uniq.compact
end

def bmc_proxy
@bmc_proxy ||= bmc_nic.proxy
end
Expand Down
40 changes: 40 additions & 0 deletions test/unit/host_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3225,6 +3225,46 @@ def to_managed!
end
end

describe '#smart_proxy_ids' do
test 'returns IDs for proxies associated with host services' do
# IDs are fake, just to prove host.smart_proxy_ids gathers them
host = FactoryGirl.build(:host, :with_subnet, :with_realm,
:puppet_proxy_id => 1,
:puppet_ca_proxy_id => 1)
host.realm = FactoryGirl.build(:realm, :realm_proxy_id => 1)
host.subnet.tftp_id = 2
host.subnet.dhcp_id = 3
host.subnet.dns_id = 4
assert host.smart_proxy_ids, [1,2,3,4]
end

context 'from hostgroup' do
setup do
@hostgroup = FactoryGirl.create(:hostgroup, :with_puppet_orchestration)
@host = FactoryGirl.build(:host)
@host.hostgroup = @hostgroup
@host.send(:assign_hostgroup_attributes,
[:puppet_ca_proxy_id, :puppet_proxy_id])
end

test 'returns IDs for proxies used by services inherited from hostgroup' do
@host.realm = FactoryGirl.build(:realm, :realm_proxy_id => 1)
assert_equal [@hostgroup.puppet_ca_proxy_id,
@hostgroup.puppet_proxy_id,
@host.realm.realm_proxy_id].sort,
@host.smart_proxy_ids.sort
end

test 'does not return IDs for services not inherited from the hostgroup' do
@host.realm = FactoryGirl.build(:realm, :realm_proxy_id => 1)
@host.puppet_proxy_id = nil
assert_equal [@hostgroup.puppet_ca_proxy_id,
@host.realm.realm_proxy_id].sort,
@host.smart_proxy_ids.sort
end
end
end

private

def parse_json_fixture(relative_path)
Expand Down

0 comments on commit 15f2f29

Please sign in to comment.