Skip to content

Commit

Permalink
Handle libvirt_ceph_pool as a complement of libvirt_ceph_pools
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanF committed Jan 10, 2025
1 parent cb6c1cb commit a2a8799
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 5 additions & 2 deletions lib/fog/libvirt/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def read_ceph_args(path = "/etc/foreman/ceph.conf")

args = {}

valid_keys = ["monitor", "port", "libvirt_ceph_pools", "auth_username", "auth_uuid", "bus_type"]
valid_keys = ["monitor", "port", "libvirt_ceph_pools", "libvirt_ceph_pool", "auth_username", "auth_uuid", "bus_type"]

Check warning on line 461 in lib/fog/libvirt/models/compute/server.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use `%w` or `%W` for an array of words. Raw Output: lib/fog/libvirt/models/compute/server.rb:461:24: C: Style/WordArray: Use `%w` or `%W` for an array of words.
array_values = ["monitor", "libvirt_ceph_pools"]

File.readlines(path).each do |line|
Expand All @@ -470,7 +470,10 @@ def read_ceph_args(path = "/etc/foreman/ceph.conf")
end
end

puts args
if args.has_key?("libvirt_ceph_pool")

Check warning on line 473 in lib/fog/libvirt/models/compute/server.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use `Hash#key?` instead of `Hash#has_key?`. Raw Output: lib/fog/libvirt/models/compute/server.rb:473:19: C: Style/PreferredHashMethods: Use `Hash#key?` instead of `Hash#has_key?`.
args.has_key?("libvirt_ceph_pools") ? args["libvirt_ceph_pools"] << args["libvirt_ceph_pool"] : args["libvirt_ceph_pools"] = [args["libvirt_ceph_pool"]]

Check warning on line 474 in lib/fog/libvirt/models/compute/server.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use `Hash#key?` instead of `Hash#has_key?`. Raw Output: lib/fog/libvirt/models/compute/server.rb:474:18: C: Style/PreferredHashMethods: Use `Hash#key?` instead of `Hash#has_key?`.
args.delete("libvirt_ceph_pool")
end

args
end
Expand Down
15 changes: 7 additions & 8 deletions tests/libvirt/models/compute/server_tests.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
RealFile = File
class FakeFile < RealFile
def self.file?(path)
if path == '/etc/foreman/ceph.conf'
return true
else
return RealFile.file(path)
end
path == '/etc/foreman/ceph.conf' || RealFile.file(path)
end

def self.readlines(path)
Expand All @@ -14,6 +10,7 @@ def self.readlines(path)
"monitor=mon001.example.com,mon002.example.com,mon003.example.com",
"port=6789",
"libvirt_ceph_pools=rbd_pool_name,second_rbd_pool_name",
"libvirt_ceph_pool=third_rbd_pool_name",
"auth_username=libvirt",
"auth_uuid=uuid_of_libvirt_secret",
"bus_type=virtio"
Expand Down Expand Up @@ -134,7 +131,8 @@ def self.readlines(path)
{
:nics => [],
:volumes => [
Fog::Libvirt::Compute::Volume.new({ :path => "rbd_pool_name/block-1", :pool_name => "rbd_pool_name" })
Fog::Libvirt::Compute::Volume.new({ :path => "rbd_pool_name/block-1", :pool_name => "rbd_pool_name" }),
Fog::Libvirt::Compute::Volume.new({ :path => "third_rbd_pool_name/block-2", :pool_name => "third_rbd_pool_name" })
]
}
)
Expand All @@ -143,11 +141,12 @@ def self.readlines(path)

network_disk = xml.match?(/<disk type="network" device="disk">/)
mon_host = xml.match?(%r{<host name="mon001.example.com" port="6789"/>})
source_rbd = xml.match?(%r{<source protocol="rbd" name="rbd_pool_name/block-1">})
source_block1_rbd = xml.match?(%r{<source protocol="rbd" name="rbd_pool_name/block-1">})
source_block2_rbd = xml.match?(%r{<source protocol="rbd" name="third_rbd_pool_name/block-2">})
auth_username = xml.match?(/<auth username="libvirt">/)
auth_secret = xml.match?(%r{<secret type="ceph" uuid="uuid_of_libvirt_secret"/>})

network_disk && mon_host && source_rbd && auth_username && auth_secret
network_disk && mon_host && source_block1_rbd && source_block2_rbd && auth_username && auth_secret
end
test("with q35 machine type on x86_64") { server.to_xml.match?(%r{<type arch="x86_64" machine="q35">hvm</type>}) }
end
Expand Down

0 comments on commit a2a8799

Please sign in to comment.