inventory-server 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9646b4e4c9f3f5f45ef89fa027abbbb92fa5ab74
4
- data.tar.gz: d6e13c24240418e1ceffbfece628a8c2922f8891
3
+ metadata.gz: 84d72e786ae3173c439ccb24170aa15e3a16bf0d
4
+ data.tar.gz: ad4c6d4b89247e08e5ce89b8f3d64e329223fddd
5
5
  SHA512:
6
- metadata.gz: 40480cd931607662fb2627b45e6ca30f29ea0ded355b7510ae697dab9ef5f490562a638402d5089da5358c04a451507a99ec42f7633a3513d13560a57882a116
7
- data.tar.gz: 6f7bd911501c5c8ee1dccd45b3721cc0875b8ca30ad1515aa0ab1fdadd7a3b561c150c44965c3b898e47228ca025ee1c01b8bedba210d5cfa7cf070e74350113
6
+ metadata.gz: d91e3d181aa1e25a39609a04e6fbe83976df36002da60de6b8745e0e3dbd27c16da6621cbb2afdfac8128e12ef57b500e30b9c52831abb59b725b2aaf374c496
7
+ data.tar.gz: 50a189ca44fd4d93d903d6a58e9a8042ecb27c7367570bfd4be5102756e947b2a403e22052fc4923474f1f31d9c0f8c2cb29caefa7488ea8fd6f075c5234f10f
@@ -1,5 +1,5 @@
1
1
  module Inventory
2
2
  module Server
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -21,13 +21,23 @@ module Inventory
21
21
 
22
22
  url = "#{@config[:es_host]}/#{@config[:es_failure_index]}/#{@config[:es_failure_type]}/#{id}"
23
23
  begin
24
- @app.call(env)
25
- RestClient.delete(url)
24
+ result = @app.call(env)
25
+ RestClient.delete(url) rescue result
26
+ return result
26
27
  rescue => e
28
+ InventoryLogger.logger.error $!
29
+ InventoryLogger.logger.error "#{e.backtrace}"
30
+ InventoryLogger.logger.error "Failed facts stored on #{url}"
31
+
27
32
  env['error_message'] = $!
28
33
  env['stack_trace'] = "#{e.backtrace}"
29
34
 
30
- RestClient.put(url, env.to_json)
35
+ begin
36
+ RestClient.put(url, env.to_json)
37
+ rescue => e
38
+ InventoryLogger.logger.error "Fail to store failed facts #{e}: #{e.response}"
39
+ raise e
40
+ end
31
41
 
32
42
  raise e
33
43
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require_relative '../../plugins/facts_parser'
3
3
 
4
- noop = lambda {|env|}
4
+ noop = lambda {|env| 42}
5
5
 
6
6
  RSpec.describe Inventory::Server::FactsParser, '#call' do
7
7
  context "without body" do
@@ -33,8 +33,9 @@ RSpec.describe Inventory::Server::FactsParser, '#call' do
33
33
 
34
34
  context "with good JSON" do
35
35
  env = { :body => '{"key":"value"}' }
36
- it "should throw an error" do
37
- Inventory::Server::FactsParser.new(noop, {}).call(env)
36
+ it "should not throw an error" do
37
+ result= Inventory::Server::FactsParser.new(noop, {}).call(env)
38
+ expect(result).to eq(42)
38
39
  expect(env[:facts]).to eq 'key' => 'value'
39
40
  end
40
41
  end
@@ -63,7 +63,8 @@ RSpec.describe Inventory::Server::Index, '#call' do
63
63
  env = {:id => 'MY_UUID', :facts => { :key => 'value' } }
64
64
  stub = stub_request(:put, "#{config[:es_host]}/inventory_facts/1-0-0/MY_UUID").to_return(:body => '{"OK": true}')
65
65
 
66
- Inventory::Server::Index.new(noop, config).call(env)
66
+ result = Inventory::Server::Index.new(noop, config).call(env)
67
+ expect(result).to eq({ :key => 'value' })
67
68
 
68
69
  expect(stub).to have_been_requested
69
70
  end
@@ -2,7 +2,7 @@ require_relative '../../plugins/json_schema_validator'
2
2
 
3
3
  require 'rspec/mocks'
4
4
 
5
- noop = lambda {|env|}
5
+ noop = lambda {|env| 42}
6
6
 
7
7
  config = Inventory::Server::Config::defaults
8
8
 
@@ -34,7 +34,8 @@ RSpec.describe Inventory::Server::JsonSchemaValidator, '#call' do
34
34
 
35
35
  context "without JSON schema" do
36
36
  it "should pass" do
37
- Inventory::Server::JsonSchemaValidator.new(noop, config).call(env)
37
+ result = Inventory::Server::JsonSchemaValidator.new(noop, config).call(env)
38
+ expect(result).to eq 42
38
39
  end
39
40
  end
40
41
 
@@ -1,7 +1,7 @@
1
1
  require_relative '../../plugins/log_failures_in_es'
2
2
  require 'rspec/mocks'
3
3
 
4
- noop = lambda {|env|}
4
+ noop = lambda {|env| 42}
5
5
 
6
6
  RSpec.describe Inventory::Server::LogFailuresInEs do
7
7
  config = { :failed_facts_dir => './log' , :es_failure_index => "itdiscovery-failures", :es_failure_type => "v1", :es_host => "http://localhost:9200"}
@@ -33,14 +33,21 @@ RSpec.describe Inventory::Server::LogFailuresInEs do
33
33
  it "should pass without writing anything" do
34
34
  expect(RestClient).to receive(:delete).with('http://localhost:9200/itdiscovery-failures/v1/MY_UUID')
35
35
  expect(RestClient).to_not receive(:put).with(any_args)
36
- Inventory::Server::LogFailuresInEs.new(noop, config).call(env)
36
+ result = Inventory::Server::LogFailuresInEs.new(noop, config).call(env)
37
+ expect(result).to eq 42
38
+ end
39
+
40
+ it "should pass without even when ES fails to delete the error document" do
41
+ expect(RestClient).to receive(:delete).with('http://localhost:9200/itdiscovery-failures/v1/MY_UUID').and_raise('404 Not Found')
42
+ result = Inventory::Server::LogFailuresInEs.new(noop, config).call(env)
43
+ expect(result).to eq 42
37
44
  end
38
45
  end
39
46
 
40
47
  context "with error" do
41
48
  it "should write facts" do
42
49
  raise_error = lambda{ |e| raise "an error" }
43
- expect(RestClient).to receive(:put).with('http://localhost:9200/itdiscovery-failures/v1/MY_UUID', /(?=.*my_body)(?=.*an error)(?=.*log_failures_in_es_spec.rb:42)/)
50
+ expect(RestClient).to receive(:put).with('http://localhost:9200/itdiscovery-failures/v1/MY_UUID', /(?=.*my_body)(?=.*an error)(?=.*log_failures_in_es_spec.rb:)/)
44
51
  expect {
45
52
  Inventory::Server::LogFailuresInEs.new(raise_error, config).call(env)
46
53
  }.to raise_error 'an error'
@@ -1,7 +1,7 @@
1
1
  require_relative '../../plugins/log_failures_on_disk'
2
2
  require 'rspec/mocks'
3
3
 
4
- noop = lambda {|env|}
4
+ noop = lambda {|env| 42 }
5
5
 
6
6
  RSpec.describe Inventory::Server::LogFailuresOnDisk do
7
7
  config = { :failed_facts_dir => './log' }
@@ -31,8 +31,9 @@ RSpec.describe Inventory::Server::LogFailuresOnDisk do
31
31
 
32
32
  context "without error" do
33
33
  it "should pass without writing anything" do
34
- Inventory::Server::LogFailuresOnDisk.new(noop, config).call(env)
35
34
  expect(File).to_not receive(:write)
35
+ result = Inventory::Server::LogFailuresOnDisk.new(noop, config).call(env)
36
+ expect(result).to eq 42
36
37
  end
37
38
  end
38
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inventory-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filirom1