Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default namespace for System Client #506

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Brewtils Changelog
==================

3.27.3
------
TBD

- Updated SystemClient to utilize the local Garden name for default Namespace if none can be determined

3.27.2
------
9/12/24
Expand Down
8 changes: 6 additions & 2 deletions brewtils/rest/system_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ def __init__(self, *args, **kwargs):
self._system_name = brewtils.plugin.CONFIG.name
self._version_constraint = brewtils.plugin.CONFIG.version
self._default_instance = brewtils.plugin.CONFIG.instance_name
self._system_namespace = brewtils.plugin.CONFIG.namespace or ""
self._system_namespace = brewtils.plugin.CONFIG.namespace or None

else:
self._system_name = kwargs.get("system_name")
self._version_constraint = kwargs.get("version_constraint", "latest")
self._default_instance = kwargs.get("default_instance", "default")
self._system_namespace = kwargs.get(
"system_namespace", brewtils.plugin.CONFIG.namespace or ""
"system_namespace", brewtils.plugin.CONFIG.namespace or None
)
self._system_namespaces = kwargs.get("system_namespaces", [])

Expand Down Expand Up @@ -278,6 +278,10 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault("stacklevel", 5)

self._easy_client = EasyClient(*args, **kwargs)

if self._system_namespace is None:
self._system_namespace = self._easy_client.get_config()["garden_name"]

self._resolver = ResolutionManager(easy_client=self._easy_client)
self.local_request_handler = LocalRequestProcessor(
system=self._system,
Expand Down
7 changes: 4 additions & 3 deletions test/rest/system_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def easy_client(monkeypatch, bg_system):
mock = Mock(name="easy_client")
mock.find_unique_system.return_value = bg_system
mock.find_systems.return_value = [bg_system]
mock.get_config.return_value = {"garden_name": bg_system.namespace}
mock.client.bg_host = "localhost"
mock.client.bg_port = 3000

Expand Down Expand Up @@ -104,7 +105,7 @@ def test_latest(self, client, easy_client, bg_system, bg_system_2):
assert client.bg_system == bg_system_2
assert client.bg_default_instance == "default"
easy_client.find_systems.assert_called_once_with(
name=bg_system.name, namespace="", filter_latest=True
name=bg_system.name, namespace="ns", filter_latest=True
)

@pytest.mark.parametrize(
Expand All @@ -120,7 +121,7 @@ def test_non_latest(self, client, easy_client, bg_system, constraint, systems):
assert client.bg_system == bg_system

easy_client.find_unique_system.assert_called_once_with(
name=bg_system.name, version=constraint, namespace=""
name=bg_system.name, version=constraint, namespace="ns"
)

def test_failure_with_constraint(self, client, easy_client):
Expand Down Expand Up @@ -219,7 +220,7 @@ def test_non_plugin(self):
assert client._system_name is None
assert client._version_constraint == "latest"
assert client._default_instance == "default"
assert client._system_namespace == ""
assert client._system_namespace == "ns"


class TestCreateRequest(object):
Expand Down
Loading