Reject cpu features enabled without model (#1658)

Recent Libvirt will silently drop cpu features set without a model
defined. Ensure this scenario is flagged as being invalid up front.

Fixes: #996
This commit is contained in:
Darragh Bailey
2022-11-04 17:21:42 +00:00
committed by GitHub
parent 2444889155
commit d384e63235
2 changed files with 25 additions and 9 deletions

View File

@@ -1109,6 +1109,10 @@ module VagrantPlugins
errors << "cannot set cpu_model with cpu_mode of 'host-passthrough'. leave model unset or switch mode." errors << "cannot set cpu_model with cpu_mode of 'host-passthrough'. leave model unset or switch mode."
end end
unless @cpu_model != '' || @cpu_features.empty?
errors << "cannot set cpu_features with cpu_model unset, please set a model or skip setting features."
end
# The @uri and @qemu_use_session should not conflict # The @uri and @qemu_use_session should not conflict
uri = _parse_uri(@uri) uri = _parse_uri(@uri)
if (uri.scheme.start_with? "qemu") && (uri.path.include? "session") if (uri.scheme.start_with? "qemu") && (uri.path.include? "session")

View File

@@ -857,18 +857,30 @@ describe VagrantPlugins::ProviderLibvirt::Config do
end end
end end
context 'with cpu_mode and cpu_model defined' do context 'with cpu_mode defined' do
it 'should discard model if mode is passthrough' do before do
subject.cpu_mode = 'host-passthrough' subject.cpu_mode = 'host-passthrough'
subject.cpu_model = 'qemu64'
assert_valid
expect(subject.cpu_model).to be_empty
end end
it 'should allow custom mode with model' do context 'with cpu_model defined' do
subject.cpu_mode = 'custom' it 'should discard model if mode is passthrough' do
subject.cpu_model = 'qemu64' subject.cpu_model = 'qemu64'
assert_valid assert_valid
expect(subject.cpu_model).to be_empty
end
it 'should allow custom mode with model' do
subject.cpu_mode = 'custom'
subject.cpu_model = 'qemu64'
assert_valid
end
end
context 'with cpu_model not defined' do
it 'should reject if cpu features enabled' do
subject.cpu_features = [{:name => 'feature', :policy => 'optional'}]
assert_invalid
end
end end
end end