From 791cab1afe74a0956437faebd9c2e56fb6b68545 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 16 Jul 2024 16:29:09 +0200 Subject: [PATCH] Filter out UNDEFINE_NVRAM for test:///default The test driver doesn't support UNDEFINE_NVRAM and I couldn't find a way to probe for the capability. This hacks around it by looking at the service uri and filters out the flag. It also adds an explicit test since previously the exception was swallowed. A new server is created to avoid interference with other tests. --- lib/fog/libvirt/models/compute/server.rb | 5 +++++ tests/libvirt/models/compute/server_tests.rb | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/fog/libvirt/models/compute/server.rb b/lib/fog/libvirt/models/compute/server.rb index 6cb31c3..8706f4a 100644 --- a/lib/fog/libvirt/models/compute/server.rb +++ b/lib/fog/libvirt/models/compute/server.rb @@ -97,6 +97,11 @@ def destroy(options={ :destroy_volumes => false, :flags => ::Libvirt::Domain::UN if flags.zero? service.vm_action(uuid, :undefine) else + # the test driver doesn't support UNDEFINE_NVRAM and we can't probe + # for the capability at runtime + if service.uri.uri == 'test:///default' + flags ^= ::Libvirt::Domain::UNDEFINE_NVRAM + end service.vm_action(uuid, :undefine, flags) end volumes.each { |vol| vol.destroy } if options[:destroy_volumes] diff --git a/tests/libvirt/models/compute/server_tests.rb b/tests/libvirt/models/compute/server_tests.rb index 026023c..30d45f2 100644 --- a/tests/libvirt/models/compute/server_tests.rb +++ b/tests/libvirt/models/compute/server_tests.rb @@ -13,7 +13,7 @@ %w{ start stop destroy reboot suspend }.each do |action| test(action) { server.respond_to? action } end - %w{ start reboot suspend stop destroy}.each do |action| + %w{ start reboot suspend stop }.each do |action| test("#{action} returns successfully") { begin server.send(action.to_sym) @@ -60,6 +60,11 @@ end end end + + test('can destroy') do + servers.create(:name => Fog::Mock.random_letters(8)).destroy + end + test('be a kind of Fog::Libvirt::Compute::Server') { server.kind_of? Fog::Libvirt::Compute::Server } tests("serializes to xml") do test("with memory") { server.to_xml.match?(%r{\d+}) }