vagrant-lxc 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,7 @@ describe Vagrant::LXC::Driver::CLI do
30
30
 
31
31
  describe 'version' do
32
32
  before do
33
+ allow(subject).to receive(:support_version_command?).and_return(true)
33
34
  allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
34
35
  end
35
36
 
@@ -52,6 +53,7 @@ describe Vagrant::LXC::Driver::CLI do
52
53
 
53
54
  describe 'config' do
54
55
  before do
56
+ allow(subject).to receive(:support_version_command?).and_return(support_version_command?)
55
57
  allow(subject).to receive(:run).with(:config, 'lxc.lxcpath').and_return(lxc_config_out)
56
58
  allow(subject).to receive(:run).with(:version).and_return(lxc_version_out)
57
59
  allow(subject).to receive(:run).with(:create, '--version').and_return(lxc_version_out)
@@ -97,9 +99,9 @@ describe Vagrant::LXC::Driver::CLI do
97
99
  expect(subject).to have_received(:run).with(
98
100
  :create,
99
101
  '-B', backingstore,
100
- *(backingstore_opts.flatten),
101
102
  '--template', template,
102
103
  '--name', name,
104
+ *(backingstore_opts.flatten),
103
105
  '-f', config_file,
104
106
  '--',
105
107
  '--extra-param', 'param',
@@ -180,40 +180,102 @@ describe Vagrant::LXC::Driver do
180
180
  let(:ro_rw_folder) { {guestpath: '/vagrant/ro_rw', hostpath: '/path/to/host/dir', mount_options: ['ro', 'rw']} }
181
181
  let(:with_space_folder) { {guestpath: '/tmp/with space', hostpath: '/path/with space'} }
182
182
  let(:folders) { [shared_folder, ro_rw_folder, with_space_folder] }
183
- let(:rootfs_path) { Pathname('/path/to/rootfs') }
184
183
  let(:expected_guest_path) { "vagrant" }
185
184
  let(:sudo_wrapper) { double(Vagrant::LXC::SudoWrapper, run: true) }
185
+ let(:rootfs_path) { Pathname('/path/to/rootfs') }
186
186
 
187
187
  subject { described_class.new('name', sudo_wrapper) }
188
188
 
189
- before do
190
- subject.stub(rootfs_path: rootfs_path, system: true)
191
- subject.share_folders(folders)
192
- end
189
+ describe "with fixed rootfs" do
190
+ before do
191
+ subject.stub(rootfs_path: Pathname('/path/to/rootfs'), system: true)
192
+ subject.share_folders(folders)
193
+ end
193
194
 
194
- it "creates guest folder under container's rootfs" do
195
- expect(sudo_wrapper).to have_received(:run).with("mkdir", "-p", "#{rootfs_path}/#{expected_guest_path}")
196
- end
195
+ it "creates guest folder under container's rootfs" do
196
+ expect(sudo_wrapper).to have_received(:run).with("mkdir", "-p", "#{rootfs_path}/#{expected_guest_path}")
197
+ end
198
+
199
+ it 'adds a mount.entry to its local customizations' do
200
+ expect(subject.customizations).to include [
201
+ 'mount.entry',
202
+ "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
203
+ ]
204
+ end
197
205
 
198
- it 'adds a mount.entry to its local customizations' do
199
- expect(subject.customizations).to include [
200
- 'mount.entry',
201
- "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
202
- ]
206
+ it 'supports additional mount options' do
207
+ expect(subject.customizations).to include [
208
+ 'mount.entry',
209
+ "#{ro_rw_folder[:hostpath]} vagrant/ro_rw none ro,rw 0 0"
210
+ ]
211
+ end
212
+
213
+ it 'supports directories with spaces' do
214
+ expect(subject.customizations).to include [
215
+ 'mount.entry',
216
+ "/path/with\\040space tmp/with\\040space none bind 0 0"
217
+ ]
218
+ end
203
219
  end
204
220
 
205
- it 'supports additional mount options' do
206
- expect(subject.customizations).to include [
207
- 'mount.entry',
208
- "#{ro_rw_folder[:hostpath]} vagrant/ro_rw none ro,rw 0 0"
209
- ]
221
+ describe "with directory-based LXC config" do
222
+ let(:config_string) {
223
+ <<-ENDCONFIG.gsub(/^\s+/, '')
224
+ # Blah blah comment
225
+ lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
226
+ lxc.mount.entry = sysfs sys sysfs defaults 0 0
227
+ lxc.tty = 4
228
+ lxc.pts = 1024
229
+ lxc.rootfs = #{rootfs_path}
230
+ # VAGRANT-BEGIN
231
+ lxc.network.type=veth
232
+ lxc.network.name=eth1
233
+ # VAGRANT-END
234
+ ENDCONFIG
235
+ }
236
+
237
+ before do
238
+ subject { described_class.new('name', sudo_wrapper) }
239
+ subject.stub(config_string: config_string)
240
+ subject.share_folders(folders)
241
+ end
242
+
243
+ it 'adds a mount.entry to its local customizations' do
244
+ expect(subject.customizations).to include [
245
+ 'mount.entry',
246
+ "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
247
+ ]
248
+ end
210
249
  end
211
250
 
212
- it 'supports directories with spaces' do
213
- expect(subject.customizations).to include [
214
- 'mount.entry',
215
- "/path/with\\040space tmp/with\\040space none bind 0 0"
216
- ]
251
+ describe "with overlayfs-based LXC config" do
252
+ let(:config_string) {
253
+ <<-ENDCONFIG.gsub(/^\s+/, '')
254
+ # Blah blah comment
255
+ lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0
256
+ lxc.mount.entry = sysfs sys sysfs defaults 0 0
257
+ lxc.tty = 4
258
+ lxc.pts = 1024
259
+ lxc.rootfs = overlayfs:/path/to/master/directory:#{rootfs_path}
260
+ # VAGRANT-BEGIN
261
+ lxc.network.type=veth
262
+ lxc.network.name=eth1
263
+ # VAGRANT-END
264
+ ENDCONFIG
265
+ }
266
+
267
+ before do
268
+ subject { described_class.new('name', sudo_wrapper) }
269
+ subject.stub(config_string: config_string)
270
+ subject.share_folders(folders)
271
+ end
272
+
273
+ it 'adds a mount.entry to its local customizations' do
274
+ expect(subject.customizations).to include [
275
+ 'mount.entry',
276
+ "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
277
+ ]
278
+ end
217
279
  end
218
280
  end
219
281
  end
@@ -4,25 +4,41 @@
4
4
  class Whitelist
5
5
  class << self
6
6
  def add(command, *args)
7
+ list[command] ||= []
7
8
  list[command] << args
8
9
  end
9
10
 
11
+ def add_regex(regex, *args)
12
+ regex_list << [regex, [args]]
13
+ end
14
+
10
15
  def list
11
- @list ||= Hash.new do |key, hsh|
12
- key[hsh] = []
13
- end
16
+ @list ||= {}
17
+ end
18
+
19
+ def regex_list
20
+ @regex_list ||= []
14
21
  end
15
22
 
16
23
  def allowed(command)
17
- list[command] || []
24
+ list[command] || allowed_regex(command) || []
25
+ end
26
+
27
+ def allowed_regex(command)
28
+ found = regex_list.find { |r| r[0] =~ command }
29
+ return found[1] if found
18
30
  end
19
31
 
20
32
  def run!(argv)
21
33
  begin
22
34
  command, args = `which #{argv.shift}`.chomp, argv || []
23
35
  check!(command, args)
24
- puts `#{command} #{args.join(" ")}`
25
- exit $?.to_i
36
+ system "#{command} #{args.join(" ")}"
37
+
38
+ exit_code = $?.to_i
39
+ exit_code = 1 if exit_code == 256
40
+
41
+ exit exit_code
26
42
  rescue => e
27
43
  STDERR.puts e.message
28
44
  exit 1
@@ -88,6 +104,11 @@ Whitelist.add '<%= cmd_paths['rm'] %>', templates_path
88
104
  # - Packaging
89
105
  Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/rootfs.tar.gz}, '-C', base_path, './rootfs'
90
106
  Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}
107
+ # - Private network script and commands
108
+ Whitelist.add '<%= cmd_paths['ip'] %>', 'addr', 'add', /(\d+|\.)+\/24/, 'dev', /.+/
109
+ Whitelist.add '<%= cmd_paths['ifconfig'] %>', /.+/, 'down'
110
+ Whitelist.add '<%= cmd_paths['brctl'] %>', 'delbr', /.+/
111
+ Whitelist.add_regex %r{<%= pipework_regex %>}, '**'
91
112
 
92
113
  ##
93
114
  # Commands from driver/cli.rb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux Containers provider for Vagrant
14
14
  email:
@@ -30,13 +30,6 @@ files:
30
30
  - LICENSE.txt
31
31
  - README.md
32
32
  - Rakefile
33
- - lib/vagrant-backports/README.md
34
- - lib/vagrant-backports/action/handle_box.rb
35
- - lib/vagrant-backports/action/is_state.rb
36
- - lib/vagrant-backports/action/message.rb
37
- - lib/vagrant-backports/action/wait_for_communicator.rb
38
- - lib/vagrant-backports/ui.rb
39
- - lib/vagrant-backports/utils.rb
40
33
  - lib/vagrant-lxc.rb
41
34
  - lib/vagrant-lxc/action.rb
42
35
  - lib/vagrant-lxc/action/boot.rb
@@ -49,14 +42,14 @@ files:
49
42
  - lib/vagrant-lxc/action/fetch_ip_with_lxc_attach.rb
50
43
  - lib/vagrant-lxc/action/forced_halt.rb
51
44
  - lib/vagrant-lxc/action/forward_ports.rb
45
+ - lib/vagrant-lxc/action/gc_private_network_bridges.rb
52
46
  - lib/vagrant-lxc/action/handle_box_metadata.rb
53
- - lib/vagrant-lxc/action/message.rb
54
47
  - lib/vagrant-lxc/action/prepare_nfs_settings.rb
55
48
  - lib/vagrant-lxc/action/prepare_nfs_valid_ids.rb
49
+ - lib/vagrant-lxc/action/private_networks.rb
56
50
  - lib/vagrant-lxc/action/remove_temporary_files.rb
57
51
  - lib/vagrant-lxc/action/setup_package_files.rb
58
52
  - lib/vagrant-lxc/action/warn_networks.rb
59
- - lib/vagrant-lxc/backports/action/share_folders.rb
60
53
  - lib/vagrant-lxc/command/root.rb
61
54
  - lib/vagrant-lxc/command/sudoers.rb
62
55
  - lib/vagrant-lxc/config.rb
@@ -71,6 +64,7 @@ files:
71
64
  - lib/vagrant-lxc/version.rb
72
65
  - locales/en.yml
73
66
  - scripts/lxc-template
67
+ - scripts/pipework
74
68
  - spec/Vagrantfile
75
69
  - spec/fixtures/sample-ip-addr-output
76
70
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- # vagrant-backports
2
-
3
- <!--
4
- [![Build Status](https://travis-ci.org/fgrehm/vagrant-backports.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-backports) [![Gem Version](https://badge.fury.io/rb/vagrant-backports.png)](http://badge.fury.io/rb/vagrant-backports) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-backports.png)](https://codeclimate.com/github/fgrehm/vagrant-backports) [![Coverage Status](https://coveralls.io/repos/fgrehm/vagrant-backports/badge.png?branch=master)](https://coveralls.io/r/fgrehm/vagrant-backports) [![Gittip](http://img.shields.io/gittip/fgrehm.svg)](https://www.gittip.com/fgrehm/)
5
- -->
6
-
7
- A _"hypothetical"_ gem that helps Vagrant plugin developers to stay sane when
8
- keeping up with Vagrant improvements by backporting parts of its recent versions
9
- functionality.
10
-
11
- More information will be provided if there is enough interest on having this
12
- extracted as a separate gem.
@@ -1 +0,0 @@
1
- Vagrant::Action::Builtin.const_set :HandleBox, Vagrant::Action::Builtin::HandleBoxUrl
@@ -1,34 +0,0 @@
1
- module Vagrant
2
- module Backports
3
- module Action
4
- # This middleware is meant to be used with Call and can check if
5
- # a machine is in the given state ID.
6
- class IsState
7
- # Note: Any of the arguments can be arrays as well.
8
- #
9
- # @param [Symbol] target_state The target state ID that means that
10
- # the machine was properly shut down.
11
- # @param [Symbol] source_state The source state ID that the machine
12
- # must be in to be shut down.
13
- def initialize(app, env, check, **opts)
14
- @app = app
15
- @logger = Log4r::Logger.new("vagrant::action::builtin::is_state")
16
- @check = check
17
- @invert = !!opts[:invert]
18
- end
19
-
20
- def call(env)
21
- @logger.debug("Checking if machine state is '#{@check}'")
22
- state = env[:machine].state.id
23
- @logger.debug("-- Machine state: #{state}")
24
-
25
- env[:result] = @check == state
26
- env[:result] = !env[:result] if @invert
27
- @app.call(env)
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
34
- Vagrant::Action::Builtin.const_set :IsState, Vagrant::Backports::Action::IsState
@@ -1,20 +0,0 @@
1
- module Vagrant
2
- module Backports
3
- module Action
4
- # This middleware simply outputs a message to the UI.
5
- class Message
6
- def initialize(app, env, message, **opts)
7
- @app = app
8
- @message = message
9
- end
10
-
11
- def call(env)
12
- env[:ui].info(@message)
13
- @app.call(env)
14
- end
15
- end
16
- end
17
- end
18
- end
19
-
20
- Vagrant::Action::Builtin.const_set :Message, Vagrant::Backports::Action::Message
@@ -1,42 +0,0 @@
1
- # This acts like a backport of Vagrant's built in action from 1.3+ for previous version
2
- # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb
3
- module Vagrant
4
- module Backports
5
- module Action
6
- class WaitForCommunicator
7
- def initialize(app, env)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- @env = env
13
-
14
- raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator
15
-
16
- @app.call env
17
- end
18
-
19
- def wait_for_communicator
20
- max_tries = @env[:machine].config.ssh.max_tries.to_i
21
- max_tries.times do |i|
22
- if @env[:machine].communicate.ready?
23
- @env[:ui].info 'Machine booted and ready!'
24
- return true
25
- end
26
-
27
- # Return true so that the vm_failed_to_boot error doesn't
28
- # get shown
29
- return true if @env[:interrupted]
30
-
31
- sleep 1 if !@env["vagrant.test"]
32
- end
33
-
34
- @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
35
- false
36
- end
37
- end
38
- end
39
- end
40
- end
41
-
42
- Vagrant::Action::Builtin.const_set :WaitForCommunicator, Vagrant::Backports::Action::WaitForCommunicator
@@ -1,12 +0,0 @@
1
- module Vagrant
2
- module UI
3
- class Interface
4
- def output(*args)
5
- info(*args)
6
- end
7
- def detail(*args)
8
- info(*args)
9
- end
10
- end
11
- end
12
- end
@@ -1,27 +0,0 @@
1
- module Vagrant
2
- module Backports
3
- class << self
4
- def vagrant_1_2_or_later?
5
- greater_than?('1.2.0')
6
- end
7
-
8
- def vagrant_1_3_or_later?
9
- greater_than?('1.3.0')
10
- end
11
-
12
- def vagrant_1_4_or_later?
13
- greater_than?('1.4.0')
14
- end
15
-
16
- def vagrant_1_5_or_later?
17
- greater_than?('1.5.0')
18
- end
19
-
20
- private
21
-
22
- def greater_than?(version)
23
- Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new(version)
24
- end
25
- end
26
- end
27
- end
File without changes
@@ -1,67 +0,0 @@
1
- module Vagrant
2
- module LXC
3
- module Action
4
- class ShareFolders
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- @env = env
11
- prepare_folders
12
- add_override_configs
13
- @app.call env
14
- end
15
-
16
- # This method returns an actual list of synced folders to create and their
17
- # proper path.
18
- def shared_folders
19
- {}.tap do |result|
20
- @env[:machine].config.vm.synced_folders.each do |id, data|
21
- # Ignore disabled shared folders
22
- next if data[:disabled]
23
- # This to prevent overwriting the actual shared folders data
24
- result[id] = data.dup
25
- end
26
- end
27
- end
28
-
29
- # Prepares the shared folders by verifying they exist and creating them
30
- # if they don't.
31
- def prepare_folders
32
- shared_folders.each do |id, options|
33
- hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])
34
-
35
- if !hostpath.directory? && options[:create]
36
- # Host path doesn't exist, so let's create it.
37
- @logger.debug("Host path doesn't exist, creating: #{hostpath}")
38
-
39
- begin
40
- hostpath.mkpath
41
- rescue Errno::EACCES
42
- raise Vagrant::Errors::SharedFolderCreateFailed,
43
- :path => hostpath.to_s
44
- end
45
- end
46
- end
47
- end
48
-
49
- def add_override_configs
50
- @env[:ui].info I18n.t("vagrant.actions.lxc.share_folders.preparing")
51
-
52
- folders = []
53
- shared_folders.each do |id, data|
54
- folders << {
55
- :name => id,
56
- :hostpath => File.expand_path(data[:hostpath], @env[:root_path]),
57
- :guestpath => data[:guestpath]
58
- }
59
- @env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
60
- :guest_path => data[:guestpath]))
61
- end
62
- @env[:machine].provider.driver.share_folders(folders)
63
- end
64
- end
65
- end
66
- end
67
- end