vagrant 0.1.4 → 0.2.0.pre
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/Gemfile +1 -1
 - data/Rakefile +1 -1
 - data/VERSION +1 -1
 - data/bin/vagrant-box +1 -2
 - data/bin/vagrant-down +1 -2
 - data/bin/vagrant-halt +1 -2
 - data/bin/vagrant-init +1 -2
 - data/bin/vagrant-package +1 -2
 - data/bin/vagrant-reload +1 -2
 - data/bin/vagrant-resume +1 -2
 - data/bin/vagrant-ssh +1 -2
 - data/bin/vagrant-status +29 -0
 - data/bin/vagrant-suspend +1 -2
 - data/bin/vagrant-up +1 -2
 - data/config/default.rb +5 -9
 - data/keys/README.md +10 -0
 - data/keys/vagrant +27 -0
 - data/keys/vagrant.pub +1 -0
 - data/lib/vagrant/actions/base.rb +14 -0
 - data/lib/vagrant/actions/collection.rb +36 -0
 - data/lib/vagrant/actions/runner.rb +4 -10
 - data/lib/vagrant/actions/vm/boot.rb +4 -5
 - data/lib/vagrant/actions/vm/customize.rb +17 -0
 - data/lib/vagrant/actions/vm/destroy.rb +11 -2
 - data/lib/vagrant/actions/vm/forward_ports.rb +24 -0
 - data/lib/vagrant/actions/vm/import.rb +1 -0
 - data/lib/vagrant/actions/vm/provision.rb +30 -52
 - data/lib/vagrant/actions/vm/reload.rb +2 -2
 - data/lib/vagrant/actions/vm/shared_folders.rb +37 -25
 - data/lib/vagrant/actions/vm/up.rb +8 -4
 - data/lib/vagrant/active_list.rb +66 -0
 - data/lib/vagrant/commands.rb +44 -0
 - data/lib/vagrant/config.rb +64 -47
 - data/lib/vagrant/downloaders/file.rb +2 -12
 - data/lib/vagrant/env.rb +48 -12
 - data/lib/vagrant/provisioners/base.rb +22 -0
 - data/lib/vagrant/provisioners/chef.rb +102 -0
 - data/lib/vagrant/provisioners/chef_server.rb +96 -0
 - data/lib/vagrant/provisioners/chef_solo.rb +67 -0
 - data/lib/vagrant/ssh.rb +25 -6
 - data/lib/vagrant/stacked_proc_runner.rb +33 -0
 - data/lib/vagrant/vm.rb +8 -0
 - data/lib/vagrant.rb +10 -5
 - data/test/test_helper.rb +22 -6
 - data/test/vagrant/actions/collection_test.rb +110 -0
 - data/test/vagrant/actions/runner_test.rb +11 -7
 - data/test/vagrant/actions/vm/boot_test.rb +7 -7
 - data/test/vagrant/actions/vm/customize_test.rb +16 -0
 - data/test/vagrant/actions/vm/destroy_test.rb +19 -6
 - data/test/vagrant/actions/vm/forward_ports_test.rb +52 -0
 - data/test/vagrant/actions/vm/import_test.rb +10 -3
 - data/test/vagrant/actions/vm/provision_test.rb +75 -70
 - data/test/vagrant/actions/vm/reload_test.rb +3 -2
 - data/test/vagrant/actions/vm/shared_folders_test.rb +62 -9
 - data/test/vagrant/actions/vm/up_test.rb +4 -4
 - data/test/vagrant/active_list_test.rb +169 -0
 - data/test/vagrant/config_test.rb +145 -29
 - data/test/vagrant/downloaders/file_test.rb +4 -19
 - data/test/vagrant/env_test.rb +96 -23
 - data/test/vagrant/provisioners/base_test.rb +27 -0
 - data/test/vagrant/provisioners/chef_server_test.rb +175 -0
 - data/test/vagrant/provisioners/chef_solo_test.rb +142 -0
 - data/test/vagrant/provisioners/chef_test.rb +116 -0
 - data/test/vagrant/ssh_test.rb +29 -8
 - data/test/vagrant/stacked_proc_runner_test.rb +43 -0
 - data/test/vagrant/vm_test.rb +23 -0
 - data/vagrant.gemspec +35 -8
 - metadata +42 -11
 - data/script/vagrant-ssh-expect.sh +0 -22
 
    
        data/test/vagrant/config_test.rb
    CHANGED
    
    | 
         @@ -1,6 +1,23 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.join(File.dirname(__FILE__), '..', 'test_helper')
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class ConfigTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              context "the ssh config" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                should "expand any path when requesting the value" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  Vagrant::Env.stubs(:root_path).returns('foo')
         
     | 
| 
      
 7 
     | 
    
         
            +
                  File.stubs(:expand_path).with(Vagrant.config.ssh[:private_key_path], 'foo').returns('success')
         
     | 
| 
      
 8 
     | 
    
         
            +
                  assert Vagrant.config.ssh.private_key_path, 'success'
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              context "adding configures" do
         
     | 
| 
      
 13 
     | 
    
         
            +
                should "forward the method to the Top class" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  key = mock("key")
         
     | 
| 
      
 15 
     | 
    
         
            +
                  klass = mock("klass")
         
     | 
| 
      
 16 
     | 
    
         
            +
                  Vagrant::Config::Top.expects(:configures).with(key, klass)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  Vagrant::Config.configures(key, klass)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       4 
21 
     | 
    
         
             
              context "resetting" do
         
     | 
| 
       5 
22 
     | 
    
         
             
                setup do
         
     | 
| 
       6 
23 
     | 
    
         
             
                  Vagrant::Config.run { |config| }
         
     | 
| 
         @@ -18,10 +35,10 @@ class ConfigTest < Test::Unit::TestCase 
     | 
|
| 
       18 
35 
     | 
    
         
             
                  assert !config.equal?(Vagrant::Config.config)
         
     | 
| 
       19 
36 
     | 
    
         
             
                end
         
     | 
| 
       20 
37 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                should "empty the  
     | 
| 
       22 
     | 
    
         
            -
                  assert !Vagrant::Config. 
     | 
| 
      
 38 
     | 
    
         
            +
                should "empty the proc stack" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  assert !Vagrant::Config.proc_stack.empty?
         
     | 
| 
       23 
40 
     | 
    
         
             
                  Vagrant::Config.reset!
         
     | 
| 
       24 
     | 
    
         
            -
                  assert Vagrant::Config. 
     | 
| 
      
 41 
     | 
    
         
            +
                  assert Vagrant::Config.proc_stack.empty?
         
     | 
| 
       25 
42 
     | 
    
         
             
                end
         
     | 
| 
       26 
43 
     | 
    
         
             
              end
         
     | 
| 
       27 
44 
     | 
    
         | 
| 
         @@ -37,30 +54,18 @@ class ConfigTest < Test::Unit::TestCase 
     | 
|
| 
       37 
54 
     | 
    
         
             
              end
         
     | 
| 
       38 
55 
     | 
    
         | 
| 
       39 
56 
     | 
    
         
             
              context "initializing" do
         
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
       41 
     | 
    
         
            -
                  Vagrant::Config. 
     | 
| 
       42 
     | 
    
         
            -
                  Vagrant::Config.instance_variable_set(:@config, nil)
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                should "not run the blocks right away" do
         
     | 
| 
       46 
     | 
    
         
            -
                  obj = mock("obj")
         
     | 
| 
       47 
     | 
    
         
            -
                  obj.expects(:foo).never
         
     | 
| 
       48 
     | 
    
         
            -
                  Vagrant::Config.run { |config| obj.foo }
         
     | 
| 
       49 
     | 
    
         
            -
                  Vagrant::Config.run { |config| obj.foo }
         
     | 
| 
       50 
     | 
    
         
            -
                  Vagrant::Config.run { |config| obj.foo }
         
     | 
| 
      
 57 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  Vagrant::Config.reset!
         
     | 
| 
       51 
59 
     | 
    
         
             
                end
         
     | 
| 
       52 
60 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                should " 
     | 
| 
       54 
     | 
    
         
            -
                   
     | 
| 
       55 
     | 
    
         
            -
                   
     | 
| 
       56 
     | 
    
         
            -
                  Vagrant::Config. 
     | 
| 
       57 
     | 
    
         
            -
                  Vagrant::Config.run { |config| obj.foo }
         
     | 
| 
       58 
     | 
    
         
            -
                  Vagrant::Config.execute!
         
     | 
| 
      
 61 
     | 
    
         
            +
                should "add the given block to the proc stack" do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  proc = Proc.new {}
         
     | 
| 
      
 63 
     | 
    
         
            +
                  Vagrant::Config.run(&proc)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  assert_equal [proc], Vagrant::Config.proc_stack
         
     | 
| 
       59 
65 
     | 
    
         
             
                end
         
     | 
| 
       60 
66 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
                should "run the  
     | 
| 
       62 
     | 
    
         
            -
                  Vagrant::Config. 
     | 
| 
       63 
     | 
    
         
            -
                  Vagrant::Config.run { |config| assert config }
         
     | 
| 
      
 67 
     | 
    
         
            +
                should "run the proc stack with the config when execute is called" do
         
     | 
| 
      
 68 
     | 
    
         
            +
                  Vagrant::Config.expects(:run_procs!).with(Vagrant::Config.config).once
         
     | 
| 
       64 
69 
     | 
    
         
             
                  Vagrant::Config.execute!
         
     | 
| 
       65 
70 
     | 
    
         
             
                end
         
     | 
| 
       66 
71 
     | 
    
         | 
| 
         @@ -109,15 +114,126 @@ class ConfigTest < Test::Unit::TestCase 
     | 
|
| 
       109 
114 
     | 
    
         
             
                end
         
     | 
| 
       110 
115 
     | 
    
         
             
              end
         
     | 
| 
       111 
116 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
              context " 
     | 
| 
      
 117 
     | 
    
         
            +
              context "top config class" do
         
     | 
| 
       113 
118 
     | 
    
         
             
                setup do
         
     | 
| 
       114 
     | 
    
         
            -
                  @ 
     | 
| 
       115 
     | 
    
         
            -
                  @ 
     | 
| 
      
 119 
     | 
    
         
            +
                  @configures_list = []
         
     | 
| 
      
 120 
     | 
    
         
            +
                  Vagrant::Config::Top.stubs(:configures_list).returns(@configures_list)
         
     | 
| 
       116 
121 
     | 
    
         
             
                end
         
     | 
| 
       117 
122 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
                 
     | 
| 
       119 
     | 
    
         
            -
                   
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
      
 123 
     | 
    
         
            +
                context "adding configure keys" do
         
     | 
| 
      
 124 
     | 
    
         
            +
                  setup do
         
     | 
| 
      
 125 
     | 
    
         
            +
                    @key = "top_config_foo"
         
     | 
| 
      
 126 
     | 
    
         
            +
                    @klass = mock("klass")
         
     | 
| 
      
 127 
     | 
    
         
            +
                  end
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                  should "add key and klass to configures list" do
         
     | 
| 
      
 130 
     | 
    
         
            +
                    @configures_list.expects(:<<).with([@key, @klass])
         
     | 
| 
      
 131 
     | 
    
         
            +
                    Vagrant::Config::Top.configures(@key, @klass)
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
      
 133 
     | 
    
         
            +
                end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                context "configuration keys on instance" do
         
     | 
| 
      
 136 
     | 
    
         
            +
                  setup do
         
     | 
| 
      
 137 
     | 
    
         
            +
                    @configures_list.clear
         
     | 
| 
      
 138 
     | 
    
         
            +
                  end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                  should "initialize each configurer and set it to its key" do
         
     | 
| 
      
 141 
     | 
    
         
            +
                    5.times do |i|
         
     | 
| 
      
 142 
     | 
    
         
            +
                      key = "key#{i}"
         
     | 
| 
      
 143 
     | 
    
         
            +
                      klass = mock("klass#{i}")
         
     | 
| 
      
 144 
     | 
    
         
            +
                      instance = mock("instance#{i}")
         
     | 
| 
      
 145 
     | 
    
         
            +
                      klass.expects(:new).returns(instance)
         
     | 
| 
      
 146 
     | 
    
         
            +
                      @configures_list << [key, klass]
         
     | 
| 
      
 147 
     | 
    
         
            +
                    end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                    Vagrant::Config::Top.new
         
     | 
| 
      
 150 
     | 
    
         
            +
                  end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                  should "allow reading via methods" do
         
     | 
| 
      
 153 
     | 
    
         
            +
                    key = "my_foo_bar_key"
         
     | 
| 
      
 154 
     | 
    
         
            +
                    klass = mock("klass")
         
     | 
| 
      
 155 
     | 
    
         
            +
                    instance = mock("instance")
         
     | 
| 
      
 156 
     | 
    
         
            +
                    klass.expects(:new).returns(instance)
         
     | 
| 
      
 157 
     | 
    
         
            +
                    Vagrant::Config::Top.configures(key, klass)
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                    config = Vagrant::Config::Top.new
         
     | 
| 
      
 160 
     | 
    
         
            +
                    assert_equal instance, config.send(key)
         
     | 
| 
      
 161 
     | 
    
         
            +
                  end
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                context "loaded status" do
         
     | 
| 
      
 165 
     | 
    
         
            +
                  setup do
         
     | 
| 
      
 166 
     | 
    
         
            +
                    @top= Vagrant::Config::Top.new
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                  should "not be loaded by default" do
         
     | 
| 
      
 170 
     | 
    
         
            +
                    assert !@top.loaded?
         
     | 
| 
      
 171 
     | 
    
         
            +
                  end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                  should "be loaded after calling loaded!" do
         
     | 
| 
      
 174 
     | 
    
         
            +
                    @top.loaded!
         
     | 
| 
      
 175 
     | 
    
         
            +
                    assert @top.loaded?
         
     | 
| 
      
 176 
     | 
    
         
            +
                  end
         
     | 
| 
      
 177 
     | 
    
         
            +
                end
         
     | 
| 
      
 178 
     | 
    
         
            +
              end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
              context "vagrant configuration" do
         
     | 
| 
      
 181 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 182 
     | 
    
         
            +
                  @config = Vagrant::Config::VagrantConfig.new
         
     | 
| 
      
 183 
     | 
    
         
            +
                end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                should "return nil if home is nil" do
         
     | 
| 
      
 186 
     | 
    
         
            +
                  File.expects(:expand_path).never
         
     | 
| 
      
 187 
     | 
    
         
            +
                  assert @config.home.nil?
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                should "expand the path if home is not nil" do
         
     | 
| 
      
 191 
     | 
    
         
            +
                  @config.home = "foo"
         
     | 
| 
      
 192 
     | 
    
         
            +
                  File.expects(:expand_path).with("foo").once.returns("result")
         
     | 
| 
      
 193 
     | 
    
         
            +
                  assert_equal "result", @config.home
         
     | 
| 
      
 194 
     | 
    
         
            +
                end
         
     | 
| 
      
 195 
     | 
    
         
            +
              end
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
              context "VM configuration" do
         
     | 
| 
      
 198 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 199 
     | 
    
         
            +
                  @config = Vagrant::Config::VMConfig.new
         
     | 
| 
      
 200 
     | 
    
         
            +
                  @username = "bob"
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
      
 202 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 203 
     | 
    
         
            +
                    config.ssh.username = @username
         
     | 
| 
      
 204 
     | 
    
         
            +
                  end
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                should "include the stacked proc runner module" do
         
     | 
| 
      
 208 
     | 
    
         
            +
                  assert @config.class.included_modules.include?(Vagrant::StackedProcRunner)
         
     | 
| 
      
 209 
     | 
    
         
            +
                end
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
                should "add the customize proc to the proc stack" do
         
     | 
| 
      
 212 
     | 
    
         
            +
                  proc = Proc.new {}
         
     | 
| 
      
 213 
     | 
    
         
            +
                  @config.customize(&proc)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  assert_equal [proc], @config.proc_stack
         
     | 
| 
      
 215 
     | 
    
         
            +
                end
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                context "uid/gid" do
         
     | 
| 
      
 218 
     | 
    
         
            +
                  should "return the shared folder UID if set" do
         
     | 
| 
      
 219 
     | 
    
         
            +
                    @config.shared_folder_uid = "foo"
         
     | 
| 
      
 220 
     | 
    
         
            +
                    assert_equal "foo", @config.shared_folder_uid
         
     | 
| 
      
 221 
     | 
    
         
            +
                  end
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
                  should "return the SSH username if UID not set" do
         
     | 
| 
      
 224 
     | 
    
         
            +
                    @config.shared_folder_uid = nil
         
     | 
| 
      
 225 
     | 
    
         
            +
                    assert_equal @username, @config.shared_folder_uid
         
     | 
| 
      
 226 
     | 
    
         
            +
                  end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                  should "return the shared folder GID if set" do
         
     | 
| 
      
 229 
     | 
    
         
            +
                    @config.shared_folder_gid = "foo"
         
     | 
| 
      
 230 
     | 
    
         
            +
                    assert_equal "foo", @config.shared_folder_gid
         
     | 
| 
      
 231 
     | 
    
         
            +
                  end
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                  should "return the SSH username if GID not set" do
         
     | 
| 
      
 234 
     | 
    
         
            +
                    @config.shared_folder_gid = nil
         
     | 
| 
      
 235 
     | 
    
         
            +
                    assert_equal @username, @config.shared_folder_gid
         
     | 
| 
      
 236 
     | 
    
         
            +
                  end
         
     | 
| 
       121 
237 
     | 
    
         
             
                end
         
     | 
| 
       122 
238 
     | 
    
         
             
              end
         
     | 
| 
       123 
239 
     | 
    
         
             
            end
         
     | 
| 
         @@ -7,25 +7,10 @@ class FileDownloaderTest < Test::Unit::TestCase 
     | 
|
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
              context "downloading" do
         
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
       12 
     | 
    
         
            -
                  @ 
     | 
| 
       13 
     | 
    
         
            -
                   
     | 
| 
       14 
     | 
    
         
            -
                  @downloader.stubs(:open).yields(@file)
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                should "open with the given uri" do
         
     | 
| 
       18 
     | 
    
         
            -
                  @downloader.expects(:open).with(@uri).once
         
     | 
| 
       19 
     | 
    
         
            -
                  @downloader.download!(@uri, @tempfile)
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                should "buffer the read from the file and write to the tempfile" do
         
     | 
| 
       23 
     | 
    
         
            -
                  data = mock("data")
         
     | 
| 
       24 
     | 
    
         
            -
                  write_seq = sequence("write_seq")
         
     | 
| 
       25 
     | 
    
         
            -
                  @file.stubs(:eof?).returns(false).in_sequence(write_seq)
         
     | 
| 
       26 
     | 
    
         
            -
                  @file.expects(:read).returns(data).in_sequence(write_seq)
         
     | 
| 
       27 
     | 
    
         
            -
                  @tempfile.expects(:write).with(data).in_sequence(write_seq)
         
     | 
| 
       28 
     | 
    
         
            -
                  @file.stubs(:eof?).returns(true).in_sequence(write_seq)
         
     | 
| 
      
 10 
     | 
    
         
            +
                should "cp the file" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  path = '/path'
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @tempfile.expects(:path).returns(path)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  FileUtils.expects(:cp).with(@uri, path)
         
     | 
| 
       29 
14 
     | 
    
         
             
                  @downloader.download!(@uri, @tempfile)
         
     | 
| 
       30 
15 
     | 
    
         
             
                end
         
     | 
| 
       31 
16 
     | 
    
         
             
              end
         
     | 
    
        data/test/vagrant/env_test.rb
    CHANGED
    
    | 
         @@ -15,6 +15,24 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       15 
15 
     | 
    
         
             
                Vagrant::Box.stubs(:find).returns("foo")
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
              context "checking virtualbox version" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  VirtualBox::Command.stubs(:version)
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                should "error and exit if VirtualBox is not installed or detected" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Vagrant::Env.expects(:error_and_exit).once
         
     | 
| 
      
 25 
     | 
    
         
            +
                  VirtualBox::Command.expects(:version).returns(nil)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  Vagrant::Env.check_virtualbox!
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                should "error and exit if VirtualBox is lower than version 3.1" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  Vagrant::Env.expects(:error_and_exit).once
         
     | 
| 
      
 31 
     | 
    
         
            +
                  VirtualBox::Command.expects(:version).returns("3.0.12r1041")
         
     | 
| 
      
 32 
     | 
    
         
            +
                  Vagrant::Env.check_virtualbox!
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       18 
36 
     | 
    
         
             
              context "requiring a VM" do
         
     | 
| 
       19 
37 
     | 
    
         
             
                setup do
         
     | 
| 
       20 
38 
     | 
    
         
             
                  Vagrant::Env.stubs(:require_root_path)
         
     | 
| 
         @@ -89,6 +107,20 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       89 
107 
     | 
    
         
             
                  Vagrant::Env.load_config!
         
     | 
| 
       90 
108 
     | 
    
         
             
                end
         
     | 
| 
       91 
109 
     | 
    
         | 
| 
      
 110 
     | 
    
         
            +
                should "load from the home directory" do
         
     | 
| 
      
 111 
     | 
    
         
            +
                  File.expects(:exist?).with(File.join(Vagrant::Env.home_path, Vagrant::Env::ROOTFILE_NAME)).once
         
     | 
| 
      
 112 
     | 
    
         
            +
                  Vagrant::Env.load_config!
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                should "not load from the home directory if the home config is nil" do
         
     | 
| 
      
 116 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 117 
     | 
    
         
            +
                    config.vagrant.home = nil
         
     | 
| 
      
 118 
     | 
    
         
            +
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                  File.expects(:exist?).with(File.join(Vagrant::Env.home_path, Vagrant::Env::ROOTFILE_NAME)).never
         
     | 
| 
      
 121 
     | 
    
         
            +
                  Vagrant::Env.load_config!
         
     | 
| 
      
 122 
     | 
    
         
            +
                end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
       92 
124 
     | 
    
         
             
                should "not load from the root path if nil" do
         
     | 
| 
       93 
125 
     | 
    
         
             
                  Vagrant::Env.stubs(:root_path).returns(nil)
         
     | 
| 
       94 
126 
     | 
    
         
             
                  File.expects(:exist?).with(File.join(@root_path, Vagrant::Env::ROOTFILE_NAME)).never
         
     | 
| 
         @@ -129,29 +161,69 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       129 
161 
     | 
    
         
             
              end
         
     | 
| 
       130 
162 
     | 
    
         | 
| 
       131 
163 
     | 
    
         
             
              context "initial load" do
         
     | 
| 
       132 
     | 
    
         
            -
                 
     | 
| 
       133 
     | 
    
         
            -
                   
     | 
| 
       134 
     | 
    
         
            -
                  Vagrant::Env.expects(: 
     | 
| 
       135 
     | 
    
         
            -
                  Vagrant::Env.expects(: 
     | 
| 
       136 
     | 
    
         
            -
                  Vagrant::Env.expects(:load_home_directory!).once
         
     | 
| 
       137 
     | 
    
         
            -
                  Vagrant::Env.expects(:load_box!).once
         
     | 
| 
      
 164 
     | 
    
         
            +
                should "load! should load the config and set the persisted_uid" do
         
     | 
| 
      
 165 
     | 
    
         
            +
                  call_seq = sequence("call_sequence")
         
     | 
| 
      
 166 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq)
         
     | 
| 
      
 168 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_home_directory!).once.in_sequence(call_seq)
         
     | 
| 
      
 169 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_box!).once.in_sequence(call_seq)
         
     | 
| 
      
 170 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq)
         
     | 
| 
      
 171 
     | 
    
         
            +
                  Vagrant::Env.expects(:check_virtualbox!).once.in_sequence(call_seq)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  Vagrant::Env.expects(:load_vm!).once.in_sequence(call_seq)
         
     | 
| 
       138 
173 
     | 
    
         
             
                  Vagrant::Env.load!
         
     | 
| 
       139 
174 
     | 
    
         
             
                end
         
     | 
| 
       140 
175 
     | 
    
         
             
              end
         
     | 
| 
       141 
176 
     | 
    
         | 
| 
       142 
177 
     | 
    
         
             
              context "persisting the VM into a file" do
         
     | 
| 
       143 
178 
     | 
    
         
             
                setup do
         
     | 
| 
       144 
     | 
    
         
            -
                   
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
      
 179 
     | 
    
         
            +
                  @vm = mock("vm")
         
     | 
| 
      
 180 
     | 
    
         
            +
                  @vm.stubs(:uuid).returns("foo")
         
     | 
| 
       146 
181 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
                   
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
      
 182 
     | 
    
         
            +
                  File.stubs(:open)
         
     | 
| 
      
 183 
     | 
    
         
            +
                  Vagrant::ActiveList.stubs(:add)
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
       150 
185 
     | 
    
         | 
| 
      
 186 
     | 
    
         
            +
                should "should save it to the dotfile path" do
         
     | 
| 
       151 
187 
     | 
    
         
             
                  filemock = mock("filemock")
         
     | 
| 
       152 
     | 
    
         
            -
                  filemock.expects(:write).with(vm.uuid)
         
     | 
| 
      
 188 
     | 
    
         
            +
                  filemock.expects(:write).with(@vm.uuid)
         
     | 
| 
       153 
189 
     | 
    
         
             
                  File.expects(:open).with(Vagrant::Env.dotfile_path, 'w+').once.yields(filemock)
         
     | 
| 
       154 
     | 
    
         
            -
                  Vagrant::Env.persist_vm(vm)
         
     | 
| 
      
 190 
     | 
    
         
            +
                  Vagrant::Env.persist_vm(@vm)
         
     | 
| 
      
 191 
     | 
    
         
            +
                end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                should "add the VM to the activelist" do
         
     | 
| 
      
 194 
     | 
    
         
            +
                  Vagrant::ActiveList.expects(:add).with(@vm)
         
     | 
| 
      
 195 
     | 
    
         
            +
                  Vagrant::Env.persist_vm(@vm)
         
     | 
| 
      
 196 
     | 
    
         
            +
                end
         
     | 
| 
      
 197 
     | 
    
         
            +
              end
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
              context "depersisting the VM" do
         
     | 
| 
      
 200 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 201 
     | 
    
         
            +
                  File.stubs(:exist?).returns(false)
         
     | 
| 
      
 202 
     | 
    
         
            +
                  File.stubs(:delete)
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                  Vagrant::ActiveList.stubs(:remove)
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                  @dotfile_path = "foo"
         
     | 
| 
      
 207 
     | 
    
         
            +
                  Vagrant::Env.stubs(:dotfile_path).returns(@dotfile_path)
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                  @vm = mock("vm")
         
     | 
| 
      
 210 
     | 
    
         
            +
                end
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
                should "remove the dotfile if it exists" do
         
     | 
| 
      
 213 
     | 
    
         
            +
                  File.expects(:exist?).with(Vagrant::Env.dotfile_path).returns(true)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  File.expects(:delete).with(Vagrant::Env.dotfile_path).once
         
     | 
| 
      
 215 
     | 
    
         
            +
                  Vagrant::Env.depersist_vm(@vm)
         
     | 
| 
      
 216 
     | 
    
         
            +
                end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                should "not remove the dotfile if it doesn't exist" do
         
     | 
| 
      
 219 
     | 
    
         
            +
                  File.expects(:exist?).returns(false)
         
     | 
| 
      
 220 
     | 
    
         
            +
                  File.expects(:delete).never
         
     | 
| 
      
 221 
     | 
    
         
            +
                  Vagrant::Env.depersist_vm(@vm)
         
     | 
| 
      
 222 
     | 
    
         
            +
                end
         
     | 
| 
      
 223 
     | 
    
         
            +
             
     | 
| 
      
 224 
     | 
    
         
            +
                should "remove from the active list" do
         
     | 
| 
      
 225 
     | 
    
         
            +
                  Vagrant::ActiveList.expects(:remove).with(@vm)
         
     | 
| 
      
 226 
     | 
    
         
            +
                  Vagrant::Env.depersist_vm(@vm)
         
     | 
| 
       155 
227 
     | 
    
         
             
                end
         
     | 
| 
       156 
228 
     | 
    
         
             
              end
         
     | 
| 
       157 
229 
     | 
    
         | 
| 
         @@ -191,7 +263,7 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       191 
263 
     | 
    
         
             
              context "loading the root path" do
         
     | 
| 
       192 
264 
     | 
    
         
             
                should "default the path to the pwd if nil" do
         
     | 
| 
       193 
265 
     | 
    
         
             
                  @path = mock("path")
         
     | 
| 
       194 
     | 
    
         
            -
                  @path.stubs(: 
     | 
| 
      
 266 
     | 
    
         
            +
                  @path.stubs(:root?).returns(true)
         
     | 
| 
       195 
267 
     | 
    
         
             
                  Pathname.expects(:new).with(Dir.pwd).returns(@path)
         
     | 
| 
       196 
268 
     | 
    
         
             
                  Vagrant::Env.load_root_path!(nil)
         
     | 
| 
       197 
269 
     | 
    
         
             
                end
         
     | 
| 
         @@ -199,7 +271,9 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       199 
271 
     | 
    
         
             
                should "not default the path to pwd if its not nil" do
         
     | 
| 
       200 
272 
     | 
    
         
             
                  @path = mock("path")
         
     | 
| 
       201 
273 
     | 
    
         
             
                  @path.stubs(:to_s).returns("/")
         
     | 
| 
       202 
     | 
    
         
            -
                   
     | 
| 
      
 274 
     | 
    
         
            +
                  File.expects(:expand_path).with(@path).returns("/")
         
     | 
| 
      
 275 
     | 
    
         
            +
                  Pathname.expects(:new).with("/").returns(@path)
         
     | 
| 
      
 276 
     | 
    
         
            +
                  @path.stubs(:root?).returns(true)
         
     | 
| 
       203 
277 
     | 
    
         
             
                  Vagrant::Env.load_root_path!(@path)
         
     | 
| 
       204 
278 
     | 
    
         
             
                end
         
     | 
| 
       205 
279 
     | 
    
         | 
| 
         @@ -224,8 +298,13 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       224 
298 
     | 
    
         
             
                end
         
     | 
| 
       225 
299 
     | 
    
         | 
| 
       226 
300 
     | 
    
         
             
                should "return false if not found on windows-style root" do
         
     | 
| 
       227 
     | 
    
         
            -
                   
     | 
| 
       228 
     | 
    
         
            -
                   
     | 
| 
      
 301 
     | 
    
         
            +
                  # TODO: Is there _any_ way to test this on unix machines? The
         
     | 
| 
      
 302 
     | 
    
         
            +
                  # expand path doesn't work [properly for the test] on unix machines.
         
     | 
| 
      
 303 
     | 
    
         
            +
                  if RUBY_PLATFORM.downcase.include?("mswin")
         
     | 
| 
      
 304 
     | 
    
         
            +
                    # Note the escaped back slash
         
     | 
| 
      
 305 
     | 
    
         
            +
                    path = Pathname.new("C:\\")
         
     | 
| 
      
 306 
     | 
    
         
            +
                    assert !Vagrant::Env.load_root_path!(path)
         
     | 
| 
      
 307 
     | 
    
         
            +
                  end
         
     | 
| 
       229 
308 
     | 
    
         
             
                end
         
     | 
| 
       230 
309 
     | 
    
         | 
| 
       231 
310 
     | 
    
         
             
                should "should set the path for the rootfile" do
         
     | 
| 
         @@ -283,12 +362,6 @@ class EnvTest < Test::Unit::TestCase 
     | 
|
| 
       283 
362 
     | 
    
         
             
                  Vagrant::Env.load_box!
         
     | 
| 
       284 
363 
     | 
    
         
             
                  assert @box.equal?(Vagrant::Env.box)
         
     | 
| 
       285 
364 
     | 
    
         
             
                end
         
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
                should "load the config if a box is loaded" do
         
     | 
| 
       288 
     | 
    
         
            -
                  Vagrant::Env.expects(:load_config!).once
         
     | 
| 
       289 
     | 
    
         
            -
                  Vagrant::Box.expects(:find).returns(@box)
         
     | 
| 
       290 
     | 
    
         
            -
                  Vagrant::Env.load_box!
         
     | 
| 
       291 
     | 
    
         
            -
                end
         
     | 
| 
       292 
365 
     | 
    
         
             
              end
         
     | 
| 
       293 
366 
     | 
    
         | 
| 
       294 
367 
     | 
    
         
             
              context "requiring boxes" do
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class BaseProvisionerTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              should "include the util class so subclasses have access to it" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                assert Vagrant::Provisioners::Base.include?(Vagrant::Util)
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              context "base instance" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @base = Vagrant::Provisioners::Base.new
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                should "implement provision! which does nothing" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 15 
     | 
    
         
            +
                    assert @base.respond_to?(:provision!)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @base.provision!
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                should "implement prepare which does nothing" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 22 
     | 
    
         
            +
                    assert @base.respond_to?(:prepare)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @base.prepare
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,175 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class ChefServerProvisionerTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              setup do
         
     | 
| 
      
 5 
     | 
    
         
            +
                @action = Vagrant::Provisioners::ChefServer.new
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                Vagrant::SSH.stubs(:execute)
         
     | 
| 
      
 8 
     | 
    
         
            +
                Vagrant::SSH.stubs(:upload!)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                mock_config
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              context "provisioning" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                should "run the proper sequence of methods in order" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  prov_seq = sequence("prov_seq")
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @action.expects(:create_client_key_folder).once.in_sequence(prov_seq)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @action.expects(:upload_validation_key).once.in_sequence(prov_seq)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @action.expects(:setup_json).once.in_sequence(prov_seq)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @action.expects(:setup_config).once.in_sequence(prov_seq)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @action.expects(:run_chef_client).once.in_sequence(prov_seq)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @action.provision!
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              context "preparing" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  File.stubs(:file?).returns(true)
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                should "not raise an exception if validation_key_path is set" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 33 
     | 
    
         
            +
                    config.chef.validation_key_path = "7"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  assert_nothing_raised { @action.prepare }
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                should "raise an exception if validation_key_path is nil" do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 41 
     | 
    
         
            +
                    config.chef.validation_key_path = nil
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  assert_raises(Vagrant::Actions::ActionException) {
         
     | 
| 
      
 45 
     | 
    
         
            +
                    @action.prepare
         
     | 
| 
      
 46 
     | 
    
         
            +
                  }
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                should "not raise an exception if validation_key_path does exist" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 51 
     | 
    
         
            +
                    config.chef.validation_key_path = "7"
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(true)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  assert_nothing_raised { @action.prepare }
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                should "raise an exception if validation_key_path doesn't exist" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 60 
     | 
    
         
            +
                    config.chef.validation_key_path = "7"
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  File.expects(:file?).with(Vagrant.config.chef.validation_key_path).returns(false)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  assert_raises(Vagrant::Actions::ActionException) {
         
     | 
| 
      
 65 
     | 
    
         
            +
                    @action.prepare
         
     | 
| 
      
 66 
     | 
    
         
            +
                  }
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                should "not raise an exception if chef_server_url is set" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 71 
     | 
    
         
            +
                    config.chef.chef_server_url = "7"
         
     | 
| 
      
 72 
     | 
    
         
            +
                  end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  assert_nothing_raised { @action.prepare }
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                should "raise an exception if chef_server_url is nil" do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 79 
     | 
    
         
            +
                    config.chef.chef_server_url = nil
         
     | 
| 
      
 80 
     | 
    
         
            +
                  end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                  assert_raises(Vagrant::Actions::ActionException) {
         
     | 
| 
      
 83 
     | 
    
         
            +
                    @action.prepare
         
     | 
| 
      
 84 
     | 
    
         
            +
                  }
         
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              context "creating the client key folder" do
         
     | 
| 
      
 89 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  @raw_path = "/foo/bar/baz.pem"
         
     | 
| 
      
 91 
     | 
    
         
            +
                  mock_config do |config|
         
     | 
| 
      
 92 
     | 
    
         
            +
                    config.chef.client_key_path = @raw_path
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  @path = Pathname.new(@raw_path)
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                should "create the folder using the dirname of the path" do
         
     | 
| 
      
 99 
     | 
    
         
            +
                  ssh = mock("ssh")
         
     | 
| 
      
 100 
     | 
    
         
            +
                  ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
         
     | 
| 
      
 101 
     | 
    
         
            +
                  Vagrant::SSH.expects(:execute).yields(ssh)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  @action.create_client_key_folder
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
              context "uploading the validation key" do
         
     | 
| 
      
 107 
     | 
    
         
            +
                should "upload the validation key to the provisioning path" do
         
     | 
| 
      
 108 
     | 
    
         
            +
                  @action.expects(:validation_key_path).once.returns("foo")
         
     | 
| 
      
 109 
     | 
    
         
            +
                  @action.expects(:guest_validation_key_path).once.returns("bar")
         
     | 
| 
      
 110 
     | 
    
         
            +
                  Vagrant::SSH.expects(:upload!).with("foo", "bar").once
         
     | 
| 
      
 111 
     | 
    
         
            +
                  @action.upload_validation_key
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              context "the validation key path" do
         
     | 
| 
      
 116 
     | 
    
         
            +
                should "expand the configured key path" do
         
     | 
| 
      
 117 
     | 
    
         
            +
                  result = mock("result")
         
     | 
| 
      
 118 
     | 
    
         
            +
                  File.expects(:expand_path).with(Vagrant.config.chef.validation_key_path, Vagrant::Env.root_path).once.returns(result)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  assert_equal result, @action.validation_key_path
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
              end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
              context "the guest validation key path" do
         
     | 
| 
      
 124 
     | 
    
         
            +
                should "be the provisioning path joined with validation.pem" do
         
     | 
| 
      
 125 
     | 
    
         
            +
                  result = mock("result")
         
     | 
| 
      
 126 
     | 
    
         
            +
                  File.expects(:join).with(Vagrant.config.chef.provisioning_path, "validation.pem").once.returns(result)
         
     | 
| 
      
 127 
     | 
    
         
            +
                  assert_equal result, @action.guest_validation_key_path
         
     | 
| 
      
 128 
     | 
    
         
            +
                end
         
     | 
| 
      
 129 
     | 
    
         
            +
              end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
              context "generating and uploading chef client configuration file" do
         
     | 
| 
      
 132 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 133 
     | 
    
         
            +
                  @action.stubs(:guest_validation_key_path).returns("foo")
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                should "upload properly generate the configuration file using configuration data" do
         
     | 
| 
      
 137 
     | 
    
         
            +
                  expected_config = <<-config
         
     | 
| 
      
 138 
     | 
    
         
            +
            log_level          :info
         
     | 
| 
      
 139 
     | 
    
         
            +
            log_location       STDOUT
         
     | 
| 
      
 140 
     | 
    
         
            +
            ssl_verify_mode    :verify_none
         
     | 
| 
      
 141 
     | 
    
         
            +
            chef_server_url    "#{Vagrant.config.chef.chef_server_url}"
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            validation_client_name "#{Vagrant.config.chef.validation_client_name}"
         
     | 
| 
      
 144 
     | 
    
         
            +
            validation_key         "#{@action.guest_validation_key_path}"
         
     | 
| 
      
 145 
     | 
    
         
            +
            client_key             "#{Vagrant.config.chef.client_key_path}"
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
            file_store_path    "/srv/chef/file_store"
         
     | 
| 
      
 148 
     | 
    
         
            +
            file_cache_path    "/srv/chef/cache"
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
            pid_file           "/var/run/chef/chef-client.pid"
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
            Mixlib::Log::Formatter.show_time = true
         
     | 
| 
      
 153 
     | 
    
         
            +
            config
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                  StringIO.expects(:new).with(expected_config).once
         
     | 
| 
      
 156 
     | 
    
         
            +
                  @action.setup_config
         
     | 
| 
      
 157 
     | 
    
         
            +
                end
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                should "upload this file as client.rb to the provisioning folder" do
         
     | 
| 
      
 160 
     | 
    
         
            +
                  StringIO.expects(:new).returns("foo")
         
     | 
| 
      
 161 
     | 
    
         
            +
                  File.expects(:join).with(Vagrant.config.chef.provisioning_path, "client.rb").once.returns("bar")
         
     | 
| 
      
 162 
     | 
    
         
            +
                  Vagrant::SSH.expects(:upload!).with("foo", "bar").once
         
     | 
| 
      
 163 
     | 
    
         
            +
                  @action.setup_config
         
     | 
| 
      
 164 
     | 
    
         
            +
                end
         
     | 
| 
      
 165 
     | 
    
         
            +
              end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
              context "running chef client" do
         
     | 
| 
      
 168 
     | 
    
         
            +
                should "cd into the provisioning directory and run chef client" do
         
     | 
| 
      
 169 
     | 
    
         
            +
                  ssh = mock("ssh")
         
     | 
| 
      
 170 
     | 
    
         
            +
                  ssh.expects(:exec!).with("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
         
     | 
| 
      
 171 
     | 
    
         
            +
                  Vagrant::SSH.expects(:execute).yields(ssh)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  @action.run_chef_client
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
              end
         
     | 
| 
      
 175 
     | 
    
         
            +
            end
         
     |