bmabey-vagrant 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +17 -0
  3. data/LICENSE +21 -0
  4. data/README.md +53 -0
  5. data/Rakefile +41 -0
  6. data/VERSION +1 -0
  7. data/bin/.gitignore +0 -0
  8. data/bin/vagrant +15 -0
  9. data/bin/vagrant-box +34 -0
  10. data/bin/vagrant-down +27 -0
  11. data/bin/vagrant-halt +28 -0
  12. data/bin/vagrant-init +27 -0
  13. data/bin/vagrant-package +29 -0
  14. data/bin/vagrant-reload +29 -0
  15. data/bin/vagrant-resume +27 -0
  16. data/bin/vagrant-ssh +27 -0
  17. data/bin/vagrant-status +29 -0
  18. data/bin/vagrant-suspend +27 -0
  19. data/bin/vagrant-up +29 -0
  20. data/config/default.rb +26 -0
  21. data/keys/README.md +10 -0
  22. data/keys/vagrant +27 -0
  23. data/keys/vagrant.pub +1 -0
  24. data/lib/vagrant.rb +19 -0
  25. data/lib/vagrant/actions/base.rb +118 -0
  26. data/lib/vagrant/actions/box/add.rb +22 -0
  27. data/lib/vagrant/actions/box/destroy.rb +14 -0
  28. data/lib/vagrant/actions/box/download.rb +72 -0
  29. data/lib/vagrant/actions/box/unpackage.rb +43 -0
  30. data/lib/vagrant/actions/collection.rb +36 -0
  31. data/lib/vagrant/actions/runner.rb +132 -0
  32. data/lib/vagrant/actions/vm/boot.rb +47 -0
  33. data/lib/vagrant/actions/vm/customize.rb +17 -0
  34. data/lib/vagrant/actions/vm/destroy.rb +23 -0
  35. data/lib/vagrant/actions/vm/down.rb +12 -0
  36. data/lib/vagrant/actions/vm/export.rb +41 -0
  37. data/lib/vagrant/actions/vm/forward_ports.rb +46 -0
  38. data/lib/vagrant/actions/vm/halt.rb +14 -0
  39. data/lib/vagrant/actions/vm/import.rb +18 -0
  40. data/lib/vagrant/actions/vm/move_hard_drive.rb +51 -0
  41. data/lib/vagrant/actions/vm/package.rb +65 -0
  42. data/lib/vagrant/actions/vm/provision.rb +49 -0
  43. data/lib/vagrant/actions/vm/reload.rb +17 -0
  44. data/lib/vagrant/actions/vm/resume.rb +16 -0
  45. data/lib/vagrant/actions/vm/shared_folders.rb +81 -0
  46. data/lib/vagrant/actions/vm/start.rb +18 -0
  47. data/lib/vagrant/actions/vm/suspend.rb +16 -0
  48. data/lib/vagrant/actions/vm/up.rb +40 -0
  49. data/lib/vagrant/active_list.rb +73 -0
  50. data/lib/vagrant/box.rb +152 -0
  51. data/lib/vagrant/busy.rb +73 -0
  52. data/lib/vagrant/commands.rb +219 -0
  53. data/lib/vagrant/config.rb +183 -0
  54. data/lib/vagrant/downloaders/base.rb +16 -0
  55. data/lib/vagrant/downloaders/file.rb +17 -0
  56. data/lib/vagrant/downloaders/http.rb +47 -0
  57. data/lib/vagrant/environment.rb +263 -0
  58. data/lib/vagrant/provisioners/base.rb +29 -0
  59. data/lib/vagrant/provisioners/chef.rb +103 -0
  60. data/lib/vagrant/provisioners/chef_server.rb +84 -0
  61. data/lib/vagrant/provisioners/chef_solo.rb +97 -0
  62. data/lib/vagrant/ssh.rb +104 -0
  63. data/lib/vagrant/util.rb +51 -0
  64. data/lib/vagrant/util/errors.rb +36 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +61 -0
  68. data/templates/Vagrantfile.erb +8 -0
  69. data/templates/errors.yml +117 -0
  70. data/test/test_helper.rb +163 -0
  71. data/test/vagrant/actions/base_test.rb +32 -0
  72. data/test/vagrant/actions/box/add_test.rb +37 -0
  73. data/test/vagrant/actions/box/destroy_test.rb +18 -0
  74. data/test/vagrant/actions/box/download_test.rb +131 -0
  75. data/test/vagrant/actions/box/unpackage_test.rb +100 -0
  76. data/test/vagrant/actions/collection_test.rb +110 -0
  77. data/test/vagrant/actions/runner_test.rb +265 -0
  78. data/test/vagrant/actions/vm/boot_test.rb +55 -0
  79. data/test/vagrant/actions/vm/customize_test.rb +16 -0
  80. data/test/vagrant/actions/vm/destroy_test.rb +36 -0
  81. data/test/vagrant/actions/vm/down_test.rb +32 -0
  82. data/test/vagrant/actions/vm/export_test.rb +88 -0
  83. data/test/vagrant/actions/vm/forward_ports_test.rb +104 -0
  84. data/test/vagrant/actions/vm/halt_test.rb +27 -0
  85. data/test/vagrant/actions/vm/import_test.rb +43 -0
  86. data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
  87. data/test/vagrant/actions/vm/package_test.rb +181 -0
  88. data/test/vagrant/actions/vm/provision_test.rb +108 -0
  89. data/test/vagrant/actions/vm/reload_test.rb +47 -0
  90. data/test/vagrant/actions/vm/resume_test.rb +27 -0
  91. data/test/vagrant/actions/vm/shared_folders_test.rb +176 -0
  92. data/test/vagrant/actions/vm/start_test.rb +36 -0
  93. data/test/vagrant/actions/vm/suspend_test.rb +27 -0
  94. data/test/vagrant/actions/vm/up_test.rb +107 -0
  95. data/test/vagrant/active_list_test.rb +190 -0
  96. data/test/vagrant/box_test.rb +151 -0
  97. data/test/vagrant/busy_test.rb +83 -0
  98. data/test/vagrant/commands_test.rb +307 -0
  99. data/test/vagrant/config_test.rb +256 -0
  100. data/test/vagrant/downloaders/base_test.rb +27 -0
  101. data/test/vagrant/downloaders/file_test.rb +26 -0
  102. data/test/vagrant/downloaders/http_test.rb +40 -0
  103. data/test/vagrant/environment_test.rb +607 -0
  104. data/test/vagrant/provisioners/base_test.rb +33 -0
  105. data/test/vagrant/provisioners/chef_server_test.rb +187 -0
  106. data/test/vagrant/provisioners/chef_solo_test.rb +149 -0
  107. data/test/vagrant/provisioners/chef_test.rb +117 -0
  108. data/test/vagrant/ssh_test.rb +222 -0
  109. data/test/vagrant/util/errors_test.rb +57 -0
  110. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  111. data/test/vagrant/util/template_renderer_test.rb +138 -0
  112. data/test/vagrant/util_test.rb +64 -0
  113. data/test/vagrant/vm_test.rb +114 -0
  114. data/vagrant.gemspec +216 -0
  115. metadata +285 -0
@@ -0,0 +1,36 @@
1
+ require 'yaml'
2
+
3
+ module Vagrant
4
+ module Util
5
+ # This class is responsible for outputting errors. It retrieves the errors,
6
+ # based on their key, from the error file, and then outputs it.
7
+ class Errors
8
+ @@errors = nil
9
+
10
+ class <<self
11
+ # Resets the internal errors hash to nil, forcing a reload on the next
12
+ # access of {errors}.
13
+ def reset!
14
+ @@errors = nil
15
+ end
16
+
17
+ # Returns the hash of errors from the error YML files. This only loads once,
18
+ # then returns a cached value until {reset!} is called.
19
+ #
20
+ # @return [Hash]
21
+ def errors
22
+ @@errors ||= YAML.load_file(File.join(PROJECT_ROOT, "templates", "errors.yml"))
23
+ end
24
+
25
+ # Renders the error with the given key and data parameters and returns
26
+ # the rendered result.
27
+ #
28
+ # @return [String]
29
+ def error_string(key, data = {})
30
+ template = errors[key] || "Unknown error key: #{key}"
31
+ TemplateRenderer.render_string(template, data)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Vagrant
2
+ module Util
3
+ # Represents the "stacked proc runner" behavior which is used a
4
+ # couple places within Vagrant. This allows procs to "stack" on
5
+ # each other, then all execute in a single action. An example of
6
+ # its uses can be seen in the {Config} class.
7
+ module StackedProcRunner
8
+ # Returns the proc stack. This should always be called as the
9
+ # accessor of the stack. The instance variable itself should _never_
10
+ # be used.
11
+ #
12
+ # @return [Array<Proc>]
13
+ def proc_stack
14
+ @_proc_stack ||= []
15
+ end
16
+
17
+ # Adds (pushes) a proc to the stack. The actual proc added here is
18
+ # not executed, but merely stored.
19
+ #
20
+ # @param [Proc] block
21
+ def push_proc(&block)
22
+ proc_stack << block
23
+ end
24
+
25
+ # Executes all the procs on the stack, passing in the given arguments.
26
+ # The stack is not cleared afterwords. It is up to the user of this
27
+ # mixin to clear the stack by calling `proc_stack.clear`.
28
+ def run_procs!(*args)
29
+ proc_stack.each do |proc|
30
+ proc.call(*args)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,83 @@
1
+ require 'ostruct'
2
+ require 'erb'
3
+
4
+ module Vagrant
5
+ module Util
6
+ # This class is used to render the ERB templates in the
7
+ # `GEM_ROOT/templates` directory.
8
+ class TemplateRenderer < OpenStruct
9
+ class <<self
10
+ # Render a given template and return the result. This method optionally
11
+ # takes a block which will be passed the renderer prior to rendering, which
12
+ # allows the caller to set any view variables within the renderer itself.
13
+ #
14
+ # @return [String] Rendered template
15
+ def render(*args)
16
+ render_with(:render, *args)
17
+ end
18
+
19
+ # Render a given string and return the result. This method optionally
20
+ # takes a block which will be passed the renderer prior to rendering, which
21
+ # allows the caller to set any view variables within the renderer itself.
22
+ #
23
+ # @param [String] template The template data string.
24
+ # @return [String] Rendered template
25
+ def render_string(*args)
26
+ render_with(:render_string, *args)
27
+ end
28
+
29
+ # Method used internally to DRY out the other renderers. This method
30
+ # creates and sets up the renderer before calling a specified method on it.
31
+ def render_with(method, template, data={})
32
+ renderer = new(template, data)
33
+ yield renderer if block_given?
34
+ renderer.send(method.to_sym)
35
+ end
36
+ end
37
+
38
+ def initialize(template, data = {})
39
+ super()
40
+
41
+ data[:template] = template
42
+ data.each do |key, value|
43
+ send("#{key}=", value)
44
+ end
45
+ end
46
+
47
+ # Renders the template using the class intance as the binding. Because the
48
+ # renderer inherits from `OpenStruct`, additional view variables can be
49
+ # added like normal accessors.
50
+ #
51
+ # @return [String]
52
+ def render
53
+ # TODO: Seems like a pretty dirty way to do this. Perhaps refactor this
54
+ old_template = template
55
+ result = nil
56
+ File.open(full_template_path, 'r') do |f|
57
+ self.template = f.read
58
+ result = render_string
59
+ end
60
+
61
+ result
62
+ ensure
63
+ self.template = old_template
64
+ end
65
+
66
+ # Renders a template, handling the template as a string, but otherwise
67
+ # acting the same way as {#render}.
68
+ #
69
+ # @return [String]
70
+ def render_string
71
+ ERB.new(template).result(binding)
72
+ end
73
+
74
+ # Returns the full path to the template, taking into accoun the gem directory
75
+ # and adding the `.erb` extension to the end.
76
+ #
77
+ # @return [String]
78
+ def full_template_path
79
+ File.join(PROJECT_ROOT, 'templates', "#{template}.erb")
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,61 @@
1
+ module Vagrant
2
+ class VM < Actions::Runner
3
+ include Vagrant::Util
4
+
5
+ attr_accessor :env
6
+ attr_accessor :vm
7
+ attr_accessor :from
8
+
9
+ class << self
10
+ # Finds a virtual machine by a given UUID and either returns
11
+ # a Vagrant::VM object or returns nil.
12
+ def find(uuid)
13
+ vm = VirtualBox::VM.find(uuid)
14
+ return nil if vm.nil?
15
+ new(vm)
16
+ end
17
+ end
18
+
19
+ def initialize(vm=nil)
20
+ @vm = vm
21
+ end
22
+
23
+ def uuid
24
+ vm ? vm.uuid : nil
25
+ end
26
+
27
+ def reload!
28
+ @vm = VirtualBox::VM.find(@vm.uuid)
29
+ end
30
+
31
+ def package(out_path, include_files=[])
32
+ add_action(Actions::VM::Export)
33
+ add_action(Actions::VM::Package, out_path, include_files)
34
+ execute!
35
+ end
36
+
37
+ def start
38
+ return if @vm.running?
39
+
40
+ execute!(Actions::VM::Start)
41
+ end
42
+
43
+ def destroy
44
+ execute!(Actions::VM::Down)
45
+ end
46
+
47
+ def suspend
48
+ execute!(Actions::VM::Suspend)
49
+ end
50
+
51
+ def resume
52
+ execute!(Actions::VM::Resume)
53
+ end
54
+
55
+ def saved?
56
+ @vm.saved?
57
+ end
58
+
59
+ def powered_off?; @vm.powered_off? end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ Vagrant::Config.run do |config|
2
+ # All Vagrant configuration is done here. For a detailed explanation
3
+ # and listing of configuration options, please view the documentation
4
+ # online.
5
+
6
+ # Every Vagrant virtual environment requires a box to build off of.
7
+ config.vm.box = "<%= default_box %>"
8
+ end
@@ -0,0 +1,117 @@
1
+ :box_already_exists: "This box appears to already exist! Please call `vagrant box remove <%= box_name %>`
2
+ \nand then try to add it again."
3
+ :box_add_already_exists: "A box with the name '<%= box_name %>' already exists, please use another name or use `vagrant box remove <%= box_name %>`"
4
+ :box_download_unknown_type: "Unknown URI type for box download."
5
+ :box_remove_doesnt_exist: "The box you're attempting to remove does not exist!"
6
+ :box_specified_doesnt_exist: "Specified box `<%= box_name %>` does not exist!
7
+
8
+ \nThe box must be added through the `vagrant box add` command. Please view
9
+ \nthe documentation associated with the command for more information."
10
+ :box_not_specified: "No base box was specified! A base box is required as a staring point
11
+ \nfor every vagrant virtual machine. Please specify one in your Vagrantfile
12
+ \nusing `config.vm.box`"
13
+ :chef_base_invalid_provisioner: "Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefServer instead."
14
+ :chef_server_url_required: "Chef server provisioning requires that the `config.chef.chef_server_url` be set to the
15
+ \nURL of your chef server. Examples include \"http://12.12.12.12:4000\" and
16
+ \n\"http://myserver.com:4000\" (the port of course can be different, but 4000 is the default)"
17
+ :chef_server_validation_key_required: "Chef server provisioning requires that the `config.chef.validation_key_path` configuration
18
+ \nbe set to a path on your local machine of the validation key used to register the
19
+ \nVM with the chef server."
20
+ :chef_server_validation_key_doesnt_exist: "The validation key set for `config.chef.validation_key_path` does not exist! This
21
+ \nfile needs to exist so it can be uploaded to the virtual machine. It is
22
+ \ncurrently set to \"<%= Vagrant.config.chef.validation_key_path %>\""
23
+ :command_box_invalid: "Please specify a valid action to take on the boxes, either
24
+ \n`add` or `remove`. Examples:
25
+
26
+ \nvagrant box add name uri
27
+ \nvagrant box remove name
28
+ \nvagrant box list"
29
+ :dotfile_error: "The dotfile which Vagrant uses to store the UUID of the project's
30
+ \nvirtual machine already exists and is not a file! The dotfile is
31
+ \ncurrently configured to be `<%= env.dotfile_path %>`
32
+
33
+ \nTo change this value, please see `config.vagrant.dotfile_name`
34
+
35
+ \nThis often exists if you're trying to create a Vagrant virtual
36
+ \nenvironment from your home directory. To resolve this, you can either
37
+ \nmodify the configuration a bit, or simply use a different directory."
38
+ :downloader_file_doesnt_exist: "The given box does not exist on the file system:\n
39
+
40
+ \n<%= source_url %>"
41
+ :environment_not_created: "The task you're trying to run requires that the vagrant environment
42
+ \nalready be created, but unfortunately this vagrant still appears to
43
+ \nhave no box! You can setup the environment by setting up your
44
+ \n<%= Vagrant::Environment::ROOTFILE_NAME %> and running `vagrant up`"
45
+ :package_include_file_doesnt_exist: "File specified to include: '<%= filename %>' does not exist!"
46
+ :package_requires_export: "Package must be used in conjunction with export."
47
+ :provisioner_invalid_class: "Provisioners must be an instance of Vagrant::Provisioners::Base"
48
+ :provisioner_unknown_type: "Unknown provisioner type: <%= provisioner %>"
49
+ :rootfile_already_exists: "It looks like this directory is already setup for vagrant! (A <%= Vagrant::Environment::ROOTFILE_NAME %>
50
+ \nalready exists.)"
51
+ :rootfile_not_found: "A `<%= Vagrant::Environment::ROOTFILE_NAME %>` was not found! This file is required for vagrant to run
52
+ \nsince it describes the expected environment that vagrant is supposed
53
+ \nto manage. Please create a `<%= Vagrant::Environment::ROOTFILE_NAME %>` and place it in your project
54
+ \nroot."
55
+ :ssh_bad_permissions: "The private key to connect to this box via SSH has invalid permissions
56
+ \nset on it. The permissions of the private key should be set to 0600, otherwise SSH will
57
+ \nignore the key. Vagrant tried to do this automatically for you but failed. Please set the
58
+ \npermissions on the following file to 0600 and then try running this command again:
59
+
60
+ \n<%= key_path %>"
61
+ :virtualbox_import_failure: "The VM import failed! Try running `VBoxManage import` on the box file manually for more verbose error output."
62
+ :virtualbox_invalid_version: "Vagrant has detected that you have VirtualBox version <%= version %> installed!
63
+ \nVagrant requires that you use at least VirtualBox version 3.1. Please install
64
+ \na more recent version of VirtualBox to continue."
65
+ :virtualbox_not_detected: "Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
66
+ \nIf VirtualBox is installed, you may need to tweak the paths to the `VBoxManage`
67
+ \napplication which ships with VirtualBox and the path to the global XML configuration
68
+ \nwhich VirtualBox typically stores somewhere in your home directory.
69
+
70
+ \nThe following shows how to configure VirtualBox. This can be done in the
71
+ \nVagrantfile. Note that 90% of the time, you shouldn't need to do this if VirtualBox
72
+ \nis installed. Please use the various Vagrant support lines to request more information
73
+ \nif you can't get this working.
74
+
75
+ \nVirtualBox::Command.vboxmanage = \"/path/to/my/VBoxManage\"
76
+ \nVirtualBox::Global.vboxconfig = \"~/path/to/VirtualBox.xml\""
77
+ :virtualbox_xml_not_detected: "Vagrant couldn't find your global VirtualBox.xml file!
78
+
79
+ \nIf you just recently installed VirtualBox, make sure you've launched
80
+ \nit at least once, since the initial launch will typically create this
81
+ \nfile.
82
+
83
+ \nOtherwise, you may need to set the path to the VirtualBox.xml file
84
+ \nmanually. Note that 90% of people should never have to do this, so
85
+ \ndon't be afraid to use the various Vagrant support lines to ask for
86
+ \nhelp. To set the path manually:
87
+
88
+ \nVirtualBox::Global.vboxconfig = \"/path/to/VirtualBox.xml\""
89
+ :vm_failed_to_boot: "Failed to connect to VM! Failed to boot?"
90
+ :vm_not_running: "VM is not running! Nothing to shut down!"
91
+ :vm_not_running_for_suspend: "The vagrant virtual environment you are trying to suspend must be running to be suspended."
92
+ :vm_not_suspended: "The vagrant virtual environment you are trying to resume is not in a suspended state."
93
+ :vm_port_collision: "Vagrant cannot forward the specified ports on this VM, since they
94
+ \nwould collide with another VirtualBox virtual machine's forwarded
95
+ \nports! The \"<%= name %>\" forwarded port (<%= hostport %>) is already in use on the host
96
+ \nmachine.
97
+
98
+ \nTo fix this, modify your current projects Vagrantfile to use another
99
+ \nport. Example, where '1234' would be replaced by a unique host port:
100
+
101
+ \nconfig.vm.forward_port(\"<%= name %>\", <%= guestport %>, 1234)"
102
+ :vm_power_off_to_move_hd: "The virtual machine must be powered off to move its disk."
103
+ :vm_power_off_to_package: "The vagrant virtual environment you are trying to package must be powered off."
104
+ :vm_mount_fail: "Failed to mount shared folders. vboxsf was not available."
105
+ :vm_ssh_auth_failed: "SSH authentication failed! While this could be due to a variety of reasons,
106
+ \nthe two most common are: private key path is incorrect or you're using a box
107
+ \nwhich was built for Vagrant 0.1.x.
108
+
109
+ \nVagrant 0.2.x dropped support for password-based authentication. If you're
110
+ \ntring to `vagrant up` a box which does not support Vagrant's private/public
111
+ \nkeypair, then this error will be raised. To resolve this, read the guide
112
+ \non converting base boxes from password-based to keypairs here:
113
+
114
+ \nhttp://vagrantup.com/docs/converting_password_to_key_ssh.html
115
+
116
+ \nIf the box was built for 0.2.x and contains a custom public key, perhaps
117
+ \nthe path to the private key is incorrect. Check your `config.ssh.private_key_path`."
@@ -0,0 +1,163 @@
1
+ begin
2
+ require File.expand_path('../.bundle/environment', __FILE__)
3
+ rescue LoadError
4
+ # Fallback on doing the resolve at runtime.
5
+ require "rubygems"
6
+ require "bundler"
7
+ Bundler.setup
8
+ end
9
+
10
+ # ruby-debug, not necessary, but useful if we have it
11
+ begin
12
+ require 'ruby-debug'
13
+ rescue LoadError; end
14
+
15
+
16
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'vagrant')
17
+ require 'contest'
18
+ require 'mocha'
19
+
20
+ class Test::Unit::TestCase
21
+ # Mocks an environment, setting it up with the given config.
22
+ def mock_environment
23
+ environment = Vagrant::Environment.new
24
+
25
+ Vagrant::Config.reset!(environment)
26
+
27
+ Vagrant::Config.run do |config|
28
+ config.vagrant.dotfile_name = ".vagrant"
29
+
30
+ config.ssh.username = "foo"
31
+ config.ssh.password = "bar"
32
+ config.ssh.host = "baz"
33
+ config.ssh.forwarded_port_key = "ssh"
34
+ config.ssh.max_tries = 10
35
+ config.ssh.timeout = 10
36
+ config.ssh.private_key_path = '~/foo'
37
+
38
+ config.vm.box = "foo"
39
+ config.vm.box_ovf = "box.ovf"
40
+ config.vm.base_mac = "42"
41
+ config.vm.project_directory = "/vagrant"
42
+ config.vm.disk_image_format = 'VMDK'
43
+ config.vm.forward_port("ssh", 22, 2222)
44
+ config.vm.shared_folder_uid = nil
45
+ config.vm.shared_folder_gid = nil
46
+
47
+ config.package.name = 'vagrant'
48
+ config.package.extension = '.box'
49
+
50
+ # Chef
51
+ config.chef.chef_server_url = "http://localhost:4000"
52
+ config.chef.validation_key_path = "validation.pem"
53
+ config.chef.client_key_path = "/zoo/foo/bar.pem"
54
+ config.chef.cookbooks_path = "cookbooks"
55
+ config.chef.provisioning_path = "/tmp/vagrant-chef"
56
+ config.chef.json = {
57
+ :recipes => ["vagrant_main"]
58
+ }
59
+
60
+ config.vagrant.home = '~/.home'
61
+ end
62
+
63
+ if block_given?
64
+ Vagrant::Config.run do |config|
65
+ yield config
66
+ end
67
+ end
68
+
69
+ config = Vagrant::Config.execute!
70
+
71
+ environment.instance_variable_set(:@config, config)
72
+ environment
73
+ end
74
+
75
+ # Clears the previous config and sets up the new config
76
+ def mock_config
77
+ Vagrant::Config.reset!
78
+
79
+ Vagrant::Config.run do |config|
80
+ config.vagrant.dotfile_name = ".vagrant"
81
+
82
+ config.ssh.username = "foo"
83
+ config.ssh.password = "bar"
84
+ config.ssh.host = "baz"
85
+ config.ssh.forwarded_port_key = "ssh"
86
+ config.ssh.max_tries = 10
87
+ config.ssh.timeout = 10
88
+ config.ssh.private_key_path = '~/foo'
89
+
90
+ config.vm.box = "foo"
91
+ config.vm.box_ovf = "box.ovf"
92
+ config.vm.base_mac = "42"
93
+ config.vm.project_directory = "/vagrant"
94
+ config.vm.disk_image_format = 'VMDK'
95
+ config.vm.forward_port("ssh", 22, 2222)
96
+ config.vm.shared_folder_uid = nil
97
+ config.vm.shared_folder_gid = nil
98
+
99
+ config.package.name = 'vagrant'
100
+ config.package.extension = '.box'
101
+
102
+ # Chef
103
+ config.chef.chef_server_url = "http://localhost:4000"
104
+ config.chef.validation_key_path = "validation.pem"
105
+ config.chef.client_key_path = "/zoo/foo/bar.pem"
106
+ config.chef.cookbooks_path = "cookbooks"
107
+ config.chef.provisioning_path = "/tmp/vagrant-chef"
108
+ config.chef.json = {
109
+ :recipes => ["vagrant_main"]
110
+ }
111
+
112
+ config.vagrant.home = '~/.home'
113
+ end
114
+
115
+ if block_given?
116
+ Vagrant::Config.run do |config|
117
+ yield config
118
+ end
119
+ end
120
+
121
+ if block_given?
122
+ Vagrant::Config.run do |config|
123
+ yield config
124
+ end
125
+ end
126
+
127
+ Vagrant::Config.execute!
128
+ end
129
+
130
+ # Sets up the mocks and instantiates an action for testing
131
+ def mock_action(action_klass, *args)
132
+ vm = mock("vboxvm")
133
+ mock_vm = mock("vm")
134
+ action = action_klass.new(mock_vm, *args)
135
+ stub_default_action_dependecies(action)
136
+
137
+ mock_vm.stubs(:vm).returns(vm)
138
+ mock_vm.stubs(:vm=)
139
+ mock_vm.stubs(:invoke_callback)
140
+ mock_vm.stubs(:invoke_around_callback).yields
141
+ mock_vm.stubs(:actions).returns([action])
142
+ mock_vm.stubs(:env).returns(mock_environment)
143
+
144
+ [mock_vm, vm, action]
145
+ end
146
+
147
+ def stub_default_action_dependecies(mock, klass=MockAction)
148
+ mock.stubs(:precedes).returns([])
149
+ mock.stubs(:follows).returns([])
150
+ end
151
+
152
+ # Sets up the mocks and stubs for a downloader
153
+ def mock_downloader(downloader_klass)
154
+ tempfile = mock("tempfile")
155
+ tempfile.stubs(:write)
156
+
157
+ [downloader_klass.new, tempfile]
158
+ end
159
+ end
160
+
161
+ class MockAction; end
162
+ class MockActionOther; end
163
+