Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/codeflare_sdk/common/kubernetes_cluster/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def load_kube_config(self):
global config_path
global api_client
try:
if self.kube_config_path == None:
if self.kube_config_path is None:
return "Please specify a config file path"
config_path = self.kube_config_path
api_client = None
Expand Down Expand Up @@ -183,7 +183,7 @@ def config_check() -> str:
global config_path
global api_client
home_directory = os.path.expanduser("~")
if config_path == None and api_client == None:
if config_path is None and api_client is None:
if os.path.isfile("%s/.kube/config" % home_directory):
try:
config.load_kube_config()
Expand All @@ -199,7 +199,7 @@ def config_check() -> str:
"Action not permitted, have you put in correct/up-to-date auth credentials?"
)

if config_path != None and api_client == None:
if config_path is not None and api_client is None:
return config_path


Expand Down Expand Up @@ -237,7 +237,7 @@ def get_api_client() -> client.ApiClient:
client.ApiClient:
The Kubernetes API client object.
"""
if api_client != None:
if api_client is not None:
return api_client
to_return = client.ApiClient()
_client_with_cert(to_return)
Expand Down
16 changes: 8 additions & 8 deletions src/codeflare_sdk/common/kubernetes_cluster/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ def test_token_auth_creation():
token_auth = TokenAuthentication(token="token", server="server")
assert token_auth.token == "token"
assert token_auth.server == "server"
assert token_auth.skip_tls == False
assert token_auth.ca_cert_path == None
assert token_auth.skip_tls is False
assert token_auth.ca_cert_path is None

token_auth = TokenAuthentication(token="token", server="server", skip_tls=True)
assert token_auth.token == "token"
assert token_auth.server == "server"
assert token_auth.skip_tls == True
assert token_auth.ca_cert_path == None
assert token_auth.skip_tls is True
assert token_auth.ca_cert_path is None

os.environ["CF_SDK_CA_CERT_PATH"] = "/etc/pki/tls/custom-certs/ca-bundle.crt"
token_auth = TokenAuthentication(token="token", server="server", skip_tls=False)
assert token_auth.token == "token"
assert token_auth.server == "server"
assert token_auth.skip_tls == False
assert token_auth.skip_tls is False
assert token_auth.ca_cert_path == "/etc/pki/tls/custom-certs/ca-bundle.crt"
os.environ.pop("CF_SDK_CA_CERT_PATH")

Expand All @@ -55,7 +55,7 @@ def test_token_auth_creation():
)
assert token_auth.token == "token"
assert token_auth.server == "server"
assert token_auth.skip_tls == False
assert token_auth.skip_tls is False
assert token_auth.ca_cert_path == f"{parent}/tests/auth-test.crt"


Expand Down Expand Up @@ -116,7 +116,7 @@ def test_config_check_with_incluster_config(mocker):
mocker.patch("codeflare_sdk.common.kubernetes_cluster.auth.api_client", None)

result = config_check()
assert result == None
assert result is None


def test_config_check_with_existing_config_file(mocker):
Expand All @@ -127,7 +127,7 @@ def test_config_check_with_existing_config_file(mocker):
mocker.patch("codeflare_sdk.common.kubernetes_cluster.auth.api_client", None)

result = config_check()
assert result == None
assert result is None


def test_config_check_with_config_path_and_no_api_client(mocker):
Expand Down
2 changes: 1 addition & 1 deletion src/codeflare_sdk/common/kueue/kueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def add_queue_label(item: dict, namespace: str, local_queue: Optional[str]):
If the provided or default local queue does not exist in the namespace.
"""
lq_name = local_queue or get_default_kueue_name(namespace)
if lq_name == None:
if lq_name is None:
return
elif not local_queue_exists(namespace, lq_name):
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion src/codeflare_sdk/common/kueue/test_kueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_none_local_queue(mocker):
config.local_queue = None

cluster = Cluster(config)
assert cluster.config.local_queue == None
assert cluster.config.local_queue is None


def test_cluster_creation_no_aw_local_queue(mocker):
Expand Down
8 changes: 4 additions & 4 deletions src/codeflare_sdk/common/utils/test_generate_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def test_generate_ca_cert():
cert_pub_key_bytes = cert.public_key().public_bytes(
Encoding.PEM, PublicFormat.SubjectPublicKeyInfo
)
assert type(key) == str
assert type(certificate) == str
assert isinstance(key, str)
assert isinstance(certificate, str)
# Veirfy ca.cert is self signed
assert cert.verify_directly_issued_by(cert) == None
assert cert.verify_directly_issued_by(cert) is None
# Verify cert has the public key bytes from the private key
assert cert_pub_key_bytes == private_pub_key_bytes

Expand Down Expand Up @@ -84,7 +84,7 @@ def test_generate_tls_cert(mocker):
tls_cert = load_pem_x509_certificate(f.read().encode("utf-8"))
with open(os.path.join("tls-cluster-namespace", "ca.crt"), "r") as f:
root_cert = load_pem_x509_certificate(f.read().encode("utf-8"))
assert tls_cert.verify_directly_issued_by(root_cert) == None
assert tls_cert.verify_directly_issued_by(root_cert) is None


def test_export_env():
Expand Down
12 changes: 6 additions & 6 deletions src/codeflare_sdk/ray/appwrapper/test_awload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def test_AWManager_creation(mocker):
testaw = AWManager(f"{aw_dir}test.yaml")
assert testaw.name == "test"
assert testaw.namespace == "ns"
assert testaw.submitted == False
assert testaw.submitted is False
try:
testaw = AWManager("fake")
except Exception as e:
assert type(e) == FileNotFoundError
assert isinstance(e, FileNotFoundError)
assert str(e) == "[Errno 2] No such file or directory: 'fake'"
try:
testaw = apply_template(
Expand All @@ -56,7 +56,7 @@ def test_AWManager_creation(mocker):
get_template_variables(),
)
except Exception as e:
assert type(e) == ValueError
assert isinstance(e, ValueError)
assert (
str(e)
== f"{parent}/tests/test_cluster_yamls/appwrapper/test-case-bad.yaml is not a correctly formatted AppWrapper yaml"
Expand All @@ -72,7 +72,7 @@ def test_AWManager_submit_remove(mocker, capsys):
captured.out
== "AppWrapper not submitted by this manager yet, nothing to remove\n"
)
assert testaw.submitted == False
assert testaw.submitted is False
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
mocker.patch(
"kubernetes.client.CustomObjectsApi.create_namespaced_custom_object",
Expand All @@ -83,9 +83,9 @@ def test_AWManager_submit_remove(mocker, capsys):
side_effect=arg_check_aw_del_effect,
)
testaw.submit()
assert testaw.submitted == True
assert testaw.submitted is True
testaw.remove()
assert testaw.submitted == False
assert testaw.submitted is False


# Make sure to always keep this function last
Expand Down
14 changes: 7 additions & 7 deletions src/codeflare_sdk/ray/appwrapper/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,34 @@ def test_cluster_status(mocker):
)
status, ready = cf.status()
assert status == CodeFlareClusterStatus.UNKNOWN
assert ready == False
assert ready is False

mocker.patch(
"codeflare_sdk.ray.cluster.cluster._app_wrapper_status", return_value=fake_aw
)
status, ready = cf.status()
assert status == CodeFlareClusterStatus.FAILED
assert ready == False
assert ready is False

fake_aw.status = AppWrapperStatus.SUSPENDED
status, ready = cf.status()
assert status == CodeFlareClusterStatus.QUEUED
assert ready == False
assert ready is False

fake_aw.status = AppWrapperStatus.RESUMING
status, ready = cf.status()
assert status == CodeFlareClusterStatus.STARTING
assert ready == False
assert ready is False

fake_aw.status = AppWrapperStatus.RESETTING
status, ready = cf.status()
assert status == CodeFlareClusterStatus.STARTING
assert ready == False
assert ready is False

fake_aw.status = AppWrapperStatus.RUNNING
status, ready = cf.status()
assert status == CodeFlareClusterStatus.UNKNOWN
assert ready == False
assert ready is False


def aw_status_fields(group, version, namespace, plural, *args):
Expand All @@ -97,7 +97,7 @@ def test_aw_status(mocker):
side_effect=aw_status_fields,
)
aw = _app_wrapper_status("test-aw", "test-ns")
assert aw == None
assert aw is None


# Make sure to always keep this function last
Expand Down
2 changes: 1 addition & 1 deletion src/codeflare_sdk/ray/cluster/build_ray_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def add_queue_label(cluster: "codeflare_sdk.ray.cluster.Cluster", labels: dict):
The add_queue_label() function updates the given base labels with the local queue label if Kueue exists on the Cluster
"""
lq_name = cluster.config.local_queue or get_default_local_queue(cluster, labels)
if lq_name == None:
if lq_name is None:
return
elif not local_queue_exists(cluster):
# ValueError removed to pass validation to validating admission policy
Expand Down
58 changes: 20 additions & 38 deletions src/codeflare_sdk/ray/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,33 @@
cluster setup queue, a list of all existing clusters, and the user's working namespace.
"""

from time import sleep
from typing import List, Optional, Tuple, Dict
import copy

from ray.job_submission import JobSubmissionClient, JobStatus
import os
import time
import uuid
import warnings
from time import sleep
from typing import Dict, List, Optional, Tuple

from ...common.utils import get_current_namespace
import requests
import yaml
from kubernetes import client
from kubernetes import client as k8s_client
from kubernetes import config
from kubernetes.client.rest import ApiException
from kubernetes.dynamic import DynamicClient
from ray.job_submission import JobStatus, JobSubmissionClient

from ...common.kubernetes_cluster.auth import (
config_check,
get_api_client,
)
from ...common import _kube_api_error_handling
from ...common.kubernetes_cluster.auth import config_check, get_api_client
from ...common.utils import get_current_namespace
from ...common.widgets.widgets import cluster_apply_down_buttons, is_notebook
from ..appwrapper import AppWrapper, AppWrapperStatus
from . import pretty_print
from .build_ray_cluster import build_ray_cluster, head_worker_gpu_count_from_cluster
from .build_ray_cluster import write_to_file as write_cluster_to_file
from ...common import _kube_api_error_handling

from .config import ClusterConfiguration
from .status import (
CodeFlareClusterStatus,
RayCluster,
RayClusterStatus,
)
from ..appwrapper import (
AppWrapper,
AppWrapperStatus,
)
from ...common.widgets.widgets import (
cluster_apply_down_buttons,
is_notebook,
)
from kubernetes import client
import yaml
import os
import requests

from kubernetes import config
from kubernetes.dynamic import DynamicClient
from kubernetes import client as k8s_client
from kubernetes.client.rest import ApiException

from kubernetes.client.rest import ApiException
from .status import CodeFlareClusterStatus, RayCluster, RayClusterStatus

CF_SDK_FIELD_MANAGER = "codeflare-sdk"

Expand Down Expand Up @@ -546,7 +528,7 @@ def cluster_dashboard_uri(self) -> str:
ingress.metadata.name == f"ray-dashboard-{self.config.name}"
or ingress.metadata.name.startswith(f"{self.config.name}-ingress")
):
if annotations == None:
if annotations is None:
protocol = "http"
elif "route.openshift.io/termination" in annotations:
protocol = "https"
Expand Down Expand Up @@ -874,7 +856,7 @@ def _check_aw_exists(name: str, namespace: str) -> bool:
def _get_ingress_domain(self): # pragma: no cover
config_check()

if self.config.namespace != None:
if self.config.namespace is not None:
namespace = self.config.namespace
else:
namespace = get_current_namespace()
Expand Down Expand Up @@ -1052,7 +1034,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
ingress.metadata.name == f"ray-dashboard-{rc_name}"
or ingress.metadata.name.startswith(f"{rc_name}-ingress")
):
if annotations == None:
if annotations is None:
protocol = "http"
elif "route.openshift.io/termination" in annotations:
protocol = "https"
Expand Down
4 changes: 2 additions & 2 deletions src/codeflare_sdk/ray/cluster/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def test_wait_ready(mocker, capsys):
cf.wait_ready(timeout=5)
assert 1 == 0
except Exception as e:
assert type(e) == TimeoutError
assert isinstance(e, TimeoutError)

captured = capsys.readouterr()
assert (
Expand Down Expand Up @@ -613,7 +613,7 @@ def test_list_queue_rayclusters(mocker, capsys):
]
mocker.patch("kubernetes.client.ApisApi", return_value=mock_api)

assert _is_openshift_cluster() == True
assert _is_openshift_cluster() is True
mocker.patch(
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
return_value=get_obj_none("ray.io", "v1", "ns", "rayclusters"),
Expand Down
8 changes: 4 additions & 4 deletions src/codeflare_sdk/ray/cluster/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ def test_config_creation_all_parameters(mocker):
assert cluster.config.num_workers == 10
assert cluster.config.worker_memory_requests == "12G"
assert cluster.config.worker_memory_limits == "16G"
assert cluster.config.appwrapper == False
assert cluster.config.appwrapper is False
assert cluster.config.envs == {
"key1": "value1",
"key2": "value2",
"RAY_USAGE_STATS_ENABLED": "0",
}
assert cluster.config.image == "example/ray:tag"
assert cluster.config.image_pull_secrets == ["secret1", "secret2"]
assert cluster.config.write_to_file == True
assert cluster.config.verify_tls == True
assert cluster.config.write_to_file is True
assert cluster.config.verify_tls is True
assert cluster.config.labels == {"key1": "value1", "key2": "value2"}
assert cluster.config.worker_extended_resource_requests == {"nvidia.com/gpu": 1}
assert (
cluster.config.extended_resource_mapping == expected_extended_resource_mapping
)
assert cluster.config.overwrite_default_resource_mapping == True
assert cluster.config.overwrite_default_resource_mapping is True
assert cluster.config.local_queue == "local-queue-default"
assert cluster.config.annotations == {
"app.kubernetes.io/managed-by": "test-prefix",
Expand Down
Loading
Loading