public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: Chuck Lever <cel@kernel.org>, Daniel Gomez <da.gomez@kruces.com>,
	kdevops@lists.linux.dev
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 6/8] gen_nodes: fix duplicate pcipassthrough keys in YAML output
Date: Mon, 11 Aug 2025 13:12:28 -0700	[thread overview]
Message-ID: <20250811201230.2145164-7-mcgrof@kernel.org> (raw)
In-Reply-To: <20250811201230.2145164-1-mcgrof@kernel.org>

The template was generating multiple 'pcipassthrough' keys for each
device, causing YAML parsing warnings about duplicate mapping keys.

Fixed by collecting all devices for a target guest first, then
outputting a single 'pcipassthrough' key with all devices under it.
This uses Jinja2's namespace feature to maintain state across loop
iterations.

Generated-by: Claude AI
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 .../roles/gen_nodes/templates/gen_nodes_list.j2   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/playbooks/roles/gen_nodes/templates/gen_nodes_list.j2 b/playbooks/roles/gen_nodes/templates/gen_nodes_list.j2
index e8f5e34..6ad2af1 100644
--- a/playbooks/roles/gen_nodes/templates/gen_nodes_list.j2
+++ b/playbooks/roles/gen_nodes/templates/gen_nodes_list.j2
@@ -1,18 +1,19 @@
 {%- macro gen_pci_passthrough_each(n, device_list) -%}
-{%- set found_pcie_devices_on_node = False -%}
+{%- set ns = namespace(has_devices=false, device_index=1) -%}
 {%- for d in device_list %}
 {%- if n == d.target_guest -%}
-{%- if not found_pcie_devices_on_node -%}
-{% set found_pcie_devices_on_node = True %}
+{%- if not ns.has_devices -%}
+{%- set ns.has_devices = true %}
     pcipassthrough:
-{% endif %}
-      passthrough{{ loop.index | string }}:
+{% endif -%}
+      passthrough{{ ns.device_index | string }}:
         domain: {{ d.domain }}
         bus: {{ d.bus }}
         slot: {{ d.slot }}
         function: {{ d.function }}
-{% endif %}
-{% endfor -%}
+{%- set ns.device_index = ns.device_index + 1 -%}
+{%- endif %}
+{%- endfor -%}
 {%- endmacro -%}
 {%- macro gen_pci_passthrough( device_list ) -%}
 {%- for d in device_list %}
-- 
2.47.2


  parent reply	other threads:[~2025-08-11 20:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 20:12 [PATCH 0/8] various fixes Luis Chamberlain
2025-08-11 20:12 ` [PATCH 1/8] libvirt: fix PCI-E passthrough configuration after Vagrant removal Luis Chamberlain
2025-08-11 20:12 ` [PATCH 2/8] gen-dynamic-pci: fix PCI passthrough target guest default value Luis Chamberlain
2025-08-11 20:12 ` [PATCH 3/8] gen-dynamic-pci: add GPU detection and naming support Luis Chamberlain
2025-08-11 20:12 ` [PATCH 4/8] guestfs / devconfig: allow for upgrade from Debian testing to forky Luis Chamberlain
2025-08-11 20:12 ` [PATCH 5/8] guestfs: add OVMF package for UEFI firmware support Luis Chamberlain
2025-08-11 20:12 ` Luis Chamberlain [this message]
2025-08-11 20:12 ` [PATCH 7/8] gen_nodes: fix YAML indentation in pcipassthrough template Luis Chamberlain
2025-08-11 20:12 ` [PATCH 8/8] guestfs: fix PCIe passthrough device attachment Luis Chamberlain
2025-08-11 20:38 ` [PATCH 0/8] various fixes Chuck Lever
2025-08-11 21:31   ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250811201230.2145164-7-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=cel@kernel.org \
    --cc=da.gomez@kruces.com \
    --cc=kdevops@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox