puppetdb_foreman 5.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -14
- data/Rakefile +9 -6
- data/app/controllers/api/v2/puppetdb_nodes_controller.rb +8 -6
- data/app/controllers/puppetdb_foreman/nodes_controller.rb +22 -8
- data/app/helpers/concerns/puppetdb_foreman/hosts_helper_extensions.rb +5 -3
- data/app/models/concerns/orchestration/puppetdb.rb +16 -8
- data/app/models/puppetdb_foreman/host_extensions.rb +5 -4
- data/app/services/puppetdb.rb +8 -12
- data/app/services/puppetdb_client/base.rb +8 -6
- data/app/services/puppetdb_client/v4.rb +48 -1
- data/app/services/puppetdb_host.rb +4 -2
- data/app/views/api/v2/puppetdb_nodes/import.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/index.json.rabl +2 -0
- data/app/views/api/v2/puppetdb_nodes/unknown.json.rabl +2 -0
- data/config/routes.rb +11 -9
- data/db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb +4 -2
- data/db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb +3 -1
- data/db/migrate/20221026123754_fix_puppetdb_settings_category_to_dsl.rb +9 -0
- data/lib/puppetdb_foreman/engine.rb +55 -27
- data/lib/puppetdb_foreman/version.rb +3 -1
- data/lib/puppetdb_foreman.rb +2 -0
- data/lib/tasks/puppetdb_foreman_tasks.rake +4 -4
- data/test/controllers/api/v2/puppetdb_nodes_controller_test.rb +60 -55
- data/test/controllers/nodes_controller_test.rb +7 -6
- data/test/models/host_test.rb +6 -5
- data/test/test_plugin_helper.rb +2 -4
- data/test/unit/puppetdb_host_test.rb +5 -4
- data/test/unit/puppetdb_test.rb +18 -135
- metadata +21 -26
- data/app/models/setting/puppetdb.rb +0 -49
- data/app/services/puppetdb_client/v1.rb +0 -33
- data/app/services/puppetdb_client/v3.rb +0 -49
- 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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
+
context '#destroy' do
|
39
|
+
let(:node) { 'test.example.com' }
|
40
|
+
let(:uuid) { SecureRandom.uuid }
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
before do
|
43
|
+
::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(node).returns(uuid)
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
+
context '#import' do
|
56
|
+
let(:node) { 'test.example.com' }
|
57
|
+
let(:host) { FactoryBot.create(:host) }
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
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: { :
|
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: { :
|
71
|
+
put :import, params: { id: node }, session: set_session_user
|
71
72
|
assert_response :found
|
72
|
-
assert_redirected_to host_path(:
|
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]
|
data/test/models/host_test.rb
CHANGED
@@ -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 '#
|
28
|
-
::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(host.
|
29
|
-
host.send(:
|
28
|
+
test '#del_puppetdb' do
|
29
|
+
::PuppetdbClient::V4.any_instance.expects(:deactivate_node).with(host.certname).returns(true)
|
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
|
-
|
44
|
+
assert_empty tasks
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -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(:
|
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, :
|
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(:
|
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
|
data/test/unit/puppetdb_test.rb
CHANGED
@@ -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(
|
148
|
-
|
149
|
-
|
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(:
|
157
|
-
.to_return(:
|
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(:
|
165
|
-
.to_return(:
|
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(:
|
187
|
-
.to_return(:
|
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:
|
4
|
+
version: 6.0.1
|
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:
|
11
|
+
date: 2022-11-03 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.
|
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
|
+
version: 0.1.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Disable hosts on PuppetDB after they are deleted or built in Foreman.
|
70
70
|
Follow https://github.com/theforeman/puppetdb_foreman and raise an issue/submit
|
71
|
-
a pull request if you need extra functionality. You can also find some help
|
72
|
-
|
71
|
+
a pull request if you need extra functionality. You can also find some help via
|
72
|
+
the Foreman support pages (https://theforeman.org/support.html).
|
73
73
|
email: elobatocs@gmail.com
|
74
74
|
executables: []
|
75
75
|
extensions: []
|
@@ -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
|
@@ -98,6 +95,7 @@ files:
|
|
98
95
|
- config/routes.rb
|
99
96
|
- db/migrate/20170717140010_migrate_puppetdb_api_version_setting.rb
|
100
97
|
- db/migrate/20181001113836_remove_puppetdb_dashboard_address_setting.puppetdb_foreman.rb
|
98
|
+
- db/migrate/20221026123754_fix_puppetdb_settings_category_to_dsl.rb
|
101
99
|
- lib/puppetdb_foreman.rb
|
102
100
|
- lib/puppetdb_foreman/engine.rb
|
103
101
|
- lib/puppetdb_foreman/version.rb
|
@@ -106,7 +104,6 @@ files:
|
|
106
104
|
- test/controllers/nodes_controller_test.rb
|
107
105
|
- test/models/host_test.rb
|
108
106
|
- test/static_fixtures/facts.json
|
109
|
-
- test/static_fixtures/query_nodes.json
|
110
107
|
- test/static_fixtures/query_nodes_v3_4.json
|
111
108
|
- test/static_fixtures/resources.json
|
112
109
|
- test/test_plugin_helper.rb
|
@@ -116,7 +113,7 @@ homepage: http://www.github.com/theforeman/puppetdb_foreman
|
|
116
113
|
licenses:
|
117
114
|
- GPL-3.0
|
118
115
|
metadata: {}
|
119
|
-
post_install_message:
|
116
|
+
post_install_message:
|
120
117
|
rdoc_options: []
|
121
118
|
require_paths:
|
122
119
|
- lib
|
@@ -131,19 +128,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
128
|
- !ruby/object:Gem::Version
|
132
129
|
version: '0'
|
133
130
|
requirements: []
|
134
|
-
|
135
|
-
|
136
|
-
signing_key:
|
131
|
+
rubygems_version: 3.3.7
|
132
|
+
signing_key:
|
137
133
|
specification_version: 4
|
138
134
|
summary: This is a Foreman plugin to interact with PuppetDB.
|
139
135
|
test_files:
|
140
|
-
- test/
|
141
|
-
- test/
|
136
|
+
- test/controllers/api/v2/puppetdb_nodes_controller_test.rb
|
137
|
+
- test/controllers/nodes_controller_test.rb
|
142
138
|
- test/models/host_test.rb
|
143
|
-
- test/
|
139
|
+
- test/static_fixtures/facts.json
|
144
140
|
- test/static_fixtures/query_nodes_v3_4.json
|
145
|
-
- test/static_fixtures/query_nodes.json
|
146
141
|
- test/static_fixtures/resources.json
|
147
|
-
- test/
|
148
|
-
- test/
|
149
|
-
- test/
|
142
|
+
- test/test_plugin_helper.rb
|
143
|
+
- test/unit/puppetdb_host_test.rb
|
144
|
+
- 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
|