Skip to content

Commit

Permalink
Issue vagrant-landrush#171 Adding test harness. Experimenting with VB…
Browse files Browse the repository at this point in the history
…oxManage
  • Loading branch information
Hardy Ferentschik authored and hferentschik committed Jun 23, 2016
1 parent 5007fef commit 97af5f8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 197 deletions.
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Bundler
Gemfile.lock
.bundle

# Ruby / RVM
.ruby-gemset
.ruby-version
*.rbc
.bundle

# Rake / Build
.yardoc
InstalledFiles
_yardoc
coverage
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
build
tmp
tags

.vagrant

# IDE
*.iml
.idea
175 changes: 0 additions & 175 deletions Gemfile.lock

This file was deleted.

8 changes: 7 additions & 1 deletion lib/landrush/action/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ def record_dependent_vm
end

def setup_host_resolver
ResolverConfig.new(env).ensure_config_exists!
if Vagrant::Util::Platform.windows?
WinNetworkConfig.new(env)
elsif Vagrant::Util::Platform.darwin?
ResolverConfig.new(env).ensure_config_exists!
else
#TODO
end
end

def add_prerequisite_network_interface
Expand Down
10 changes: 3 additions & 7 deletions lib/landrush/resolver_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ def desired_contents; <<-EOS.gsub(/^ /, '')
EOS
end

def osx?
`uname`.chomp == 'Darwin'
end

def config_dir
self.class.config_dir
end
Expand All @@ -46,7 +42,7 @@ def contents_match?
end

def write_config!
info "Momentarily using sudo to put the host config in place..."
info 'Momentarily using sudo to put the host config in place...'
system "#{self.class.sudo} mkdir #{config_dir}" unless config_dir.directory?
Tempfile.open('vagrant_landrush_host_config') do |f|
f.write(desired_contents)
Expand All @@ -58,9 +54,9 @@ def write_config!

def ensure_config_exists!
if contents_match?
info "Host DNS resolver config looks good."
info 'Host DNS resolver config looks good.'
else
info "Need to configure the host."
info 'Need to configure the host.'
write_config!
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'win32/registry'

module Landrush
class RegistryConfig
class WinNetworkConfig

# Windows registry path under which network interface configuration is stored
INTERFACES = 'SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces'
Expand All @@ -17,8 +17,7 @@ def initialize(env={})
@env = env
end

def info(msg)
@env[:ui].info("[landrush] #{msg}")
def configure_network_adapter
end

def self.update_network_adapter ip
Expand Down Expand Up @@ -76,5 +75,5 @@ def self.registry_key_exists?(path, key)
# instead of having been required or loaded by another file
if __FILE__ == $0
# TODO, Add some argument checks
Landrush::RegistryConfig.update_network_adapter ARGV[0]
Landrush::WinNetworkConfig.update_network_adapter ARGV[0]
end
2 changes: 0 additions & 2 deletions test/landrush/resolver_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module Landrush
describe 'ensure_config_exists' do
it 'writes a resolver config on the host if one is not already there' do
resolver_config = ResolverConfig.new(fake_environment)
skip("Only supported on OSX") unless resolver_config.osx?

resolver_config.config_file.exist?.must_equal false
resolver_config.ensure_config_exists!
resolver_config.config_file.exist?.must_equal true
Expand Down
31 changes: 31 additions & 0 deletions test/landrush/win_network_config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative '../test_helper'

VBOXMANAGE_BINARY = 'C:\\DeveloperPlatform\\virtualbox\\VBoxManage'
module Landrush
describe WinNetworkConfig do
before do
created_interface = `#{VBOXMANAGE_BINARY} hostonlyif create`
p "#{created_interface}"
end

after do
#delete_interface = `C:\\DeveloperPlatform\\virtualbox\\VBoxManage hostonlyif remove \"#{name}\"`
#p "#{delete_interface}"
end

describe 'create network interface' do
it 'a network interface with the required DNS settings is created' do
skip('Only supported on Windows') unless Vagrant::Util::Platform.windows?

# netsh interface ip show config name="VirtualBox Host-Only Network #3"
# netsh interface ip show ipaddresses interface="VirtualBox Host-Only Network #3"

#network_config = WinNetworkConfig.new(fake_environment)

#WinNetworkConfig.update_network_adapter '10.1.2.1'
#WinNetworkConfig.create_network_adapter
#WinNetworkConfig.delete_network_adapter 'VirtualBox Host-Only Ethernet Adapter #2'
end
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'landrush/cap/linux/configured_dns_servers'
require 'landrush/cap/linux/redirect_dns'
require 'landrush/cap/all/read_host_visible_ip_address'
require 'landrush/win_network_config'

require 'minitest/autorun'
require 'mocha/mini_test'
Expand Down

0 comments on commit 97af5f8

Please sign in to comment.