|
| 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 | + |
1 | 27 | Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do |
2 | 28 |
|
3 | 29 | servers = Fog::Compute[:libvirt].servers |
4 | 30 | # Match the mac in dhcp_leases mock |
5 | 31 | nics = Fog.mock? ? [{ :type => 'network', :network => 'default', :mac => 'aa:bb:cc:dd:ee:ff' }] : nil |
6 | 32 | server = servers.create(:name => Fog::Mock.random_letters(8), :nics => nics) |
7 | 33 |
|
| 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 | + |
8 | 48 | tests('The server model should') do |
9 | 49 | tests('have the action') do |
10 | 50 | test('autostart') { server.respond_to? 'autostart' } |
|
89 | 129 | xml = server.to_xml |
90 | 130 | xml.match?(/<disk type="block" device="disk">/) && xml.match?(%r{<source dev="/dev/sda"/>}) |
91 | 131 | 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 |
92 | 152 | test("with q35 machine type on x86_64") { server.to_xml.match?(%r{<type arch="x86_64" machine="q35">hvm</type>}) } |
93 | 153 | end |
94 | 154 | test("with efi firmware") do |
|
0 commit comments