From a812b7c756780d1c0126f294eca575d688ac23b7 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 14 May 2025 14:30:54 +0100 Subject: [PATCH] Fix PCI passthrough default templates Even though the variable ``gpu_group_map`` has default value of {} defined at stackhpc-compute.yml, it can be set to anything by users. Therefore, Using dict2items filter with it can cause unexpected templating error. Fixing this by setting {} as a default of ``gpu_group_map`` before using dict2items filter. So even if ``gpu_group_map`` becomes undefined for some reason, it doesn't fail in run time. --- etc/kayobe/ansible/pci-passthrough.yml | 2 +- etc/kayobe/kolla/config/nova/nova-api.conf | 2 +- etc/kayobe/kolla/config/nova/nova-compute.conf | 2 +- .../notes/fix-pci-default-template-8660ab2a7a106376.yaml | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-pci-default-template-8660ab2a7a106376.yaml diff --git a/etc/kayobe/ansible/pci-passthrough.yml b/etc/kayobe/ansible/pci-passthrough.yml index 59803ccf3..392713c35 100644 --- a/etc/kayobe/ansible/pci-passthrough.yml +++ b/etc/kayobe/ansible/pci-passthrough.yml @@ -11,7 +11,7 @@ vfio_pci_ids: |- {% set gpu_list = [] %} {% set output = [] %} - {% for gpu_group in gpu_group_map | dict2items | default([]) %} + {% for gpu_group in (gpu_group_map | default({})) | dict2items %} {% if gpu_group.key in group_names %} {% set _ = gpu_list.append(gpu_group.value) %} {% endif %} diff --git a/etc/kayobe/kolla/config/nova/nova-api.conf b/etc/kayobe/kolla/config/nova/nova-api.conf index 59e3a6102..ba96a2ddb 100644 --- a/etc/kayobe/kolla/config/nova/nova-api.conf +++ b/etc/kayobe/kolla/config/nova/nova-api.conf @@ -1,4 +1,4 @@ [pci] -{% for item in gpu_group_map | dict2items | map(attribute='value') | flatten | unique | list %} +{% for item in (gpu_group_map | default({})) | dict2items | map(attribute='value') | flatten | unique | list %} alias = { "vendor_id":"{{ stackhpc_gpu_data[item].vendor_id }}", "product_id":"{{ stackhpc_gpu_data[item].product_id }}", "device_type":"{{ stackhpc_gpu_data[item].device_type }}", "name":"{{ stackhpc_gpu_data[item].resource_name }}" } {% endfor %} diff --git a/etc/kayobe/kolla/config/nova/nova-compute.conf b/etc/kayobe/kolla/config/nova/nova-compute.conf index 5f8593dde..ed83c7101 100644 --- a/etc/kayobe/kolla/config/nova/nova-compute.conf +++ b/etc/kayobe/kolla/config/nova/nova-compute.conf @@ -1,7 +1,7 @@ [pci] {% raw %} {% set gpu_list = [] %} -{% for gpu_group in gpu_group_map | dict2items | default([]) %} +{% for gpu_group in (gpu_group_map | default({})) | dict2items %} {% if gpu_group.key in group_names %} {% set _ = gpu_list.append(gpu_group.value) %} {% endif %} diff --git a/releasenotes/notes/fix-pci-default-template-8660ab2a7a106376.yaml b/releasenotes/notes/fix-pci-default-template-8660ab2a7a106376.yaml new file mode 100644 index 000000000..affc29fd8 --- /dev/null +++ b/releasenotes/notes/fix-pci-default-template-8660ab2a7a106376.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixes possible templating error with PCI passthrough configuration.