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

Use session-scoped inventory by default #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

synkd
Copy link
Collaborator

@synkd synkd commented Nov 22, 2024

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.

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.
@synkd synkd added enhancement New feature or request DRAFT Work in progress labels Nov 22, 2024
@synkd synkd self-assigned this Nov 22, 2024
Copy link

@Copilot Copilot AI left a 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"]])
Copy link
Preview

Copilot AI Nov 22, 2024

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.

Suggested change
_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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Comment on lines +174 to +185
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)
Copy link
Member

Choose a reason for hiding this comment

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

could this be simplified?

Suggested change
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)

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DRAFT Work in progress enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants