]> git.ipfire.org Git - thirdparty/pdns.git/blame - modules/remotebackend/unittest_pipe.rb
Merge pull request #9106 from omoerbeek/release-cycles
[thirdparty/pdns.git] / modules / remotebackend / unittest_pipe.rb
CommitLineData
e57df425 1#!/usr/bin/env ruby
0bc67a4f
AT
2
3require 'rubygems'
a7db8aa6 4require 'bundler/setup'
0bc67a4f
AT
5require 'json'
6require './unittest'
7
8h = Handler.new()
9492f34d
AT
9f = File.open "/tmp/remotebackend.txt.#{$$}","a"
10f.sync
0bc67a4f
AT
11
12STDOUT.sync = true
13begin
14 STDIN.each_line do |line|
9492f34d 15 f.puts "#{Time.now.to_f}: [pipe] #{line}"
0bc67a4f
AT
16 # expect json
17 input = {}
18 line = line.strip
19 next if line.empty?
20 begin
21 input = JSON.parse(line)
22 method = "do_#{input["method"].downcase}"
f7b89fc4 23 args = input["parameters"] || []
0bc67a4f
AT
24
25 if h.respond_to?(method.to_sym) == false
26 res = false
27 elsif args.size > 0
28 res, log = h.send(method,args)
29 else
30 res, log = h.send(method)
31 end
32 puts ({:result => res, :log => log}).to_json
9492f34d 33 f.puts "#{Time.now.to_f} [pipe]: #{({:result => res, :log => log}).to_json}"
0bc67a4f
AT
34 rescue JSON::ParserError
35 puts ({:result => false, :log => "Cannot parse input #{line}"}).to_json
9492f34d 36 f.puts "#{Time.now.to_f} [pipe]: #{({:result => false, :log => "Cannot parse input #{line}"}).to_json}"
0bc67a4f
AT
37 next
38 end
39 end
40rescue SystemExit, Interrupt
41end