-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use session-scoped inventory by default #55
base: master
Are you sure you want to change the base?
Conversation
Currently, Manifester syncs its inventory multiple times while generating a manifest to ensure that the inventory data matches with the corresponding data in RHSM. For some use cases, though, this behavior is not desirable. Notably, in a CI scenario in which multiple workers share the same `username_prefix` setting, syncing the inventory with RHSM prevents those workers from running `manifester delete --all` at the end of each pipeline, as this could delete allocations that are still being used by other workers. This PR addresses this issue by converting the default inventory behavior to not sync from RHSM unless a sync is explicitly invoked.
Copilot
AI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 suggestion.
_dump_inventory_file(inventory_path, inventory_data) | ||
elif remove: | ||
inv = load_inventory_file(inventory_path) | ||
_dump_inventory_file(inventory_path, [alloc for alloc in inv if uuid not in alloc["uuid"]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition 'uuid not in alloc["uuid"]' should be 'uuid != alloc["uuid"]' to correctly filter out the allocation with the matching UUID.
_dump_inventory_file(inventory_path, [alloc for alloc in inv if uuid not in alloc["uuid"]]) | |
_dump_inventory_file(inventory_path, [alloc for alloc in inv if uuid != alloc["uuid"]]) |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
def _dump_inventory_file(inventory_path, inventory): | ||
"""Write inventory data to local inventory file.""" | ||
with inventory_path.open("w") as inventory_file: | ||
yaml.dump(inventory, inventory_file, allow_unicode=True) | ||
|
||
|
||
def _update_inventory(inventory_path, inventory, allocation): | ||
"""Add new allocation, remove and recreate inventory file.""" | ||
inventory.append(allocation) | ||
inventory_path.unlink() | ||
inventory_path.touch() | ||
_dump_inventory_file(inventory_path, inventory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be simplified?
def _dump_inventory_file(inventory_path, inventory): | |
"""Write inventory data to local inventory file.""" | |
with inventory_path.open("w") as inventory_file: | |
yaml.dump(inventory, inventory_file, allow_unicode=True) | |
def _update_inventory(inventory_path, inventory, allocation): | |
"""Add new allocation, remove and recreate inventory file.""" | |
inventory.append(allocation) | |
inventory_path.unlink() | |
inventory_path.touch() | |
_dump_inventory_file(inventory_path, inventory) | |
def _update_inventory(inventory_path, inventory, allocation): | |
"""Add new allocation, remove and recreate inventory file.""" | |
inventory.append(allocation) | |
inventory_path.unlink() | |
inventory_path.touch() | |
yaml.dump(inventory, inventory_path, allow_unicode=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacobCallahan Per the PyYAML docs, yaml.dump
needs an open file in order to write to it directly. Your proposed changed throws an AttributeError: 'PosixPath' object has no attribute 'write'. Did you mean: 'drive'?
when it tries to dump to the Path
object. So we need a second line before yaml.dump
to open the inventory file. I think it's slightly cleaner to move that action into a separate helper function since it gets used in three places, but that part isn't strictly necessary.
Currently, Manifester syncs its inventory multiple times while generating a manifest to ensure that the inventory data matches with the corresponding data in RHSM. For some use cases, though, this behavior is not desirable. Notably, in a CI scenario in which multiple workers share the same
username_prefix
setting, syncing the inventory with RHSM prevents those workers from runningmanifester delete --all
at the end of each pipeline, as this could delete allocations that are still being used by other workers.This PR addresses this issue by converting the default inventory behavior to not sync from RHSM unless a sync is explicitly invoked.