diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 71b8906..dc62dab 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -82,10 +82,12 @@ module Vagrant opts = cmd.pop namespaces = Array(opts[:namespaces]).map(&:upcase).join('|') - if run(:attach, '-h').include?('--namespaces') - extra = ['--namespaces', namespaces] if namespaces - else - raise LXC::Errors::NamespacesNotSupported + if namespaces + if supports_attach_with_namespaces? + extra = ['--namespaces', namespaces] if namespaces + else + raise LXC::Errors::NamespacesNotSupported + end end end @@ -114,6 +116,14 @@ module Vagrant def run(command, *args) @sudo_wrapper.run("lxc-#{command}", *args) end + + def supports_attach_with_namespaces? + unless defined?(@supports_attach_with_namespaces) + @supports_attach_with_namespaces = run(:attach, '-h', '2>&1').include?('--namespaces') + end + + return @supports_attach_with_namespaces + end end end end diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index 54e848b..595ff5a 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -146,13 +146,13 @@ describe Vagrant::LXC::Driver::CLI do end it 'supports a "namespaces" parameter' do - subject.stub(:run).with(:attach, '-h').and_return('--namespaces') + subject.stub(:run).with(:attach, '-h', '2>&1').and_return('--namespaces') subject.attach *(command + [{namespaces: ['network', 'mount']}]) subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command) end it 'raises a NamespacesNotSupported error if not supported' do - subject.stub(:run).with(:attach, '-h').and_return('not supported') + subject.stub(:run).with(:attach, '-h', '2>&1').and_return('not supported') expect { subject.attach *(command + [{namespaces: ['network', 'mount']}]) }.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)