puppetdb_foreman 2.0.0 → 3.0.0

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.
@@ -0,0 +1,61 @@
1
+ [ {
2
+ "name" : "server1.example.com",
3
+ "deactivated" : null,
4
+ "catalog_timestamp" : "2017-04-20T15:07:27.114Z",
5
+ "facts_timestamp" : "2017-04-20T15:06:52.738Z",
6
+ "report_timestamp" : null
7
+ }, {
8
+ "name" : "server2.example.com",
9
+ "deactivated" : null,
10
+ "catalog_timestamp" : "2017-04-20T15:06:28.282Z",
11
+ "facts_timestamp" : "2017-04-20T15:06:12.253Z",
12
+ "report_timestamp" : null
13
+ }, {
14
+ "name" : "server3.example.com",
15
+ "deactivated" : null,
16
+ "catalog_timestamp" : "2017-04-20T15:12:56.090Z",
17
+ "facts_timestamp" : "2017-04-20T15:12:32.117Z",
18
+ "report_timestamp" : null
19
+ }, {
20
+ "name" : "server4.example.com",
21
+ "deactivated" : null,
22
+ "catalog_timestamp" : "2017-04-20T15:04:01.154Z",
23
+ "facts_timestamp" : "2017-04-20T15:03:38.150Z",
24
+ "report_timestamp" : null
25
+ }, {
26
+ "name" : "server5.example.com",
27
+ "deactivated" : null,
28
+ "catalog_timestamp" : "2017-04-20T15:20:06.853Z",
29
+ "facts_timestamp" : "2017-04-20T15:19:49.088Z",
30
+ "report_timestamp" : null
31
+ }, {
32
+ "name" : "server6.example.com",
33
+ "deactivated" : null,
34
+ "catalog_timestamp" : "2017-04-20T15:21:11.520Z",
35
+ "facts_timestamp" : "2017-04-20T15:20:57.685Z",
36
+ "report_timestamp" : null
37
+ }, {
38
+ "name" : "server7.example.com",
39
+ "deactivated" : null,
40
+ "catalog_timestamp" : "2017-04-20T15:15:37.033Z",
41
+ "facts_timestamp" : "2017-04-20T15:15:13.918Z",
42
+ "report_timestamp" : null
43
+ }, {
44
+ "name" : "server8.example.com",
45
+ "deactivated" : null,
46
+ "catalog_timestamp" : "2017-04-20T15:19:18.236Z",
47
+ "facts_timestamp" : "2017-04-20T15:19:02.659Z",
48
+ "report_timestamp" : null
49
+ }, {
50
+ "name" : "server9.example.com",
51
+ "deactivated" : null,
52
+ "catalog_timestamp" : "2017-04-20T14:39:35.070Z",
53
+ "facts_timestamp" : "2017-04-20T14:39:19.003Z",
54
+ "report_timestamp" : null
55
+ }, {
56
+ "name" : "server10.example.com",
57
+ "deactivated" : null,
58
+ "catalog_timestamp" : "2017-04-20T15:17:06.209Z",
59
+ "facts_timestamp" : "2017-04-20T15:16:50.007Z",
60
+ "report_timestamp" : null
61
+ } ]
@@ -0,0 +1,27 @@
1
+ # This calls the main test_helper in Foreman-core
2
+ require 'test_helper'
3
+ require 'database_cleaner'
4
+ require 'webmock/minitest'
5
+
6
+ # Foreman's setup doesn't handle cleaning up for Minitest::Spec
7
+ DatabaseCleaner.strategy = :transaction
8
+
9
+ def setup_settings
10
+ Setting::Puppetdb.load_defaults
11
+ end
12
+
13
+ def fixture(name)
14
+ File.read(File.expand_path("../static_fixtures/#{name}", __FILE__))
15
+ end
16
+
17
+ module Minitest
18
+ class Spec
19
+ before :each do
20
+ DatabaseCleaner.start
21
+ end
22
+
23
+ after :each do
24
+ DatabaseCleaner.clean
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class PuppetdbHostTest < ActiveSupport::TestCase
4
+ setup do
5
+ User.current = FactoryGirl.create(:user, :admin)
6
+ disable_orchestration
7
+ setup_settings
8
+ end
9
+
10
+ let(:sample_facts) do
11
+ JSON.parse(fixture('facts.json'))
12
+ end
13
+
14
+ let(:pdbhost) do
15
+ PuppetdbHost.new(:facts => sample_facts)
16
+ end
17
+
18
+ test 'parses facts' do
19
+ assert_kind_of HashWithIndifferentAccess, pdbhost.facts
20
+ assert_equal 'host.example.com', pdbhost.certname
21
+ assert_equal 'CEST', pdbhost.facts[:timezone]
22
+ assert_nil pdbhost.environment
23
+ end
24
+
25
+ test 'creates a new host by facts' do
26
+ host = pdbhost.to_host
27
+ assert_equal 'host.example.com', host.name
28
+ assert_equal '1.1.1.174', host.ip
29
+ assert_equal Operatingsystem.find_by(title: 'RedHat 7.3'), host.operatingsystem
30
+ assert_equal Domain.find_by(name: 'example.com'), host.domain
31
+ end
32
+
33
+ test 'updates an existing host by facts' do
34
+ Setting[:update_subnets_from_facts] = true
35
+ FactoryGirl.create(:host, :managed, :hostname => 'host', :domain => FactoryGirl.create(:domain, :name => 'example.com'))
36
+ pdbhost.to_host
37
+ host = Host.find_by(name: 'host.example.com')
38
+ assert_equal 'host.example.com', host.name
39
+ # foreman core does not delete old interfaces when importing interfaces from facts
40
+ assert host.interfaces.where(:ip => '1.1.1.174').first
41
+ assert_equal Operatingsystem.find_by(title: 'RedHat 7.3'), host.operatingsystem
42
+ end
43
+ end
@@ -0,0 +1,86 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class PuppetdbTest < ActiveSupport::TestCase
4
+ setup do
5
+ User.current = FactoryGirl.build(:user, :admin)
6
+ setup_settings
7
+ disable_orchestration
8
+ end
9
+
10
+ let(:client) { Puppetdb.client }
11
+ let(:uuid) { SecureRandom.uuid }
12
+
13
+ context 'with V1 API' do
14
+ setup do
15
+ Setting[:puppetdb_address] = 'https://localhost:8080/v3/commands'
16
+ end
17
+
18
+ test 'deactivate_node' do
19
+ stub_request(:post, 'https://localhost:8080/v3/commands')
20
+ .with(:body => 'payload={"command":"deactivate node","version":1,"payload":"\\"www.example.com\\""}',
21
+ :headers => { 'Accept' => 'application/json' })
22
+ .to_return(:status => 200, :body => "{\"uuid\" : \"#{uuid}\"}", :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
23
+
24
+ assert_equal uuid, client.deactivate_node('www.example.com')
25
+ end
26
+
27
+ test 'query_nodes' do
28
+ stub_request(:get, 'https://localhost:8080/v3/nodes')
29
+ .with(:headers => { 'Accept' => 'application/json' })
30
+ .to_return(:status => 200, :body => fixture('query_nodes.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
31
+ expected = (1..10).map { |i| "server#{i}.example.com" }
32
+ assert_equal expected, client.query_nodes
33
+ end
34
+
35
+ test 'facts' do
36
+ stub_request(:get, 'https://localhost:8080/v3/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
37
+ .with(:headers => { 'Accept' => 'application/json' })
38
+ .to_return(:status => 200, :body => fixture('facts.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
39
+ facts = client.facts('host.example.com')
40
+ assert_kind_of Array, facts
41
+ sample = {
42
+ 'value' => 'CEST',
43
+ 'name' => 'timezone',
44
+ 'certname' => 'host.example.com'
45
+ }
46
+ assert_includes facts, sample
47
+ end
48
+ end
49
+
50
+ context 'with V3 API' do
51
+ let(:producer_timestamp) { Time.now.iso8601.to_s }
52
+
53
+ test 'deactivate_node' do
54
+ client.stubs(:producer_timestamp).returns(producer_timestamp)
55
+
56
+ stub_request(:post, 'https://puppetdb:8081/pdb/cmd/v1')
57
+ .with(:body => "{\"command\":\"deactivate node\",\"version\":3,\"payload\":{\"certname\":\"www.example.com\",\"producer_timestamp\":\"#{producer_timestamp}\"}}",
58
+ :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/json' })
59
+ .to_return(:status => 200, :body => "{\"uuid\" : \"#{uuid}\"}", :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
60
+
61
+ assert_equal uuid, client.deactivate_node('www.example.com')
62
+ end
63
+
64
+ test 'query_nodes' do
65
+ stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/nodes')
66
+ .with(:headers => { 'Accept' => 'application/json' })
67
+ .to_return(:status => 200, :body => fixture('query_nodes.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
68
+ expected = (1..10).map { |i| "server#{i}.example.com" }
69
+ assert_equal expected, client.query_nodes
70
+ end
71
+
72
+ test 'facts' do
73
+ stub_request(:get, 'https://puppetdb:8081/pdb/query/v4/facts?query=%5B%22=%22,%20%22certname%22,%20%22host.example.com%22%5D')
74
+ .with(:headers => { 'Accept' => 'application/json' })
75
+ .to_return(:status => 200, :body => fixture('facts.json'), :headers => { 'Content-Type' => 'application/json; charset=utf-8' })
76
+ facts = client.facts('host.example.com')
77
+ assert_kind_of Array, facts
78
+ sample = {
79
+ 'value' => 'CEST',
80
+ 'name' => 'timezone',
81
+ 'certname' => 'host.example.com'
82
+ }
83
+ assert_includes facts, sample
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  description: 'Disable hosts on PuppetDB after they are deleted or built in Foreman,
14
70
  and proxy the PuppetDB dashboard to Foreman. Follow https://github.com/theforeman/puppetdb_foreman
15
71
  and raise an issue/submit a pull request if you need extra functionality. You can
@@ -19,17 +75,41 @@ executables: []
19
75
  extensions: []
20
76
  extra_rdoc_files: []
21
77
  files:
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - app/controllers/api/v2/puppetdb_nodes_controller.rb
82
+ - app/controllers/puppetdb_foreman/nodes_controller.rb
22
83
  - app/controllers/puppetdb_foreman/puppetdb_controller.rb
84
+ - app/models/concerns/orchestration/puppetdb.rb
23
85
  - app/models/puppetdb_foreman/host_extensions.rb
24
86
  - app/models/setting/puppetdb.rb
87
+ - app/services/puppetdb.rb
88
+ - app/services/puppetdb_client/base.rb
89
+ - app/services/puppetdb_client/v1.rb
90
+ - app/services/puppetdb_client/v3.rb
91
+ - app/services/puppetdb_host.rb
92
+ - app/views/api/v2/puppetdb_nodes/import.json.rabl
93
+ - app/views/api/v2/puppetdb_nodes/index.json.rabl
94
+ - app/views/api/v2/puppetdb_nodes/unknown.json.rabl
95
+ - app/views/puppetdb_foreman/nodes/index.html.erb
25
96
  - app/views/puppetdb_foreman/puppetdb/error.html.erb
26
97
  - config/routes.rb
27
98
  - lib/puppetdb_foreman.rb
28
99
  - lib/puppetdb_foreman/engine.rb
29
100
  - lib/puppetdb_foreman/version.rb
101
+ - lib/tasks/puppetdb_foreman_tasks.rake
102
+ - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
103
+ - test/controllers/nodes_controller_test.rb
104
+ - test/models/host_test.rb
105
+ - test/static_fixtures/facts.json
106
+ - test/static_fixtures/query_nodes.json
107
+ - test/test_plugin_helper.rb
108
+ - test/unit/puppetdb_host_test.rb
109
+ - test/unit/puppetdb_test.rb
30
110
  homepage: http://www.github.com/theforeman/puppetdb_foreman
31
111
  licenses:
32
- - GPL-3
112
+ - GPL-3.0
33
113
  metadata: {}
34
114
  post_install_message:
35
115
  rdoc_options: []
@@ -47,8 +127,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
127
  version: '0'
48
128
  requirements: []
49
129
  rubyforge_project:
50
- rubygems_version: 2.4.5.1
130
+ rubygems_version: 2.6.11
51
131
  signing_key:
52
132
  specification_version: 4
53
133
  summary: This is a Foreman plugin to interact with PuppetDB.
54
- test_files: []
134
+ test_files:
135
+ - test/controllers/api/v2/puppetdb_nodes_controller_test.rb
136
+ - test/controllers/nodes_controller_test.rb
137
+ - test/models/host_test.rb
138
+ - test/static_fixtures/facts.json
139
+ - test/static_fixtures/query_nodes.json
140
+ - test/test_plugin_helper.rb
141
+ - test/unit/puppetdb_host_test.rb
142
+ - test/unit/puppetdb_test.rb