juju / python-libjuju

Python library for the Juju API
Apache License 2.0
57 stars 93 forks source link

"controller.get_cloud() IndexError: list index out of range" for users without access to controller model #1064

Open yanksyoon opened 1 week ago

yanksyoon commented 1 week ago

Description

When using lib juju with a user that does not have access to the controller model, many of the controller functions would raise an error in controller.py line 561:

  File ".../juju/controller.py", line 561, in get_cloud
    cloud = list(result.clouds.keys())[0]  # only lives on one cloud
IndexError: list index out of range

Urgency

Annoying bug in our test suite

Python-libjuju version

3.5.0.0

Juju version

3.5.0

Reproduce / Test

Assuming bootstrapped juju controller with localhost (LXD) as admin:

  1. juju add-user testuser
  2. juju add-model testmodel
  3. juju grant testuer testmodel
  4. juju change-user-password (required to logout of admin account)
  5. juju logout
  6. juju login -u testuser -c localhost

In a Python REPL env: python3 -m asyncio

from juju.controller import Controller
c = Controller()
await c.connect("localhost", password="<your password for testing user>")
await c.get_cloud()
# LIST INDEX ERROR HERE

Because this user does not have access to the controller, the response coming from CloudFacade is empty.

'juju.client._definitions.CloudsResult'>({'clouds': {}, 'unknown_fields': {}})

This is currently blocking testing done via private endpoints on PS6.