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.
Files changed (84) hide show
  1. data/.watchr +11 -3
  2. data/Rakefile +12 -5
  3. data/functional/.gitignore +1 -0
  4. data/{bin/datagram_example → functional/bin/datagram} +2 -0
  5. data/{config/environments/development.rb → functional/config/.gitignore} +0 -0
  6. data/{config → functional/config}/boot.rb +0 -0
  7. data/functional/config/daemons.yml +12 -0
  8. data/{config → functional/config}/environment.rb +0 -0
  9. data/{config/environments/production.rb → functional/config/environments/development.rb} +0 -0
  10. data/{config/environments/test.rb → functional/config/environments/production.rb} +0 -0
  11. data/{lib/jobs/Rakefile → functional/config/environments/test.rb} +0 -0
  12. data/functional/lib/daemon/datagram.rb +23 -0
  13. data/functional/lib/handler/socket_to_file.rb +36 -0
  14. data/functional/lib/protocol/socket_to_file.rb +55 -0
  15. data/{libexec → functional/libexec}/daemon.rb +14 -3
  16. data/functional/log/.gitignore +3 -0
  17. data/functional/tmp/README +1 -0
  18. data/lib/langrove.rb +1 -0
  19. data/lib/langrove/_base.rb +26 -0
  20. data/lib/langrove/adaptor/base.rb +3 -0
  21. data/lib/langrove/adaptor/datagram.rb +27 -0
  22. data/lib/langrove/adaptor_base.rb +89 -0
  23. data/lib/langrove/client/base.rb +2 -0
  24. data/lib/langrove/client/datagram.rb +28 -0
  25. data/lib/langrove/client_base.rb +114 -0
  26. data/lib/langrove/daemon/base.rb +2 -0
  27. data/lib/{daemon_base.rb → langrove/daemon_base.rb} +30 -23
  28. data/lib/langrove/ext.rb +7 -0
  29. data/lib/langrove/ext/class_loader.rb +146 -0
  30. data/lib/{ext → langrove/ext}/config_item.rb +4 -5
  31. data/lib/{ext → langrove/ext}/config_loader.rb +2 -2
  32. data/lib/langrove/ext/fake_logger.rb +8 -0
  33. data/lib/{ext → langrove/ext}/persistable.rb +2 -2
  34. data/lib/{ext → langrove/ext}/string.rb +0 -0
  35. data/lib/langrove/handler/base.rb +2 -0
  36. data/lib/{handler_base.rb → langrove/handler_base.rb} +25 -9
  37. data/lib/langrove/protocol/base.rb +2 -0
  38. data/lib/langrove/protocol/syslog.rb +32 -0
  39. data/lib/langrove/protocol_base.rb +32 -0
  40. data/lib/langrove/version.rb +3 -0
  41. data/spec/functional/daemon/datagram_spec.rb +115 -0
  42. data/spec/langrove/adaptor/datagram_spec.rb +6 -0
  43. data/spec/langrove/adaptor_base_spec.rb +48 -0
  44. data/spec/langrove/client/datagram_spec.rb +1 -0
  45. data/spec/langrove/client_base_spec.rb +5 -0
  46. data/spec/langrove/daemon_base_spec.rb +101 -0
  47. data/spec/langrove/ext/class_loader_spec.rb +83 -0
  48. data/spec/langrove/ext/config_item_spec.rb +81 -0
  49. data/spec/langrove/ext/config_loader_spec.rb +5 -0
  50. data/{tmp/TMP → spec/langrove/ext/fake_logger_spec.rb} +0 -0
  51. data/spec/{ext → langrove/ext}/persistable_spec.rb +8 -9
  52. data/spec/{ext → langrove/ext}/string_spec.rb +1 -1
  53. data/spec/langrove/handler_base_spec.rb +57 -0
  54. data/spec/langrove/protocol/syslog_spec.rb +45 -0
  55. data/spec/langrove/protocol_base_spec.rb +6 -0
  56. data/spec/todo_spec.rb +1 -2
  57. data/tmp/README +2 -0
  58. metadata +150 -46
  59. data/config/daemons.yml.tmpl +0 -78
  60. data/lib/adaptor/base.rb +0 -1
  61. data/lib/adaptor/datagram.rb +0 -20
  62. data/lib/adaptor/socket_handler.rb +0 -27
  63. data/lib/adaptor_base.rb +0 -39
  64. data/lib/client/base.rb +0 -1
  65. data/lib/client/puppet_state.rb +0 -74
  66. data/lib/client/radio_state.rb +0 -81
  67. data/lib/client_base.rb +0 -24
  68. data/lib/daemon/base.rb +0 -1
  69. data/lib/daemon/datagram_example.rb +0 -12
  70. data/lib/handler/base.rb +0 -1
  71. data/lib/handler/socket_to_file.rb +0 -30
  72. data/lib/jobs/jobs.rb +0 -1
  73. data/lib/jobs/updated_puppet_state.rb +0 -17
  74. data/lib/protocol_base.rb +0 -5
  75. data/spec/adaptor/datagram_spec.rb +0 -6
  76. data/spec/adaptor/socket_handler_spec.rb +0 -5
  77. data/spec/adaptor_base_spec.rb +0 -45
  78. data/spec/client_base_spec.rb +0 -5
  79. data/spec/daemon_base_spec.rb +0 -97
  80. data/spec/ext/config_item_spec.rb +0 -77
  81. data/spec/ext/config_loader_spec.rb +0 -5
  82. data/spec/functional/datagram_spec.rb +0 -122
  83. data/spec/handler_base_spec.rb +0 -71
  84. 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,5 +0,0 @@
1
- require 'ext/config_loader'
2
-
3
- describe ConfigLoader do
4
-
5
- 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
@@ -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
@@ -1,6 +0,0 @@
1
- require 'protocol_base'
2
-
3
- describe Protocol::Base do
4
-
5
-
6
- end