[sushy_emulator] Fix list handling for VM instances#3678
[sushy_emulator] Fix list handling for VM instances#3678holser wants to merge 1 commit intoopenstack-k8s-operators:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
d26f7a6 to
54cf81a
Compare
|
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/06565e38a53248ac9155519606efd3f4 ✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 54m 41s |
54cf81a to
d79c2ac
Compare
| {{ matching_vms }} | ||
| ansible.builtin.set_fact: | ||
| _cifmw_sushy_emulator_instances: "{{ _matching_vms | regex_replace('\n(?!.*\n)', ', ')}}" | ||
| _cifmw_sushy_emulator_instances: "{{ _matching_vms }}" |
There was a problem hiding this comment.
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:
_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 ?
There was a problem hiding this comment.
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] }}');
d79c2ac to
95eca9c
Compare
95eca9c to
2221d49
Compare
| # 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(", ") }}' |
There was a problem hiding this comment.
if we need CSV in template we should add it to template and operate lists in ansible code
|
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/8836ee39b1574d0d98c28b131b7794d5 ✔️ openstack-k8s-operators-content-provider SUCCESS in 2h 19m 26s |
2221d49 to
449f48c
Compare
- Replace complex Jinja2 for-loop with idiomatic filter chain
(dict2items | selectattr | map | list)
- Remove regex_replace in favor of join(', ') in template
- Keep variable as list for loop/index access in tasks
- Template formats output as comma-separated: uuid1, uuid2, uuid3
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Sergii Golovatiuk <sgolovat@redhat.com>
449f48c to
2434a20
Compare
|
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/0ce7a2e60fa3444c9989ebe7fd09b9b1 ✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 37m 13s |
(dict2items | selectattr | map | list)
Co-authored-by: Cursor cursoragent@cursor.com
Signed-off-by: Sergii Golovatiuk sgolovat@redhat.com