Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions roles/sushy_emulator/tasks/collect_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@
- name: Generate list of filtered VMs
vars:
_matching_vms: >-
{% set matching_vms = [] -%}
{% for host, uuid in cifmw_libvirt_manager_uuids.items() -%}
{% if host | regex_search(cifmw_sushy_emulator_vm_prefix_filter | default('') + '.*') -%}
{% set _ = matching_vms.append(uuid) -%}
{% endif -%}
{% endfor -%}
{{ matching_vms }}
{{
cifmw_libvirt_manager_uuids |
dict2items |
selectattr('key', 'match', cifmw_sushy_emulator_vm_prefix_filter | default('') ~ '.*') |
map(attribute='value') |
list
}}
ansible.builtin.set_fact:
_cifmw_sushy_emulator_instances: "{{ _matching_vms | regex_replace('\n(?!.*\n)', ', ')}}"
_cifmw_sushy_emulator_instances: "{{ _matching_vms }}"
Copy link
Contributor

@hjensas hjensas Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the regex to convert this to a comma separated string, instead of a \n line-break reparated string. Because it is the input for sushy emulator config file:

SUSHY_EMULATOR_ALLOWED_INSTANCES = {{ _cifmw_sushy_emulator_instances }}

_matching_vms is of tpy string, not of type list.

hmm, so rethinking - the string would not be newline separated, it would be a ["uuid-0", "uuid-1", "uuid-2"] ?

so what we actually need is something like:

_cifmw_sushy_emulator_instances: "{{ _matching_vms | from_yaml }} or from_json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so as

We have libvirt-uuids.yml with the following content

libvirt_uuid:
    cifmw-ocp-master-0: 17a164e9-46af-504d-b750-4d768f4b1b71
    cifmw-ocp-master-1: a91fb6bc-1bf2-532a-b3ef-4bdecda8a0dd
    cifmw-ocp-master-2: 8e6c659c-27df-5ead-bdf2-59b8dde77263
    cifmw-ocp-worker-0: f2db0152-6cdc-5cef-9294-f1248364389a

When we slurp data we get the following structure

        "cifmw_libvirt_manager_uuids": {
            "cifmw-ocp-master-0": "17a164e9-46af-504d-b750-4d768f4b1b71",
            "cifmw-ocp-master-1": "a91fb6bc-1bf2-532a-b3ef-4bdecda8a0dd",
            "cifmw-ocp-master-2": "8e6c659c-27df-5ead-bdf2-59b8dde77263",
            "cifmw-ocp-worker-0": "f2db0152-6cdc-5cef-9294-f1248364389a"
        }

In Generate list of filtered VMs task we set matching_vms as empty list by

matching_vms = []

then in for loop we add UUIDs to list of matching vms as

set _ = matching_vms.append(uuid)

so we get the following list

"_cifmw_sushy_emulator_instances": [
            "17a164e9-46af-504d-b750-4d768f4b1b71",
            "a91fb6bc-1bf2-532a-b3ef-4bdecda8a0dd",
            "8e6c659c-27df-5ead-bdf2-59b8dde77263",
            "f2db0152-6cdc-5cef-9294-f1248364389a"
        ]

after my change. We don't need to convert it to comma separated string as whole code is around list for _cifmw_sushy_emulator_instances variable. In roles/reproducer/tasks/generate_bm_info.yml we have the following code

{% if item.value in _cifmw_sushy_emulator_instances | default([]) %}

or roles/sushy_emulator/tasks/create_container.yml has

req = urllib.request.Request('http://localhost:8000/redfish/v1/Systems/{{ _cifmw_sushy_emulator_instances[0] }}');

when:
- _matching_vms | length > 0

Expand Down
2 changes: 1 addition & 1 deletion roles/sushy_emulator/templates/config_conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ SUSHY_EMULATOR_IGNORE_BOOT_DEVICE = False
# This list contains the identities of instances that the driver will filter by.
# It is useful in a tenant environment where only some instances represent
# virtual baremetal.
SUSHY_EMULATOR_ALLOWED_INSTANCES = {{ _cifmw_sushy_emulator_instances }}
SUSHY_EMULATOR_ALLOWED_INSTANCES = {{ _cifmw_sushy_emulator_instances | join(', ') }}
{% endif %}