LanGrove 0.0.1 → 0.0.2
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.
- data/.watchr +11 -3
- data/Rakefile +12 -5
- data/functional/.gitignore +1 -0
- data/{bin/datagram_example → functional/bin/datagram} +2 -0
- data/{config/environments/development.rb → functional/config/.gitignore} +0 -0
- data/{config → functional/config}/boot.rb +0 -0
- data/functional/config/daemons.yml +12 -0
- data/{config → functional/config}/environment.rb +0 -0
- data/{config/environments/production.rb → functional/config/environments/development.rb} +0 -0
- data/{config/environments/test.rb → functional/config/environments/production.rb} +0 -0
- data/{lib/jobs/Rakefile → functional/config/environments/test.rb} +0 -0
- data/functional/lib/daemon/datagram.rb +23 -0
- data/functional/lib/handler/socket_to_file.rb +36 -0
- data/functional/lib/protocol/socket_to_file.rb +55 -0
- data/{libexec → functional/libexec}/daemon.rb +14 -3
- data/functional/log/.gitignore +3 -0
- data/functional/tmp/README +1 -0
- data/lib/langrove.rb +1 -0
- data/lib/langrove/_base.rb +26 -0
- data/lib/langrove/adaptor/base.rb +3 -0
- data/lib/langrove/adaptor/datagram.rb +27 -0
- data/lib/langrove/adaptor_base.rb +89 -0
- data/lib/langrove/client/base.rb +2 -0
- data/lib/langrove/client/datagram.rb +28 -0
- data/lib/langrove/client_base.rb +114 -0
- data/lib/langrove/daemon/base.rb +2 -0
- data/lib/{daemon_base.rb → langrove/daemon_base.rb} +30 -23
- data/lib/langrove/ext.rb +7 -0
- data/lib/langrove/ext/class_loader.rb +146 -0
- data/lib/{ext → langrove/ext}/config_item.rb +4 -5
- data/lib/{ext → langrove/ext}/config_loader.rb +2 -2
- data/lib/langrove/ext/fake_logger.rb +8 -0
- data/lib/{ext → langrove/ext}/persistable.rb +2 -2
- data/lib/{ext → langrove/ext}/string.rb +0 -0
- data/lib/langrove/handler/base.rb +2 -0
- data/lib/{handler_base.rb → langrove/handler_base.rb} +25 -9
- data/lib/langrove/protocol/base.rb +2 -0
- data/lib/langrove/protocol/syslog.rb +32 -0
- data/lib/langrove/protocol_base.rb +32 -0
- data/lib/langrove/version.rb +3 -0
- data/spec/functional/daemon/datagram_spec.rb +115 -0
- data/spec/langrove/adaptor/datagram_spec.rb +6 -0
- data/spec/langrove/adaptor_base_spec.rb +48 -0
- data/spec/langrove/client/datagram_spec.rb +1 -0
- data/spec/langrove/client_base_spec.rb +5 -0
- data/spec/langrove/daemon_base_spec.rb +101 -0
- data/spec/langrove/ext/class_loader_spec.rb +83 -0
- data/spec/langrove/ext/config_item_spec.rb +81 -0
- data/spec/langrove/ext/config_loader_spec.rb +5 -0
- data/{tmp/TMP → spec/langrove/ext/fake_logger_spec.rb} +0 -0
- data/spec/{ext → langrove/ext}/persistable_spec.rb +8 -9
- data/spec/{ext → langrove/ext}/string_spec.rb +1 -1
- data/spec/langrove/handler_base_spec.rb +57 -0
- data/spec/langrove/protocol/syslog_spec.rb +45 -0
- data/spec/langrove/protocol_base_spec.rb +6 -0
- data/spec/todo_spec.rb +1 -2
- data/tmp/README +2 -0
- metadata +150 -46
- data/config/daemons.yml.tmpl +0 -78
- data/lib/adaptor/base.rb +0 -1
- data/lib/adaptor/datagram.rb +0 -20
- data/lib/adaptor/socket_handler.rb +0 -27
- data/lib/adaptor_base.rb +0 -39
- data/lib/client/base.rb +0 -1
- data/lib/client/puppet_state.rb +0 -74
- data/lib/client/radio_state.rb +0 -81
- data/lib/client_base.rb +0 -24
- data/lib/daemon/base.rb +0 -1
- data/lib/daemon/datagram_example.rb +0 -12
- data/lib/handler/base.rb +0 -1
- data/lib/handler/socket_to_file.rb +0 -30
- data/lib/jobs/jobs.rb +0 -1
- data/lib/jobs/updated_puppet_state.rb +0 -17
- data/lib/protocol_base.rb +0 -5
- data/spec/adaptor/datagram_spec.rb +0 -6
- data/spec/adaptor/socket_handler_spec.rb +0 -5
- data/spec/adaptor_base_spec.rb +0 -45
- data/spec/client_base_spec.rb +0 -5
- data/spec/daemon_base_spec.rb +0 -97
- data/spec/ext/config_item_spec.rb +0 -77
- data/spec/ext/config_loader_spec.rb +0 -5
- data/spec/functional/datagram_spec.rb +0 -122
- data/spec/handler_base_spec.rb +0 -71
- data/spec/protocol_base_spec.rb +0 -6
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'ext/config_item'
|
2
|
-
|
3
|
-
describe ConfigItem do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
@config_hash = {
|
7
|
-
'root' => "3",
|
8
|
-
'BLANK' => "",
|
9
|
-
'daemons' => {
|
10
|
-
'puppet_log' => {
|
11
|
-
'handler' => {
|
12
|
-
'collection' => 'SyslogStateMachines'
|
13
|
-
}
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'accesses config items' do
|
20
|
-
ConfigItem.get(@config_hash, ['root']).should == '3'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'accesses nested config items' do
|
24
|
-
ConfigItem.get(@config_hash, ['daemons','puppet_log','handler','collection']).should == 'SyslogStateMachines'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises a config exception if the key isnt present' do
|
28
|
-
|
29
|
-
expect {
|
30
|
-
|
31
|
-
ConfigItem.get(@config_hash, ['NOT'])
|
32
|
-
|
33
|
-
}.to raise_error( ConfigException, /Missing config item 'NOT'/ )
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises a config exception if the key isnt present' do
|
38
|
-
|
39
|
-
expect {
|
40
|
-
|
41
|
-
ConfigItem.get(@config_hash, ['BLANK'])
|
42
|
-
|
43
|
-
}.to raise_error( ConfigException, /Missing config item 'BLANK'/ )
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'raises a config exception if the value isnt present' do
|
48
|
-
|
49
|
-
expect {
|
50
|
-
|
51
|
-
ConfigItem.get(@config_hash, ['BLANK'], false)
|
52
|
-
|
53
|
-
}.to_not raise_error( ConfigException, /Missing config item 'BLANK'/ )
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'raises a config exception if the nested item isnt present' do
|
58
|
-
|
59
|
-
expect {
|
60
|
-
|
61
|
-
ConfigItem.get(@config_hash, ['daemons', 'NEITHER', 'this'])
|
62
|
-
|
63
|
-
}.to raise_error( ConfigException, /Missing config item 'NEITHER'/ )
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'does not raise on not mandatory fields' do
|
68
|
-
|
69
|
-
expect {
|
70
|
-
|
71
|
-
ConfigItem.get(@config_hash, ['daemons', 'NEITHER'], false)
|
72
|
-
|
73
|
-
}.to_not raise_error( ConfigException )
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'daemon/base'
|
2
|
-
|
3
|
-
require 'ext/fake_logger'
|
4
|
-
|
5
|
-
describe 'A daemon' do
|
6
|
-
|
7
|
-
before :all do
|
8
|
-
|
9
|
-
@daemon_name = 'test_daemon'
|
10
|
-
@adaptor_class = 'Datagram'
|
11
|
-
@collection_class = 'SocketToFile'
|
12
|
-
|
13
|
-
@logger = FakeLogger.new :silent
|
14
|
-
|
15
|
-
@file = File.dirname( __FILE__ ) + "/../../tmp/datagram.txt"
|
16
|
-
`rm -f #{@file}`
|
17
|
-
@mesg = "Send This As Datagram"
|
18
|
-
|
19
|
-
@config = {
|
20
|
-
|
21
|
-
'daemons' => {
|
22
|
-
|
23
|
-
@daemon_name => {
|
24
|
-
|
25
|
-
'adaptor' => {
|
26
|
-
|
27
|
-
'connection' => @adaptor_class
|
28
|
-
|
29
|
-
},
|
30
|
-
|
31
|
-
'handler' => {
|
32
|
-
|
33
|
-
'collection' => @collection_class
|
34
|
-
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
#
|
41
|
-
# start the daemon
|
42
|
-
#
|
43
|
-
@pid = fork do
|
44
|
-
|
45
|
-
#
|
46
|
-
# after :each should kill it,
|
47
|
-
#
|
48
|
-
# but just incase, it can be found in the
|
49
|
-
# process table with
|
50
|
-
#
|
51
|
-
# ps aux | grep test_daemon
|
52
|
-
#
|
53
|
-
$0 = @daemon_name
|
54
|
-
|
55
|
-
Daemon::Base.new( @config, @daemon_name, @logger ).run
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
after :all do
|
62
|
-
|
63
|
-
#
|
64
|
-
# stop the daemon
|
65
|
-
#
|
66
|
-
`kill #{@pid}`
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'running a server' do
|
71
|
-
|
72
|
-
it 'receives a message' do
|
73
|
-
|
74
|
-
require "eventmachine"
|
75
|
-
|
76
|
-
class Sender < EventMachine::Connection
|
77
|
-
|
78
|
-
def send( data )
|
79
|
-
|
80
|
-
send_datagram( data, '127.0.0.1', 12701 )
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
EM.run do
|
87
|
-
|
88
|
-
sender = nil
|
89
|
-
|
90
|
-
EM.add_periodic_timer(1) do
|
91
|
-
|
92
|
-
sender.send( "#{@file}|#{@mesg}" )
|
93
|
-
EM.stop
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
EM.open_datagram_socket "127.0.0.1", 0, Sender do |connected|
|
98
|
-
|
99
|
-
sender = connected
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
#
|
106
|
-
# Give the daemon a moment to write the file
|
107
|
-
#
|
108
|
-
sleep 1
|
109
|
-
|
110
|
-
File.file?( @file ).should == true
|
111
|
-
|
112
|
-
File.open( @file, 'r' ).each_line do |line|
|
113
|
-
|
114
|
-
line.should == @mesg
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
data/spec/handler_base_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'handler/base'
|
2
|
-
|
3
|
-
require 'ext/fake_logger'
|
4
|
-
|
5
|
-
describe Handler::Base do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
|
9
|
-
@logger = FakeLogger.new :silent
|
10
|
-
|
11
|
-
@daemon_name = 'test_daemon'
|
12
|
-
|
13
|
-
@config = {
|
14
|
-
|
15
|
-
'daemons' => {
|
16
|
-
|
17
|
-
@daemon_name => {
|
18
|
-
|
19
|
-
'handler' => {
|
20
|
-
|
21
|
-
'collection' => 'Base'
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'uses a protocol' do
|
30
|
-
|
31
|
-
it 'that defaults to an instance of Protocol::Base' do
|
32
|
-
|
33
|
-
test = Handler::Base.new( @config, @daemon_name, @logger )
|
34
|
-
|
35
|
-
protocol = test.instance_variable_get( :@protocol )
|
36
|
-
|
37
|
-
protocol.should be_a( Protocol.const_get('Base') )
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'as defined by the config_hash' do
|
42
|
-
|
43
|
-
@config['daemons'][@daemon_name]['handler']['protocol'] = 'MedievalLanternMorse'
|
44
|
-
|
45
|
-
expect {
|
46
|
-
|
47
|
-
test = Handler::Base.new( @config, @daemon_name, @logger )
|
48
|
-
|
49
|
-
}.to raise_error( LoadError,
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"no such file to load -- protocol/medieval_lantern_morse"
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
)
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|