fgrehm/vagrant-lxc

vagrant-lxc customizations are not merged correctly

Closed this issue · 1 comments

vagrant-lxc does not merge its customizations and backingstore_options correctly.

According to https://www.vagrantup.com/docs/plugins/configuration.html, plugin configurations should default their fields to UNSET_VALUE, and by default all fields in configuration that are not set to UNSET_VALUE in a configuration block are used to override the existing values in the merged configuration.

Currently, the Config class initializes @customizations and @backingstore_options to [] instead of UNSET_VALUE and does not override the merge method, so if you have more than one configuration block, all LXC customizations and backing store options must exist in the final block.

e.g.

config.vm.provider :lxc do |lxc, override|
  lxc.customize 'aa_profile', 'unconfined'
end

# ... some time later
config.vm.provider :lxc do |lxc, override|
  override.vm.box = 'my/box'
end

The expected outcome of the above is that lxc.aa_profile=unconfined appears in the LXC configuration file. However, since there is a second configuration defined in the second config.vm.provider block, its empty @customizations field overrides the one that was set earlier.

I've not tested it, but since @backingstore_options is also initialized to [], I suspect it behaves the same.

Host: Ubuntu 16.04
Vagrant-lxc: 1.2.1
Vagrant: 1.8.1

Minimal reproduction:

$ cat Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.provider :lxc do |lxc, override|
    lxc.customize 'aa_profile', 'unconfined'
  end

  config.vm.provider :lxc do |lxc, override|
    override.vm.box = 'fgrehm/trusty64-lxc'
  end
end
$ vagrant up --provider lxc
$ sudo grep VAGRANT-BEGIN -B2 -A10 /var/lib/lxc/$(cat .vagrant/machines/default/lxc/id)/config
##############################################
# vagrant-lxc container specific configuration
# VAGRANT-BEGIN
lxc.utsname=repro_default_1468373710595_38820
lxc.mount.entry=/sys/fs/pstore sys/fs/pstore none bind,optional 0 0
lxc.mount.entry=tmpfs tmp tmpfs nodev,nosuid,size=2G 0 0
lxc.mount.entry=/tmp/repro vagrant none bind,create=dir 0 0
# VAGRANT-END

Workaround: reorder the configuration blocks so the one that calls lxc.customize is the final one and/or move lxc.customize calls into the final configuration block:

$ cat Vagrantfile 
Vagrant.configure(2) do |config|
  config.vm.provider :lxc do |lxc, override|
    override.vm.box = 'fgrehm/trusty64-lxc'
  end
  config.vm.provider :lxc do |lxc, override|
    lxc.customize 'aa_profile', 'unconfined'
  end
end
$ sudo grep VAGRANT-BEGIN -B2 -A10 /var/lib/lxc/$(cat .vagrant/machines/default/lxc/id)/config
##############################################
# vagrant-lxc container specific configuration
# VAGRANT-BEGIN
lxc.aa_profile=unconfined
lxc.utsname=repro_default_1468373843249_93633
lxc.mount.entry=/sys/fs/pstore sys/fs/pstore none bind,optional 0 0
lxc.mount.entry=tmpfs tmp tmpfs nodev,nosuid,size=2G 0 0
lxc.mount.entry=/tmp/repro vagrant none bind,create=dir 0 0
# VAGRANT-END

Hey, sorry for the silence here but this project is looking for maintainers 😅

As per #499, I've added the ignored label and will close this issue. Thanks for the interest in the project and LMK if you want to step up and take ownership of this project on that other issue 👋