vagrant-lxc 0.3.4 → 0.4.0

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.
@@ -9,24 +9,24 @@ describe Vagrant::LXC::Driver do
9
9
  let(:unknown_container) { described_class.new('unknown', cli) }
10
10
  let(:valid_container) { described_class.new('valid', cli) }
11
11
  let(:new_container) { described_class.new(nil) }
12
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', list: ['valid']) }
12
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', list: ['valid']) }
13
13
 
14
14
  it 'raises a ContainerNotFound error if an unknown container name gets provided' do
15
15
  expect {
16
16
  unknown_container.validate!
17
- }.to raise_error(Vagrant::LXC::Driver::ContainerNotFound)
17
+ }.to raise_error
18
18
  end
19
19
 
20
20
  it 'does not raise a ContainerNotFound error if a valid container name gets provided' do
21
21
  expect {
22
22
  valid_container.validate!
23
- }.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound)
23
+ }.not_to raise_error
24
24
  end
25
25
 
26
26
  it 'does not raise a ContainerNotFound error if nil is provider as name' do
27
27
  expect {
28
28
  new_container.validate!
29
- }.to_not raise_error(Vagrant::LXC::Driver::ContainerNotFound)
29
+ }.not_to raise_error
30
30
  end
31
31
  end
32
32
 
@@ -35,14 +35,15 @@ describe Vagrant::LXC::Driver do
35
35
  let(:template_name) { 'auto-assigned-template-id' }
36
36
  let(:template_path) { '/path/to/lxc-template-from-box' }
37
37
  let(:template_opts) { {'--some' => 'random-option'} }
38
+ let(:config_file) { '/path/to/lxc-config-from-box' }
38
39
  let(:rootfs_tarball) { '/path/to/cache/rootfs.tar.gz' }
39
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :create => true, :name= => true) }
40
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', :create => true, :name= => true) }
40
41
 
41
42
  subject { described_class.new(nil, cli) }
42
43
 
43
44
  before do
44
45
  subject.stub(:import_template).and_yield(template_name)
45
- subject.create name, template_path, template_opts
46
+ subject.create name, template_path, config_file, template_opts
46
47
  end
47
48
 
48
49
  it 'sets the cli object container name' do
@@ -52,13 +53,14 @@ describe Vagrant::LXC::Driver do
52
53
  it 'creates container with the right arguments' do
53
54
  cli.should have_received(:create).with(
54
55
  template_name,
56
+ config_file,
55
57
  template_opts
56
58
  )
57
59
  end
58
60
  end
59
61
 
60
62
  describe 'destruction' do
61
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', destroy: true) }
63
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', destroy: true) }
62
64
 
63
65
  subject { described_class.new('name', cli) }
64
66
 
@@ -72,7 +74,7 @@ describe Vagrant::LXC::Driver do
72
74
  describe 'start' do
73
75
  let(:customizations) { [['a', '1'], ['b', '2']] }
74
76
  let(:internal_customization) { ['internal', 'customization'] }
75
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', start: true) }
77
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', start: true) }
76
78
 
77
79
  subject { described_class.new('name', cli) }
78
80
 
@@ -92,7 +94,7 @@ describe Vagrant::LXC::Driver do
92
94
  end
93
95
 
94
96
  describe 'halt' do
95
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', shutdown: true) }
97
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', shutdown: true) }
96
98
 
97
99
  subject { described_class.new('name', cli) }
98
100
 
@@ -120,7 +122,7 @@ describe Vagrant::LXC::Driver do
120
122
 
121
123
  describe 'state' do
122
124
  let(:cli_state) { :something }
123
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', state: cli_state) }
125
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', state: cli_state) }
124
126
 
125
127
  subject { described_class.new('name', cli) }
126
128
 
@@ -133,7 +135,7 @@ describe Vagrant::LXC::Driver do
133
135
  # This ip is set on the sample-ip-addr-output fixture
134
136
  let(:ip) { "10.0.254.137" }
135
137
  let(:ifconfig_output) { File.read('spec/fixtures/sample-ip-addr-output') }
136
- let(:cli) { fire_double('Vagrant::LXC::Driver::CLI', :attach => ifconfig_output) }
138
+ let(:cli) { instance_double('Vagrant::LXC::Driver::CLI', :attach => ifconfig_output) }
137
139
 
138
140
  subject { described_class.new('name', cli) }
139
141
 
data/tasks/boxes.rake CHANGED
@@ -1,50 +1,11 @@
1
1
  require 'pathname'
2
2
  require 'rake/tasklib'
3
+ load 'tasks/boxes.v2.rake'
3
4
 
4
- class BuildGenericBoxTask < ::Rake::TaskLib
5
- include ::Rake::DSL
6
-
7
- attr_reader :name
8
-
9
- def initialize(name, distrib, release, arch, opts = {})
10
- @name = name
11
- @distrib = distrib
12
- @release = release.to_s
13
- @arch = arch.to_s
14
- @install_chef = opts.fetch(:chef, true)
15
- @install_puppet = opts.fetch(:puppet, true)
16
- @install_babushka = opts.fetch(:babushka, true)
17
- @file = opts[:file] || default_box_file
18
- @scripts_path = Pathname(Dir.pwd).join('boxes')
19
-
20
- desc "Build an #{distrib.upcase} #{release} #{arch} box" unless
21
- ::Rake.application.last_comment
22
- task name do
23
- RakeFileUtils.send(:verbose, true) do
24
- build
25
- end
26
- end
27
- end
28
-
29
- def default_box_file
30
- require 'time'
31
- "lxc-#{@release}-#{@arch}-#{Date.today}.box"
32
- end
33
-
34
- def run(script_name, *args)
35
- unless (script = @scripts_path.join(@distrib, script_name)).readable?
36
- script = @scripts_path.join('common', script_name)
37
- end
38
-
39
- if script.readable?
40
- sh "sudo #{script} #{args.join(' ')}"
41
- else
42
- STDERR.puts "cannot execute #{install_path} (not found?)"
43
- exit 1
44
- end
45
- end
46
-
5
+ class BuildGenericBoxTaskV3 < BuildGenericBoxTaskV2
47
6
  def build
7
+ require 'vagrant'
8
+
48
9
  check_if_box_has_been_built!
49
10
 
50
11
  FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
@@ -55,6 +16,7 @@ class BuildGenericBoxTask < ::Rake::TaskLib
55
16
  Dir.chdir 'boxes/temp' do
56
17
  download
57
18
  install_cfg_engines
19
+ finalize
58
20
  prepare_package_contents pwd
59
21
  sh 'sudo rm -rf rootfs'
60
22
  sh "tar -czf tmp-package.box ./*"
@@ -65,64 +27,34 @@ class BuildGenericBoxTask < ::Rake::TaskLib
65
27
  sh "rm -rf boxes/temp"
66
28
  end
67
29
 
68
- def check_if_box_has_been_built!
69
- return unless File.exists?("./boxes/output/#{@file}")
70
-
71
- puts 'Box has been built already!'
72
- exit 1
73
- end
74
-
75
- def check_for_partially_built_box!
76
- return unless Dir.entries('boxes/temp').size > 2
77
-
78
- puts 'There is a partially built box under ' +
79
- File.expand_path('./boxes/temp') +
80
- ', please remove it before building a new box'
81
- exit 1
82
- end
83
-
84
- def download
85
- run 'download', @arch, @release
86
- end
87
-
88
- def install_cfg_engines
89
- [ :puppet, :chef, :babushka ].each do |cfg_engine|
90
- next unless instance_variable_get :"@install_#{cfg_engine}"
91
- script_name = "install-#{cfg_engine}"
92
- run script_name
93
- end
30
+ def finalize
31
+ auth_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s
32
+ run 'finalize', @arch, @release, auth_key
94
33
  end
95
34
 
96
35
  def prepare_package_contents(pwd)
97
36
  run 'cleanup'
98
37
  sh 'sudo rm -f rootfs.tar.gz'
99
38
  sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
100
- sh "sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz"
101
- sh "cp #{pwd}/boxes/#{@distrib}/lxc-template ."
102
- compile_metadata(pwd)
103
- end
104
-
105
- def compile_metadata(pwd)
106
- metadata = File.read("#{pwd}/boxes/#{@distrib}/metadata.json.template")
107
- metadata.gsub!('ARCH', @arch)
108
- metadata.gsub!('RELEASE', @release)
109
- File.open('metadata.json', 'w') { |f| f.print metadata }
39
+ sh "sudo chown #{ENV['USER']}:#{`id -gn`.strip} rootfs.tar.gz"
40
+ sh "cp #{pwd}/boxes/common/lxc-template ."
41
+ sh "cp #{pwd}/boxes/common/lxc.conf ."
42
+ sh "cp #{pwd}/boxes/common/metadata.json ."
110
43
  end
111
44
  end
112
45
 
113
- class BuildDebianBoxTask < BuildGenericBoxTask
46
+ class BuildDebianBoxTaskV3 < BuildGenericBoxTaskV3
114
47
  def initialize(name, release, arch, opts = {})
115
48
  super(name, 'debian', release, arch, opts)
116
49
  end
117
50
  end
118
51
 
119
- class BuildUbuntuBoxTask < BuildGenericBoxTask
52
+ class BuildUbuntuBoxTaskV3 < BuildGenericBoxTaskV3
120
53
  def initialize(name, release, arch, opts = {})
121
54
  super(name, 'ubuntu', release, arch, opts)
122
55
  end
123
56
  end
124
57
 
125
- chef = ENV['CHEF'] == '1'
126
58
  puppet = ENV['PUPPET'] == '1'
127
59
  babushka = ENV['BABUSHKA'] == '1'
128
60
 
@@ -131,43 +63,41 @@ namespace :boxes do
131
63
  namespace :build do
132
64
 
133
65
  desc 'Build an Ubuntu Precise 64 bits box'
134
- BuildUbuntuBoxTask.
66
+ BuildUbuntuBoxTaskV3.
135
67
  new(:precise64,
136
- :precise, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
68
+ :precise, 'amd64', puppet: puppet, babushka: babushka)
137
69
 
138
70
  desc 'Build an Ubuntu Quantal 64 bits box'
139
- BuildUbuntuBoxTask.
71
+ BuildUbuntuBoxTaskV3.
140
72
  new(:quantal64,
141
- :quantal, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
73
+ :quantal, 'amd64', puppet: puppet, babushka: babushka)
142
74
 
143
- # FIXME: Find out how to install chef on raring
144
75
  desc 'Build an Ubuntu Raring 64 bits box'
145
- BuildUbuntuBoxTask.
76
+ BuildUbuntuBoxTaskV3.
146
77
  new(:raring64,
147
- :raring, 'amd64', chef: false, puppet: puppet, babushka: babushka)
78
+ :raring, 'amd64', puppet: puppet, babushka: babushka)
148
79
 
149
80
  desc 'Build all Ubuntu boxes'
150
81
  task :all => %w( precise64 quantal64 raring64 )
151
82
  end
152
83
  end
153
84
 
154
- # FIXME: Find out how to install chef on debian boxes
155
85
  namespace :debian do
156
86
  namespace :build do
157
87
  desc 'Build an Debian Squeeze 64 bits box'
158
- BuildDebianBoxTask.
88
+ BuildDebianBoxTaskV3.
159
89
  new(:squeeze64,
160
- :squeeze, 'amd64', chef: false, puppet: puppet, babushka: babushka)
90
+ :squeeze, 'amd64', puppet: puppet, babushka: babushka)
161
91
 
162
92
  desc 'Build an Debian Wheezy 64 bits box'
163
- BuildDebianBoxTask.
93
+ BuildDebianBoxTaskV3.
164
94
  new(:wheezy64,
165
- :wheezy, 'amd64', chef: false, puppet: puppet, babushka: babushka)
95
+ :wheezy, 'amd64', puppet: puppet, babushka: babushka)
166
96
 
167
97
  desc 'Build an Debian Sid/unstable 64 bits box'
168
- BuildDebianBoxTask.
98
+ BuildDebianBoxTaskV3.
169
99
  new(:sid64,
170
- :sid, 'amd64', chef: false, puppet: puppet, babushka: babushka)
100
+ :sid, 'amd64', puppet: puppet, babushka: babushka)
171
101
 
172
102
  desc 'Build all Debian boxes'
173
103
  task :all => %w( squeeze64 wheezy64 sid64 )
@@ -0,0 +1,181 @@
1
+ require 'pathname'
2
+ require 'rake/tasklib'
3
+
4
+ class BuildGenericBoxTaskV2 < ::Rake::TaskLib
5
+ include ::Rake::DSL
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name, distrib, release, arch, opts = {})
10
+ @name = name
11
+ @distrib = distrib
12
+ @release = release.to_s
13
+ @arch = arch.to_s
14
+ @install_chef = opts.fetch(:chef, false)
15
+ @install_puppet = opts.fetch(:puppet, true)
16
+ @install_babushka = opts.fetch(:babushka, true)
17
+ @file = opts[:file] || default_box_file
18
+ @scripts_path = Pathname(Dir.pwd).join('boxes')
19
+
20
+ desc "Build an #{distrib.upcase} #{release} #{arch} box" unless
21
+ ::Rake.application.last_comment
22
+ task name do
23
+ RakeFileUtils.send(:verbose, true) do
24
+ build
25
+ end
26
+ end
27
+ end
28
+
29
+ def default_box_file
30
+ require 'time'
31
+ "lxc-#{@release}-#{@arch}-#{Date.today}.box"
32
+ end
33
+
34
+ def run(script_name, *args)
35
+ unless (script = @scripts_path.join(@distrib, script_name)).readable?
36
+ script = @scripts_path.join('common', script_name)
37
+ end
38
+
39
+ if script.readable?
40
+ sh "sudo #{script} #{args.join(' ')}"
41
+ else
42
+ STDERR.puts "cannot execute #{script_name} (not found?)"
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ def build
48
+ check_if_box_has_been_built!
49
+
50
+ FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
51
+ check_for_partially_built_box!
52
+
53
+ pwd = Dir.pwd
54
+ sh 'mkdir -p boxes/temp/'
55
+ Dir.chdir 'boxes/temp' do
56
+ download
57
+ install_cfg_engines
58
+ prepare_package_contents pwd
59
+ sh 'sudo rm -rf rootfs'
60
+ sh "tar -czf tmp-package.box ./*"
61
+ end
62
+
63
+ sh 'mkdir -p boxes/output'
64
+ sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
65
+ sh "rm -rf boxes/temp"
66
+ end
67
+
68
+ def check_if_box_has_been_built!
69
+ return unless File.exists?("./boxes/output/#{@file}")
70
+
71
+ puts 'Box has been built already!'
72
+ exit 1
73
+ end
74
+
75
+ def check_for_partially_built_box!
76
+ return unless Dir.entries('boxes/temp').size > 2
77
+
78
+ puts 'There is a partially built box under ' +
79
+ File.expand_path('./boxes/temp') +
80
+ ', please remove it before building a new box'
81
+ exit 1
82
+ end
83
+
84
+ def download
85
+ run 'download', @arch, @release
86
+ end
87
+
88
+ def install_cfg_engines
89
+ [ :puppet, :chef, :babushka ].each do |cfg_engine|
90
+ next unless instance_variable_get :"@install_#{cfg_engine}"
91
+ script_name = "install-#{cfg_engine}"
92
+ run script_name
93
+ end
94
+ end
95
+
96
+ def prepare_package_contents(pwd)
97
+ run 'cleanup'
98
+ sh 'sudo rm -f rootfs.tar.gz'
99
+ sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
100
+ sh "sudo chown #{ENV['USER']}:#{`id -gn`.strip} rootfs.tar.gz"
101
+ sh "cp #{pwd}/boxes/#{@distrib}/lxc-template ."
102
+ compile_metadata(pwd)
103
+ end
104
+
105
+ def compile_metadata(pwd)
106
+ metadata = File.read("#{pwd}/boxes/#{@distrib}/metadata.json.template")
107
+ metadata.gsub!('ARCH', @arch)
108
+ metadata.gsub!('RELEASE', @release)
109
+ File.open('metadata.json', 'w') { |f| f.print metadata }
110
+ end
111
+ end
112
+
113
+ class BuildDebianBoxTaskV2 < BuildGenericBoxTaskV2
114
+ def initialize(name, release, arch, opts = {})
115
+ super(name, 'debian', release, arch, opts)
116
+ end
117
+ end
118
+
119
+ class BuildUbuntuBoxTaskV2 < BuildGenericBoxTaskV2
120
+ def initialize(name, release, arch, opts = {})
121
+ super(name, 'ubuntu', release, arch, opts)
122
+ end
123
+ end
124
+
125
+ chef = ENV['CHEF'] == '1'
126
+ puppet = ENV['PUPPET'] == '1'
127
+ babushka = ENV['BABUSHKA'] == '1'
128
+
129
+ namespace :boxes do
130
+ namespace :v2 do
131
+ namespace :ubuntu do
132
+ namespace :build do
133
+
134
+ desc 'Build an Ubuntu Precise 64 bits box'
135
+ BuildUbuntuBoxTaskV2.
136
+ new(:precise64,
137
+ :precise, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
138
+
139
+ desc 'Build an Ubuntu Quantal 64 bits box'
140
+ BuildUbuntuBoxTaskV2.
141
+ new(:quantal64,
142
+ :quantal, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
143
+
144
+ # FIXME: Find out how to install chef on raring
145
+ desc 'Build an Ubuntu Raring 64 bits box'
146
+ BuildUbuntuBoxTaskV2.
147
+ new(:raring64,
148
+ :raring, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
149
+
150
+ desc 'Build all Ubuntu boxes'
151
+ task :all => %w( precise64 quantal64 raring64 )
152
+ end
153
+ end
154
+
155
+ # FIXME: Find out how to install chef on debian boxes
156
+ namespace :debian do
157
+ namespace :build do
158
+ desc 'Build an Debian Squeeze 64 bits box'
159
+ BuildDebianBoxTaskV2.
160
+ new(:squeeze64,
161
+ :squeeze, 'amd64', chef: false, puppet: puppet, babushka: babushka)
162
+
163
+ desc 'Build an Debian Wheezy 64 bits box'
164
+ BuildDebianBoxTaskV2.
165
+ new(:wheezy64,
166
+ :wheezy, 'amd64', chef: false, puppet: puppet, babushka: babushka)
167
+
168
+ desc 'Build an Debian Sid/unstable 64 bits box'
169
+ BuildDebianBoxTaskV2.
170
+ new(:sid64,
171
+ :sid, 'amd64', chef: false, puppet: puppet, babushka: babushka)
172
+
173
+ desc 'Build all Debian boxes'
174
+ task :all => %w( squeeze64 wheezy64 sid64 )
175
+ end
176
+ end
177
+
178
+ desc 'Build all base boxes for release'
179
+ task :build_all => %w( ubuntu:build:all debian:build:all )
180
+ end
181
+ end