vagrant-rubydns 0.2.0 → 0.2.1
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/lib/vagrant-rubydns/server.rb +28 -11
- data/lib/vagrant-rubydns/version.rb +1 -1
- data/test/support/test_server_daemon.rb +40 -0
- data/test/test_helper.rb +8 -2
- data/test/vagrant-rubydns/action/setup_test.rb +4 -1
- data/test/vagrant-rubydns/action/teardown_test.rb +3 -3
- data/test/vagrant-rubydns/server_test.rb +22 -0
- metadata +6 -4
- data/test/support/disable_server_daemon.rb +0 -37
@@ -2,36 +2,53 @@ require 'rubydns'
|
|
2
2
|
|
3
3
|
module VagrantRubydns
|
4
4
|
class Server < RExec::Daemon::Base
|
5
|
-
|
6
|
-
INTERFACES = [
|
7
|
-
[:udp, "0.0.0.0", 10053],
|
8
|
-
[:tcp, "0.0.0.0", 10053]
|
9
|
-
]
|
10
5
|
Name = Resolv::DNS::Name
|
11
|
-
IN
|
6
|
+
IN = Resolv::DNS::Resource::IN
|
7
|
+
|
8
|
+
def self.port
|
9
|
+
@port ||= 10053
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.port=(port)
|
13
|
+
@port = port
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.upstream_servers
|
17
|
+
[[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.interfaces
|
21
|
+
[
|
22
|
+
[:udp, "0.0.0.0", port],
|
23
|
+
[:tcp, "0.0.0.0", port]
|
24
|
+
]
|
25
|
+
end
|
12
26
|
|
13
27
|
def self.upstream
|
14
|
-
@upstream ||= RubyDNS::Resolver.new(
|
28
|
+
@upstream ||= RubyDNS::Resolver.new(upstream_servers)
|
15
29
|
end
|
16
30
|
|
17
|
-
def self.
|
18
|
-
|
31
|
+
def self.pid
|
32
|
+
RExec::Daemon::ProcessFile.recall(self)
|
19
33
|
end
|
20
34
|
|
21
35
|
# For RExec
|
22
|
-
|
36
|
+
def self.working_directory
|
37
|
+
VagrantRubydns.working_dir
|
38
|
+
end
|
23
39
|
|
24
40
|
def self.running?
|
25
41
|
RExec::Daemon::ProcessFile.status(self) == :running
|
26
42
|
end
|
27
43
|
|
28
44
|
def self.prefork
|
45
|
+
super
|
29
46
|
ResolverConfig.ensure_config_exists
|
30
47
|
end
|
31
48
|
|
32
49
|
def self.run
|
33
50
|
server = self
|
34
|
-
RubyDNS::run_server(:listen =>
|
51
|
+
RubyDNS::run_server(:listen => interfaces) do
|
35
52
|
self.logger.level = Logger::INFO
|
36
53
|
|
37
54
|
match(/.*/, IN::A) do |transaction|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Set test port so there's nothing colliding
|
2
|
+
VagrantRubydns::Server.port = 11153
|
3
|
+
|
4
|
+
module SilenceOutput
|
5
|
+
def silence
|
6
|
+
orig_out, orig_err = $stdout, $stderr
|
7
|
+
$stdout, $stderr = StringIO.new, StringIO.new
|
8
|
+
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
$stdout = orig_out
|
12
|
+
$stderr = orig_err
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
silence { super }
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop
|
20
|
+
silence { super }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class VagrantRubydns::Server
|
25
|
+
extend SilenceOutput
|
26
|
+
end
|
27
|
+
|
28
|
+
module TestServerHooks
|
29
|
+
def teardown
|
30
|
+
super
|
31
|
+
# Cleanup any stray server instances from tests
|
32
|
+
if VagrantRubydns::Server.running?
|
33
|
+
VagrantRubydns::Server.stop
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class MiniTest::Spec
|
39
|
+
include TestServerHooks
|
40
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -39,9 +39,15 @@ def fake_environment_with_machine(hostname, ip)
|
|
39
39
|
{ machine: machine, ui: FakeUI, global_config: env.config_global }
|
40
40
|
end
|
41
41
|
|
42
|
+
class MiniTest::Spec
|
43
|
+
alias_method :hush, :capture_io
|
44
|
+
end
|
45
|
+
|
42
46
|
# order is important on these
|
43
|
-
require 'support/fake_working_dir'
|
44
47
|
require 'support/clear_dependent_vms'
|
45
48
|
|
46
49
|
require 'support/fake_ui'
|
47
|
-
require 'support/
|
50
|
+
require 'support/test_server_daemon'
|
51
|
+
|
52
|
+
# need to be last; don't want to delete dir out from servers before they clean up
|
53
|
+
require 'support/fake_working_dir'
|
@@ -50,9 +50,12 @@ module VagrantRubydns
|
|
50
50
|
env = fake_environment_with_machine('somehost.vagrant.dev', '1.2.3.4')
|
51
51
|
|
52
52
|
Server.start
|
53
|
+
original_pid = Server.pid
|
54
|
+
|
53
55
|
setup.call(env)
|
54
56
|
|
55
|
-
Server.
|
57
|
+
Server.running?.must_equal true
|
58
|
+
Server.pid.must_equal original_pid
|
56
59
|
end
|
57
60
|
|
58
61
|
it "does nothing if it is not enabled via config" do
|
@@ -44,7 +44,7 @@ module VagrantRubydns
|
|
44
44
|
Server.start
|
45
45
|
teardown.call(env)
|
46
46
|
|
47
|
-
Server.
|
47
|
+
Server.running?.must_equal false
|
48
48
|
end
|
49
49
|
|
50
50
|
it "leaves the rubydns server when other dependent vms exist" do
|
@@ -58,7 +58,7 @@ module VagrantRubydns
|
|
58
58
|
Server.start
|
59
59
|
teardown.call(env)
|
60
60
|
|
61
|
-
Server.
|
61
|
+
Server.running?.must_equal true
|
62
62
|
end
|
63
63
|
|
64
64
|
it "leaves the server alone if it's not running" do
|
@@ -68,7 +68,7 @@ module VagrantRubydns
|
|
68
68
|
|
69
69
|
teardown.call(env)
|
70
70
|
|
71
|
-
Server.
|
71
|
+
Server.running?.must_equal false
|
72
72
|
end
|
73
73
|
|
74
74
|
it "does nothing when rubydns is disabled" do
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module VagrantRubydns
|
4
|
+
describe Server do
|
5
|
+
after {
|
6
|
+
if Server.running?
|
7
|
+
Server.stop
|
8
|
+
end
|
9
|
+
}
|
10
|
+
describe 'start/stop' do
|
11
|
+
it 'starts and stops a daemon' do
|
12
|
+
hush { Server.start }
|
13
|
+
|
14
|
+
Server.running?.must_equal true
|
15
|
+
|
16
|
+
hush { Server.stop }
|
17
|
+
|
18
|
+
Server.running?.must_equal false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-rubydns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubydns
|
@@ -87,13 +87,14 @@ files:
|
|
87
87
|
- lib/vagrant-rubydns/util.rb
|
88
88
|
- lib/vagrant-rubydns/version.rb
|
89
89
|
- test/support/clear_dependent_vms.rb
|
90
|
-
- test/support/disable_server_daemon.rb
|
91
90
|
- test/support/fake_ui.rb
|
92
91
|
- test/support/fake_working_dir.rb
|
92
|
+
- test/support/test_server_daemon.rb
|
93
93
|
- test/test_helper.rb
|
94
94
|
- test/vagrant-rubydns/action/setup_test.rb
|
95
95
|
- test/vagrant-rubydns/action/teardown_test.rb
|
96
96
|
- test/vagrant-rubydns/dependent_vms_test.rb
|
97
|
+
- test/vagrant-rubydns/server_test.rb
|
97
98
|
- test/vagrant-rubydns/store_test.rb
|
98
99
|
- vagrant-rubydns.gemspec
|
99
100
|
homepage: ''
|
@@ -123,12 +124,13 @@ specification_version: 3
|
|
123
124
|
summary: a simple dns server for vagrant guests
|
124
125
|
test_files:
|
125
126
|
- test/support/clear_dependent_vms.rb
|
126
|
-
- test/support/disable_server_daemon.rb
|
127
127
|
- test/support/fake_ui.rb
|
128
128
|
- test/support/fake_working_dir.rb
|
129
|
+
- test/support/test_server_daemon.rb
|
129
130
|
- test/test_helper.rb
|
130
131
|
- test/vagrant-rubydns/action/setup_test.rb
|
131
132
|
- test/vagrant-rubydns/action/teardown_test.rb
|
132
133
|
- test/vagrant-rubydns/dependent_vms_test.rb
|
134
|
+
- test/vagrant-rubydns/server_test.rb
|
133
135
|
- test/vagrant-rubydns/store_test.rb
|
134
136
|
has_rdoc:
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class VagrantRubydns::Server < RExec::Daemon::Base
|
2
|
-
def self.start
|
3
|
-
@start_count += 1
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.stop
|
7
|
-
@stop_count += 1
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.running?
|
11
|
-
@start_count > 0
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.clear!
|
15
|
-
@start_count = 0
|
16
|
-
@stop_count = 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.start_count
|
20
|
-
@start_count
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.stop_count
|
24
|
-
@stop_count
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module FakeServerHooks
|
29
|
-
def setup
|
30
|
-
super
|
31
|
-
VagrantRubydns::Server.clear!
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class MiniTest::Spec
|
36
|
-
include FakeServerHooks
|
37
|
-
end
|