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 @@ -163,7 +163,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 @@ -482,7 +482,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
6 changes: 3 additions & 3 deletions src/codeflare_sdk/ray/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,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 @@ -865,7 +865,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 @@ -1037,7 +1037,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
ingress.metadata.name == f"ray-dashboard-{rc['metadata']['name']}"
or ingress.metadata.name.startswith(f"{rc['metadata']['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 @@ -534,7 +534,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 @@ -606,7 +606,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
12 changes: 6 additions & 6 deletions src/codeflare_sdk/ray/cluster/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ 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._ray_cluster_status", return_value=fake_ray
)

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

fake_ray.status = RayClusterStatus.FAILED
status, ready = cf.status()
assert status == CodeFlareClusterStatus.FAILED
assert ready == False
assert ready is False

fake_ray.status = RayClusterStatus.UNHEALTHY
status, ready = cf.status()
assert status == CodeFlareClusterStatus.FAILED
assert ready == False
assert ready is False

fake_ray.status = RayClusterStatus.READY
status, ready = cf.status()
assert status == CodeFlareClusterStatus.READY
assert ready == True
assert ready is True


def rc_status_fields(group, version, namespace, plural, *args):
Expand All @@ -109,7 +109,7 @@ def test_rc_status(mocker):
side_effect=rc_status_fields,
)
rc = _ray_cluster_status("test-rc", "test-ns")
assert rc == None
assert rc is None


# Make sure to always keep this function last
Expand Down
6 changes: 1 addition & 5 deletions tests/e2e/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ def prepare_data(self):
# download
print("Downloading MNIST dataset...")

if (
STORAGE_BUCKET_EXISTS
and os.environ.get("AWS_DEFAULT_ENDPOINT") != ""
and os.environ.get("AWS_DEFAULT_ENDPOINT") != None
):
if STORAGE_BUCKET_EXISTS and os.environ.get("AWS_DEFAULT_ENDPOINT", "") != "":
print("Using storage bucket to download datasets...")

dataset_dir = os.path.join(self.data_dir, "MNIST/raw")
Expand Down
12 changes: 2 additions & 10 deletions tests/e2e/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,15 @@ def get_setup_env_variables(**kwargs):
env_vars[str(key)] = value

# Use specified pip index url instead of default(https://pypi.org/simple) if related environment variables exists
if (
"PIP_INDEX_URL" in os.environ
and os.environ.get("PIP_INDEX_URL") != None
and os.environ.get("PIP_INDEX_URL") != ""
):
if os.environ.get("PIP_INDEX_URL", "") != "":
env_vars["PIP_INDEX_URL"] = os.environ.get("PIP_INDEX_URL")
env_vars["PIP_TRUSTED_HOST"] = os.environ.get("PIP_TRUSTED_HOST")
else:
env_vars["PIP_INDEX_URL"] = "https://pypi.org/simple/"
env_vars["PIP_TRUSTED_HOST"] = "pypi.org"

# Use specified storage bucket reference from which to download datasets
if (
"AWS_DEFAULT_ENDPOINT" in os.environ
and os.environ.get("AWS_DEFAULT_ENDPOINT") != None
and os.environ.get("AWS_DEFAULT_ENDPOINT") != ""
):
if os.environ.get("AWS_DEFAULT_ENDPOINT", "") != "":
env_vars["AWS_DEFAULT_ENDPOINT"] = os.environ.get("AWS_DEFAULT_ENDPOINT")
env_vars["AWS_ACCESS_KEY_ID"] = os.environ.get("AWS_ACCESS_KEY_ID")
env_vars["AWS_SECRET_ACCESS_KEY"] = os.environ.get("AWS_SECRET_ACCESS_KEY")
Expand Down