From dd24cdc3d68c27b0e55b30062ce4cfc89d7fa781 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 29 Apr 2018 22:46:12 -0400 Subject: [PATCH] Fix incompatibility with LXC 3.0 LXC 3.0, unlike 2.1, doesn't support old configuration formats at all and because our previous approach to handling old format was incomplete, running `vagrant up` on a system with LXC 3.0 would fail, even if the base box itself was made with modernized config. This commit fixes this problem: is the box has a modern config, it's going to be properly created and booted under LXC 3.0. It does so without breaking the support for LXC < 2.1 --- lib/vagrant-lxc/action/boot.rb | 10 +++++++--- lib/vagrant-lxc/action/create.rb | 6 +++++- lib/vagrant-lxc/driver.rb | 5 +++++ lib/vagrant-lxc/driver/cli.rb | 2 +- scripts/lxc-template | 13 +++++++++++-- spec/unit/driver_spec.rb | 12 ++++++------ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 9741304..7dfbb6b 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -8,11 +8,15 @@ module Vagrant def call(env) @env = env - + driver = env[:machine].provider.driver config = env[:machine].provider_config utsname = env[:machine].config.vm.hostname || env[:machine].id - config.customize 'utsname', utsname + if driver.supports_new_config_format + config.customize 'uts.name', utsname + else + config.customize 'utsname', utsname + end # Fix apparmor issues when starting Ubuntu 14.04 containers # See https://github.com/fgrehm/vagrant-lxc/issues/278 for more information @@ -32,7 +36,7 @@ module Vagrant end env[:ui].info I18n.t("vagrant_lxc.messages.starting") - env[:machine].provider.driver.start(config.customizations) + driver.start(config.customizations) @app.call env end diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index f1c5740..25a7513 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -24,13 +24,17 @@ module Vagrant backingstore = config.privileged ? "best" : "dir" end driver = env[:machine].provider.driver + template_options = env[:lxc_template_opts] + if ! driver.supports_new_config_format + template_options['--oldconfig'] = '' + end driver.create( container_name, backingstore, config.backingstore_options, env[:lxc_template_src], env[:lxc_template_config], - env[:lxc_template_opts] + template_options ) driver.update_config_keys diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 4124dc9..58a6474 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -83,6 +83,7 @@ module Vagrant @cli.name = @container_name = name @logger.debug "Creating container..." + @cli.create template_path, backingstore, backingstore_options, config_file, template_options end @@ -214,6 +215,10 @@ module Vagrant @version ||= @cli.version end + def supports_new_config_format + Gem::Version.new(version) >= Gem::Version.new('2.1.0') + end + # TODO: This needs to be reviewed and specs needs to be written def compress_rootfs # TODO: Pass in tmpdir so we can clean up from outside diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 0f29caa..9832d9e 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -59,7 +59,7 @@ module Vagrant config_opts = ['-f', config_file] end - extra = template_opts.to_a.flatten + extra = template_opts.to_a.flatten.reject { |elem| elem.empty? } extra.unshift '--' unless extra.empty? run :create, diff --git a/scripts/lxc-template b/scripts/lxc-template index a8430d4..e22c033 100755 --- a/scripts/lxc-template +++ b/scripts/lxc-template @@ -33,8 +33,10 @@ LXC_PATH= LXC_ROOTFS= LXC_TARBALL= LXC_CONFIG= +LXC_USE_OLDCONFIG= LXC_STRIP_COMPONENTS=2 + usage() { cat <> ${LXC_PATH}/config rm ${LXC_PATH}/config-auto fi -echo "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config + +if [ $LXC_USE_OLDCONFIG ]; then + echo "lxc.utsname = ${LXC_NAME}" >> ${LXC_PATH}/config +else + echo "lxc.uts.name = ${LXC_NAME}" >> ${LXC_PATH}/config +fi ## Re-add the previously removed network config if [ -e "${LXC_PATH}/config-network" ]; then diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index 7aae013..1d78e64 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -211,9 +211,9 @@ describe Vagrant::LXC::Driver do # Blah blah comment lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 lxc.mount.entry = sysfs sys sysfs defaults 0 0 - lxc.tty = 4 - lxc.pts = 1024 - lxc.rootfs = #{rootfs_path} + lxc.tty.max = 4 + lxc.pty.max = 1024 + lxc.rootfs.path = #{rootfs_path} # VAGRANT-BEGIN lxc.network.type=veth lxc.network.name=eth1 @@ -241,9 +241,9 @@ describe Vagrant::LXC::Driver do # Blah blah comment lxc.mount.entry = proc proc proc nodev,noexec,nosuid 0 0 lxc.mount.entry = sysfs sys sysfs defaults 0 0 - lxc.tty = 4 - lxc.pts = 1024 - lxc.rootfs = overlayfs:/path/to/master/directory:#{rootfs_path} + lxc.tty.max = 4 + lxc.pty.max = 1024 + lxc.rootfs.path = overlayfs:/path/to/master/directory:#{rootfs_path} # VAGRANT-BEGIN lxc.network.type=veth lxc.network.name=eth1