This commit is contained in:
2025-10-23 04:55:46 +03:00
parent b6bc15fd17
commit f0d0fe9760
4 changed files with 112 additions and 17 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -43,6 +43,21 @@
target_version: "{{ target_version | default('') }}" target_version: "{{ target_version | default('') }}"
target_version_full: "{{ target_version_full | default(target_version | default('')) }}" target_version_full: "{{ target_version_full | default(target_version | default('')) }}"
- name: Debug | snapshot of incoming scheduler metadata
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "attempt={{ attempt | default('') }}"
- "max_attempts={{ max_attempts | default('') }}"
- "current_delay_sec={{ current_delay_sec | default('') }}"
- "correlation_id={{ correlation_id | default('') }}"
- "original_emitted_at={{ original_emitted_at | default('') }}"
- "target_version_full={{ target_version_full | default('') }}"
- "target_version={{ target_version | default('') }}"
- "schema_version={{ schema_version | default('') }}"
# Visibility of what scheduler sent # Visibility of what scheduler sent
- name: Debug show received scheduler metadata - name: Debug show received scheduler metadata
delegate_to: localhost delegate_to: localhost
@@ -152,8 +167,8 @@
max_attempts: "{{ effective_max_attempts | int }}" max_attempts: "{{ effective_max_attempts | int }}"
correlation_id: "{{ correlation_id }}" correlation_id: "{{ correlation_id }}"
original_emitted_at: "{{ original_emitted_at }}" original_emitted_at: "{{ original_emitted_at }}"
target_version_full: "{{ target_version_full }}" # <-- ADD target_version_full: "{{ target_version_full }}"
target_version: "{{ target_version | default(target_version_full) }}" # <-- ADD (keeps core if it was sent) target_version: "{{ target_version | default(target_version_full) }}"
current_delay_sec: "{{ next_delay_sec | int }}" current_delay_sec: "{{ next_delay_sec | int }}"
schema_version: 1 schema_version: 1
@@ -336,6 +351,15 @@
changed_when: false changed_when: false
ignore_errors: true ignore_errors: true
- name: Debug | banner normalization inputs
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "banner_raw={{ (firmware_banner.stdout | default(firmware_banner) | default('')) | trim }}"
- "normalize rule: '2.2.1 rev 6801' -> '2.2.1-r6801'"
- name: Debug show raw firmware readout from DEV2 - name: Debug show raw firmware readout from DEV2
delegate_to: localhost delegate_to: localhost
ansible.builtin.debug: ansible.builtin.debug:
@@ -365,6 +389,16 @@
ansible.builtin.set_fact: ansible.builtin.set_fact:
expected_norm_step1: "{{ (target_version_full | default('') | trim) }}" expected_norm_step1: "{{ (target_version_full | default('') | trim) }}"
- name: Debug | expected target base and regex extraction inputs
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "target_version(raw)={{ target_version | default('') }}"
- "target_version_full(raw)={{ target_version_full | default('') }}"
- "regex='[0-9]+\\.[0-9]+\\.[0-9]+-r[0-9]+'"
- name: Extract version core X dot Y dot Z dash rNNNN from target if present - name: Extract version core X dot Y dot Z dash rNNNN from target if present
delegate_to: localhost delegate_to: localhost
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -380,6 +414,14 @@
ansible.builtin.set_fact: ansible.builtin.set_fact:
expected_norm: "{{ (expected_norm_core | default('') | length > 0) | ternary(expected_norm_core, expected_norm_step1) }}" expected_norm: "{{ (expected_norm_core | default('') | length > 0) | ternary(expected_norm_core, expected_norm_step1) }}"
- name: Debug | final expected normalized version (what we will compare against)
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "expected_norm={{ expected_norm | default('') }}"
# 1 capture raw banner line from DEV2 # 1 capture raw banner line from DEV2
- name: Capture firmware banner line from DEV2 - name: Capture firmware banner line from DEV2
delegate_to: localhost delegate_to: localhost
@@ -399,6 +441,24 @@
) )
}} }}
- name: Debug | banner normalized result
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "banner_norm={{ banner_norm | default('') }}"
- name: Debug | version compare inputs and strategy
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "expected_norm={{ expected_norm | default('') }}"
- "banner_norm={{ banner_norm | default('') }}"
- "eq={{ (expected_norm | default('')) == (banner_norm | default('')) }}"
- "substr={{ (banner_norm | default('')) is search((expected_norm | default('')), ignorecase=False) if (expected_norm | default('') | length) > 0 else 'N/A' }}"
- name: Evaluate version match using normalized equality or substring - name: Evaluate version match using normalized equality or substring
delegate_to: localhost delegate_to: localhost
ansible.builtin.set_fact: ansible.builtin.set_fact:
@@ -412,6 +472,14 @@
) )
}} }}
- name: Debug | version match outcome
delegate_to: localhost
when: debug_aic | bool
ansible.builtin.debug:
msg:
- "version_match={{ version_match | default(false) }}"
- name: Debug snapshot of expected and actual normalized versions - name: Debug snapshot of expected and actual normalized versions
delegate_to: localhost delegate_to: localhost
ansible.builtin.debug: ansible.builtin.debug:
@@ -700,11 +768,21 @@
max_attempts: "{{ effective_max_attempts | int }}" max_attempts: "{{ effective_max_attempts | int }}"
correlation_id: "{{ correlation_id | default('') }}" correlation_id: "{{ correlation_id | default('') }}"
original_emitted_at: "{{ original_emitted_at | default('') }}" original_emitted_at: "{{ original_emitted_at | default('') }}"
target_version_full: "{{ target_version_full }}" # <-- ADD target_version_full: "{{ target_version_full }}"
target_version: "{{ target_version | default(target_version_full) }}" # <-- ADD target_version: "{{ target_version | default(target_version_full) }}"
current_delay_sec: "{{ next_delay_sec | int }}" current_delay_sec: "{{ next_delay_sec | int }}"
schema_version: 1 schema_version: 1
- name: Debug | next attempt backoff plan
delegate_to: localhost
when: debug_aic | bool and (version_match | default(false) | bool) == false
ansible.builtin.debug:
msg:
- "attempt={{ attempt | default('') }} / max_attempts={{ max_attempts | default('') }}"
- "next_delay_sec={{ next_delay_sec | default('') }}"
- "routing_key={{ routing_key | default('deviceconfig') }}"
- "correlation_id={{ correlation_id | default('') }}"
- name: Publish delayed next indoor attempt to holding with TTL routed to deviceconfig - name: Publish delayed next indoor attempt to holding with TTL routed to deviceconfig
when: delayed_payload is defined when: delayed_payload is defined
delegate_to: localhost delegate_to: localhost

View File

@@ -64,24 +64,41 @@ dispatch_task() {
task="$(jq -er '.task_name // empty' <<<"$json")" || task="" task="$(jq -er '.task_name // empty' <<<"$json")" || task=""
task_options="$(jq -r '.task_options // empty' <<<"$json")" || task_options="" task_options="$(jq -r '.task_options // empty' <<<"$json")" || task_options=""
# Pass after-upgrade metadata via -e by augmenting task_options (single source of truth) # Pass after-upgrade metadata via -e by augmenting task_options (single source of truth)
if [[ "$task" == "afterupgrade_check" ]]; then # Supports both historic 'afterupgrade_check' and current 'afterupgrade_indoor_check'
local attempt corr_id orig_at target_ver if [[ "$task" == "afterupgrade_indoor_check" || "$task" == "afterupgrade_check" ]]; then
attempt="$(jq -r '.attempt // empty' <<<"$json")" # Extract everything the publisher may send
corr_id="$(jq -r '.correlation_id // empty' <<<"$json")" local attempt max_attempts cur_delay corr_id orig_at target_ver tv_full schema
orig_at="$(jq -r '.original_emitted_at // empty' <<<"$json")" attempt="$(jq -r '.attempt // ""' <<<"$json")"
target_ver="$(jq -r '.target_version // empty' <<<"$json")" max_attempts="$(jq -r '.max_attempts // ""' <<<"$json")"
cur_delay="$(jq -r '.current_delay_sec // ""' <<<"$json")"
corr_id="$(jq -r '.correlation_id // ""' <<<"$json")"
orig_at="$(jq -r '.original_emitted_at // ""' <<<"$json")"
target_ver="$(jq -r '.target_version // ""' <<<"$json")"
tv_full="$(jq -r '.target_version_full // ""' <<<"$json")"
schema="$(jq -r '.schema_version // ""' <<<"$json")"
[[ -n "$attempt" ]] && task_options+=" -e attempt=${attempt}" # Backfill target_version from target_version_full if missing (e.g., fox200-2.2.1-r6801.bin → 2.2.1-r6801)
[[ -n "$corr_id" ]] && task_options+=" -e correlation_id=${corr_id}" if [[ -z "$target_ver" && -n "$tv_full" ]]; then
[[ -n "$orig_at" ]] && task_options+=" -e original_emitted_at=${orig_at}" target_ver="$(sed -nE 's/.*([0-9]+\.[0-9]+\.[0-9]+-r[0-9]+).*/\1/p' <<<"$tv_full" || true)"
if [[ -n "$target_ver" ]]; then
local esc_tv=${target_ver//\'/\'\"\'\"\'} # replace ' with '\'' safely
task_options+=" -e target_version='${esc_tv}'"
fi fi
# Safe single-quote escaper for -e 'value'
esc() { local s="$1"; printf "%s" "${s//\'/\047}"; }
# Always pass the vars (even if empty), so the play never sees undefined
task_options+=" -e attempt='$(esc "$attempt")'"
task_options+=" -e max_attempts='$(esc "$max_attempts")'"
task_options+=" -e current_delay_sec='$(esc "$cur_delay")'"
task_options+=" -e correlation_id='$(esc "$corr_id")'"
task_options+=" -e original_emitted_at='$(esc "$orig_at")'"
task_options+=" -e target_version='$(esc "$target_ver")'"
task_options+=" -e target_version_full='$(esc "$tv_full")'"
task_options+=" -e schema_version='$(esc "$schema")'"
fi fi
if [[ -z "$device" || -z "$task" ]]; then if [[ -z "$device" || -z "$task" ]]; then
warn "payload missing required keys (inscope_device/task_name). Skipping." warn "payload missing required keys (inscope_device/task_name). Skipping."
return 0 return 0