Skip to content

Commit b30393f

Browse files
committed
Fixes #455 - skip Proxmox compute orchestration for unmanaged hosts
When a host is registered via Global Registration with a hostgroup that has a Compute Resource (Proxmox), the compute orchestration methods (setComputeUpdate, delComputeUpdate, setComputeDetails) are triggered even though the host is unmanaged (managed: false). This causes errors like "protected method setCompute called" because the orchestration tries to interact with the Proxmox API for a host that was not provisioned through Foreman. This patch adds managed? guards with log messages to skip Proxmox-specific compute orchestration for unmanaged hosts, analogous to foreman core PR #10905. Unit tests verify all three methods skip orchestration and log appropriately for unmanaged hosts. Assisted-By: Claude (Anthropic)
1 parent f6cf842 commit b30393f

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

app/models/concerns/orchestration/proxmox/compute.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def setComputeUpdate
2626
if compute_resource.class != ForemanFogProxmox::Proxmox
2727
super
2828
else
29+
unless managed?
30+
logger.info(format("Skipping Proxmox compute update for %s - host is not managed", name))
31+
return true
32+
end
33+
2934
logger.info "Update Proxmox Compute instance for #{name}"
3035
final_compute_attributes = compute_attributes.merge(compute_resource.host_compute_attrs(self))
3136
logger.debug("setComputeUpdate: final_compute_attributes=#{final_compute_attributes}")
@@ -40,6 +45,11 @@ def delComputeUpdate
4045
if compute_resource.class != ForemanFogProxmox::Proxmox
4146
super
4247
else
48+
unless managed?
49+
logger.info(format("Skipping Proxmox compute update rollback for %s - host is not managed", name))
50+
return true
51+
end
52+
4353
logger.info "Undo Update Proxmox Compute instance for #{name}"
4454
final_compute_attributes = old.compute_attributes.merge(compute_resource.host_compute_attrs(old))
4555
compute_resource.save_vm uuid, final_compute_attributes
@@ -97,6 +107,9 @@ def setVmDetails
97107
def setComputeDetails
98108
if compute_resource.class != ForemanFogProxmox::Proxmox
99109
super
110+
elsif !managed?
111+
logger.info(format("Skipping Proxmox compute details for %s - host is not managed", name))
112+
true
100113
elsif vm
101114
setVmDetails
102115
else
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright 2018 Tristan Robert
4+
5+
# This file is part of ForemanFogProxmox.
6+
7+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
12+
# ForemanFogProxmox is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
17+
# You should have received a copy of the GNU General Public License
18+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19+
20+
require 'test_plugin_helper'
21+
22+
module ForemanFogProxmox
23+
class ProxmoxOrchestrationComputeTest < ActiveSupport::TestCase
24+
describe 'unmanaged host with Proxmox compute resource' do
25+
let(:cr) { FactoryBot.build_stubbed(:proxmox_cr) }
26+
let(:host) do
27+
FactoryBot.build(:host_empty,
28+
:managed => false,
29+
:compute_resource => cr,
30+
:compute_attributes => { 'type' => 'qemu' })
31+
end
32+
33+
test 'setComputeUpdate skips orchestration for unmanaged host' do
34+
assert host.setComputeUpdate
35+
end
36+
37+
test 'setComputeUpdate logs info when skipping for unmanaged host' do
38+
mock_logger = mock('logger')
39+
mock_logger.expects(:info).with(format("Skipping Proxmox compute update for %s - host is not managed", host.name))
40+
host.stubs(:logger).returns(mock_logger)
41+
host.setComputeUpdate
42+
end
43+
44+
test 'delComputeUpdate skips orchestration for unmanaged host' do
45+
assert host.delComputeUpdate
46+
end
47+
48+
test 'delComputeUpdate logs info when skipping for unmanaged host' do
49+
mock_logger = mock('logger')
50+
mock_logger.expects(:info).with(format("Skipping Proxmox compute update rollback for %s - host is not managed", host.name))
51+
host.stubs(:logger).returns(mock_logger)
52+
host.delComputeUpdate
53+
end
54+
55+
test 'setComputeDetails skips orchestration for unmanaged host' do
56+
assert host.setComputeDetails
57+
end
58+
59+
test 'setComputeDetails logs info when skipping for unmanaged host' do
60+
mock_logger = mock('logger')
61+
mock_logger.expects(:info).with(format("Skipping Proxmox compute details for %s - host is not managed", host.name))
62+
host.stubs(:logger).returns(mock_logger)
63+
host.setComputeDetails
64+
end
65+
end
66+
end
67+
end

0 commit comments

Comments
 (0)