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
|
opts = cmd.pop
|
||||||
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
|
namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
|
||||||
|
|
||||||
if run(:attach, '-h').include?('--namespaces')
|
if namespaces
|
||||||
extra = ['--namespaces', namespaces] if namespaces
|
if supports_attach_with_namespaces?
|
||||||
else
|
extra = ['--namespaces', namespaces] if namespaces
|
||||||
raise LXC::Errors::NamespacesNotSupported
|
else
|
||||||
|
raise LXC::Errors::NamespacesNotSupported
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,6 +116,14 @@ module Vagrant
|
||||||
def run(command, *args)
|
def run(command, *args)
|
||||||
@sudo_wrapper.run("lxc-#{command}", *args)
|
@sudo_wrapper.run("lxc-#{command}", *args)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -146,13 +146,13 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'supports a "namespaces" parameter' do
|
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.attach *(command + [{namespaces: ['network', 'mount']}])
|
||||||
subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command)
|
subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises a NamespacesNotSupported error if not supported' do
|
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 {
|
expect {
|
||||||
subject.attach *(command + [{namespaces: ['network', 'mount']}])
|
subject.attach *(command + [{namespaces: ['network', 'mount']}])
|
||||||
}.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)
|
}.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)
|
||||||
|
|
Loading…
Reference in a new issue