Skip to content

Commit 51d0a00

Browse files
committed
Implement Ceph multiple pools and tests
1 parent ffae6a5 commit 51d0a00

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

lib/fog/libvirt/models/compute/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ After adding the authentication key to a libvirt secret, it can be configured as
3232
```
3333
monitor=mon001.example.com,mon002.example.com,mon003.example.com
3434
port=6789
35-
libvirt_ceph_pool=rbd_pool_name
35+
libvirt_ceph_pool=rbd_pool_name,second_rbd_pool_name
3636
auth_username=libvirt
3737
auth_uuid=uuid_of_libvirt_secret
3838
bus_type=virtio

lib/fog/libvirt/models/compute/server.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ def to_xml
346346

347347
volumes.each_with_index do |volume, index|
348348
target_device = "vd#{('a'..'z').to_a[index]}"
349-
if ceph_args && volume.pool_name.include?(ceph_args["libvirt_ceph_pool"])
349+
if ceph_args && ceph_args["libvirt_ceph_pool"]&.split(",")&.include?(volume.pool_name)
350350
xml.disk(:type => "network", :device => "disk") do
351351
xml.driver(:name => "qemu", :type => volume.format_type, :cache => "writeback", :discard => "unmap")
352-
xml.source(:protocol => "rbd", :name => volume.path)
353-
354-
ceph_args["monitor"]&.split(",")&.each do |monitor|
355-
xml.host(:name => monitor, :port => ceph_args["port"])
352+
xml.source(:protocol => "rbd", :name => volume.path) do
353+
ceph_args["monitor"]&.split(",")&.each do |monitor|
354+
xml.host(:name => monitor, :port => ceph_args["port"])
355+
end
356356
end
357357

358358
xml.auth(:username => ceph_args["auth_username"]) do
@@ -363,7 +363,7 @@ def to_xml
363363
end
364364
end
365365

366-
xml.target(:dev => target_device, :bus => args["bus_type"] == "virtio" ? "virtio" : "scsi")
366+
xml.target(:dev => target_device, :bus => ceph_args["bus_type"] == "virtio" ? "virtio" : "scsi")
367367
end
368368
else
369369
is_block = volume.path.start_with?("/dev/")

tests/libvirt/models/compute/server_tests.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
1+
RealFile = File
2+
class FakeFile < RealFile
3+
def self.file?(path)
4+
if path == '/etc/foreman/ceph.conf'
5+
return true
6+
else
7+
return RealFile.file(path)
8+
end
9+
end
10+
11+
def self.readlines(path)
12+
if path == '/etc/foreman/ceph.conf'
13+
return [
14+
"monitor=mon001.example.com,mon002.example.com,mon003.example.com",
15+
"port=6789",
16+
"libvirt_ceph_pool=rbd_pool_name,second_rbd_pool_name",
17+
"auth_username=libvirt",
18+
"auth_uuid=uuid_of_libvirt_secret",
19+
"bus_type=virtio"
20+
]
21+
else
22+
return RealFile.readlines(path)
23+
end
24+
end
25+
end
26+
127
Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do
228

329
servers = Fog::Compute[:libvirt].servers
430
# Match the mac in dhcp_leases mock
531
nics = Fog.mock? ? [{ :type => 'network', :network => 'default', :mac => 'aa:bb:cc:dd:ee:ff' }] : nil
632
server = servers.create(:name => Fog::Mock.random_letters(8), :nics => nics)
733

34+
before do
35+
Object.class_eval do
36+
remove_const(:File)
37+
const_set(:File, FakeFile)
38+
end
39+
end
40+
41+
after do
42+
Object.class_eval do
43+
remove_const(:File)
44+
const_set(:File, RealFile)
45+
end
46+
end
47+
848
tests('The server model should') do
949
tests('have the action') do
1050
test('autostart') { server.respond_to? 'autostart' }
@@ -89,6 +129,26 @@
89129
xml = server.to_xml
90130
xml.match?(/<disk type="block" device="disk">/) && xml.match?(%r{<source dev="/dev/sda"/>})
91131
end
132+
test("with disk of type ceph") do
133+
server = Fog::Libvirt::Compute::Server.new(
134+
{
135+
:nics => [],
136+
:volumes => [
137+
Fog::Libvirt::Compute::Volume.new({ :path => "rbd_pool_name/block-1", :pool_name => "rbd_pool_name" })
138+
]
139+
}
140+
)
141+
142+
xml = server.to_xml
143+
144+
network_disk = xml.match?(/<disk type="network" device="disk">/)
145+
mon_host = xml.match?(%r{<host name="mon001.example.com" port="6789"/>})
146+
source_rbd = xml.match?(%r{<source protocol="rbd" name="rbd_pool_name/block-1">})
147+
auth_username = xml.match?(/<auth username="libvirt">/)
148+
auth_secret = xml.match?(%r{<secret type="ceph" uuid="uuid_of_libvirt_secret"/>})
149+
150+
network_disk && mon_host && source_rbd && auth_username && auth_secret
151+
end
92152
test("with q35 machine type on x86_64") { server.to_xml.match?(%r{<type arch="x86_64" machine="q35">hvm</type>}) }
93153
end
94154
test("with efi firmware") do

0 commit comments

Comments
 (0)