landrush 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +100 -12
  4. data/.travis.yml +1 -2
  5. data/CHANGELOG.md +11 -0
  6. data/Gemfile +11 -11
  7. data/README.adoc +8 -1
  8. data/Rakefile +3 -3
  9. data/appveyor.yml +3 -1
  10. data/doc/Development.adoc +24 -19
  11. data/doc/Usage.adoc +17 -6
  12. data/features/dns_resolution.feature +3 -0
  13. data/features/docker_provider.feature +32 -0
  14. data/features/support/env.rb +2 -2
  15. data/landrush.gemspec +3 -3
  16. data/lib/landrush.rb +1 -0
  17. data/lib/landrush/action/common.rb +7 -2
  18. data/lib/landrush/action/redirect_dns.rb +3 -0
  19. data/lib/landrush/action/setup.rb +16 -12
  20. data/lib/landrush/action/teardown.rb +2 -0
  21. data/lib/landrush/cap/guest/all/read_host_visible_ip_address.rb +2 -2
  22. data/lib/landrush/cap/guest/linux/add_iptables_rule.rb +2 -2
  23. data/lib/landrush/cap/guest/linux/configured_dns_servers.rb +1 -0
  24. data/lib/landrush/cap/guest/linux/redirect_dns.rb +1 -1
  25. data/lib/landrush/cap/guest/suse/add_iptables_rule.rb +2 -2
  26. data/lib/landrush/cap/host/arch/dnsmasq_installed.rb +11 -0
  27. data/lib/landrush/cap/host/arch/install_dnsmasq.rb +16 -0
  28. data/lib/landrush/cap/host/arch/restart_dnsmasq.rb +21 -0
  29. data/lib/landrush/cap/host/darwin/configure_visibility_on_host.rb +21 -18
  30. data/lib/landrush/cap/host/debian/host.rb +1 -0
  31. data/lib/landrush/cap/host/linux/configure_visibility_on_host.rb +5 -3
  32. data/lib/landrush/cap/host/linux/create_dnsmasq_config.rb +3 -0
  33. data/lib/landrush/cap/host/redhat/restart_dnsmasq.rb +8 -2
  34. data/lib/landrush/cap/host/ubuntu/host.rb +1 -0
  35. data/lib/landrush/cap/host/windows/configure_visibility_on_host.rb +14 -6
  36. data/lib/landrush/command.rb +18 -3
  37. data/lib/landrush/config.rb +6 -2
  38. data/lib/landrush/dns_server.rb +82 -0
  39. data/lib/landrush/plugin.rb +18 -0
  40. data/lib/landrush/server.rb +147 -205
  41. data/lib/landrush/start_server.rb +1 -1
  42. data/lib/landrush/store.rb +53 -24
  43. data/lib/landrush/util/dnsmasq.rb +10 -0
  44. data/lib/landrush/util/process_helper.rb +16 -16
  45. data/lib/landrush/util/retry.rb +1 -0
  46. data/lib/landrush/version.rb +1 -1
  47. data/test/landrush/action/setup_test.rb +8 -7
  48. data/test/landrush/action/teardown_test.rb +5 -5
  49. data/test/landrush/cap/guest/linux/redirect_dns_test.rb +1 -1
  50. data/test/landrush/cap/host/darwin/configure_visibility_on_host_test.rb +10 -6
  51. data/test/landrush/cap/host/linux/configure_visibility_on_host_test.rb +1 -1
  52. data/test/landrush/cap/host/windows/configure_visibility_on_host_test.rb +35 -4
  53. data/test/landrush/issues/255.rb +55 -55
  54. data/test/landrush/parallel_store_use_test.rb +50 -0
  55. data/test/landrush/server_test.rb +6 -17
  56. data/test/landrush/store_test.rb +8 -8
  57. data/test/landrush/util/dnsmasq_test.rb +42 -0
  58. data/test/support/create_fake_working_dir.rb +3 -2
  59. data/test/support/delete_fake_working_dir.rb +1 -1
  60. data/test/support/test_server_daemon.rb +1 -1
  61. data/test/test_helper.rb +6 -8
  62. metadata +42 -17
@@ -0,0 +1,50 @@
1
+ require_relative '../test_helper'
2
+
3
+ module Landrush
4
+ describe Store do
5
+ before do
6
+ @temp_file = Tempfile.new(%w[landrush_test_store .json])
7
+ end
8
+
9
+ after do
10
+ @temp_file.unlink
11
+ end
12
+
13
+ def parallel(thread_count = 10)
14
+ Timeout.timeout(5) do
15
+ (1..thread_count).map do |n|
16
+ Thread.new do
17
+ store = Store.new(@temp_file)
18
+ yield(store, n)
19
+ end
20
+ end.map(&:join)
21
+ end
22
+ end
23
+
24
+ describe 'parallel store use' do
25
+ it 'sets the key to the value and makes it available for getting' do
26
+ thread_count = 10
27
+ parallel(thread_count) do |store, n|
28
+ store.set("foo-#{n}", "bar-#{n}")
29
+ sleep 0.1
30
+ assert_equal(store.get("foo-#{n}"), "bar-#{n}")
31
+ end
32
+
33
+ store = Store.new(@temp_file)
34
+ (1..thread_count).each do |n|
35
+ assert_equal(store.get("foo-#{n}"), "bar-#{n}")
36
+ end
37
+ end
38
+
39
+ it 'lock timeout throws Vagrant error' do
40
+ file = File.open(@temp_file)
41
+ file.flock(File::LOCK_EX)
42
+
43
+ assert_raises Landrush::ConfigLockError do
44
+ store = Store.new(@temp_file)
45
+ store.set('foo', 'bar')
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -14,30 +14,19 @@ module Landrush
14
14
 
15
15
  def wait_for_port
16
16
  sleep 1 until begin
17
- TCPSocket.open('127.0.0.1', Server.port)
18
- rescue
19
- nil
20
- end
21
- end
22
-
23
- before do
24
- @tmp_dir = Dir.mktmpdir('landrush-server-test-')
25
- Server.working_dir = @tmp_dir
26
- Server.gems_dir = gem_dir
27
- end
28
-
29
- after do
30
- Server.stop
31
- FileUtils.rm_rf(@tmp_dir) if File.exist?(@tmp_dir)
17
+ TCPSocket.open('127.0.0.1', Server.port)
18
+ rescue StandardError
19
+ nil
20
+ end
32
21
  end
33
22
 
34
23
  describe 'start/stop' do
35
24
  it 'starts and stops a daemon' do
36
25
  Server.start
37
- Server.running?.must_equal true
26
+ Server.status.must_equal :running
38
27
 
39
28
  Server.stop
40
- Server.running?.must_equal false
29
+ Server.status.must_equal :stopped
41
30
  end
42
31
 
43
32
  # FIXME: This test requires network access.
@@ -3,7 +3,7 @@ require_relative '../test_helper'
3
3
  module Landrush
4
4
  describe Store do
5
5
  before do
6
- @temp_file = Tempfile.new(%w(landrush_test_store .json))
6
+ @temp_file = Tempfile.new(%w[landrush_test_store .json])
7
7
  @store = Store.new(@temp_file)
8
8
  end
9
9
 
@@ -28,7 +28,7 @@ module Landrush
28
28
 
29
29
  describe 'get' do
30
30
  it 'returns nil for unset values' do
31
- @store.get('notakey').must_equal nil
31
+ assert_nil @store.get('notakey')
32
32
  end
33
33
 
34
34
  it 'returns the latest set value (no caching)' do
@@ -37,7 +37,7 @@ module Landrush
37
37
  @store.set('foo', 'second')
38
38
  @store.get('foo').must_equal 'second'
39
39
  @store.delete('foo')
40
- @store.get('foo').must_equal nil
40
+ assert_nil @store.get('foo')
41
41
  end
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ module Landrush
49
49
 
50
50
  @store.delete('now')
51
51
 
52
- @store.get('now').must_equal nil # you don't!
52
+ assert_nil @store.get('now')
53
53
  end
54
54
  end
55
55
 
@@ -59,8 +59,8 @@ module Landrush
59
59
 
60
60
  @store.find('foo.somehost.vagrant.test').must_equal 'somehost.vagrant.test'
61
61
  @store.find('bar.somehost.vagrant.test').must_equal 'somehost.vagrant.test'
62
- @store.find('foo.otherhost.vagrant.test').must_equal nil
63
- @store.find('host.vagrant.test').must_equal nil
62
+ assert_nil @store.find('foo.otherhost.vagrant.test')
63
+ assert_nil @store.find('host.vagrant.test')
64
64
  end
65
65
 
66
66
  it 'returns exact matches too' do
@@ -73,8 +73,8 @@ module Landrush
73
73
 
74
74
  @store.find('somehost').must_equal 'somehost.vagrant.test'
75
75
  @store.find('somehost.vagrant').must_equal 'somehost.vagrant.test'
76
- @store.find('somehost.vagr').must_equal nil
77
- @store.find('someh').must_equal nil
76
+ assert_nil @store.find('somehost.vagr')
77
+ assert_nil @store.find('someh')
78
78
  end
79
79
  end
80
80
 
@@ -0,0 +1,42 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Landrush
4
+ module Util
5
+ describe Dnsmasq do
6
+ MANAGED_DNSMASQ = '# Configuration file for NetworkManager.
7
+ [main]
8
+ dns=dnsmasq
9
+
10
+ [logging]
11
+ '.split('\n')
12
+
13
+ UNMANAGED_DNSMASQ = '# Configuration file for NetworkManager.
14
+ [main]
15
+ #dns=dnsmasq
16
+
17
+ [logging]
18
+ '.split('\n')
19
+
20
+ describe 'nm_managed?' do
21
+ it 'No NetworkManager config exists' do
22
+ File.expects(:exist?).returns(false)
23
+ Dnsmasq.nm_managed?.must_equal false
24
+ end
25
+
26
+ it 'NetworkManager manages dnsmasq' do
27
+ File.expects(:exist?).returns(true)
28
+ File.expects(:readlines).returns(MANAGED_DNSMASQ)
29
+
30
+ Dnsmasq.nm_managed?.must_equal true
31
+ end
32
+
33
+ it 'NetworkManager does not manage dnsmasq' do
34
+ File.expects(:exist?).returns(true)
35
+ File.expects(:readlines).returns(UNMANAGED_DNSMASQ)
36
+
37
+ Dnsmasq.nm_managed?.must_equal false
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,14 +1,15 @@
1
1
  module CreateFakeWorkingDirHooks
2
2
  def setup
3
3
  super
4
- tempdir = Dir.mktmpdir('vagrant_landrush_test_working_dir-')
5
- working_dir = File.join(tempdir, 'data', 'landrush')
4
+ @temp_dir = Dir.mktmpdir('vagrant_landrush_test_working_dir-')
5
+ working_dir = File.join(@temp_dir, 'data', 'landrush')
6
6
  FileUtils.mkpath working_dir
7
7
 
8
8
  # Make sure that for all tests where we use Landrush::Server the working directory
9
9
  # is set to a temp directory.
10
10
  # this gets deleted in DeleteFakeWorkingDirHooks
11
11
  Landrush::Server.working_dir = working_dir
12
+ Landrush::Server.gems_dir = gem_dir
12
13
  end
13
14
  end
14
15
 
@@ -1,7 +1,7 @@
1
1
  module DeleteFakeWorkingDirHooks
2
2
  def teardown
3
3
  super
4
- Landrush::Server.working_dir.rmtree if Landrush::Server.working_dir.directory?
4
+ FileUtils.rm_rf(@temp_dir)
5
5
  end
6
6
  end
7
7
 
@@ -31,7 +31,7 @@ module TestServerHooks
31
31
  def teardown
32
32
  super
33
33
  # Cleanup any stray server instances from tests
34
- Landrush::Server.stop if Landrush::Server.running?
34
+ Landrush::Server.stop
35
35
  Landrush::Store.reset
36
36
  end
37
37
  end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.push(File.expand_path('../../lib', __FILE__))
1
+ $LOAD_PATH.push(File.expand_path('../lib', __dir__))
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'minitest/spec'
@@ -11,9 +11,10 @@ require 'landrush/cap/host/darwin/configure_visibility_on_host'
11
11
  require 'landrush/cap/host/windows/configure_visibility_on_host'
12
12
  require 'landrush/cap/host/linux/configure_visibility_on_host'
13
13
  require 'landrush/util/retry'
14
+ require 'landrush/util/dnsmasq'
14
15
 
15
16
  require 'minitest/autorun'
16
- require 'mocha/mini_test'
17
+ require 'mocha/minitest'
17
18
 
18
19
  # Make sure to keep the numbering sequential here
19
20
  # Putting include/exclude out of order is kind of the point though ;)
@@ -105,14 +106,11 @@ end
105
106
 
106
107
  module Landrush
107
108
  class FakeProvider
108
- def initialize(*args)
109
- end
109
+ def initialize(*args); end
110
110
 
111
- def _initialize(*args)
112
- end
111
+ def _initialize(*args); end
113
112
 
114
- def ssh_info
115
- end
113
+ def ssh_info; end
116
114
 
117
115
  def state
118
116
  @state ||= Vagrant::MachineState.new('fake-state', 'fake-state', 'fake-state')
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: landrush
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Hinze
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2018-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: filelock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: landrush-ip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.5
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rubydns
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +66,6 @@ dependencies:
38
66
  - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: landrush-ip
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.2.5
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.2.5
55
69
  description: |
56
70
  Forget about IPs in Vagrant - Automated DNS for your VMs
57
71
 
@@ -95,6 +109,7 @@ files:
95
109
  - doc/vagrant_dns_without_landrush.svg
96
110
  - features/commands.feature
97
111
  - features/dns_resolution.feature
112
+ - features/docker_provider.feature
98
113
  - features/landrush_ip.feature
99
114
  - features/step_definitions/landrush_custom_steps.rb
100
115
  - features/support/env.rb
@@ -116,6 +131,9 @@ files:
116
131
  - lib/landrush/cap/guest/suse/add_iptables_rule.rb
117
132
  - lib/landrush/cap/guest/suse/install_iptables.rb
118
133
  - lib/landrush/cap/guest/suse/iptables_installed.rb
134
+ - lib/landrush/cap/host/arch/dnsmasq_installed.rb
135
+ - lib/landrush/cap/host/arch/install_dnsmasq.rb
136
+ - lib/landrush/cap/host/arch/restart_dnsmasq.rb
119
137
  - lib/landrush/cap/host/darwin/configure_visibility_on_host.rb
120
138
  - lib/landrush/cap/host/debian/dnsmasq_installed.rb
121
139
  - lib/landrush/cap/host/debian/host.rb
@@ -134,10 +152,12 @@ files:
134
152
  - lib/landrush/command.rb
135
153
  - lib/landrush/config.rb
136
154
  - lib/landrush/dependent_vms.rb
155
+ - lib/landrush/dns_server.rb
137
156
  - lib/landrush/plugin.rb
138
157
  - lib/landrush/server.rb
139
158
  - lib/landrush/start_server.rb
140
159
  - lib/landrush/store.rb
160
+ - lib/landrush/util/dnsmasq.rb
141
161
  - lib/landrush/util/path.rb
142
162
  - lib/landrush/util/process_helper.rb
143
163
  - lib/landrush/util/retry.rb
@@ -153,8 +173,10 @@ files:
153
173
  - test/landrush/config_test.rb
154
174
  - test/landrush/dependent_vms_test.rb
155
175
  - test/landrush/issues/255.rb
176
+ - test/landrush/parallel_store_use_test.rb
156
177
  - test/landrush/server_test.rb
157
178
  - test/landrush/store_test.rb
179
+ - test/landrush/util/dnsmasq_test.rb
158
180
  - test/landrush/util/rety_test.rb
159
181
  - test/support/clear_dependent_vms.rb
160
182
  - test/support/create_fake_working_dir.rb
@@ -181,13 +203,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
203
  version: '0'
182
204
  requirements: []
183
205
  rubyforge_project:
184
- rubygems_version: 2.4.8
206
+ rubygems_version: 2.7.7
185
207
  signing_key:
186
208
  specification_version: 4
187
209
  summary: a vagrant plugin providing consistent DNS visible on host and guests
188
210
  test_files:
189
211
  - features/commands.feature
190
212
  - features/dns_resolution.feature
213
+ - features/docker_provider.feature
191
214
  - features/landrush_ip.feature
192
215
  - features/step_definitions/landrush_custom_steps.rb
193
216
  - features/support/env.rb
@@ -202,8 +225,10 @@ test_files:
202
225
  - test/landrush/config_test.rb
203
226
  - test/landrush/dependent_vms_test.rb
204
227
  - test/landrush/issues/255.rb
228
+ - test/landrush/parallel_store_use_test.rb
205
229
  - test/landrush/server_test.rb
206
230
  - test/landrush/store_test.rb
231
+ - test/landrush/util/dnsmasq_test.rb
207
232
  - test/landrush/util/rety_test.rb
208
233
  - test/support/clear_dependent_vms.rb
209
234
  - test/support/create_fake_working_dir.rb