landrush 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/landrush/cap/linux/{configured_dns_server.rb → configured_dns_servers.rb} +5 -5
- data/lib/landrush/cap/linux/redirect_dns.rb +7 -8
- data/lib/landrush/version.rb +1 -1
- data/test/landrush/cap/linux/configured_dns_servers_test.rb +33 -0
- data/test/landrush/cap/linux/redirect_dns_test.rb +25 -0
- data/test/test_helper.rb +3 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce32119bf22f210583466e45565a25bb76d50c11
|
4
|
+
data.tar.gz: 1422b70557f4fb76170b4a234eddf8e151c6ac40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ffb382a44d8bb6812ca230d15d25db1832737888dde303daba4f1c0f67e6e6f03692a4e6d34ca0f2fe0c7ea10d3d08e695d2654b4864ec9469b43f0a7fad1ab
|
7
|
+
data.tar.gz: 73f06fab9d25d8c2958b66e1a0390e83c342035ee48b8268fb3dd136fa3052ad99b4efe4bb8dd81fc11298dec3c13390caed8f6fab6fc427847ba6468aa80de5
|
data/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Landrush
|
2
2
|
module Cap
|
3
3
|
module Linux
|
4
|
-
module
|
5
|
-
def self.
|
6
|
-
return @
|
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
|
-
@
|
9
|
+
@dns_servers = Array(data.scan(/\d+\.\d+\.\d+\.\d+/))
|
10
10
|
end
|
11
11
|
end
|
12
|
-
@
|
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
|
-
|
8
|
-
|
9
|
-
|
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
|
data/lib/landrush/version.rb
CHANGED
@@ -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.
|
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-
|
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/
|
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
|