Skip to content

Commit 3786137

Browse files
committed
Remove dependency to juju cli for controller_name
controllers.yaml is read for the controller_name after a connection is established, and this creates a depends on the juju-cli to be installed in the system, which is not required for pylibjuju.
1 parent beed55f commit 3786137

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

juju/client/connector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from juju.client.gocookies import GoCookieJar, go_to_py_cookie
1010
from juju.client.jujudata import FileJujuData, API_ENDPOINTS_KEY
1111
from juju.client.proxy.factory import proxy_from_config
12-
from juju.errors import JujuConnectionError, JujuError, PylibjujuProgrammingError
12+
from juju.errors import JujuConnectionError, JujuError, PylibjujuProgrammingError, ControllerNameNotFound
1313
from juju.client import client
1414

1515
log = logging.getLogger('connector')
@@ -97,7 +97,11 @@ async def connect(self, **kwargs):
9797
if not self.controller_name:
9898
if 'endpoint' not in kwargs:
9999
raise PylibjujuProgrammingError("Please report this error to the maintainers.")
100-
self.controller_name = self.jujudata.controller_name_by_endpoint(kwargs['endpoint'])
100+
try:
101+
self.controller_name = self.jujudata.controller_name_by_endpoint(kwargs['endpoint'])
102+
except ControllerNameNotFound:
103+
# It's ok because we might not have the juju cli (controllers.yaml)
104+
pass
101105

102106
# Check if we support the target controller
103107
if not self._connection.info['server-version'].startswith(SUPPORTED_JUJU_API_PREFIX):

juju/client/jujudata.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import yaml
1111
from juju import tag
1212
from juju.client.gocookies import GoCookieJar
13-
from juju.errors import JujuError, PylibjujuProgrammingError
13+
from juju.errors import JujuError, PylibjujuProgrammingError, ControllerNameNotFound
1414
from juju.utils import juju_config_dir
1515

1616
API_ENDPOINTS_KEY = 'api-endpoints'
@@ -133,7 +133,11 @@ def controller_name_by_endpoint(self, endpoint):
133133
134134
:param str endpoint: The endpoint of the controller we're looking for
135135
"""
136-
for controller_name, controller in self.controllers().items():
136+
try:
137+
contrs = self.controllers()
138+
except FileNotFoundError:
139+
raise ControllerNameNotFound()
140+
for controller_name, controller in contrs.items():
137141
if isinstance(endpoint, str):
138142
if endpoint in controller[API_ENDPOINTS_KEY]:
139143
return controller_name

juju/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,7 @@ class JujuModelConfigError(JujuConfigError):
118118

119119
class AbstractMethodError(Exception):
120120
pass
121+
122+
123+
class ControllerNameNotFound(Exception):
124+
pass

0 commit comments

Comments
 (0)