Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/concerns/orchestration/proxmox/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def setComputeUpdate
if compute_resource.class != ForemanFogProxmox::Proxmox
super
else
unless managed?
logger.info(format("Skipping Proxmox compute update for %s - host is not managed", name))
return true
end

logger.info "Update Proxmox Compute instance for #{name}"
final_compute_attributes = compute_attributes.merge(compute_resource.host_compute_attrs(self))
logger.debug("setComputeUpdate: final_compute_attributes=#{final_compute_attributes}")
Expand All @@ -40,6 +45,11 @@ def delComputeUpdate
if compute_resource.class != ForemanFogProxmox::Proxmox
super
else
unless managed?
logger.info(format("Skipping Proxmox compute update rollback for %s - host is not managed", name))
return true
end

logger.info "Undo Update Proxmox Compute instance for #{name}"
final_compute_attributes = old.compute_attributes.merge(compute_resource.host_compute_attrs(old))
compute_resource.save_vm uuid, final_compute_attributes
Expand Down Expand Up @@ -97,6 +107,9 @@ def setVmDetails
def setComputeDetails
if compute_resource.class != ForemanFogProxmox::Proxmox
super
elsif !managed?
logger.info(format("Skipping Proxmox compute details for %s - host is not managed", name))
true
elsif vm
setVmDetails
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of ForemanFogProxmox.

# ForemanFogProxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# ForemanFogProxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

require 'test_plugin_helper'

module ForemanFogProxmox
class ProxmoxOrchestrationComputeTest < ActiveSupport::TestCase
describe 'unmanaged host with Proxmox compute resource' do
let(:cr) { FactoryBot.build_stubbed(:proxmox_cr) }
let(:host) do
FactoryBot.build(:host_empty,
:managed => false,
:compute_resource => cr,
:compute_attributes => { 'type' => 'qemu' })
end

test 'setComputeUpdate skips orchestration for unmanaged host' do
assert host.setComputeUpdate
end

test 'setComputeUpdate logs info when skipping for unmanaged host' do
mock_logger = mock('logger')
mock_logger.expects(:info).with(format("Skipping Proxmox compute update for %s - host is not managed", host.name))
host.stubs(:logger).returns(mock_logger)
host.setComputeUpdate
end

test 'delComputeUpdate skips orchestration for unmanaged host' do
assert host.delComputeUpdate
end

test 'delComputeUpdate logs info when skipping for unmanaged host' do
mock_logger = mock('logger')
mock_logger.expects(:info).with(format("Skipping Proxmox compute update rollback for %s - host is not managed", host.name))
host.stubs(:logger).returns(mock_logger)
host.delComputeUpdate
end

test 'setComputeDetails skips orchestration for unmanaged host' do
assert host.setComputeDetails
end

test 'setComputeDetails logs info when skipping for unmanaged host' do
mock_logger = mock('logger')
mock_logger.expects(:info).with(format("Skipping Proxmox compute details for %s - host is not managed", host.name))
host.stubs(:logger).returns(mock_logger)
host.setComputeDetails
end
end
end
end
Loading