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

Update bundle related methods #99

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

NucciTheBoss
Copy link

Description

This pull request aims to fix the issues that I identified in issue #98. Here is the summary of modifications that I made below:

  • Modify build_bundle method to use charmcraft pack rather than juju-bundle. It now returns a Path object that points to where the built bundle zip archive is stored.
  • Added the build_bundles method to build bundles asynchronously .
  • Modified deploy_bundle to use juju deploy ... rather than juju-bundle.
  • Updated the regex in render_bundle to also accept the .tmpl file extension. I also enhanced the robustness of the expression. The original regex would match inputs such as xyamlij2, Byaml, etc since "." means any character. I modified it so that the regex would only accept the "." character.

Related issues

Miscellaneous

I updated the .gitignore file to ignore the .idea directory. I made this modification since I use PyCharm. I also added a hashbang and copyright information to the top of plugin.py.

Notes:
* What was wrong?
1. In `deploy_bundle`, I needed to convert the Path object for the bundle file to a string. If you do not convert to string first, Python will throw errors about trying to pass a Path object instead of a string to subprocess.
2. In `render_bundle`, I needed to update the regex to allow files with just the extension .j2 and .tmpl instead of being prefixed with .yaml. If I did not do that, the function would try to perform string operations on the Path object which would throw type errors.
.gitignore Show resolved Hide resolved
Copy link
Member

@addyess addyess left a comment

Choose a reason for hiding this comment

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

Effectively there's some missing documentation and an update to setup.py to major rev this package with these non-backwards compatible changes. Seems like there's some more work necessary to get the tests passing with these changes

if serial:
cmd += ["--serial"]
await self.run(*cmd, check=True)
bundle: Union[str, os.PathLike],
Copy link
Member

Choose a reason for hiding this comment

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

this changes the signature of this method. We'll need to major rev the package and update the docs accordingly

Copy link

Choose a reason for hiding this comment

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

I'm not actually convinced that the signature actually needs to change. The method signature and docstrings of an API essentially define the contract for method itself. The existing contract is fairly vague in the specification, but clear in the parameters. This change can largely (if not wholly) still honor the contract of the method without making a breaking API change. An additional advantage/improvement would be to further refine and clarify the method contract in the docstrings.

As there are existing users of this library, if the API is changed then it will break a downstream consumer of the library. Since the method contract can be upheld with the existing signature, it seems better to me to not change the signature and subsequently not break downstream consumers.

Just my $0.02

Comment on lines -1110 to -1116
async def deploy_bundle(
self,
bundle: Optional[str] = None,
build: bool = True,
serial: bool = False,
extra_args: Iterable[str] = (),
):
Copy link
Member

Choose a reason for hiding this comment

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

this method now has a new signature and will also need the documentation updated

Comment on lines +29 to +30
Any,
Dict,
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this is here to create a type like Dict[str,Any] in quite a few places to indicate a a dict for templating context

Maybe its worth defining a local type like

Context = Dict[str, Any]

to use when we intend to render some context

technically jinja2 is very loose on it's typing.

effectively...

def render(*args: Any, **kwargs: Any):
    ...

@NucciTheBoss
Copy link
Author

Hi there @addyess - thank you for the initial round of reviews. I will work through them as I have the time 😄 Either way, we should get folks off of using juju-bundle to deploy bundles via pytest_operator. I will most likely get to it later this week or next depending on how the pulse lines up.

@addyess
Copy link
Member

addyess commented Feb 8, 2023

Hi there @addyess - thank you for the initial round of reviews. I will work through them as I have the time smile Either way, we should get folks off of using juju-bundle to deploy bundles via pytest_operator. I will most likely get to it later this week or next depending on how the pulse lines up.

Cool, i can agree with getting off juju-bundle. I dunno who it would break. Just wanna make sure it doesn't break me :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

juju-bundle causes breakage when calling deploy_bundle
4 participants