|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test_plugin_helper' |
| 4 | + |
| 5 | +module ForemanBootdisk |
| 6 | + class OrchestrationProxmoxComputeTest < ActiveSupport::TestCase |
| 7 | + setup do |
| 8 | + disable_orchestration |
| 9 | + skip unless ForemanBootdisk.with_proxmox? |
| 10 | + @proxmox_cr = FactoryBot.build(:proxmox_cr) |
| 11 | + @proxmox_host = FactoryBot.build(:host, :managed, |
| 12 | + compute_resource: @proxmox_cr, |
| 13 | + provision_method: 'bootdisk') |
| 14 | + end |
| 15 | + |
| 16 | + test 'provisioning a host with provision method bootdisk in proxmox should upload iso' do |
| 17 | + @proxmox_cr.expects(:iso_upload) |
| 18 | + @proxmox_host.send(:setIsoImage) |
| 19 | + end |
| 20 | + |
| 21 | + test 'provisioning a host with provision method bootdisk in proxmox should attach iso' do |
| 22 | + @proxmox_cr.expects(:iso_attach) |
| 23 | + @proxmox_host.send(:setAttachIsoImage) |
| 24 | + end |
| 25 | + |
| 26 | + test 'provisioning a host with provision method bootdisk in proxmox should detach iso' do |
| 27 | + @proxmox_cr.expects(:iso_detach) |
| 28 | + @proxmox_host.send(:setDetachIsoImage) |
| 29 | + end |
| 30 | + |
| 31 | + test 'provisioning a new proxmox host with provision method bootdisk should queue bootdisk tasks' do |
| 32 | + @proxmox_host.stubs(:compute?).returns(true) |
| 33 | + @proxmox_host.stubs(:build?).returns(true) |
| 34 | + @proxmox_host.send(:queue_bootdisk_compute) |
| 35 | + tasks = @proxmox_host.queue.all.map(&:name) |
| 36 | + assert_includes tasks, "Generating ISO image for #{@proxmox_host.name}" |
| 37 | + assert_includes tasks, "Upload ISO image to datastore for #{@proxmox_host.name}" |
| 38 | + assert_includes tasks, "Attach ISO image to CDROM drive for #{@proxmox_host.name}" |
| 39 | + assert_not_includes tasks, "Detach ISO image from CDROM drive for #{@proxmox_host.name}" |
| 40 | + end |
| 41 | + |
| 42 | + test 'rebuilding a proxmox host with provision method bootdisk should queue bootdisk tasks' do |
| 43 | + @proxmox_host.stubs(:compute?).returns(true) |
| 44 | + old = stub() |
| 45 | + old.stubs(:build?).returns(false) |
| 46 | + @proxmox_host.stubs(:old).returns(old) |
| 47 | + @proxmox_host.stubs(:build?).returns(true) |
| 48 | + @proxmox_host.send(:queue_bootdisk_compute) |
| 49 | + tasks = @proxmox_host.queue.all.map(&:name) |
| 50 | + assert_includes tasks, "Generating ISO image for #{@proxmox_host.name}" |
| 51 | + assert_includes tasks, "Upload ISO image to datastore for #{@proxmox_host.name}" |
| 52 | + assert_includes tasks, "Attach ISO image to CDROM drive for #{@proxmox_host.name}" |
| 53 | + assert_not_includes tasks, "Detach ISO image from CDROM drive for #{@proxmox_host.name}" |
| 54 | + end |
| 55 | + |
| 56 | + test 'the iso should be detached when the proxmox host leaves build mode' do |
| 57 | + @proxmox_host.stubs(:compute?).returns(true) |
| 58 | + old = stub() |
| 59 | + old.stubs(:build?).returns(true) |
| 60 | + @proxmox_host.stubs(:old).returns(old) |
| 61 | + @proxmox_host.stubs(:build?).returns(false) |
| 62 | + @proxmox_host.send(:queue_bootdisk_compute) |
| 63 | + tasks = @proxmox_host.queue.all.map(&:name) |
| 64 | + assert_not_includes tasks, "Generating ISO image for #{@proxmox_host.name}" |
| 65 | + assert_not_includes tasks, "Upload ISO image to datastore for #{@proxmox_host.name}" |
| 66 | + assert_not_includes tasks, "Attach ISO image to CDROM drive for #{@proxmox_host.name}" |
| 67 | + assert_includes tasks, "Detach ISO image from CDROM drive for #{@proxmox_host.name}" |
| 68 | + end |
| 69 | + end |
| 70 | +end |
0 commit comments