Skip to content

Commit

Permalink
Proxmox extention for foreman_bootdisk
Browse files Browse the repository at this point in the history
  • Loading branch information
Manisha15 committed Mar 23, 2020
1 parent 6353a53 commit bf1c6dc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def capabilities

def iso_upload(iso, vm_uuid)
server = find_vm_by_uuid(vm_uuid)
config_attributes = {
'bootdisk' => 'ide2',
'boot' => 'dcn'
}
server.update(config_attributes)
server.ssh_options={password: fog_credentials[:pve_password]}
server.ssh_ip_address= bridges.first.address
server.scp_upload(iso,'/var/lib/vz/template/iso/')
Expand Down
32 changes: 32 additions & 0 deletions test/factories/proxmox_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'fog/compute/proxmox/models/node'

FactoryBot.define do
factory :proxmox_resource, :class => ComputeResource do
sequence(:name) { |n| "compute_resource#{n}" }
organizations { [Organization.find_by(name: 'Organization 1')] }
locations { [Location.find_by(name: 'Location 1')] }

trait :proxmox do
provider { 'Proxmox' }
user { 'root@pam' }
password { 'proxmox01' }
url { 'https://192.168.56.101:8006/api2/json' }
end

after(:build) do |site|
WebMock.stub_request(:post, "https://192.168.56.101:8006/api2/json/access/ticket").

with(
body: "username=root%40pam&password=proxmox01",
headers: {
'Accept'=>'application/json',
'Host'=>'192.168.56.101:8006',
'User-Agent'=>'fog-core/2.1.0'
}).
to_return(status: 200, body: "", headers: {})
end
factory :proxmox_cr, :class => ForemanFogProxmox::Proxmox, :traits => [:proxmox]
end
end
3 changes: 3 additions & 0 deletions test/test_plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
require 'webmock/minitest'
require 'webmock'

FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
FactoryBot.reload

module ForemanBootdiskTestHelper
def setup_bootdisk
setup_routes
Expand Down
60 changes: 60 additions & 0 deletions test/unit/concerns/compute_resources/proxmox_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require 'test_plugin_helper'

module ForemanBootdisk
class ProxmoxTest < ActiveSupport::TestCase
describe '#create_vm' do
setup do
@cr = FactoryBot.build(:proxmox_cr)
end


test 'does not call clone_vm when bootdisk provisioning' do
args = { 'provision_method' => 'bootdisk' }
mock_vm = mock('vm')
mock_vm.stubs(:firmware)
mock_vm.expects(:save).returns(mock_vm)
@cr.stubs(:parse_networks).returns(args)
@cr.expects(:clone_vm).times(0)
@cr.expects(:new_vm).returns(mock_vm)
@cr.create_vm(args)
end
end

describe '#new_vm' do
setup do
@cr = FactoryBot.build(:proxmox_cr)
end

test 'calls client with cdrom drive and correct boot order when bootdisk provisioning' do
args = { 'provision_method' => 'bootdisk' }
#mock_client = mock('client')
mock_servers = mock('servers')
mock_cdrom = mock('cdrom')
#mock_client.expects(:servers).returns(mock_servers)
mock_servers.expects(:new).with do |opts|
assert_equal opts[:boot], 'dcn'
assert_equal opts[:bootdisk], 'ide2'
#assert_includes opts[:cdroms], mock_cdrom
end
#@cr.expects(:new_cdrom).returns(mock_cdrom)
@cr.expects(:new_interface)
@cr.expects(:new_volume)
#@cr.expects(:datacenter)
#@cr.expects(:client).returns(mock_client)
@cr.new_vm(args)
end
end

describe '#capabilities' do
setup do
@cr = FactoryBot.build(:proxmox_cr)
end

test 'should include bootdisk' do
assert_includes @cr.capabilities, :bootdisk
end
end
end
end

0 comments on commit bf1c6dc

Please sign in to comment.