B #-: Fix oneks env isolation and ODS workflow races (#4670)

(cherry picked from commit d64a4333bf7ac3b24b48a628682a50672a0e117a)
This commit is contained in:
Victor Palma authored and Ruben S. Montero committed 2026-10-29 16:24:05 +01:00
1 parent 867a20299a
commit 32a41f9e7d
5 files changed
+124 -10

No files matched your search

+26
View File
@@ -629,6 +629,7 @@ module OpenNebula
# Creates or reuses a child operation under only the child owner lock.
def request_child(child, parent:, actor:)
result = nil
mismatched_op_id = nil
rc = pool.get(child.owner_id, actor) do |resource|
context = resource.active_job
@@ -636,6 +637,7 @@ module OpenNebula
if context
if child.operation_id.nil? &&
(context.step != child.step || context.args != child.args)
mismatched_op_id = context.id
result = ExecResult.error(
OpenNebula::Error.new(
"Child #{id} #{child.owner_id} has incompatible " \
@@ -687,6 +689,30 @@ module OpenNebula
return ExecResult.retry(rc)
end
if mismatched_op_id
# Another coordinator may have confirmed and advanced this child
# after our intent was read. Reload the parent without holding
# the child lock and reconnect only to its confirmed operation.
confirmed = nil
workflow = scheduler.workflow_for_id(parent.workflow)
rc = workflow.pool.get(parent.owner_id, actor) do |resource|
context = resource.active_job
next unless context&.id == parent.operation_id
confirmed = context.children.find do |current|
current.identity == child.identity &&
current.operation_id == mismatched_op_id
end
end
return ExecResult.retry(rc) if OpenNebula.is_error?(rc)
return request_child(
confirmed, :parent => parent, :actor => actor
) if confirmed
end
result
rescue ArgumentError => e
ExecResult.error(
+65
View File
@@ -588,6 +588,71 @@ RSpec.describe ODS::JobWorkflow, 'parent-child composition' do
expect(result.value.message).to include('incompatible step or arguments')
end
context 'when another coordinator confirms and advances a child' do
let(:child_workflow_class) do
klass = super()
klass.step :finish,
:handler => :perform,
:state => :RUNNING,
:success => ODS::Job.complete(:DONE),
:failure => :RUNNING_FAILURE
klass
end
it 'reconnects a stale request to the confirmed operation and completes the parent' do
parent = persist_parent_intent
job = parent_workflow.build_job(parent_owner)
advanced = false
allow(child_workflow).to(
receive(:request_child).and_wrap_original do |method, child, **opts|
if child.owner_id == 11 && !advanced
advanced = true
created = method.call(child, **opts)
expect(created).to be_ok
confirmed = child.with(
:status => :active,
:operation_id => created.value[:operation_id]
)
# Interleave a second coordinator's confirmation and the child's
# next step before the first coordinator uses its stale intent.
parent_pool.get(parent_owner.id) do |owner|
children = owner.active_job.children.map do |current|
current.identity == child.identity ? confirmed : current
end
owner.update_job_children!(job, children)
end
child_pool.get(child.owner_id) do |owner|
child_job = child_workflow.build_job(owner)
owner.transition_job!(
child_job,
ODS::Job.next(:finish, :args => child.args.merge(:phase => :next))
)
end
end
method.call(child, **opts)
end
)
expect(parent_workflow.resume_children(parent_owner)).to be_a(String)
expect(parent_owner.active_job.pending_failure).to be_nil
confirmed = parent_owner.active_job.children.last
expect(confirmed.operation_id).to eq(child_owners.last.active_job.id)
expect(child_owners.last.active_job.step).to eq(:finish)
expect(child_owners.last.active_job.parent).to eq(parent)
controls[10] = :ready
controls[11] = :ready
scheduler.start
wait_until { parent_owner.state == :DONE }
expect(child_workflow.calls).to eq(10 => 1, 11 => 1)
expect(parent_owner.active_job).to be_nil
end
end
context 'with a missing child accepted by the domain predicate' do
let(:descriptors) do
[{
+21 -5
View File
@@ -94,13 +94,29 @@ stop()
exit 1
fi
# Kill the oneks-server daemon
ONEKSPID=$(cat "$ONEKS_PID")
case "$ONEKSPID" in
''|*[!0-9]*|0|1)
echo "Invalid OneKS server PID: $ONEKSPID"
exit 1
;;
esac
kill -INT `cat $ONEKS_PID` > /dev/null 2>&1
kill -INT "$ONEKSPID" > /dev/null 2>&1
# Remove pid files
rm -f $ONEKS_PID > /dev/null 2>&1
rm -f $ONEKS_LOCK_FILE &> /dev/null
# Keep the PID and lock until the daemon has finished shutting down
STOP_TIMEOUT=60
while ps -p "$ONEKSPID" -o stat= 2>/dev/null | grep -qv '^[[:space:]]*Z'; do
if [ "$STOP_TIMEOUT" -eq 0 ]; then
echo "Timed out waiting for OneKS server to stop (PID:$ONEKSPID)."
exit 1
fi
sleep 1
STOP_TIMEOUT=$((STOP_TIMEOUT - 1))
done
rm -f "$ONEKS_PID" "$ONEKS_LOCK_FILE"
echo "oneks-server stopped"
}
+1 -1
View File
@@ -16,7 +16,7 @@
ONEKS_SPEC_DIR = File.join(VAR_LOCATION, 'oneks')
TPROXY_PATH = File.join(VAR_LOCATION, 'remotes', 'etc', 'vnm', 'OpenNebulaNetwork.conf')
SKIP_DEPENDENCIES = ENV['RACK_ENV'] == 'development'
SKIP_DEPENDENCIES = SERVER_CONF[:server][:environment] == 'development'
# -------------------------------------------------------------------------- #
# Required classes
+11 -4
View File
@@ -29,9 +29,7 @@ module OneKS
READINESS_STATES = [
:PROVISIONING,
:SCALING,
:UPGRADING,
:RUNNING,
:WARNING
:UPGRADING
]
CONTROL_PLANE_PODS = [
@@ -200,7 +198,7 @@ module OneKS
if action == :event
begin
rc = publish_node_ready(**event)
remember_ready_report(event) unless OpenNebula.is_error?(rc)
remember_ready_report(event) if rc && !OpenNebula.is_error?(rc)
rescue StandardError => e
log_error(
"Could not publish readiness for VM #{event[:vm_id]}: " \
@@ -431,6 +429,15 @@ module OneKS
def publish_node_ready(cluster_id:, group_id:, vm_id:, cluster: nil)
return true if stopped?
group = @group_pool.get(group_id)
if OpenNebula.is_error?(group)
log_error("Could not load Group #{group_id}: #{group.message}", cluster_id)
return group
end
return false unless READINESS_STATES.include?(group.state.to_sym)
cluster ||= @cluster_pool.get(cluster_id)
if OpenNebula.is_error?(cluster)