puppetdb_foreman 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -13
  3. data/Rakefile +9 -6
  4. data/app/controllers/api/v2/puppetdb_nodes_controller.rb +8 -6
  5. data/app/controllers/puppetdb_foreman/nodes_controller.rb +22 -8
  6. data/app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb +5 -3
  7. data/app/models/concerns/orchestration/puppetdb.rb +13 -6
  8. data/app/models/puppetdb_foreman/host_extensions.rb +5 -4
  9. data/app/services/puppetdb.rb +8 -12
  10. data/app/services/puppetdb_client/base.rb +8 -6
  11. data/app/services/puppetdb_client/v4.rb +48 -1
  12. data/app/services/puppetdb_host.rb +4 -2
  13. data/app/views/api/v2/puppetdb_nodes/import.json.rabl +2 -0
  14. data/app/views/api/v2/puppetdb_nodes/index.json.rabl +2 -0
  15. data/app/views/api/v2/puppetdb_nodes/unknown.json.rabl +2 -0
  16. data/config/routes.rb +11 -9
  17. data/db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb +4 -2
  18. data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb +3 -1
  19. data/lib/puppetdb_foreman/engine.rb +55 -27
  20. data/lib/puppetdb_foreman/version.rb +3 -1
  21. data/lib/puppetdb_foreman.rb +2 -0
  22. data/lib/tasks/puppetdb_foreman_tasks.rake +4 -4
  23. data/test/controllers/api/v2/puppetdb_nodes_controller_test.rb +60 -55
  24. data/test/controllers/nodes_controller_test.rb +7 -6
  25. data/test/models/host_test.rb +5 -4
  26. data/test/test_plugin_helper.rb +2 -4
  27. data/test/unit/puppetdb_host_test.rb +5 -4
  28. data/test/unit/puppetdb_test.rb +18 -135
  29. metadata +17 -23
  30. data/app/models/setting/puppetdb.rb +0 -49
  31. data/app/services/puppetdb_client/v1.rb +0 -33
  32. data/app/services/puppetdb_client/v3.rb +0 -49
  33. data/test/static_fixtures/query_nodes.json +0 -61
@@ -1,68 +1,73 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
- class Api::V2::PuppetdbNodesControllerTest < ActionController::TestCase
4
- setup do
5
- setup_settings
6
- User.current = users(:admin)
7
- @host = FactoryBot.create(:host, :managed)
8
- end
5
+ module Api
6
+ module V2
7
+ class PuppetdbNodesControllerTest < ActionController::TestCase
8
+ setup do
9
+ User.current = users(:admin)
10
+ @host = FactoryBot.create(:host, :managed)
11
+ end
9
12
 
10
- context '#index' do
11
- test 'lists puppetdb nodes unknown to foreman' do
12
- ::PuppetdbClient::V4.any_instance.stubs(:query_nodes).returns(['one.example.com', 'two.example.com'])
13
- get :index, session: set_session_user
14
- assert_response :success
15
- response = ActiveSupport::JSON.decode(@response.body)
16
- hosts = response['results']
17
- assert_includes hosts, 'name' => 'one.example.com'
18
- assert_includes hosts, 'name' => 'two.example.com'
19
- end
20
- end
13
+ context '#index' do
14
+ test 'lists puppetdb nodes unknown to foreman' do
15
+ ::PuppetdbClient::V4.any_instance.stubs(:query_nodes).returns(['one.example.com', 'two.example.com'])
16
+ get :index, session: set_session_user
17
+ assert_response :success
18
+ response = ActiveSupport::JSON.decode(@response.body)
19
+ hosts = response['results']
20
+ assert_includes hosts, 'name' => 'one.example.com'
21
+ assert_includes hosts, 'name' => 'two.example.com'
22
+ end
23
+ end
21
24
 
22
- context '#unknown' do
23
- test 'lists puppetdb nodes unknown to foreman' do
24
- host = FactoryBot.create(:host, :managed)
25
- ::PuppetdbClient::V4.any_instance.stubs(:query_nodes).returns([host.name, 'two.example.com'])
26
- get :unknown, session: set_session_user
27
- assert_response :success
28
- response = ActiveSupport::JSON.decode(@response.body)
29
- hosts = response['results']
30
- refute_includes hosts, 'name' => host.name
31
- assert_includes hosts, 'name' => 'two.example.com'
32
- end
33
- end
25
+ context '#unknown' do
26
+ test 'lists puppetdb nodes unknown to foreman' do
27
+ host = FactoryBot.create(:host, :managed)
28
+ ::PuppetdbClient::V4.any_instance.stubs(:query_nodes).returns([host.name, 'two.example.com'])
29
+ get :unknown, session: set_session_user
30
+ assert_response :success
31
+ response = ActiveSupport::JSON.decode(@response.body)
32
+ hosts = response['results']
33
+ assert_not_includes hosts, 'name' => host.name
34
+ assert_includes hosts, 'name' => 'two.example.com'
35
+ end
36
+ end
34
37
 
35
- context '#destroy' do
36
- let(:node) { 'test.example.com' }
37
- let(:uuid) { SecureRandom.uuid }
38
+ context '#destroy' do
39
+ let(:node) { 'test.example.com' }
40
+ let(:uuid) { SecureRandom.uuid }
38
41
 
39
- before do
40
- ::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(node).returns(uuid)
41
- end
42
+ before do
43
+ ::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(node).returns(uuid)
44
+ end
42
45
 
43
- test 'imports a host by puppetdb facts' do
44
- delete :destroy, params: { :id => node }, session: set_session_user
45
- assert_response :success
46
- response = ActiveSupport::JSON.decode(@response.body)
47
- expected = { 'job' => { 'uuid' => uuid } }
48
- assert_equal expected, response
49
- end
50
- end
46
+ test 'imports a host by puppetdb facts' do
47
+ delete :destroy, params: { id: node }, session: set_session_user
48
+ assert_response :success
49
+ response = ActiveSupport::JSON.decode(@response.body)
50
+ expected = { 'job' => { 'uuid' => uuid } }
51
+ assert_equal expected, response
52
+ end
53
+ end
51
54
 
52
- context '#import' do
53
- let(:node) { 'test.example.com' }
54
- let(:host) { FactoryBot.create(:host) }
55
+ context '#import' do
56
+ let(:node) { 'test.example.com' }
57
+ let(:host) { FactoryBot.create(:host) }
55
58
 
56
- before do
57
- ::PuppetdbClient::V4.any_instance.expects(:facts).with(node).returns({})
58
- PuppetdbHost.any_instance.expects(:to_host).returns(host)
59
- end
59
+ before do
60
+ ::PuppetdbClient::V4.any_instance.expects(:facts).with(node).returns({})
61
+ PuppetdbHost.any_instance.expects(:to_host).returns(host)
62
+ end
60
63
 
61
- test 'imports a host by puppetdb facts' do
62
- put :import, params: { :id => node }, session: set_session_user
63
- assert_response :success
64
- response = ActiveSupport::JSON.decode(@response.body)
65
- assert_equal host.id, response['id']
64
+ test 'imports a host by puppetdb facts' do
65
+ put :import, params: { id: node }, session: set_session_user
66
+ assert_response :success
67
+ response = ActiveSupport::JSON.decode(@response.body)
68
+ assert_equal host.id, response['id']
69
+ end
70
+ end
66
71
  end
67
72
  end
68
73
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class NodesControllerTest < ActionController::TestCase
4
6
  tests ::PuppetdbForeman::NodesController
5
7
 
6
8
  setup do
7
- setup_settings
8
9
  User.current = users(:admin)
9
10
  @host = FactoryBot.create(:host, :managed)
10
11
  end
@@ -15,7 +16,7 @@ class NodesControllerTest < ActionController::TestCase
15
16
  ::PuppetdbClient::V4.any_instance.stubs(:query_nodes).returns([host.name, 'two.example.com'])
16
17
  get :index, session: set_session_user
17
18
  assert_response :success
18
- refute response.body =~ /#{host.name}/m
19
+ assert_not response.body =~ /#{host.name}/m
19
20
  assert response.body =~ /two.example.com/m
20
21
  end
21
22
  end
@@ -27,7 +28,7 @@ class NodesControllerTest < ActionController::TestCase
27
28
  resources_resp = [
28
29
  { 'type' => 'Class', 'title' => 'main' },
29
30
  { 'type' => 'Class', 'title' => 'Settings' },
30
- { 'type' => 'Stage', 'title' => 'main' }
31
+ { 'type' => 'Stage', 'title' => 'main' },
31
32
  ]
32
33
 
33
34
  ::PuppetdbClient::V4.any_instance.stubs(:resources).returns(resources_resp)
@@ -48,7 +49,7 @@ class NodesControllerTest < ActionController::TestCase
48
49
  let(:node) { 'test.example.com' }
49
50
  test 'deactivating a node in puppetdb' do
50
51
  ::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(node).returns(true)
51
- delete :destroy, params: { :id => node }, session: set_session_user
52
+ delete :destroy, params: { id: node }, session: set_session_user
52
53
  assert_response :found
53
54
  assert_redirected_to puppetdb_foreman_nodes_path
54
55
  assert_nil flash[:error]
@@ -67,9 +68,9 @@ class NodesControllerTest < ActionController::TestCase
67
68
  end
68
69
 
69
70
  test 'imports a host from puppetdb facts' do
70
- put :import, params: { :id => node }, session: set_session_user
71
+ put :import, params: { id: node }, session: set_session_user
71
72
  assert_response :found
72
- assert_redirected_to host_path(:id => host)
73
+ assert_redirected_to host_path(id: host)
73
74
  assert_nil flash[:error]
74
75
  assert_not_nil flash[:notice] || flash[:success]
75
76
  assert_equal "Imported host #{node} from PuppetDB", flash[:notice] || flash[:success]
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class HostTest < ActiveSupport::TestCase
4
6
  setup do
5
7
  User.current = FactoryBot.build(:user, :admin)
6
- setup_settings
7
8
  disable_orchestration
8
9
  end
9
10
 
@@ -24,9 +25,9 @@ class HostTest < ActiveSupport::TestCase
24
25
  assert_equal 1, tasks.size
25
26
  end
26
27
 
27
- test '#delPuppetdb' do
28
+ test '#del_puppetdb' do
28
29
  ::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(host.name).returns(true)
29
- host.send(:delPuppetdb)
30
+ host.send(:del_puppetdb)
30
31
  end
31
32
  end
32
33
 
@@ -40,7 +41,7 @@ class HostTest < ActiveSupport::TestCase
40
41
  host.queue.clear
41
42
  host.send(:queue_puppetdb_destroy)
42
43
  tasks = host.queue.all.map(&:name)
43
- assert_equal [], tasks
44
+ assert_empty tasks
44
45
  end
45
46
  end
46
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
  require 'test_helper'
3
5
  require 'database_cleaner'
@@ -6,10 +8,6 @@ require 'webmock/minitest'
6
8
  # Foreman's setup doesn't handle cleaning up for Minitest::Spec
7
9
  DatabaseCleaner.strategy = :transaction
8
10
 
9
- def setup_settings
10
- Setting::Puppetdb.load_defaults
11
- end
12
-
13
11
  def fixture(name)
14
12
  File.read(File.expand_path("../static_fixtures/#{name}", __FILE__))
15
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class PuppetdbHostTest < ActiveSupport::TestCase
@@ -7,7 +9,6 @@ class PuppetdbHostTest < ActiveSupport::TestCase
7
9
  setup do
8
10
  User.current = FactoryBot.create(:user, :admin)
9
11
  disable_orchestration
10
- setup_settings
11
12
  end
12
13
 
13
14
  let(:sample_facts) do
@@ -15,7 +16,7 @@ class PuppetdbHostTest < ActiveSupport::TestCase
15
16
  end
16
17
 
17
18
  let(:pdbhost) do
18
- PuppetdbHost.new(:facts => sample_facts)
19
+ PuppetdbHost.new(facts: sample_facts)
19
20
  end
20
21
 
21
22
  test 'parses facts' do
@@ -35,12 +36,12 @@ class PuppetdbHostTest < ActiveSupport::TestCase
35
36
 
36
37
  test 'updates an existing host by facts' do
37
38
  Setting[:update_subnets_from_facts] = true
38
- FactoryBot.create(:host, :managed, :hostname => 'host', :domain => FactoryBot.create(:domain, :name => 'example.com'))
39
+ FactoryBot.create(:host, :managed, hostname: 'host', domain: FactoryBot.create(:domain, name: 'example.com'))
39
40
  pdbhost.to_host
40
41
  host = Host.find_by(name: 'host.example.com')
41
42
  assert_equal 'host.example.com', host.name
42
43
  # foreman core does not delete old interfaces when importing interfaces from facts
43
- assert host.interfaces.where(:ip => '1.1.1.174').first
44
+ assert host.interfaces.where(ip: '1.1.1.174').first
44
45
  assert_equal Operatingsystem.find_by(title: 'RedHat 7.3'), host.operatingsystem
45
46
  end
46
47
  end
@@ -1,138 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class PuppetdbTest < ActiveSupport::TestCase
4
6
  setup do
5
7
  User.current = FactoryBot.build(:user, :admin)
6
- setup_settings
7
8
  disable_orchestration
8
9
  end
9
10
 
10
11
  let(:client) { Puppetdb.client }
11
12
  let(:uuid) { SecureRandom.uuid }
12
13
 
13
- context 'with V1 API' do
14
- setup do
15
- Setting[:puppetdb_api_version] = 1
16
- Setting[:puppetdb_address] = 'https://localhost:8080/v3/commands'
17
- end
18
-
19
- test 'deactivate_node' do
20
- stub_request(:post, 'https://localhost:8080/v3/commands')
21
- .with(:body => 'payload={"command":"deactivate node","version":1,"payload":"\\"www.example.com\\""}',
22
- :headers => { 'Accept' => 'application/json' })
23
- .to_return(:status => 200, :body => "{\"uuid\" : \"#{uuid}\"}", :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
24
-
25
- assert_equal uuid, client.deactivate_node('www.example.com')
26
- end
27
-
28
- test 'query_nodes' do
29
- stub_request(:get, 'https://localhost:8080/v3/nodes')
30
- .with(:headers => { 'Accept' => 'application/json' })
31
- .to_return(:status => 200, :body => fixture('query_nodes.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
32
- expected = (1..10).map { |i| "server#{i}.example.com" }
33
- assert_equal expected, client.query_nodes
34
- end
35
-
36
- test 'resources' do
37
- stub_request(:get, 'https://localhost:8080/v3/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
38
- .with(:headers => { 'Accept' => 'application/json' })
39
- .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
40
-
41
- resources = client.resources('host.example.com')
42
- sample = {
43
- 'tags' => %w[params class],
44
- 'file' => nil,
45
- 'type' => 'Class',
46
- 'title' => 'Cron',
47
- 'line' => nil,
48
- 'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
49
- 'certname' => 'host.example.com',
50
- 'parameters' => {},
51
- 'exported' => false
52
- }
53
-
54
- assert_kind_of Array, resources
55
- assert_includes resources, sample
56
- end
57
-
58
- test 'facts' do
59
- stub_request(:get, 'https://localhost:8080/v3/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
60
- .with(:headers => { 'Accept' => 'application/json' })
61
- .to_return(:status => 200, :body => fixture('facts.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
62
- facts = client.facts('host.example.com')
63
- assert_kind_of Array, facts
64
- sample = {
65
- 'value' => 'CEST',
66
- 'name' => 'timezone',
67
- 'certname' => 'host.example.com'
68
- }
69
- assert_includes facts, sample
70
- end
71
- end
72
-
73
- context 'with V3 API' do
74
- setup do
75
- Setting[:puppetdb_api_version] = 3
76
- end
77
-
78
- let(:producer_timestamp) { Time.now.iso8601.to_s }
79
-
80
- test 'deactivate_node' do
81
- client.stubs(:producer_timestamp).returns(producer_timestamp)
82
-
83
- stub_request(:post, 'https://puppetdb:8081/pdb/cmd/v1')
84
- .with(:body => "{\"command\":\"deactivate node\",\"version\":3,\"payload\":{\"certname\":\"www.example.com\",\"producer_timestamp\":\"#{producer_timestamp}\"}}",
85
- :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/json' })
86
- .to_return(:status => 200, :body => "{\"uuid\" : \"#{uuid}\"}", :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
87
-
88
- assert_equal uuid, client.deactivate_node('www.example.com')
89
- end
90
-
91
- test 'query_nodes' do
92
- stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/nodes')
93
- .with(:headers => { 'Accept' => 'application/json' })
94
- .to_return(:status => 200, :body => fixture('query_nodes_v3_4.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
95
- expected = (1..10).map { |i| "server#{i}.example.com" }
96
- assert_equal expected, client.query_nodes
97
- end
98
-
99
- test 'resources' do
100
- stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
101
- .with(:headers => { 'Accept' => 'application/json' })
102
- .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
103
-
104
- resources = client.resources('host.example.com')
105
- sample = {
106
- 'tags' => %w[params class],
107
- 'file' => nil,
108
- 'type' => 'Class',
109
- 'title' => 'Cron',
110
- 'line' => nil,
111
- 'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
112
- 'certname' => 'host.example.com',
113
- 'parameters' => {},
114
- 'exported' => false
115
- }
116
-
117
- assert_kind_of Array, resources
118
- assert_includes resources, sample
119
- end
120
-
121
- test 'facts' do
122
- stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
123
- .with(:headers => { 'Accept' => 'application/json' })
124
- .to_return(:status => 200, :body => fixture('facts.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
125
- facts = client.facts('host.example.com')
126
- assert_kind_of Array, facts
127
- sample = {
128
- 'value' => 'CEST',
129
- 'name' => 'timezone',
130
- 'certname' => 'host.example.com'
131
- }
132
- assert_includes facts, sample
133
- end
134
- end
135
-
136
14
  context 'with V4 API' do
137
15
  setup do
138
16
  Setting[:puppetdb_api_version] = 4
@@ -144,25 +22,30 @@ class PuppetdbTest < ActiveSupport::TestCase
144
22
  client.stubs(:producer_timestamp).returns(producer_timestamp)
145
23
 
146
24
  stub_request(:post, 'https://puppetdb:8081/pdb/cmd/v1')
147
- .with(:body => "{\"command\":\"deactivate node\",\"version\":3,\"payload\":{\"certname\":\"www.example.com\",\"producer_timestamp\":\"#{producer_timestamp}\"}}",
148
- :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/json' })
149
- .to_return(:status => 200, :body => "{\"uuid\" : \"#{uuid}\"}", :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
25
+ .with(
26
+ body: "{\"command\":\"deactivate node\",\"version\":3,\"payload\":{\"certname\":\"www.example.com\",\"producer_timestamp\":\"#{producer_timestamp}\"}}",
27
+ headers: {
28
+ 'Accept' => 'application/json',
29
+ 'Content-Type' => 'application/json',
30
+ }
31
+ )
32
+ .to_return(status: 200, body: "{\"uuid\" : \"#{uuid}\"}", headers: { 'Content-Type' => 'application/json; charset=utf-8' })
150
33
 
151
34
  assert_equal uuid, client.deactivate_node('www.example.com')
152
35
  end
153
36
 
154
37
  test 'query_nodes' do
155
38
  stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/nodes')
156
- .with(:headers => { 'Accept' => 'application/json' })
157
- .to_return(:status => 200, :body => fixture('query_nodes_v3_4.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
39
+ .with(headers: { 'Accept' => 'application/json' })
40
+ .to_return(status: 200, body: fixture('query_nodes_v3_4.json'), headers: { 'Content-Type' => 'application/json; charset=utf-8' })
158
41
  expected = (1..10).map { |i| "server#{i}.example.com" }
159
42
  assert_equal expected, client.query_nodes
160
43
  end
161
44
 
162
45
  test 'resources' do
163
46
  stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/resources?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
164
- .with(:headers => { 'Accept' => 'application/json' })
165
- .to_return(:status => 200, :body => fixture('resources.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
47
+ .with(headers: { 'Accept' => 'application/json' })
48
+ .to_return(status: 200, body: fixture('resources.json'), headers: { 'Content-Type' => 'application/json; charset=utf-8' })
166
49
 
167
50
  resources = client.resources('host.example.com')
168
51
  sample = {
@@ -174,7 +57,7 @@ class PuppetdbTest < ActiveSupport::TestCase
174
57
  'resource' => 'f13ec266-2914-420c-8d71-13e3466c5856',
175
58
  'certname' => 'host.example.com',
176
59
  'parameters' => {},
177
- 'exported' => false
60
+ 'exported' => false,
178
61
  }
179
62
 
180
63
  assert_kind_of Array, resources
@@ -183,14 +66,14 @@ class PuppetdbTest < ActiveSupport::TestCase
183
66
 
184
67
  test 'facts' do
185
68
  stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
186
- .with(:headers => { 'Accept' => 'application/json' })
187
- .to_return(:status => 200, :body => fixture('facts.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
69
+ .with(headers: { 'Accept' => 'application/json' })
70
+ .to_return(status: 200, body: fixture('facts.json'), headers: { 'Content-Type' => 'application/json; charset=utf-8' })
188
71
  facts = client.facts('host.example.com')
189
72
  assert_kind_of Array, facts
190
73
  sample = {
191
74
  'value' => 'CEST',
192
75
  'name' => 'timezone',
193
- 'certname' => 'host.example.com'
76
+ 'certname' => 'host.example.com',
194
77
  }
195
78
  assert_includes facts, sample
196
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rubocop
42
+ name: theforeman-rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.54.0
47
+ version: 0.1.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.54.0
54
+ version: 0.1.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -83,11 +83,8 @@ files:
83
83
  - app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb
84
84
  - app/models/concerns/orchestration/puppetdb.rb
85
85
  - app/models/puppetdb_foreman/host_extensions.rb
86
- - app/models/setting/puppetdb.rb
87
86
  - app/services/puppetdb.rb
88
87
  - app/services/puppetdb_client/base.rb
89
- - app/services/puppetdb_client/v1.rb
90
- - app/services/puppetdb_client/v3.rb
91
88
  - app/services/puppetdb_client/v4.rb
92
89
  - app/services/puppetdb_host.rb
93
90
  - app/views/api/v2/puppetdb_nodes/import.json.rabl
@@ -106,7 +103,6 @@ files:
106
103
  - test/controllers/nodes_controller_test.rb
107
104
  - test/models/host_test.rb
108
105
  - test/static_fixtures/facts.json
109
- - test/static_fixtures/query_nodes.json
110
106
  - test/static_fixtures/query_nodes_v3_4.json
111
107
  - test/static_fixtures/resources.json
112
108
  - test/test_plugin_helper.rb
@@ -116,7 +112,7 @@ homepage: http://www.github.com/theforeman/puppetdb_foreman
116
112
  licenses:
117
113
  - GPL-3.0
118
114
  metadata: {}
119
- post_install_message:
115
+ post_install_message:
120
116
  rdoc_options: []
121
117
  require_paths:
122
118
  - lib
@@ -131,19 +127,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
127
  - !ruby/object:Gem::Version
132
128
  version: '0'
133
129
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.7.3
136
- signing_key:
130
+ rubygems_version: 3.3.7
131
+ signing_key:
137
132
  specification_version: 4
138
133
  summary: This is a Foreman plugin to interact with PuppetDB.
139
134
  test_files:
140
- - test/unit/puppetdb_test.rb
141
- - test/unit/puppetdb_host_test.rb
135
+ - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
136
+ - test/controllers/nodes_controller_test.rb
142
137
  - test/models/host_test.rb
143
- - test/test_plugin_helper.rb
138
+ - test/static_fixtures/facts.json
144
139
  - test/static_fixtures/query_nodes_v3_4.json
145
- - test/static_fixtures/query_nodes.json
146
140
  - test/static_fixtures/resources.json
147
- - test/static_fixtures/facts.json
148
- - test/controllers/nodes_controller_test.rb
149
- - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
141
+ - test/test_plugin_helper.rb
142
+ - test/unit/puppetdb_host_test.rb
143
+ - test/unit/puppetdb_test.rb
@@ -1,49 +0,0 @@
1
- class Setting::Puppetdb < ::Setting
2
- BLANK_ATTRS << 'puppetdb_address'
3
- BLANK_ATTRS << 'puppetdb_ssl_ca_file'
4
- BLANK_ATTRS << 'puppetdb_ssl_certificate'
5
- BLANK_ATTRS << 'puppetdb_ssl_private_key'
6
- BLANK_ATTRS << 'puppetdb_api_version'
7
-
8
- def self.default_settings
9
- if SETTINGS[:puppetdb].present?
10
- default_enabled = SETTINGS[:puppetdb][:enabled]
11
- default_address = SETTINGS[:puppetdb][:address]
12
- default_ssl_ca_file = SETTINGS[:puppetdb][:ssl_ca_file]
13
- default_ssl_certificate = SETTINGS[:puppetdb][:ssl_certificate]
14
- default_ssl_private_key = SETTINGS[:puppetdb][:ssl_private_key]
15
- default_api_version = SETTINGS[:puppetdb][:api_version]
16
- end
17
-
18
- default_enabled = false if default_enabled.nil?
19
- default_address ||= 'https://puppetdb:8081/pdb/cmd/v1'
20
- default_ssl_ca_file ||= (SETTINGS[:ssl_ca_file]).to_s
21
- default_ssl_certificate ||= (SETTINGS[:ssl_certificate]).to_s
22
- default_ssl_private_key ||= (SETTINGS[:ssl_priv_key]).to_s
23
- default_api_version ||= 4
24
-
25
- [
26
- set('puppetdb_enabled', _("Integration with PuppetDB, enabled will deactivate a host in PuppetDB when it's deleted in Foreman"), default_enabled),
27
- set('puppetdb_address', _('Foreman will send PuppetDB requests to this address'), default_address),
28
- set('puppetdb_ssl_ca_file', _('Foreman will send PuppetDB requests with this CA file'), default_ssl_ca_file),
29
- set('puppetdb_ssl_certificate', _('Foreman will send PuppetDB requests with this certificate file'), default_ssl_certificate),
30
- set('puppetdb_ssl_private_key', _('Foreman will send PuppetDB requests with this key file'), default_ssl_private_key),
31
- set('puppetdb_api_version', _('Foreman will use this PuppetDB API version'), default_api_version, N_('PuppetDB API Version'), nil, collection: proc { ::Puppetdb::API_VERSIONS })
32
- ]
33
- end
34
-
35
- def self.load_defaults
36
- # Check the table exists
37
- return unless super
38
-
39
- transaction do
40
- default_settings.each { |s| create! s.update(:category => 'Setting::Puppetdb') }
41
- end
42
-
43
- true
44
- end
45
-
46
- def self.humanized_category
47
- N_('PuppetDB')
48
- end
49
- end
@@ -1,33 +0,0 @@
1
- module PuppetdbClient
2
- class V1 < Base
3
- # The payload is expected to be the certname of a node as a serialized JSON string.
4
- def deactivate_node_payload(nodename)
5
- payload = {
6
- 'command' => 'deactivate node',
7
- 'version' => 1,
8
- 'payload' => nodename.to_json
9
- }.to_json
10
- 'payload=' + payload
11
- end
12
-
13
- def command_url
14
- '/v3/commands'
15
- end
16
-
17
- def nodes_url
18
- '/v3/nodes'
19
- end
20
-
21
- def facts_url
22
- '/v3/facts'
23
- end
24
-
25
- def resources_url
26
- '/v3/resources'
27
- end
28
-
29
- def query_nodes
30
- super.map { |node| node['name'] }
31
- end
32
- end
33
- end