juju/python-libjuju

Keyerror "controller" when connecting

Closed this issue · 1 comments

Description

I want to test the connection to a controller, when I'm faced with a KeyError 'controller'

It works with the admin account (since it can see the controller model).

DEBUG:websockets.client:> TEXT '{\n  "type": "Pinger",\n  "request": "Ping",\n ...,\n  "request-id": 3\n}' [94 bytes]
DEBUG:websockets.client:< TEXT '{"request-id":3,"response":{}}\n' [31 bytes]
DEBUG:juju.client.connection:connection 140522019237424 <- {'request-id': 3, 'response': {}}
DEBUG:websockets.client:< TEXT '{"request-id":2,"response":{"user-models":null}}\n' [49 bytes]
DEBUG:juju.client.connection:connection 140522019237424 <- {'request-id': 2, 'response': {'user-models': None}}
Traceback (most recent call last):
  File "/root/deployments_site/jsync/./connect-controller.py", line 28, in <module>
    jasyncio.run(main())
  File "/usr/local/lib/python3.10/dist-packages/juju/jasyncio.py", line 120, in run
    raise task.exception()
  File "/root/deployments_site/jsync/./connect-controller.py", line 18, in main
    await controller.connect(endpoint="10.10.10.2:17070",
  File "/usr/local/lib/python3.10/dist-packages/juju/controller.py", line 139, in connect
    await self.update_endpoints()
  File "/usr/local/lib/python3.10/dist-packages/juju/controller.py", line 142, in update_endpoints
    info = await self.info()
  File "/usr/local/lib/python3.10/dist-packages/juju/controller.py", line 285, in info
    params = [client.Entity(tag.model(uuids["controller"]))]
KeyError: 'controller'

Urgency

Annoying bug in our test suite

Python-libjuju version

2.9.46.0

Juju version

2.9.46

Reproduce / Test

#!/usr/bin/env python3

import logging
from juju.controller import Controller
from juju import jasyncio
import jujuutils

async def main():
    """
    Gets all models from a Juju controller and returns a list of JujuModel objects
    """
    controller = Controller()
    crt = jujuutils.get_controller_cacert('my-controller')
    print(crt)
    await controller.connect(endpoint="10.10.10.2:17070",
                            username='my-user', 
                            password='my-password', 
                            cacert=jujuutils.get_controller_cacert('my-controller.crt'))
    await controller.disconnect()

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    ws_logger = logging.getLogger('websockets.protocol')
    ws_logger.setLevel(logging.INFO)
    jasyncio.run(main())

Duplicated from #998