Skip to content

Commit b169b5c

Browse files
committed
Fix lack of idempotency in foreman_smartproxy_host provider
1 parent 4fd5a79 commit b169b5c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/puppet/provider/foreman_smartproxy_host/rest_v3.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def exists?
55
return false if host.nil? || proxy.nil?
66

7-
host['smart_proxy_id'] == proxy_id
7+
host.fetch('infrastructure_facet', {})['smart_proxy_id'] == proxy_id
88
end
99

1010
def create

spec/unit/foreman_smartproxy_host_rest_v3_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@
5252
describe '#exists?' do
5353
it 'returns true when host is marked as current proxy' do
5454
expect(provider).to receive(:proxy).thrice.and_return({"id" => 1})
55-
expect(provider).to receive(:host).twice.and_return({"smart_proxy_id" => 1})
55+
expect(provider).to receive(:host).twice.and_return({"infrastructure_facet" => {"smart_proxy_id" => 1}})
5656
expect(provider.exists?).to be true
5757
end
5858

5959
it 'returns false when host is marked as a different smart proxy' do
6060
expect(provider).to receive(:proxy).thrice.and_return({"id" => 1})
61-
expect(provider).to receive(:host).twice.and_return({"smart_proxy_id" => 2})
61+
expect(provider).to receive(:host).twice.and_return({"infrastructure_facet" => {"smart_proxy_id" => 2}})
6262
expect(provider.exists?).to be false
6363
end
6464

6565
it 'returns false when host is not marked as a smart proxy' do
6666
expect(provider).to receive(:proxy).thrice.and_return({"id" => 1})
67-
expect(provider).to receive(:host).twice.and_return({"smart_proxy_id" => nil})
67+
expect(provider).to receive(:host).twice.and_return({"infrastructure_facet" => {"smart_proxy_id" => nil}})
6868
expect(provider.exists?).to be false
6969
end
7070

@@ -74,7 +74,7 @@
7474
end
7575

7676
it 'returns false when smart proxy does not exist' do
77-
expect(provider).to receive(:host).and_return({"smart_proxy_id" => 1})
77+
expect(provider).to receive(:host).and_return({"infrastructure_facet" => {"smart_proxy_id" => 1}})
7878
expect(provider).to receive(:proxy).and_return(nil)
7979
expect(provider.exists?).to be false
8080
end

0 commit comments

Comments
 (0)