rvagrant 0.8.7.dev
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.
- data/.gitignore +25 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +386 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/Rakefile +11 -0
- data/bin/vagrant +28 -0
- data/config/default.rb +38 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.ppk +26 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +44 -0
- data/lib/vagrant/action.rb +138 -0
- data/lib/vagrant/action/box.rb +11 -0
- data/lib/vagrant/action/box/destroy.rb +21 -0
- data/lib/vagrant/action/box/download.rb +72 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +55 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +124 -0
- data/lib/vagrant/action/builtin.rb +108 -0
- data/lib/vagrant/action/env.rb +7 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +50 -0
- data/lib/vagrant/action/general.rb +8 -0
- data/lib/vagrant/action/general/package.rb +113 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +34 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_accessible.rb +23 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +35 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +26 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +27 -0
- data/lib/vagrant/action/vm/customize.rb +26 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +52 -0
- data/lib/vagrant/action/vm/forward_ports.rb +133 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +29 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +40 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +26 -0
- data/lib/vagrant/action/vm/modify.rb +37 -0
- data/lib/vagrant/action/vm/network.rb +146 -0
- data/lib/vagrant/action/vm/nfs.rb +160 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
- data/lib/vagrant/action/vm/provision.rb +34 -0
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +78 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +85 -0
- data/lib/vagrant/box.rb +90 -0
- data/lib/vagrant/box_collection.rb +53 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command.rb +25 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +107 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +23 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +49 -0
- data/lib/vagrant/command/ssh_config.rb +29 -0
- data/lib/vagrant/command/status.rb +31 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +19 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +123 -0
- data/lib/vagrant/config/base.rb +85 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +38 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +17 -0
- data/lib/vagrant/config/vm.rb +148 -0
- data/lib/vagrant/config/vm/provisioner.rb +56 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +70 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +23 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +70 -0
- data/lib/vagrant/environment.rb +516 -0
- data/lib/vagrant/errors.rb +352 -0
- data/lib/vagrant/hosts.rb +9 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +76 -0
- data/lib/vagrant/hosts/bsd.rb +58 -0
- data/lib/vagrant/hosts/fedora.rb +11 -0
- data/lib/vagrant/hosts/linux.rb +69 -0
- data/lib/vagrant/plugin.rb +79 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +67 -0
- data/lib/vagrant/provisioners/chef.rb +155 -0
- data/lib/vagrant/provisioners/chef_client.rb +120 -0
- data/lib/vagrant/provisioners/chef_solo.rb +135 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +96 -0
- data/lib/vagrant/ssh.rb +224 -0
- data/lib/vagrant/ssh/session.rb +136 -0
- data/lib/vagrant/systems.rb +13 -0
- data/lib/vagrant/systems/arch.rb +34 -0
- data/lib/vagrant/systems/base.rb +87 -0
- data/lib/vagrant/systems/debian.rb +36 -0
- data/lib/vagrant/systems/freebsd.rb +84 -0
- data/lib/vagrant/systems/gentoo.rb +27 -0
- data/lib/vagrant/systems/linux.rb +82 -0
- data/lib/vagrant/systems/linux/config.rb +21 -0
- data/lib/vagrant/systems/linux/error.rb +9 -0
- data/lib/vagrant/systems/redhat.rb +48 -0
- data/lib/vagrant/systems/solaris.rb +67 -0
- data/lib/vagrant/systems/suse.rb +9 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +81 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/counter.rb +24 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/platform.rb +57 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/safe_exec.rb +35 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +181 -0
- data/templates/chef_server_client.erb +32 -0
- data/templates/chef_solo_solo.erb +23 -0
- data/templates/commands/init/Vagrantfile.erb +86 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +556 -0
- data/templates/network_entry_arch.erb +9 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +9 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +15 -0
- data/test/unit/locales/en.yml +8 -0
- data/test/unit/test_helper.rb +28 -0
- data/test/unit/vagrant/action/box/destroy_test.rb +18 -0
- data/test/unit/vagrant/action/box/download_test.rb +125 -0
- data/test/unit/vagrant/action/box/package_test.rb +25 -0
- data/test/unit/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/unit/vagrant/action/box/verify_test.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +207 -0
- data/test/unit/vagrant/action/env/set_test.rb +24 -0
- data/test/unit/vagrant/action/environment_test.rb +27 -0
- data/test/unit/vagrant/action/general/package_test.rb +268 -0
- data/test/unit/vagrant/action/general/validate_test.rb +31 -0
- data/test/unit/vagrant/action/vm/boot_test.rb +66 -0
- data/test/unit/vagrant/action/vm/check_accessible_test.rb +61 -0
- data/test/unit/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/unit/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/unit/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/unit/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
- data/test/unit/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/unit/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
- data/test/unit/vagrant/action/vm/customize_test.rb +37 -0
- data/test/unit/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/unit/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/unit/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/unit/vagrant/action/vm/export_test.rb +107 -0
- data/test/unit/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
- data/test/unit/vagrant/action/vm/forward_ports_test.rb +213 -0
- data/test/unit/vagrant/action/vm/halt_test.rb +79 -0
- data/test/unit/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/unit/vagrant/action/vm/import_test.rb +66 -0
- data/test/unit/vagrant/action/vm/match_mac_address_test.rb +40 -0
- data/test/unit/vagrant/action/vm/modify_test.rb +38 -0
- data/test/unit/vagrant/action/vm/network_test.rb +286 -0
- data/test/unit/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/unit/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/unit/vagrant/action/vm/package_test.rb +25 -0
- data/test/unit/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/unit/vagrant/action/vm/provision_test.rb +65 -0
- data/test/unit/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/unit/vagrant/action/vm/resume_test.rb +35 -0
- data/test/unit/vagrant/action/vm/share_folders_test.rb +144 -0
- data/test/unit/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/unit/vagrant/action/warden_test.rb +125 -0
- data/test/unit/vagrant/action_test.rb +89 -0
- data/test/unit/vagrant/box_collection_test.rb +45 -0
- data/test/unit/vagrant/box_test.rb +74 -0
- data/test/unit/vagrant/cli_test.rb +35 -0
- data/test/unit/vagrant/command/base_test.rb +23 -0
- data/test/unit/vagrant/command/group_base_test.rb +15 -0
- data/test/unit/vagrant/command/helpers_test.rb +88 -0
- data/test/unit/vagrant/command/package_test.rb +27 -0
- data/test/unit/vagrant/config/base_test.rb +52 -0
- data/test/unit/vagrant/config/error_recorder_test.rb +18 -0
- data/test/unit/vagrant/config/ssh_test.rb +12 -0
- data/test/unit/vagrant/config/vagrant_test.rb +35 -0
- data/test/unit/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/unit/vagrant/config/vm_test.rb +56 -0
- data/test/unit/vagrant/config_test.rb +162 -0
- data/test/unit/vagrant/data_store_test.rb +77 -0
- data/test/unit/vagrant/downloaders/base_test.rb +28 -0
- data/test/unit/vagrant/downloaders/file_test.rb +48 -0
- data/test/unit/vagrant/downloaders/http_test.rb +82 -0
- data/test/unit/vagrant/environment_test.rb +598 -0
- data/test/unit/vagrant/errors_test.rb +42 -0
- data/test/unit/vagrant/hosts/base_test.rb +46 -0
- data/test/unit/vagrant/hosts/bsd_test.rb +53 -0
- data/test/unit/vagrant/hosts/linux_test.rb +54 -0
- data/test/unit/vagrant/plugin_test.rb +9 -0
- data/test/unit/vagrant/provisioners/base_test.rb +63 -0
- data/test/unit/vagrant/provisioners/chef_client_test.rb +190 -0
- data/test/unit/vagrant/provisioners/chef_solo_test.rb +114 -0
- data/test/unit/vagrant/provisioners/chef_test.rb +202 -0
- data/test/unit/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/unit/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/unit/vagrant/provisioners/shell_test.rb +79 -0
- data/test/unit/vagrant/ssh/session_test.rb +40 -0
- data/test/unit/vagrant/ssh_test.rb +307 -0
- data/test/unit/vagrant/systems/base_test.rb +18 -0
- data/test/unit/vagrant/systems/linux_test.rb +104 -0
- data/test/unit/vagrant/ui_test.rb +29 -0
- data/test/unit/vagrant/util/busy_test.rb +106 -0
- data/test/unit/vagrant/util/counter_test.rb +29 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/unit/vagrant/util/platform_test.rb +18 -0
- data/test/unit/vagrant/util/retryable_test.rb +50 -0
- data/test/unit/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/unit/vagrant/util/template_renderer_test.rb +145 -0
- data/test/unit/vagrant/vm_test.rb +300 -0
- data/vagrant.gemspec +35 -0
- metadata +431 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Systems
|
|
3
|
+
# A general Vagrant system implementation for "solaris".
|
|
4
|
+
#
|
|
5
|
+
# Contributed by Blake Irvin <b.irvin@modcloth.com>
|
|
6
|
+
class Solaris < Base
|
|
7
|
+
# A custom config class which will be made accessible via `config.solaris`
|
|
8
|
+
# This is not necessary for all system implementers, of course. However,
|
|
9
|
+
# generally, Vagrant tries to make almost every aspect of its execution
|
|
10
|
+
# configurable, and this assists that goal.
|
|
11
|
+
class SolarisConfig < Vagrant::Config::Base
|
|
12
|
+
configures :solaris
|
|
13
|
+
|
|
14
|
+
attr_accessor :halt_timeout
|
|
15
|
+
attr_accessor :halt_check_interval
|
|
16
|
+
# This sets the command to use to execute items as a superuser. sudo is default
|
|
17
|
+
attr_accessor :suexec_cmd
|
|
18
|
+
|
|
19
|
+
def initialize
|
|
20
|
+
@halt_timeout = 30
|
|
21
|
+
@halt_check_interval = 1
|
|
22
|
+
@suexec_cmd = 'sudo'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Here for whenever it may be used.
|
|
27
|
+
class SolarisError < Errors::VagrantError
|
|
28
|
+
error_namespace("vagrant.systems.solaris")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# There should be an exception raised if the line
|
|
32
|
+
#
|
|
33
|
+
# vagrant::::profiles=Primary Administrator
|
|
34
|
+
#
|
|
35
|
+
# does not exist in /etc/user_attr. TODO
|
|
36
|
+
def halt
|
|
37
|
+
vm.env.ui.info I18n.t("vagrant.systems.solaris.attempting_halt")
|
|
38
|
+
vm.ssh.execute do |ssh|
|
|
39
|
+
ssh.exec!("#{vm.env.config.solaris.suexec_cmd} /usr/sbin/poweroff")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Wait until the VM's state is actually powered off. If this doesn't
|
|
43
|
+
# occur within a reasonable amount of time (15 seconds by default),
|
|
44
|
+
# then simply return and allow Vagrant to kill the machine.
|
|
45
|
+
count = 0
|
|
46
|
+
while vm.vm.state != :powered_off
|
|
47
|
+
count += 1
|
|
48
|
+
|
|
49
|
+
return if count >= vm.env.config.solaris.halt_timeout
|
|
50
|
+
sleep vm.env.config.solaris.halt_check_interval
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def mount_shared_folder(ssh, name, guestpath, owner, group)
|
|
55
|
+
# Create the shared folder
|
|
56
|
+
ssh.exec!("#{vm.env.config.solaris.suexec_cmd} mkdir -p #{guestpath}")
|
|
57
|
+
|
|
58
|
+
# Mount the folder with the proper owner/group
|
|
59
|
+
options = "-o uid=`id -u #{owner}`,gid=`id -g #{group}`"
|
|
60
|
+
ssh.exec!("#{vm.env.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{options} #{name} #{guestpath}")
|
|
61
|
+
|
|
62
|
+
# chown the folder to the proper owner/group
|
|
63
|
+
ssh.exec!("#{vm.env.config.solaris.suexec_cmd} chown `id -u #{owner}`:`id -g #{group}` #{guestpath}")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'vagrant/systems/debian'
|
|
2
|
+
|
|
3
|
+
module Vagrant
|
|
4
|
+
module Systems
|
|
5
|
+
class Ubuntu < Debian
|
|
6
|
+
def change_host_name(name)
|
|
7
|
+
vm.ssh.execute do |ssh|
|
|
8
|
+
if !ssh.test?("sudo hostname | grep '#{name}'")
|
|
9
|
+
ssh.exec!("sudo sed -i 's/.*$/#{name}/' /etc/hostname")
|
|
10
|
+
ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]1[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
|
|
11
|
+
ssh.exec!("sudo service hostname start")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
# Test helpers provided by Vagrant to allow for plugin developers
|
|
3
|
+
# to write automated tests for their code. This module simply provides
|
|
4
|
+
# methods which can be included into any test framework (`test/unit`,
|
|
5
|
+
# RSpec, Shoulda, etc.)
|
|
6
|
+
module TestHelpers
|
|
7
|
+
#------------------------------------------------------------
|
|
8
|
+
# Environment creation helpers
|
|
9
|
+
#------------------------------------------------------------
|
|
10
|
+
# Creates a "vagrant_app" directory in the test tmp folder
|
|
11
|
+
# which can be used for creating test Vagrant environments.
|
|
12
|
+
# Returns the root directory of the app. This typically doesn't need
|
|
13
|
+
# to be called directly unless you're setting up a custom application.
|
|
14
|
+
# See the examples for common use cases.
|
|
15
|
+
def vagrant_app(*path)
|
|
16
|
+
root = tmp_path.join("vagrant_app")
|
|
17
|
+
FileUtils.rm_rf(root)
|
|
18
|
+
FileUtils.mkdir_p(root)
|
|
19
|
+
root.join(*path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Creates a Vagrantfile with the given contents in the given
|
|
23
|
+
# app directory. If no app directory is specified, then a default
|
|
24
|
+
# Vagrant app is used.
|
|
25
|
+
def vagrantfile(*args)
|
|
26
|
+
path = args.shift.join("Vagrantfile") if Pathname === args.first
|
|
27
|
+
path ||= vagrant_app("Vagrantfile")
|
|
28
|
+
|
|
29
|
+
# Create this box so that it exists
|
|
30
|
+
vagrant_box("base")
|
|
31
|
+
|
|
32
|
+
str = args.shift || ""
|
|
33
|
+
File.open(path.to_s, "w") do |f|
|
|
34
|
+
f.puts "ENV['VAGRANT_HOME'] = '#{home_path}'"
|
|
35
|
+
f.puts "Vagrant::Config.run do |config|"
|
|
36
|
+
f.puts "config.vm.base_mac = 'foo' if !config.vm.base_mac"
|
|
37
|
+
f.puts "config.vm.box = 'base'"
|
|
38
|
+
f.puts str
|
|
39
|
+
f.puts "end"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
path.parent
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Creates and _loads_ a Vagrant environment at the given path.
|
|
46
|
+
# If no path is given, then a default {#vagrantfile} is used.
|
|
47
|
+
def vagrant_env(*args)
|
|
48
|
+
path = args.shift if Pathname === args.first
|
|
49
|
+
path ||= vagrantfile
|
|
50
|
+
Vagrant::Environment.new(:cwd => path).load!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Creates the folder to contain a vagrant box. This allows for
|
|
54
|
+
# "fake" boxes to be made with the specified name.
|
|
55
|
+
#
|
|
56
|
+
# @param [String] name
|
|
57
|
+
# @return [Pathname]
|
|
58
|
+
def vagrant_box(name)
|
|
59
|
+
result = boxes_path.join(name)
|
|
60
|
+
FileUtils.mkdir_p(result)
|
|
61
|
+
result
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Returns an instantiated downloader with a mocked tempfile
|
|
65
|
+
# which can be passed into it.
|
|
66
|
+
#
|
|
67
|
+
# @param [Class] klass The downloader class
|
|
68
|
+
# @return [Array] Returns an array of `downloader` `tempfile`
|
|
69
|
+
def vagrant_mock_downloader(klass)
|
|
70
|
+
tempfile = mock("tempfile")
|
|
71
|
+
tempfile.stubs(:write)
|
|
72
|
+
|
|
73
|
+
_, env = action_env
|
|
74
|
+
[klass.new(env), tempfile]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Returns a blank app (callable) and action environment with the
|
|
78
|
+
# given vagrant environment. This allows for testing of middlewares.
|
|
79
|
+
def action_env(v_env = nil)
|
|
80
|
+
v_env ||= vagrant_env
|
|
81
|
+
app = lambda { |env| }
|
|
82
|
+
env = Vagrant::Action::Environment.new(v_env)
|
|
83
|
+
env["vagrant.test"] = true
|
|
84
|
+
[app, env]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#------------------------------------------------------------
|
|
88
|
+
# Path helpers
|
|
89
|
+
#------------------------------------------------------------
|
|
90
|
+
# Path to the tmp directory for the tests.
|
|
91
|
+
#
|
|
92
|
+
# @return [Pathname]
|
|
93
|
+
def tmp_path
|
|
94
|
+
result = Vagrant.source_root.join("test", "tmp")
|
|
95
|
+
FileUtils.mkdir_p(result)
|
|
96
|
+
result
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Path to the "home" directory for the tests
|
|
100
|
+
#
|
|
101
|
+
# @return [Pathname]
|
|
102
|
+
def home_path
|
|
103
|
+
result = tmp_path.join("home")
|
|
104
|
+
FileUtils.mkdir_p(result)
|
|
105
|
+
result
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Path to the boxes directory in the home directory
|
|
109
|
+
#
|
|
110
|
+
# @return [Pathname]
|
|
111
|
+
def boxes_path
|
|
112
|
+
result = home_path.join("boxes")
|
|
113
|
+
FileUtils.mkdir_p(result)
|
|
114
|
+
result
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Cleans all the test temp paths, which includes the boxes path,
|
|
118
|
+
# home path, etc. This allows for cleaning between tests.
|
|
119
|
+
def clean_paths
|
|
120
|
+
FileUtils.rm_rf(tmp_path)
|
|
121
|
+
|
|
122
|
+
# Call these methods only to rebuild the directories
|
|
123
|
+
tmp_path
|
|
124
|
+
home_path
|
|
125
|
+
boxes_path
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
data/lib/vagrant/ui.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
# Vagrant UIs handle communication with the outside world (typically
|
|
3
|
+
# through a shell). They must respond to the typically logger methods
|
|
4
|
+
# of `warn`, `error`, `info`, and `confirm`.
|
|
5
|
+
class UI
|
|
6
|
+
attr_accessor :env
|
|
7
|
+
|
|
8
|
+
def initialize(env)
|
|
9
|
+
@env = env
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
[:warn, :error, :info, :confirm].each do |method|
|
|
13
|
+
define_method(method) do |message|
|
|
14
|
+
# Log normal console messages
|
|
15
|
+
env.logger.info("ui") { message }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
[:clear_line, :report_progress, :ask, :no?, :yes?].each do |method|
|
|
20
|
+
# By default do nothing, these aren't logged
|
|
21
|
+
define_method(method) { |*args| }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# A shell UI, which uses a `Thor::Shell` object to talk with
|
|
25
|
+
# a terminal.
|
|
26
|
+
class Shell < UI
|
|
27
|
+
def initialize(env, shell)
|
|
28
|
+
super(env)
|
|
29
|
+
|
|
30
|
+
@shell = shell
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
[[:warn, :yellow], [:error, :red], [:info, nil], [:confirm, :green]].each do |method, color|
|
|
34
|
+
class_eval <<-CODE
|
|
35
|
+
def #{method}(message, opts=nil)
|
|
36
|
+
super(message)
|
|
37
|
+
opts ||= {}
|
|
38
|
+
opts[:new_line] = true if !opts.has_key?(:new_line)
|
|
39
|
+
@shell.say("\#{format_message(message, opts)}", #{color.inspect}, opts[:new_line])
|
|
40
|
+
end
|
|
41
|
+
CODE
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
[:ask, :no?, :yes?].each do |method|
|
|
45
|
+
class_eval <<-CODE
|
|
46
|
+
def #{method}(message, opts=nil)
|
|
47
|
+
super(message)
|
|
48
|
+
opts ||= {}
|
|
49
|
+
@shell.send(#{method.inspect}, format_message(message, opts), opts[:color])
|
|
50
|
+
end
|
|
51
|
+
CODE
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def report_progress(progress, total, show_parts=true)
|
|
55
|
+
percent = (progress.to_f / total.to_f) * 100
|
|
56
|
+
line = "Progress: #{percent.to_i}%"
|
|
57
|
+
line << " (#{progress} / #{total})" if show_parts
|
|
58
|
+
|
|
59
|
+
@shell.say(line, nil, false)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def clear_line
|
|
63
|
+
@shell.say(line_reset, nil, false)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
protected
|
|
67
|
+
|
|
68
|
+
def format_message(message, opts=nil)
|
|
69
|
+
opts = { :prefix => true }.merge(opts || {})
|
|
70
|
+
message = "[#{env.resource}] #{message}" if opts[:prefix]
|
|
71
|
+
message
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def line_reset
|
|
75
|
+
reset = "\r"
|
|
76
|
+
reset += "\e[0K" unless Util::Platform.windows?
|
|
77
|
+
reset
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
data/lib/vagrant/util.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Util
|
|
3
|
+
autoload :Busy, 'vagrant/util/busy'
|
|
4
|
+
autoload :Counter, 'vagrant/util/counter'
|
|
5
|
+
autoload :GlobLoader, 'vagrant/util/glob_loader'
|
|
6
|
+
autoload :HashWithIndifferentAccess, 'vagrant/util/hash_with_indifferent_access'
|
|
7
|
+
autoload :Platform, 'vagrant/util/platform'
|
|
8
|
+
autoload :Retryable, 'vagrant/util/retryable'
|
|
9
|
+
autoload :SafeExec, 'vagrant/util/safe_exec'
|
|
10
|
+
autoload :StackedProcRunner, 'vagrant/util/stacked_proc_runner'
|
|
11
|
+
autoload :TemplateRenderer, 'vagrant/util/template_renderer'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Util
|
|
3
|
+
# Utility class which allows blocks of code to be marked as "busy"
|
|
4
|
+
# with a specified interrupt handler. During busy areas of code, it
|
|
5
|
+
# is often undesirable for SIGINTs to immediately kill the application.
|
|
6
|
+
# This class is a helper to cleanly register callbacks to handle this
|
|
7
|
+
# situation.
|
|
8
|
+
class Busy
|
|
9
|
+
@@registered = []
|
|
10
|
+
@@mutex = Mutex.new
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
# Mark a given block of code as a "busy" block of code, which will
|
|
14
|
+
# register a SIGINT handler for the duration of the block. When a
|
|
15
|
+
# SIGINT occurs, the `sig_callback` proc will be called. It is up
|
|
16
|
+
# to the callback to behave properly and exit the application.
|
|
17
|
+
def busy(sig_callback)
|
|
18
|
+
register(sig_callback)
|
|
19
|
+
yield
|
|
20
|
+
ensure
|
|
21
|
+
unregister(sig_callback)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Registers a SIGINT handler. This typically is called from {busy}.
|
|
25
|
+
# Callbacks are only registered once, so calling this multiple times
|
|
26
|
+
# with the same callback has no consequence.
|
|
27
|
+
def register(sig_callback)
|
|
28
|
+
@@mutex.synchronize do
|
|
29
|
+
registered << sig_callback
|
|
30
|
+
registered.uniq!
|
|
31
|
+
|
|
32
|
+
# Register the handler if this is our first callback.
|
|
33
|
+
Signal.trap("INT") { fire_callbacks } if registered.length == 1
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Unregisters a SIGINT handler.
|
|
38
|
+
def unregister(sig_callback)
|
|
39
|
+
@@mutex.synchronize do
|
|
40
|
+
registered.delete(sig_callback)
|
|
41
|
+
|
|
42
|
+
# Remove the signal trap if no more registered callbacks exist
|
|
43
|
+
Signal.trap("INT", "DEFAULT") if registered.empty?
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Fires all the registered callbacks.
|
|
48
|
+
def fire_callbacks
|
|
49
|
+
registered.each { |r| r.call }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Helper method to get access to the class variable. This is mostly
|
|
53
|
+
# exposed for tests. This shouldn't be mucked with directly, since it's
|
|
54
|
+
# structure may change at any time.
|
|
55
|
+
def registered; @@registered; end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'thread'
|
|
2
|
+
|
|
3
|
+
module Vagrant
|
|
4
|
+
module Util
|
|
5
|
+
# Atomic counter implementation. This is useful for incrementing
|
|
6
|
+
# a counter which is guaranteed to only be used once in its class.
|
|
7
|
+
module Counter
|
|
8
|
+
def get_and_update_counter(name=nil)
|
|
9
|
+
name ||= :global
|
|
10
|
+
|
|
11
|
+
mutex.synchronize do
|
|
12
|
+
@__counter ||= Hash.new(1)
|
|
13
|
+
result = @__counter[name]
|
|
14
|
+
@__counter[name] += 1
|
|
15
|
+
result
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def mutex
|
|
20
|
+
@__counter_mutex ||= Mutex.new
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Vagrant
|
|
2
|
+
module Util
|
|
3
|
+
# A hash with indifferent access. Mostly taken from Thor/Rails (thanks).
|
|
4
|
+
# Normally I'm not a fan of using an indifferent access hash since Symbols
|
|
5
|
+
# are basically memory leaks in Ruby, but since Vagrant is typically a quick
|
|
6
|
+
# one-off binary run and it doesn't use too many hash keys where this is
|
|
7
|
+
# used, the effect should be minimal.
|
|
8
|
+
#
|
|
9
|
+
# hash[:foo] #=> 'bar'
|
|
10
|
+
# hash['foo'] #=> 'bar'
|
|
11
|
+
#
|
|
12
|
+
class HashWithIndifferentAccess < ::Hash
|
|
13
|
+
def initialize(hash={}, &block)
|
|
14
|
+
super(&block)
|
|
15
|
+
|
|
16
|
+
hash.each do |key, value|
|
|
17
|
+
self[convert_key(key)] = value
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def [](key)
|
|
22
|
+
super(convert_key(key))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def []=(key, value)
|
|
26
|
+
super(convert_key(key), value)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete(key)
|
|
30
|
+
super(convert_key(key))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def values_at(*indices)
|
|
34
|
+
indices.collect { |key| self[convert_key(key)] }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def merge(other)
|
|
38
|
+
dup.merge!(other)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def merge!(other)
|
|
42
|
+
other.each do |key, value|
|
|
43
|
+
self[convert_key(key)] = value
|
|
44
|
+
end
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def key?(key)
|
|
49
|
+
super(convert_key(key))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
alias_method :include?, :key?
|
|
53
|
+
alias_method :has_key?, :key?
|
|
54
|
+
alias_method :member?, :key?
|
|
55
|
+
|
|
56
|
+
protected
|
|
57
|
+
|
|
58
|
+
def convert_key(key)
|
|
59
|
+
key.is_a?(Symbol) ? key.to_s : key
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|