Skip to content

Problem when trying to attach local binary resource #654

@marceloneppel

Description

@marceloneppel

Hi Juju team!
I’m using this lib through pytest-operator in my charm integration tests where I add one .tar.gz as a resource in the deployment.

What happens is that I couldn’t find a way to attach the resource using the attach_resource method. I’m getting an error when I try to pass the resource as a binary content to that method:

resources = {"patroni": "patroni.tar.gz"}
app = await ops_test.model.deploy(
    charm, resources=resources, application_name=application_name, series=series
)
with open("patroni.tar.gz", 'rb') as f:
    app.attach_resource('patroni', "patroni.tar.gz", f)
Traceback (most recent call last):
  File "/home/neppel/Canonical/postgresql-operator/tests/integration/test_charm.py", line 60, in test_deploy
    app.attach_resource('patroni', "patroni.tar.gz", f)
  File "/home/neppel/Canonical/postgresql-operator/.tox/integration/lib/python3.8/site-packages/juju/application.py", line 454, in attach_resource
    headers['Content-Sha384'] = hashlib.sha384(bytes(data, 'utf-8')).hexdigest()
TypeError: encoding without a string argument

I could attach the resource only when using the juju function:

await ops_test.juju("attach-resource", "postgresql-focal", "patroni=patroni.tar.gz")

Am I doing something wrong when using attach_resource from the lib?

Some more details:

  • It's a machine charm.
  • I'm testing locally with a local charm (not present in charmhub).
  • The test works if I use a plain text file instead of a binary file (it looks like that the lib code is trying to convert the content to bytes to generate a sha checksum, which breaks because the content is already as bytes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions