Skip to content

Separate auth from cluster methods #69

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

Merged
merged 1 commit into from
Mar 6, 2023
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
5 changes: 4 additions & 1 deletion src/codeflare_sdk/cluster/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def login(self) -> str:
error_msg = osp.result.err()
if "The server uses a certificate signed by unknown authority" in error_msg:
return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
elif "invalid" in error_msg:
raise PermissionError(error_msg)
else:
return error_msg
return response.out()
Expand All @@ -82,7 +84,8 @@ def logout(self) -> str:
"""
This function is used to logout of an OpenShift cluster.
"""
response = oc.invoke("logout")
args = [f"--token={self.token}", f"--server={self.server}:6443"]
response = oc.invoke("logout", args)
return response.out()


Expand Down
4 changes: 0 additions & 4 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ def up(self):
Applies the AppWrapper yaml, pushing the resource request onto
the MCAD queue.
"""
resp = self.config.auth.login()
if "invalid" in resp:
raise PermissionError(resp)
namespace = self.config.namespace
try:
with oc.project(namespace):
Expand Down Expand Up @@ -135,7 +132,6 @@ def down(self):
print("Cluster not found, have you run cluster.up() yet?")
else:
raise osp
self.config.auth.logout()

def status(
self, print_to_console: bool = True
Expand Down
1 change: 0 additions & 1 deletion src/codeflare_sdk/cluster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ class ClusterConfiguration:
instascale: bool = False
envs: dict = field(default_factory=dict)
image: str = "ghcr.io/foundation-model-stack/base:ray2.1.0-py38-gpu-pytorch1.12.0cu116-20221213-193103"
auth: Authentication = Authentication()
7 changes: 4 additions & 3 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def test_token_auth_login_logout(mocker):
"login",
["--token=testtoken", "--server=testserver:6443"],
)
assert token_auth.logout() == ("logout",)
assert token_auth.logout() == (
"logout",
["--token=testtoken", "--server=testserver:6443"],
)


def test_token_auth_login_tls(mocker):
Expand Down Expand Up @@ -198,7 +201,6 @@ def test_config_creation():
gpu=7,
instascale=True,
machine_types=["cpu.small", "gpu.large"],
auth=TokenAuthentication(token="testtoken", server="testserver"),
)

assert config.name == "unit-test-cluster" and config.namespace == "ns"
Expand All @@ -213,7 +215,6 @@ def test_config_creation():
assert config.template == f"{parent}/src/codeflare_sdk/templates/new-template.yaml"
assert config.instascale
assert config.machine_types == ["cpu.small", "gpu.large"]
assert config.auth.__class__ == TokenAuthentication
return config


Expand Down