vagrant-auto_network 1.0.0 → 1.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG +14 -0
- data/Gemfile +1 -1
- data/lib/auto_network/action/filter_networks.rb +10 -1
- data/lib/auto_network/action/request.rb +17 -7
- data/lib/auto_network/settings.rb +2 -2
- data/lib/auto_network/version.rb +1 -1
- data/spec/integration/legacy_spec.rb +0 -5
- data/spec/integration/plugin_spec.rb +32 -11
- data/spec/integration/shared/auto_network_0x_context.rb +3 -32
- data/spec/integration/shared/auto_network_1x_context.rb +6 -33
- data/spec/integration/shared/auto_network_integration_context.rb +84 -0
- metadata +3 -3
- data/spec/integration/shared/isolated_settings_context.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c4da4f0bee53e5b39ea4bd507e11166a7b56e0
|
4
|
+
data.tar.gz: a35c80d6ad5fe095c669ab317f997717e382077b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65765f2eec79a431f740eeb2ad805f513eaa2eee7d35da0c98a0881c0a369e8fd5654715cdebf838d74c2d0e25b170a151ff46d77655ba1cb1c2253ad454ae0b
|
7
|
+
data.tar.gz: 9227ad6e275f71921a88019851773e86f8bdffec965555e3d525df221293c9cb507efe01de936a0e4a485015cc2cac8579623badad469f0d6e90c75a28026875
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
vagrant-auto_network
|
2
2
|
====================
|
3
3
|
|
4
|
+
1.0.1
|
5
|
+
-----
|
6
|
+
|
7
|
+
2014-06-06
|
8
|
+
|
9
|
+
This is a backwards compatible bugfix release.
|
10
|
+
|
11
|
+
* (GH-23) Fix crashes occurring when a VM has a pre-allocated AutoNetwork IP
|
12
|
+
address.
|
13
|
+
|
14
|
+
* Fix errors raised when a machine exists in the `.vagrant` directory
|
15
|
+
but no longer has a config in the `Vagrantfile`.
|
16
|
+
|
17
|
+
|
4
18
|
1.0.0
|
5
19
|
-----
|
6
20
|
|
data/Gemfile
CHANGED
@@ -33,7 +33,16 @@ class AutoNetwork::Action::FilterNetworks < AutoNetwork::Action::Base
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def machines_for_env
|
36
|
-
@global_env.active_machines.map
|
36
|
+
@global_env.active_machines.map do |vm_id|
|
37
|
+
begin
|
38
|
+
@global_env.machine(*vm_id)
|
39
|
+
rescue Vagrant::Errors::MachineNotFound
|
40
|
+
# This usually happens when the definition for a machine has been
|
41
|
+
# removed from the Vagrantfile, but the machine id still exists under
|
42
|
+
# the .vagrant directory.
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end.compact
|
37
46
|
end
|
38
47
|
|
39
48
|
def assign_address(machine)
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'auto_network/action/base'
|
2
2
|
|
3
|
+
|
4
|
+
# @todo This action should be renamed. It is more like a "pre-validation
|
5
|
+
# filter" than something that only fires during machine creation.
|
3
6
|
class AutoNetwork::Action::Request < AutoNetwork::Action::Base
|
4
7
|
# Request an auto_network IP address on VM creation
|
5
8
|
#
|
@@ -12,20 +15,27 @@ class AutoNetwork::Action::Request < AutoNetwork::Action::Base
|
|
12
15
|
def call(env)
|
13
16
|
@env = env
|
14
17
|
|
15
|
-
|
18
|
+
machine = @env[:machine]
|
19
|
+
|
20
|
+
# Move along if this machine has no AutoNetwork interfaces.
|
21
|
+
@app.call(@env) if machine_auto_networks(machine).empty?
|
22
|
+
|
23
|
+
addr = AutoNetwork.active_pool_manager.address_for(machine)
|
24
|
+
if addr.nil?
|
25
|
+
addr = AutoNetwork.active_pool_manager.request(machine)
|
26
|
+
@env[:ui].info "AutoNetwork assigning #{addr.inspect} to '#{machine.name}'",
|
27
|
+
:prefix => true
|
28
|
+
end
|
16
29
|
|
17
|
-
|
30
|
+
filter_networks(machine, addr)
|
18
31
|
|
19
32
|
@app.call(@env)
|
20
33
|
end
|
21
34
|
|
22
35
|
private
|
23
36
|
|
24
|
-
def
|
25
|
-
machine_auto_networks(
|
26
|
-
addr = AutoNetwork.active_pool_manager.request(@machine)
|
27
|
-
@env[:ui].info "AutoNetwork assigning #{addr.inspect} to '#{@machine.name}'",
|
28
|
-
:prefix => true
|
37
|
+
def filter_networks(machine, addr)
|
38
|
+
machine_auto_networks(machine).each do |net|
|
29
39
|
filter_private_network(net, addr)
|
30
40
|
end
|
31
41
|
end
|
@@ -33,7 +33,7 @@ module AutoNetwork
|
|
33
33
|
unless manager.is_a?(AutoNetwork::PoolManager)
|
34
34
|
raise InvalidSettingErrror,
|
35
35
|
:setting_name => 'pool_manager',
|
36
|
-
:value => manager
|
36
|
+
:value => manager.inspect
|
37
37
|
end
|
38
38
|
|
39
39
|
manager
|
@@ -64,7 +64,7 @@ module AutoNetwork
|
|
64
64
|
rescue ArgumentError
|
65
65
|
raise InvalidSettingErrror,
|
66
66
|
:setting_name => 'default_pool',
|
67
|
-
:value => pool
|
67
|
+
:value => pool.inspect
|
68
68
|
end
|
69
69
|
|
70
70
|
@default_pool = pool
|
data/lib/auto_network/version.rb
CHANGED
@@ -2,13 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require_relative 'shared/auto_network_0x_context'
|
3
3
|
|
4
4
|
describe 'Working with AutoNetwork 0.x data' do
|
5
|
-
include_context 'vagrant-unit'
|
6
5
|
include_context 'auto_network 0.x'
|
7
6
|
|
8
|
-
def current_ip(machine)
|
9
|
-
settings.pool_manager.with_pool_for(machine) {|p| p.address_for(machine)}
|
10
|
-
end
|
11
|
-
|
12
7
|
before(:each) do
|
13
8
|
env = test_env.create_vagrant_env
|
14
9
|
@test_machine = env.machine(:test1, :dummy)
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require_relative 'shared/auto_network_1x_context'
|
3
3
|
|
4
4
|
describe AutoNetwork::Plugin do
|
5
|
-
include_context 'vagrant-unit'
|
6
5
|
include_context 'auto_network 1.x'
|
7
6
|
|
8
7
|
context 'when a vagrant environment is initialized' do
|
@@ -24,10 +23,6 @@ describe AutoNetwork::Plugin do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
context 'when destroying a machine' do
|
27
|
-
def current_ip(machine)
|
28
|
-
settings.pool_manager.with_pool_for(machine) {|p| p.address_for(machine)}
|
29
|
-
end
|
30
|
-
|
31
26
|
it 'releases the allocated IP address' do
|
32
27
|
env = test_env.create_vagrant_env
|
33
28
|
test_machine = env.machine(:test1, :dummy)
|
@@ -40,12 +35,38 @@ describe AutoNetwork::Plugin do
|
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
describe 'when running the request action' do
|
39
|
+
subject {
|
40
|
+
Vagrant::Action::Builder.new.tap {|b| b.use AutoNetwork::Action::Request }
|
41
|
+
}
|
42
|
+
|
43
|
+
context 'on a machine with no IP allocated' do
|
44
|
+
it 'allocates an IP address' do
|
45
|
+
env = test_env.create_vagrant_env
|
46
|
+
test_machine = env.machine(:test2, :dummy)
|
47
|
+
|
48
|
+
expect(current_ip(test_machine)).to be_nil
|
49
|
+
|
50
|
+
# This emulates Machine#action_raw which didn't show up until
|
51
|
+
# Vagrant 1.6.0
|
52
|
+
action_env = { :machine => test_machine }
|
53
|
+
env.action_runner.run(subject, action_env)
|
54
|
+
|
55
|
+
expect(current_ip(test_machine)).to eq('10.20.1.3')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'on a machine with an allocated IP address' do
|
60
|
+
it 'assigns the address to unfiltered network interfaces' do
|
61
|
+
env = test_env.create_vagrant_env
|
62
|
+
test_machine = env.machine(:test3, :dummy)
|
63
|
+
|
64
|
+
action_env = { :machine => test_machine }
|
65
|
+
env.action_runner.run(subject, action_env)
|
66
|
+
|
67
|
+
_, network_opts = test_machine.config.vm.networks.find {|n| n.first == :private_network}
|
68
|
+
expect(network_opts).to include(:ip => '10.20.1.4')
|
69
|
+
end
|
49
70
|
end
|
50
71
|
end
|
51
72
|
end
|
@@ -1,19 +1,9 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'auto_network_integration_context'
|
2
2
|
|
3
3
|
# Creates an environment for each test containing data that would have been
|
4
4
|
# created by an installation of AutoNetwork 0.x.
|
5
5
|
shared_context 'auto_network 0.x' do
|
6
|
-
|
7
|
-
include_context 'auto_network-settings'
|
8
|
-
|
9
|
-
# Configure each testing environment to contain an AutoNetwork version 1 pool
|
10
|
-
# file and a single existing machine that has been allocated in the pool
|
11
|
-
let(:test_env) { isolated_environment }
|
12
|
-
let(:pool_file) { test_env.homedir.join('auto_network', 'pool.yaml') }
|
13
|
-
before(:each) do
|
14
|
-
pool_file.dirname.mkpath
|
15
|
-
pool_file.open('w+') do |f|
|
16
|
-
f.write <<-EOF
|
6
|
+
let(:pool_file_content) { <<-EOF }
|
17
7
|
--- !ruby/object:AutoNetwork::Pool
|
18
8
|
network_range: 10.20.1.0/29
|
19
9
|
pool:
|
@@ -22,27 +12,8 @@ pool:
|
|
22
12
|
10.20.1.4:
|
23
13
|
10.20.1.5:
|
24
14
|
10.20.1.6:
|
25
|
-
EOF
|
26
|
-
end
|
27
|
-
|
28
|
-
test_env.vagrantfile <<-EOF
|
29
|
-
Vagrant.configure("2") do |config|
|
30
|
-
config.vm.define 'test1' do |node|
|
31
|
-
node.vm.network :private_network, :auto_network => true
|
32
|
-
end
|
33
|
-
end
|
34
15
|
EOF
|
35
16
|
|
36
|
-
|
37
|
-
# component of the path actually tells Vagrant which provider is managing
|
38
|
-
# the machine. vagrant-spec defines a dummy provider for us.
|
39
|
-
machine_dir = test_env.workdir.join('.vagrant/machines/test1/dummy')
|
40
|
-
machine_dir.mkpath
|
41
|
-
machine_dir.join('id').open('w+') { |f| f.write('some-uuid-string') }
|
42
|
-
end
|
17
|
+
include_context 'auto_network integration'
|
43
18
|
|
44
|
-
# Dispose of the temporary directory used to run the test.
|
45
|
-
after(:each) do
|
46
|
-
test_env.close
|
47
|
-
end
|
48
19
|
end
|
@@ -1,19 +1,9 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'auto_network_integration_context'
|
2
2
|
|
3
3
|
# Creates an environment for each test containing a small pool of AutoNetwork
|
4
|
-
# addresses
|
4
|
+
# addresses.
|
5
5
|
shared_context 'auto_network 1.x' do
|
6
|
-
|
7
|
-
include_context 'auto_network-settings'
|
8
|
-
|
9
|
-
# Configure each testing environment to contain an AutoNetwork version 2 pool
|
10
|
-
# file and a single existing machine that has been allocated in the pool
|
11
|
-
let(:test_env) { isolated_environment }
|
12
|
-
let(:pool_file) { test_env.homedir.join('auto_network', 'pool.yaml') }
|
13
|
-
before(:each) do
|
14
|
-
pool_file.dirname.mkpath
|
15
|
-
pool_file.open('w+') do |f|
|
16
|
-
f.write <<-EOF
|
6
|
+
let(:pool_file_content) { <<-EOF }
|
17
7
|
---
|
18
8
|
poolfile_version: 2
|
19
9
|
pools:
|
@@ -25,29 +15,12 @@ pools:
|
|
25
15
|
name: test1
|
26
16
|
10.20.1.3:
|
27
17
|
10.20.1.4:
|
18
|
+
path: #{test_env.workdir}
|
19
|
+
name: test3
|
28
20
|
10.20.1.5:
|
29
21
|
10.20.1.6:
|
30
|
-
EOF
|
31
|
-
end
|
32
|
-
|
33
|
-
test_env.vagrantfile <<-EOF
|
34
|
-
Vagrant.configure("2") do |config|
|
35
|
-
config.vm.define 'test1' do |node|
|
36
|
-
node.vm.network :private_network, :auto_network => true
|
37
|
-
end
|
38
|
-
end
|
39
22
|
EOF
|
40
23
|
|
41
|
-
|
42
|
-
# component of the path actually tells Vagrant which provider is managing
|
43
|
-
# the machine. vagrant-spec defines a dummy provider for us.
|
44
|
-
machine_dir = test_env.workdir.join('.vagrant/machines/test1/dummy')
|
45
|
-
machine_dir.mkpath
|
46
|
-
machine_dir.join('id').open('w+') { |f| f.write('') }
|
47
|
-
end
|
24
|
+
include_context 'auto_network integration'
|
48
25
|
|
49
|
-
# Dispose of the temporary directory used to run the test.
|
50
|
-
after(:each) do
|
51
|
-
test_env.close
|
52
|
-
end
|
53
26
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# This context leverages the vagrant-spec library to set up isolated Vagrant
|
2
|
+
# Environments in which integration tests can be run. Some additions are made
|
3
|
+
# to the stop unit testing environment:
|
4
|
+
#
|
5
|
+
# - The global AutoNetwork::Settings instance is stubbed such that a new
|
6
|
+
# settings instance is created for each test.
|
7
|
+
#
|
8
|
+
# - An AutoNetwork pool file is added to each environment.
|
9
|
+
#
|
10
|
+
# - A Vagrantfile and collection of machines are added that use AutoNetwork.
|
11
|
+
#
|
12
|
+
# This context can not be used directly. Instead, include one of the
|
13
|
+
# version-specific contexts:
|
14
|
+
#
|
15
|
+
# - auto_network 1.x
|
16
|
+
# - auto_network 0.x
|
17
|
+
shared_context 'auto_network integration' do
|
18
|
+
include_context 'vagrant-unit'
|
19
|
+
|
20
|
+
# Create a Dummy settings module for each test.
|
21
|
+
let(:settings) {
|
22
|
+
Module.new do
|
23
|
+
extend AutoNetwork::Settings
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
# Stub the settings attached to the AutoNetwork module so we don't change
|
28
|
+
# global state during tests.
|
29
|
+
before(:each) do
|
30
|
+
allow(AutoNetwork).to receive(:pool_manager=) do |pool_manager|
|
31
|
+
settings.pool_manager = pool_manager
|
32
|
+
end
|
33
|
+
allow(AutoNetwork).to receive(:pool_manager).and_return { settings.pool_manager }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Configure each testing environment to include an AutoNetwork pool file and
|
37
|
+
# some machine definitions.
|
38
|
+
let(:test_env) { isolated_environment }
|
39
|
+
let(:pool_file) { test_env.homedir.join('auto_network', 'pool.yaml') }
|
40
|
+
before(:each) do
|
41
|
+
pool_file.dirname.mkpath
|
42
|
+
# The actual contents of the poolfile are defined in the version-specific
|
43
|
+
# contexts.
|
44
|
+
pool_file.open('w+') {|f| f.write pool_file_content}
|
45
|
+
|
46
|
+
# Three machines are defined:
|
47
|
+
#
|
48
|
+
# - test1 has an IP allocated in the pool and an ID allocated in the
|
49
|
+
# `.vagrant` directory.
|
50
|
+
#
|
51
|
+
# - test2 has no IP or ID allocated.
|
52
|
+
#
|
53
|
+
# - test3 has an allocated IP, but no ID.
|
54
|
+
test_env.vagrantfile <<-EOF
|
55
|
+
Vagrant.configure("2") do |config|
|
56
|
+
%w[test1 test2 test3].each do |machine|
|
57
|
+
config.vm.define machine do |node|
|
58
|
+
node.vm.network :private_network, :auto_network => true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
EOF
|
63
|
+
|
64
|
+
# Touch an ID file so that Vagrant thinks test1 exists. The 'dummy'
|
65
|
+
# component of the path actually tells Vagrant which provider is managing
|
66
|
+
# the machine. vagrant-spec defines a dummy provider for us.
|
67
|
+
machine_dir = test_env.workdir.join('.vagrant/machines/test1/dummy')
|
68
|
+
machine_dir.mkpath
|
69
|
+
machine_dir.join('id').open('w+') { |f| f.write('some-uuid-string') }
|
70
|
+
end
|
71
|
+
|
72
|
+
# Dispose of the temporary Vagrant Environment used to run the test.
|
73
|
+
after(:each) do
|
74
|
+
test_env.close
|
75
|
+
end
|
76
|
+
|
77
|
+
# A helper for grabbing the IP allocated to a machine.
|
78
|
+
#
|
79
|
+
# TODO: This should probably be in a general utility module under the
|
80
|
+
# AutoNetwork namespace.
|
81
|
+
def current_ip(machine)
|
82
|
+
settings.pool_manager.with_pool_for(machine) {|p| p.address_for(machine)}
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-auto_network
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Thebo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- spec/integration/plugin_spec.rb
|
75
75
|
- spec/integration/shared/auto_network_0x_context.rb
|
76
76
|
- spec/integration/shared/auto_network_1x_context.rb
|
77
|
-
- spec/integration/shared/
|
77
|
+
- spec/integration/shared/auto_network_integration_context.rb
|
78
78
|
- spec/spec_helper.rb
|
79
79
|
- spec/unit/pool_spec.rb
|
80
80
|
- spec/unit/settings_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
shared_context 'auto_network-settings' do
|
2
|
-
# Create a Dummy settings module for each test.
|
3
|
-
let(:settings) {
|
4
|
-
Module.new do
|
5
|
-
extend AutoNetwork::Settings
|
6
|
-
end
|
7
|
-
}
|
8
|
-
|
9
|
-
# Stub the settings attached to the AutoNetwork module so we don't change
|
10
|
-
# global state during tests.
|
11
|
-
before(:each) do
|
12
|
-
allow(AutoNetwork).to receive(:pool_manager=) do |pool_manager|
|
13
|
-
settings.pool_manager = pool_manager
|
14
|
-
end
|
15
|
-
allow(AutoNetwork).to receive(:pool_manager).and_return { settings.pool_manager }
|
16
|
-
end
|
17
|
-
end
|