Skip to content

Commit

Permalink
Filter out UNDEFINE_NVRAM for test:///default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ekohl committed Jul 16, 2024
1 parent 21fa469 commit 791cab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/fog/libvirt/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion tests/libvirt/models/compute/server_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{<memory>\d+</memory>}) }
Expand Down

0 comments on commit 791cab1

Please sign in to comment.