vagrant-auto_network 1.0.0.beta1 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d671793aef1384eda1a6563c8c5c82fb5ef080f
4
- data.tar.gz: d1e246dfdc649d07761ae4d778557ff796fb66af
3
+ metadata.gz: f95b22bf6a47ec537f8006cc11b3c3f3997507eb
4
+ data.tar.gz: 6c54bb78892dfca504042ccfd29d69fe9a7e7ca2
5
5
  SHA512:
6
- metadata.gz: de702cdcb9d60ab2d1f55116b9a6d7a4cd4f392892e49fba9ae4764c87fe2c0024e6916f439f963e2bec84b77d568a6b73bef3abd427e1f0a1499bb19a7a8d77
7
- data.tar.gz: e83c9eb3a06775ccf5fa59e5ab837a6d05f767f36babc1ce9ee7a5f08a1826a7ea18107df9df2df230032cc792cb377fc1da20e67538b1c53ada63f0b1c64e5d
6
+ metadata.gz: 6f54e0c340517c61c20969df5fd69cc4d40757ab2f355a053c5de4b1a14bc2794c8585fae6fd50d6975d5d9a2a5cd12bfc75cc83e1d43ed1f4440dd1b1d1378c
7
+ data.tar.gz: f3d2054ae710fd14231ae1ff7e3f2c058f717d468a284244f74b059bb0c4ad5b3979e35e07582013740869e8ccc3d88a2ebb76ae08f29a4991e85e515e9e184d
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle
2
+ .yardoc
3
+ Gemfile.local
4
+ Gemfile.lock
5
+ acceptance/artifacts
6
+ coverage
7
+ doc
data/CHANGELOG CHANGED
@@ -4,7 +4,7 @@ vagrant-auto_network
4
4
  1.0.0
5
5
  -----
6
6
 
7
- 2014-05-05
7
+ Unreleased
8
8
 
9
9
  This is a mostly-backwards compatible feature release.
10
10
 
@@ -26,6 +26,26 @@ Specifically, the following issues have been addressed:
26
26
  storage mechanism that offers more resiliance to race conditions and data
27
27
  loss from aborted actions.
28
28
 
29
+ * (GH-14) Remove depreciated AutoNetwork mixin module.
30
+
31
+ 1.0.0.beta2
32
+ -----------
33
+
34
+ 2014-05-09
35
+
36
+ Bug Fixes:
37
+
38
+ * (GH-20) Compatibility fixes for Vagrant 1.6
39
+
40
+ * Ensure directories exist when creating `pool.yaml` for the first time.
41
+
42
+ 1.0.0.beta1
43
+ -----------
44
+
45
+ 2014-05-05
46
+
47
+ First beta release of AutoNetwork 1.0.0.
48
+
29
49
 
30
50
  0.2.2
31
51
  -----
data/Gemfile CHANGED
@@ -1,10 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
  ruby '2.0.0'
3
3
 
4
- gemspec
4
+ # Using the :plugins group causes Vagrant to automagially load auto_network
5
+ # during acceptance tests.
6
+ group :plugins do
7
+ gemspec
8
+ end
5
9
 
6
10
  group :development do
7
11
  gem 'vagrant', :github => 'mitchellh/vagrant', :tag => 'v1.5.4'
12
+ # Pinned on 05/05/2014.
13
+ gem 'vagrant-spec', :github => 'mitchellh/vagrant-spec', :ref => 'aae28ee'
14
+ gem 'rake'
8
15
  end
9
16
 
10
17
  if File.exists? "#{__FILE__}.local"
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ task_dir = File.expand_path("../tasks", __FILE__)
2
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
3
+ load task_file
4
+ end
@@ -0,0 +1,33 @@
1
+ shared_examples 'provider/auto_network' do |provider, options|
2
+ if !File.file?(options[:box])
3
+ raise ArgumentError,
4
+ "A box file must be downloaded for provider: #{provider}. Try: rake acceptance:setup"
5
+ end
6
+
7
+ include_context 'acceptance'
8
+ let(:extra_env) { options[:env_vars] }
9
+
10
+ before do
11
+ environment.skeleton('auto_network')
12
+ assert_execute('vagrant', 'box', 'add', 'box', options[:box])
13
+ end
14
+
15
+ after do
16
+ # Ensure any VMs that survived tests are cleaned up.
17
+ execute('vagrant', 'destroy', '--force', log: false)
18
+ end
19
+
20
+ # NOTE: This is a bit tightly coupled as it strings together tests for
21
+ # vagrant up, status, reload and destroy in a single case. However, each
22
+ # invocation is dependant on the state created by the prior command.
23
+ it 'manages IP address allocation for the lifecycle of a VM' do
24
+ result = assert_execute('vagrant', 'up', "--provider=#{provider}")
25
+ expect(result.stdout).to match(/Assigning "\S+" to 'default'/)
26
+
27
+ assert_execute('vagrant', 'status')
28
+ assert_execute('vagrant', 'reload', 'default')
29
+
30
+ result = assert_execute('vagrant', 'destroy', '--force')
31
+ expect(result.stdout).to match(/Releasing "\S+" from default/)
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ # If this test is being run on a host that also uses auto_network in a normal
2
+ # Vagrant environment then there will already be network interfaces listening.
3
+ # Most likely in the range of 10.20.0.0/16. The following environment variable
4
+ # is set per-provider in the vagrant-spec config.
5
+ AutoNetwork.default_pool = ENV["AUTO_NETWORK_TEST_RANGE"]
6
+
7
+ Vagrant.configure('2') do |config|
8
+ config.vm.provider 'virtualbox' do |vb|
9
+ # Clean up network interface after tests.
10
+ vb.destroy_unused_network_interfaces = true
11
+ end
12
+
13
+ config.vm.box = 'box'
14
+ config.vm.network 'private_network', :auto_network => true
15
+ end
@@ -23,7 +23,6 @@ class AutoNetwork::Action::FilterNetworks
23
23
  def call(env)
24
24
  @env = env
25
25
 
26
- @pool = @env[:auto_network_pool]
27
26
  @global_env = @env[:env]
28
27
 
29
28
  filter if has_working_env?
@@ -49,7 +48,7 @@ class AutoNetwork::Action::FilterNetworks
49
48
 
50
49
  def assign_address(machine)
51
50
  machine_auto_networks(machine).each do |net|
52
- addr = @pool.address_for(machine)
51
+ addr = AutoNetwork.pool_manager.address_for(machine)
53
52
  @logger.info "Reassigning #{addr.inspect} to existing machine #{machine.name}"
54
53
  filter_private_network(net, addr)
55
54
  end
@@ -20,7 +20,7 @@ class AutoNetwork::Action::LoadPool
20
20
 
21
21
  if env_ready?
22
22
  setup_ivars
23
- deserialize!
23
+ deserialize! if AutoNetwork.pool_manager.nil?
24
24
  @app.call(@env)
25
25
  else
26
26
  @app.call(@env)
@@ -30,15 +30,15 @@ class AutoNetwork::Action::LoadPool
30
30
  private
31
31
 
32
32
  def env_ready?
33
- !!@env[:home_path]
33
+ !!@env[:env].home_path
34
34
  end
35
35
 
36
36
  def setup_ivars
37
- @config_path = @env[:home_path].join('auto_network')
37
+ @config_path = @env[:env].home_path.join('auto_network')
38
38
  @statefile = @config_path.join('pool.yaml')
39
39
  end
40
40
 
41
41
  def deserialize!
42
- @env[:auto_network_pool] = AutoNetwork::PoolManager.new(@statefile)
42
+ AutoNetwork.pool_manager = AutoNetwork::PoolManager.new(@statefile)
43
43
  end
44
44
  end
@@ -20,7 +20,6 @@ class AutoNetwork::Action::Release
20
20
  @env = env
21
21
 
22
22
  @machine = @env[:machine]
23
- @pool = @env[:auto_network_pool]
24
23
 
25
24
  release_network_addresses if machine_has_address?(@machine)
26
25
 
@@ -30,8 +29,8 @@ class AutoNetwork::Action::Release
30
29
  private
31
30
 
32
31
  def release_network_addresses
33
- addr = @pool.address_for(@machine)
32
+ addr = AutoNetwork.pool_manager.address_for(@machine)
34
33
  @env[:ui].info "Releasing #{addr.inspect} from #{@machine.name}", :prefix => true
35
- @pool.release(@machine)
34
+ AutoNetwork.pool_manager.release(@machine)
36
35
  end
37
36
  end
@@ -19,7 +19,6 @@ class AutoNetwork::Action::Request
19
19
  def call(env)
20
20
  @env = env
21
21
 
22
- @pool = @env[:auto_network_pool]
23
22
  @machine = @env[:machine]
24
23
 
25
24
  request_address unless machine_has_address?(@machine)
@@ -31,7 +30,7 @@ class AutoNetwork::Action::Request
31
30
 
32
31
  def request_address
33
32
  machine_auto_networks(@machine).each do |net|
34
- addr = @pool.request(@machine)
33
+ addr = AutoNetwork.pool_manager.request(@machine)
35
34
  @env[:ui].info "Assigning #{addr.inspect} to '#{@machine.name}'", :prefix => true
36
35
  filter_private_network(net, addr)
37
36
  end
@@ -7,7 +7,7 @@ module AutoNetwork
7
7
  #
8
8
  # @return [true, false]
9
9
  def machine_has_address?(machine)
10
- !!(machine and @pool.address_for(machine))
10
+ !!(machine and AutoNetwork.pool_manager.address_for(machine))
11
11
  end
12
12
 
13
13
  # Fetch all private networks that are tagged for auto networking
@@ -10,13 +10,12 @@ module AutoNetwork
10
10
  networks.
11
11
  DESC
12
12
 
13
- action_hook('Auto network: initialize address pool') do |hook|
14
- hook.prepend AutoNetwork::Action::LoadPool
15
- end
16
-
17
13
  action_hook('Auto network: filter private networks', :environment_load) do |hook|
18
- action = AutoNetwork::Action::LoadPool
19
- hook.after(action, AutoNetwork::Action::FilterNetworks)
14
+ load_pool = AutoNetwork::Action::LoadPool
15
+
16
+ # TODO: This should be re-factored to use ActionBuilder.
17
+ hook.prepend(load_pool)
18
+ hook.after(load_pool, AutoNetwork::Action::FilterNetworks)
20
19
  end
21
20
 
22
21
  action_hook('Auto network: request address') do |hook|
@@ -1,3 +1,4 @@
1
+ require 'pathname'
1
2
  require 'yaml/store'
2
3
  require 'auto_network/pool'
3
4
 
@@ -19,6 +20,10 @@ module AutoNetwork
19
20
  # @param path [String, Pathname] the location of the new pool file.
20
21
  # @return [void]
21
22
  def self.init(path)
23
+ path = Pathname.new(path)
24
+ dir = path.dirname
25
+
26
+ dir.mkpath unless dir.exist?
22
27
  File.write(path, POOLFILE_SKELETON.to_yaml)
23
28
  end
24
29
 
@@ -0,0 +1,51 @@
1
+ require 'ipaddr'
2
+ require 'vagrant/errors'
3
+
4
+ module AutoNetwork
5
+ # This module is used by AutoNetwork to store global state when running under
6
+ # Vagrant. This module is mixed into the top-level AutoNetwork namespace.
7
+ module Settings
8
+
9
+ # An error class raised when an invalid value is assigned to a setting.
10
+ #
11
+ # @api private
12
+ class InvalidSettingErrror < Vagrant::Errors::VagrantError
13
+ error_key(:invalid_setting, 'vagrant_auto_network')
14
+ end
15
+
16
+ # @!attribute [rw] pool_manager
17
+ # @return [AutoNetwork::PoolManager, nil]
18
+ attr_accessor :pool_manager
19
+
20
+ # Unless overriden, this will be the IP range assigned to the very first
21
+ # {AutoNetwork::Pool} created by {AutoNetwork::PoolManager} instances.
22
+ DEFAULT_POOL = '10.20.1.0/24'
23
+
24
+ # Retrieve the default pool that {AutoNetwork::PoolManager} instances will
25
+ # assign to the first {AutoNetwork::Pool} they create.
26
+ #
27
+ # @return [String]
28
+ def default_pool
29
+ @default_pool ||= DEFAULT_POOL
30
+ end
31
+
32
+ # Set the default pool to a new IP range.
33
+ #
34
+ # @param pool [String]
35
+ # @raise [InvalidSettingErrror] if an IPAddr object cannot be initialized
36
+ # from the value of pool.
37
+ # @return [void]
38
+ def default_pool=(pool)
39
+ # Ensure the pool is valid.
40
+ begin
41
+ IPAddr.new pool
42
+ rescue ArgumentError
43
+ raise InvalidSettingErrror,
44
+ :setting_name => 'default_pool',
45
+ :value => pool
46
+ end
47
+
48
+ @default_pool = pool
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module AutoNetwork
2
- VERSION = '1.0.0.beta1'
2
+ VERSION = '1.0.0.beta2'
3
3
  end
data/lib/auto_network.rb CHANGED
@@ -1,10 +1,9 @@
1
1
  module AutoNetwork
2
2
 
3
- require 'auto_network/default_pool'
4
- extend DefaultPool
3
+ require 'auto_network/settings'
4
+ extend Settings
5
5
 
6
6
  require 'auto_network/action'
7
- require 'auto_network/mixin'
8
7
  require 'auto_network/plugin'
9
8
  require 'auto_network/version'
10
9
  require 'auto_network/pool_manager'
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe AutoNetwork::Plugin do
4
+ include_context 'vagrant-unit'
5
+
6
+ context 'when a vagrant environment is initialized' do
7
+ let(:settings) {
8
+ Module.new do
9
+ extend AutoNetwork::Settings
10
+ end
11
+ }
12
+ let(:manager_double) { double().as_null_object }
13
+
14
+ it 'sets the global pool_manager' do
15
+ allow(AutoNetwork).to receive(:pool_manager=) do |pool_manager|
16
+ settings.pool_manager = pool_manager
17
+ end
18
+ allow(manager_double).to receive(:new).and_return('a_pool_manager')
19
+ stub_const('AutoNetwork::PoolManager', manager_double)
20
+
21
+ # Create an environment \o/
22
+ isolated_environment.create_vagrant_env
23
+
24
+ expect(settings.pool_manager).to eq('a_pool_manager')
25
+ end
26
+
27
+ end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
2
 
3
- require 'rspec'
3
+ # Disable Vagrant autoloading so that other plugins defined in the Gemfile for
4
+ # Acceptance tests are not loaded.
5
+ ENV['VAGRANT_NO_PLUGINS'] = '1'
6
+
7
+ require 'vagrant-spec/unit'
4
8
  require 'auto_network'
File without changes
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'auto_network/settings'
3
+
4
+ describe AutoNetwork::Settings do
5
+ subject {
6
+ Module.new do
7
+ extend AutoNetwork::Settings
8
+ end
9
+ }
10
+
11
+ describe 'default_pool' do
12
+
13
+ it 'returns DEFAULT_POOL if nothing has been set' do
14
+ expect(subject.default_pool).to eq(AutoNetwork::Settings::DEFAULT_POOL)
15
+ end
16
+
17
+ it 'raises an error when set to an invalid value' do
18
+ expect { subject.default_pool=nil }.to raise_error(AutoNetwork::Settings::InvalidSettingErrror)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ namespace :acceptance do
2
+ ARTIFACT_DIR = File.join('acceptance', 'artifacts')
3
+ TEST_BOXES = %w[
4
+ https://vagrantcloud.com/puppetlabs/centos-6.5-64-nocm/version/2/provider/virtualbox.box
5
+ ]
6
+
7
+ directory ARTIFACT_DIR
8
+ TEST_BOXES.each do |box_url|
9
+ file File.join(ARTIFACT_DIR, File.basename(box_url)) => ARTIFACT_DIR do |path|
10
+ puts 'Downloading: ' + box_url
11
+ Kernel.system 'curl', '-L', '-o', path.to_s, box_url
12
+ end
13
+ end
14
+
15
+ desc 'downloads test boxes and other artifacts'
16
+ task :setup => TEST_BOXES.map {|box_url| File.join(ARTIFACT_DIR, File.basename(box_url))}
17
+
18
+ desc 'runs acceptance tests'
19
+ task :run => :setup do
20
+ command = 'vagrant-spec test'
21
+ puts command
22
+ puts
23
+ exec(command)
24
+ end
25
+ end
@@ -7,3 +7,6 @@ en:
7
7
  probably due to VMs being deleted outside of Vagrant. Check the
8
8
  auto_network pool configuration file and remove the machine IDs from
9
9
  addresses that are no longer in use, or add addresses to the pool.
10
+
11
+ invalid_setting: |-
12
+ The following value is not a valid setting for '%{setting_name}': '%{value}'
@@ -0,0 +1,16 @@
1
+ require 'pathname'
2
+ require 'vagrant-spec/acceptance'
3
+
4
+ Vagrant::Spec::Acceptance.configure do |c|
5
+ acceptance_dir = Pathname.new File.expand_path('../acceptance', __FILE__)
6
+
7
+ c.component_paths = [acceptance_dir.to_s]
8
+ c.skeleton_paths = [(acceptance_dir + 'skeletons').to_s]
9
+
10
+ c.provider 'virtualbox',
11
+ box: (acceptance_dir + 'artifacts' + 'virtualbox.box').to_s,
12
+ env_vars: {
13
+ 'VBOX_USER_HOME' => '{{homedir}}',
14
+ 'AUTO_NETWORK_TEST_RANGE' => '10.42.1.0/24',
15
+ }
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-auto_network
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -30,10 +30,14 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - .gitignore
33
34
  - .yardopts
34
35
  - CHANGELOG
35
36
  - Gemfile
36
37
  - README.markdown
38
+ - Rakefile
39
+ - acceptance/auto_network/auto_network_spec.rb
40
+ - acceptance/skeletons/auto_network/Vagrantfile
37
41
  - lib/auto_network.rb
38
42
  - lib/auto_network/action.rb
39
43
  - lib/auto_network/action/filter_networks.rb
@@ -41,18 +45,21 @@ files:
41
45
  - lib/auto_network/action/release.rb
42
46
  - lib/auto_network/action/request.rb
43
47
  - lib/auto_network/action_helpers.rb
44
- - lib/auto_network/default_pool.rb
45
- - lib/auto_network/mixin.rb
46
48
  - lib/auto_network/plugin.rb
47
49
  - lib/auto_network/pool.rb
48
50
  - lib/auto_network/pool_manager.rb
49
51
  - lib/auto_network/pool_storage.rb
52
+ - lib/auto_network/settings.rb
50
53
  - lib/auto_network/version.rb
51
54
  - lib/vagrant-auto_network.rb
52
- - spec/auto_network/pool/pool_spec.rb
55
+ - spec/integration/plugin_spec.rb
53
56
  - spec/spec_helper.rb
57
+ - spec/unit/pool_spec.rb
58
+ - spec/unit/settings_spec.rb
59
+ - tasks/acceptance.rake
54
60
  - templates/locales/en.yml
55
61
  - vagrant-auto_network.gemspec
62
+ - vagrant-spec.config.rb
56
63
  homepage: https://github.com/adrienthebo/vagrant-auto_network
57
64
  licenses:
58
65
  - Apache 2.0
@@ -1,9 +0,0 @@
1
- module AutoNetwork::DefaultPool
2
- def default_pool
3
- @default_pool ||= '10.20.1.0/24'
4
- end
5
-
6
- def default_pool=(pool)
7
- @default_pool = pool
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- require 'auto_network/pool'
2
-
3
- module AutoNetwork
4
- # Extension to vagrant VM configuration to automatically configure an
5
- # internal network.
6
- module Mixin
7
- def auto_network!
8
- puts "AutoNetwork::Mixin is deprecated, use config.vm.network :private_network, :auto_network => true"
9
- network :private_network, :auto_network => true
10
- end
11
- end
12
- end