Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send events to MQ when hosts are renamed. #504

Conversation

terjekv
Copy link
Collaborator

@terjekv terjekv commented May 28, 2023

  • Captures the old name with pre_save.
  • Makes no assumtion on signal consistency in Django...

Fixes #476

@terjekv terjekv self-assigned this May 28, 2023
@coveralls
Copy link
Collaborator

coveralls commented May 28, 2023

Coverage Status

coverage: 99.221% (+0.009%) from 99.212% when pulling 954920d on terjekv:terjekv/Send-events-to-MQ-when-hosts-are-renamed into 3680b7d on unioslo:master.

@terjekv terjekv force-pushed the terjekv/Send-events-to-MQ-when-hosts-are-renamed branch from 0d6c8bf to f9eb441 Compare June 9, 2023 06:50
@terjekv
Copy link
Collaborator Author

terjekv commented Jun 9, 2023

Clean up merge commit via rebase and force push.

@terjekv terjekv force-pushed the terjekv/Send-events-to-MQ-when-hosts-are-renamed branch from f9eb441 to 9471f33 Compare June 12, 2023 14:45
Comment on lines +416 to +411
if old_name is not None and old_name != instance.name:
obj = {
"old_host": old_name,
"new_host": instance.name,
"action": "host_updated",
}
else:
obj = {
"host": instance.name,
"action": "host_updated",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What do you think about using the same field name whether we have the old name or not? E.g. "host", and "old_host" in addition if it is not None. Might be less confusing to parse.
  • How about using the event name "host_renamed" when the host has been renamed? Unless that may also happen without pre_save being called.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. The reason I opted out of using the same field name (ie, host) is that I found it ambiguous. Is host the new hostname, or the old hostname the recipient knows? If you are going to update an entry based on the event, you need to use old_host if and only if old_host is set, as that's the hostname you know, but in every other version of the host_updated event, you would use host as the host you know. It's not a big deal, but I felt it being inconsistent.
  2. We can certainly use a new event name. That would make using host above easier as we can define the API for the host_rename event.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. That makes sense, thanks
  2. Actually, I meant action and not event name. But on second thought let's keep the event name "host" and action "host_updated", that will allow us to extend the functionality in the future if there are other changes to hosts that we want to send events for.

  - Captures the old name with pre_save.
  - Makes no assumtion on signal consistency in Django...

Fixes unioslo#476
@terjekv terjekv force-pushed the terjekv/Send-events-to-MQ-when-hosts-are-renamed branch from 9471f33 to 954920d Compare July 21, 2023 08:33
@oyvindhagberg oyvindhagberg merged commit 954920d into unioslo:master Jul 25, 2023
15 checks passed
@terjekv terjekv deleted the terjekv/Send-events-to-MQ-when-hosts-are-renamed branch July 25, 2023 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send events to MQ when hosts are renamed
3 participants