diff --git a/lib/fog/libvirt/models/compute/server.rb b/lib/fog/libvirt/models/compute/server.rb index 56ef222..f0ffb0e 100644 --- a/lib/fog/libvirt/models/compute/server.rb +++ b/lib/fog/libvirt/models/compute/server.rb @@ -368,7 +368,9 @@ def to_xml else is_block = volume.path.start_with?("/dev/") xml.disk(:type => is_block ? "block" : "file", :device => "disk") do - xml.driver(:name => "qemu", :type => volume.format_type) + driver = xml.driver(:name => "qemu") + driver[:type] = volume.format_type if volume.format_type + if is_block xml.source(:dev => volume.path) else diff --git a/lib/fog/libvirt/models/compute/volume.rb b/lib/fog/libvirt/models/compute/volume.rb index 12b60ef..3699da1 100644 --- a/lib/fog/libvirt/models/compute/volume.rb +++ b/lib/fog/libvirt/models/compute/volume.rb @@ -91,7 +91,7 @@ def to_xml xml.capacity(capacity_size, :unit => capacity_unit) xml.target do - xml.format(:type => format_type) + xml.format(:type => format_type) if format_type xml_permissions(xml) end diff --git a/tests/libvirt/models/compute/server_tests.rb b/tests/libvirt/models/compute/server_tests.rb index 448baef..10db92c 100644 --- a/tests/libvirt/models/compute/server_tests.rb +++ b/tests/libvirt/models/compute/server_tests.rb @@ -129,5 +129,39 @@ os_firmware && secure_boot && enrolled_keys && loader_attributes end + + test("with volumes") do + pool = Fog::Compute[:libvirt].pools.create( + :persistent => true, + :xml => <<~XML + + lvm-pool + + vg_storage01 + + + + /dev/vg_storage01 + + + XML + ) + server = Fog::Compute[:libvirt].servers.new( + :nics => [], + :volumes => [ + { + :path => "/dev/vg_storage01/volume01", + :pool_name => pool.name + } + ] + ) + server.volumes.each do |volume| + volume.save + # mock driver doesn't simulate the real thing + # LVM doesn't have a volume type + volume.format_type = nil + end + !server.save.nil? + end end end