landrush 0.14.1 → 0.15.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31a10b90a70d8404fbed3044066323382600826b
4
- data.tar.gz: 4455aef5af2dfc204a7612897f400c60f9bf786b
3
+ metadata.gz: ce32119bf22f210583466e45565a25bb76d50c11
4
+ data.tar.gz: 1422b70557f4fb76170b4a234eddf8e151c6ac40
5
5
  SHA512:
6
- metadata.gz: 016a6c53d68daaea9fd7ee7a918c14c02d7b7f84bf271011c2029cdb8882fd973f3e6b1d3a3b825141187d32f7099b3547fef403eec32fafe7500183d14e5694
7
- data.tar.gz: ad09ecd2eb80a60d12fad7c80a94014f4b2eebc5cf9379f7a6730992c0924bea1d5eeeac4be884eba1a21e1a54598cb73597c191328a2b1455878b18a4871f19
6
+ metadata.gz: 4ffb382a44d8bb6812ca230d15d25db1832737888dde303daba4f1c0f67e6e6f03692a4e6d34ca0f2fe0c7ea10d3d08e695d2654b4864ec9469b43f0a7fad1ab
7
+ data.tar.gz: 73f06fab9d25d8c2958b66e1a0390e83c342035ee48b8268fb3dd136fa3052ad99b4efe4bb8dd81fc11298dec3c13390caed8f6fab6fc427847ba6468aa80de5
data/Gemfile CHANGED
@@ -17,4 +17,5 @@ group :development do
17
17
  :ref => 'v1.6.1'
18
18
 
19
19
  gem 'byebug'
20
+ gem 'mocha'
20
21
  end
@@ -1,15 +1,15 @@
1
1
  module Landrush
2
2
  module Cap
3
3
  module Linux
4
- module ConfiguredDnsServer
5
- def self.configured_dns_server(machine)
6
- return @dns_server if @dns_server
4
+ module ConfiguredDnsServers
5
+ def self.configured_dns_servers(machine)
6
+ return @dns_servers if @dns_servers
7
7
  machine.communicate.sudo('cat /etc/resolv.conf | grep ^nameserver') do |type, data|
8
8
  if type == :stdout
9
- @dns_server = data.scan(/\d+\.\d+\.\d+\.\d+/).first
9
+ @dns_servers = Array(data.scan(/\d+\.\d+\.\d+\.\d+/))
10
10
  end
11
11
  end
12
- @dns_server
12
+ @dns_servers
13
13
  end
14
14
  end
15
15
  end
@@ -3,18 +3,17 @@ module Landrush
3
3
  module Linux
4
4
  module RedirectDns
5
5
  def self.redirect_dns(machine, target={})
6
+ dns_servers = machine.guest.capability(:configured_dns_servers)
6
7
  %w[tcp udp].each do |proto|
7
- machine.guest.capability(
8
- :add_iptables_rule,
9
- _redirect_dns_rule(proto, _current(machine), target.fetch(:host), target.fetch(:port))
10
- )
8
+ dns_servers.each do |dns_server|
9
+ machine.guest.capability(
10
+ :add_iptables_rule,
11
+ _redirect_dns_rule(proto, dns_server, target.fetch(:host), target.fetch(:port))
12
+ )
13
+ end
11
14
  end
12
15
  end
13
16
 
14
- def self._current(machine)
15
- machine.guest.capability(:configured_dns_server)
16
- end
17
-
18
17
  def self._redirect_dns_rule(protocol, original_server, target_server, target_port)
19
18
  "OUTPUT -t nat -p #{protocol} -d #{original_server} --dport 53 -j DNAT --to-destination #{target_server}:#{target_port}"
20
19
  end
@@ -1,3 +1,3 @@
1
1
  module Landrush
2
- VERSION = "0.14.1"
2
+ VERSION = "0.15.0"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ describe Landrush::Cap::Linux::ConfiguredDnsServers do
4
+ let(:machine) { fake_machine }
5
+
6
+ before do
7
+ Landrush::Cap::Linux::ConfiguredDnsServers.instance_variable_set("@dns_servers", nil)
8
+ end
9
+
10
+ describe 'configured_dns_servers' do
11
+ it 'parses out a single resolv.conf dns server' do
12
+ machine.communicate.stubs(:sudo).yields(:stdout, "nameserver 12.23.34.45")
13
+
14
+ dns_servers = Landrush::Cap::Linux::ConfiguredDnsServers.configured_dns_servers(machine)
15
+
16
+ dns_servers.must_equal(["12.23.34.45"])
17
+ end
18
+
19
+ it 'parses out multiple the resolv.conf dns servers' do
20
+ machine.communicate.stubs(:sudo).yields(:stdout, [
21
+ "nameserver 12.23.34.45",
22
+ "nameserver 45.34.23.12",
23
+ ].join("\n"))
24
+
25
+ dns_servers = Landrush::Cap::Linux::ConfiguredDnsServers.configured_dns_servers(machine)
26
+
27
+ dns_servers.must_equal([
28
+ "12.23.34.45",
29
+ "45.34.23.12",
30
+ ])
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe Landrush::Cap::Linux::RedirectDns do
4
+ let(:machine) { fake_machine }
5
+
6
+ describe 'redirect_dns' do
7
+ it 'fetches the dns servers from the machine, and adds one iptables rule per server' do
8
+ machine.guest.stubs(:capability).with(:configured_dns_servers).returns([
9
+ '1.2.3.4',
10
+ '4.5.6.7'
11
+ ])
12
+
13
+ machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p tcp -d 1.2.3.4 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
14
+ machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p udp -d 1.2.3.4 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
15
+ machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p tcp -d 4.5.6.7 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
16
+ machine.guest.expects(:capability).with(:add_iptables_rule, "OUTPUT -t nat -p udp -d 4.5.6.7 --dport 53 -j DNAT --to-destination 2.3.4.5:4321").once
17
+
18
+ Landrush::Cap::Linux::RedirectDns.redirect_dns(
19
+ machine,
20
+ host: '2.3.4.5',
21
+ port: '4321',
22
+ )
23
+ end
24
+ end
25
+ end
data/test/test_helper.rb CHANGED
@@ -4,9 +4,12 @@ require 'bundler/setup'
4
4
  require 'minitest/spec'
5
5
 
6
6
  require 'landrush'
7
+ require 'landrush/cap/linux/configured_dns_servers'
7
8
  require 'landrush/cap/linux/read_host_visible_ip_address'
9
+ require 'landrush/cap/linux/redirect_dns'
8
10
 
9
11
  require 'minitest/autorun'
12
+ require 'mocha/mini_test'
10
13
 
11
14
  def fake_environment(options = { enabled: true })
12
15
  { machine: fake_machine(options), ui: FakeUI }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: landrush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.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: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubydns
@@ -66,7 +66,7 @@ files:
66
66
  - lib/landrush/cap/debian/install_iptables.rb
67
67
  - lib/landrush/cap/debian/iptables_installed.rb
68
68
  - lib/landrush/cap/linux/add_iptables_rule.rb
69
- - lib/landrush/cap/linux/configured_dns_server.rb
69
+ - lib/landrush/cap/linux/configured_dns_servers.rb
70
70
  - lib/landrush/cap/linux/read_host_visible_ip_address.rb
71
71
  - lib/landrush/cap/linux/redirect_dns.rb
72
72
  - lib/landrush/cap/redhat/install_iptables.rb
@@ -81,7 +81,9 @@ files:
81
81
  - lib/landrush/version.rb
82
82
  - test/landrush/action/setup_test.rb
83
83
  - test/landrush/action/teardown_test.rb
84
+ - test/landrush/cap/linux/configured_dns_servers_test.rb
84
85
  - test/landrush/cap/linux/read_host_visible_ip_address_test.rb
86
+ - test/landrush/cap/linux/redirect_dns_test.rb
85
87
  - test/landrush/config_test.rb
86
88
  - test/landrush/dependent_vms_test.rb
87
89
  - test/landrush/resolver_config_test.rb
@@ -120,7 +122,9 @@ summary: a vagrant plugin providing consistent DNS visible on host and guests
120
122
  test_files:
121
123
  - test/landrush/action/setup_test.rb
122
124
  - test/landrush/action/teardown_test.rb
125
+ - test/landrush/cap/linux/configured_dns_servers_test.rb
123
126
  - test/landrush/cap/linux/read_host_visible_ip_address_test.rb
127
+ - test/landrush/cap/linux/redirect_dns_test.rb
124
128
  - test/landrush/config_test.rb
125
129
  - test/landrush/dependent_vms_test.rb
126
130
  - test/landrush/resolver_config_test.rb