Skip to content

Commit dcac699

Browse files
committed
Implement self.prefetch for zabbix_hostgroup
This is another change for #570.
1 parent 580b484 commit dcac699

File tree

2 files changed

+45
-1
lines changed
  • lib/puppet/provider/zabbix_hostgroup
  • spec/unit/puppet/provider/zabbix_hostgroup

2 files changed

+45
-1
lines changed

lib/puppet/provider/zabbix_hostgroup/ruby.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
Puppet::Type.type(:zabbix_hostgroup).provide(:ruby, parent: Puppet::Provider::Zabbix) do
33
confine feature: :zabbixapi
44

5+
def self.instances
6+
api_hostgroups = zbx.hostgroups.all
7+
api_hostgroups.map do |group_name, _id|
8+
new(
9+
ensure: :present,
10+
name: group_name
11+
)
12+
end
13+
end
14+
15+
def self.prefetch(resources)
16+
instances.each do |prov|
17+
if (resource = resources[prov.name])
18+
resource.provider = prov
19+
end
20+
end
21+
end
22+
523
def create
624
# Connect to zabbix api
725
hgid = zbx.hostgroups.create(name: @resource[:name])
826
hgid
927
end
1028

1129
def exists?
12-
zbx.hostgroups.get_id(name: @resource[:name])
30+
@property_hash[:ensure] == :present
1331
end
1432

1533
def destroy
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
describe Puppet::Type.type(:zabbix_hostgroup).provider(:ruby) do
4+
let(:resource) do
5+
Puppet::Type.type(:zabbix_hostgroup).new(
6+
name: 'Testgroup'
7+
)
8+
end
9+
let(:provider) { resource.provider }
10+
11+
it 'be an instance of the correct provider' do
12+
expect(provider).to be_an_instance_of Puppet::Type::Zabbix_hostgroup::ProviderRuby
13+
end
14+
15+
[:instances, :prefetch].each do |method|
16+
it "should respond to the class method #{method}" do
17+
expect(described_class).to respond_to(method)
18+
end
19+
end
20+
21+
[:create, :exists?, :destroy].each do |method|
22+
it "should respond to the instance method #{method}" do
23+
expect(described_class.new).to respond_to(method)
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)