From dd639b377bea06befa34137db3841f8be12a7d84 Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Mon, 20 Sep 2021 13:26:09 -0400 Subject: [PATCH] add juju.get_controllers Fixes #529 --- juju/juju.py | 10 ++++++++-- tests/integration/test_juju.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/integration/test_juju.py diff --git a/juju/juju.py b/juju/juju.py index 444155f1a..4a076a006 100644 --- a/juju/juju.py +++ b/juju/juju.py @@ -1,4 +1,11 @@ +from juju.client.jujudata import FileJujuData + + class Juju(object): + + def __init__(self, jujudata=None): + self.jujudata = jujudata or FileJujuData() + def add_cloud(self, name, definition, replace=False): """Add a user-defined cloud to Juju from among known cloud types. @@ -58,9 +65,8 @@ def get_clouds(self): def get_controllers(self): """Return list of all available controllers. - (maybe move this to Cloud?) """ - raise NotImplementedError() + return self.jujudata.controllers() def get_plans(self, charm_url): """Return list of plans available for the specified charm. diff --git a/tests/integration/test_juju.py b/tests/integration/test_juju.py new file mode 100644 index 000000000..47c4716a8 --- /dev/null +++ b/tests/integration/test_juju.py @@ -0,0 +1,16 @@ +import pytest + +from juju.juju import Juju +from .. import base + + +@base.bootstrapped +@pytest.mark.asyncio +async def test_get_controllers(event_loop): + async with base.CleanController() as controller: + j = Juju() + + controllers = j.get_controllers() + assert isinstance(controllers, dict) + assert len(controllers) >= 1 + assert controller.controller_name in controllers