diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index b11acfc..94daf0c 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -1109,6 +1109,10 @@ module VagrantPlugins errors << "cannot set cpu_model with cpu_mode of 'host-passthrough'. leave model unset or switch mode." 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 uri = _parse_uri(@uri) if (uri.scheme.start_with? "qemu") && (uri.path.include? "session") diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index e57c118..b915415 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -857,18 +857,30 @@ describe VagrantPlugins::ProviderLibvirt::Config do end end - context 'with cpu_mode and cpu_model defined' do - it 'should discard model if mode is passthrough' do + context 'with cpu_mode defined' do + before do subject.cpu_mode = 'host-passthrough' - subject.cpu_model = 'qemu64' - 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 + context 'with cpu_model defined' do + it 'should discard model if mode is passthrough' do + subject.cpu_model = 'qemu64' + 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