Fix lxc-attach --namespaces support detection and cache the result
This commit is contained in:
parent
8bcb8b5328
commit
c194b3a24a
2 changed files with 16 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue