juju / python-libjuju

Python library for the Juju API
Apache License 2.0
59 stars 99 forks source link

Incorrect parsing of zones constraint #1050

Closed luissimas closed 2 months ago

luissimas commented 4 months ago

Description

When deploying a bundle with the zones constraint in a machine, the deployment fails with the following error from the juju API:

juju.errors.JujuAPIError: json: cannot unmarshal string into Go struct field Value.params.constraints.zones of type []string

The problem seems to be that python-libjuju sends the zones key as a string instead of an array of strings, as juju expects. See: https://github.com/juju/juju/blob/3.6/core/constraints/constraints.go#L107.

Urgency

Annoying bug in our test suite

Python-libjuju version

3.4

Juju version

3.4.2

Reproduce / Test

import asyncio
from juju.model import Model

bundle_file = "./bundle.yaml"

bundle = """
name: sample-bundle

series: jammy

machines:
  "0":
    constraints: zones=z-1

applications:
  postgresql:
    charm: postgresql
    channel: 14/stable
    num_units: 1
    to:
      - lxd:0
"""

async def main():
    with open(bundle_file, "w") as f:
        f.write(bundle)

    model = Model()
    await model.connect()
    await model.deploy(bundle_file)

asyncio.run(main())