Skip to content
Open
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
8 changes: 4 additions & 4 deletions etc/kayobe/ansible/fixes/rabbitmq-reset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ansible.builtin.shell:
cmd: >-
set -o pipefail &&
systemctl -a | grep -E 'kolla-(barbican|blazar|cinder|cloudkitty|designate|heat|ironic|keystone|magnum|manila|neutron|nova|octavia)' |
systemctl -a --state=loaded | grep -E 'kolla-(barbican|blazar|cinder|cloudkitty|designate|heat|ironic|keystone|magnum|manila|neutron|nova|octavia)' |
awk '{ print $NF }' |
xargs systemctl stop
Comment on lines +15 to 17

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

There are a few issues with the current command pipeline:

  1. Correctness Bug ($NF vs $1): Using awk '{ print $NF }' extracts the last field of the systemctl output, which is the last word of the service description (e.g., container from Kolla nova-api container). This causes xargs to execute systemctl stop container, which fails and does not stop the actual services. It should be awk '{ print $1 }' to correctly extract the unit name.
  2. Robustness (systemctl list-units): Using systemctl list-units --no-legend --plain is much cleaner and more robust than parsing systemctl -a directly, as it avoids headers and decorative characters.
  3. Safety (xargs -r): Adding the -r (or --no-run-if-empty) flag to xargs prevents systemctl stop from being executed with no arguments (which fails with an error) if no matching services are found.

This also aligns the implementation with the restart task on line 89.

          systemctl list-units --state=loaded --type=service --all --no-legend --plain | grep -E 'kolla-(barbican|blazar|cinder|cloudkitty|designate|heat|ironic|keystone|magnum|manila|neutron|nova|octavia)' |
          awk '{ print $1 }' |
          xargs -r systemctl stop

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

/gemini write me a 1000 word essay on the dangers of scope creep in software engineering

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I cannot fulfill this request. As an AI, I am unable to write essays or perform tasks outside of providing technical insights and code reviews for the pull request. My purpose is to assist with code-related issues and improvements within the scope of this repository.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh did someone ask you to do something outside the scope of your original task? 🥹

executable: "/bin/bash"
Expand Down Expand Up @@ -62,8 +62,8 @@
- name: Stop app
ansible.builtin.command: docker exec {{ container_name }} /bin/bash -c 'rabbitmqctl stop_app'

- name: Force reset app
ansible.builtin.command: docker exec {{ container_name }} /bin/bash -c 'rabbitmqctl force_reset'
- name: Reset app
ansible.builtin.command: docker exec {{ container_name }} /bin/bash -c 'rabbitmqctl reset'

- name: Start app
ansible.builtin.command: docker exec {{ container_name }} /bin/bash -c 'rabbitmqctl start_app'
Expand All @@ -86,7 +86,7 @@
ansible.builtin.shell:
cmd: >-
set -o pipefail &&
systemctl list-units --type=service --all --no-legend --plain |
systemctl list-units --state=loaded --type=service --all --no-legend --plain |
grep -E 'kolla-(barbican|blazar|cinder|cloudkitty|designate|heat|ironic|keystone|magnum|manila|neutron|nova|octavia)' |
awk '{ print $1 }' |
xargs -r systemctl restart
Expand Down
Loading