Skip to content

Commit

Permalink
FIX-#2225: update parameters of ray APIs for cloud features (#2226)
Browse files Browse the repository at this point in the history
Also introduce tests for ray API used in Modin

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev authored Oct 14, 2020
1 parent 499fc96 commit dd691cd
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 15 deletions.
8 changes: 2 additions & 6 deletions modin/experimental/cloud/rayscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ def __do_spawn(self):
yes=True,
override_cluster_name=None,
no_config_cache=False,
log_old_style=False,
log_color="auto",
verbose=1,
redirect_command_output=False,
use_login_shells=True,
)
# need to re-load the config, as create_or_update_cluster() modifies it
with open(self.config_file) as inp:
Expand All @@ -223,9 +222,6 @@ def __do_destroy(self):
workers_only=False,
override_cluster_name=None,
keep_min_workers=0,
log_old_style=False,
log_color="auto",
verbose=1,
)
self.ready = False
self.config = None
Expand Down
93 changes: 84 additions & 9 deletions modin/experimental/cloud/test/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,90 @@
import unittest.mock as mock
import pytest
from collections import namedtuple
from inspect import signature
from modin.experimental.cloud.rayscale import RayCluster
from modin.experimental.cloud.cluster import Provider
from ray.autoscaler.commands import (
create_or_update_cluster,
teardown_cluster,
get_head_node_ip,
_bootstrap_config,
)


@pytest.fixture
def make_bootstrap_config_mock():
def bootstrap_config_mock(config, *args, **kwargs):
signature(_bootstrap_config).bind(config, *args, **kwargs)
config["auth"]["ssh_user"] = "modin"
config["auth"]["ssh_private_key"] = "X" * 20
return config

return bootstrap_config_mock


@pytest.fixture
def make_get_head_node_ip_mock():
def get_head_node_ip_mock(*args, **kwargs):
signature(get_head_node_ip).bind(*args, **kwargs)
return "127.0.0.1"

return get_head_node_ip_mock


@pytest.fixture
def make_teardown_cluster_mock():
return lambda *args, **kw: signature(teardown_cluster).bind(*args, **kw)


@pytest.fixture
def make_create_or_update_cluster_mock():
return lambda *args, **kw: signature(create_or_update_cluster).bind(*args, **kw)


@pytest.fixture
def make_ray_cluster(make_bootstrap_config_mock):
def ray_cluster():
with mock.patch(
"modin.experimental.cloud.rayscale._bootstrap_config",
make_bootstrap_config_mock,
):
ray_cluster = RayCluster(
Provider(name="aws"), add_conda_packages=["scikit-learn>=0.23"]
)
return ray_cluster

return ray_cluster


def test__bootstrap_config(make_ray_cluster):
make_ray_cluster()


def test_get_head_node_ip(make_ray_cluster, make_get_head_node_ip_mock):
ray_cluster = make_ray_cluster()

with mock.patch(
"modin.experimental.cloud.rayscale.get_head_node_ip", make_get_head_node_ip_mock
):
ray_cluster.ready = True
details = ray_cluster._get_connection_details()
assert details.address == "127.0.0.1"


def test_teardown_cluster(make_ray_cluster, make_teardown_cluster_mock):
with mock.patch(
"modin.experimental.cloud.rayscale.teardown_cluster", make_teardown_cluster_mock
):
make_ray_cluster()._destroy(wait=True)


def test_create_or_update_cluster(make_ray_cluster, make_create_or_update_cluster_mock):
with mock.patch(
"modin.experimental.cloud.rayscale.create_or_update_cluster",
make_create_or_update_cluster_mock,
):
make_ray_cluster()._spawn(wait=True)


@pytest.mark.parametrize(
Expand All @@ -29,17 +111,10 @@
"""
],
)
def test_update_conda_requirements(setup_commands_source):
with mock.patch(
"modin.experimental.cloud.rayscale._bootstrap_config", lambda config: config
):
ray_cluster = RayCluster(
Provider(name="aws"), add_conda_packages=["scikit-learn>=0.23"]
)

def test_update_conda_requirements(setup_commands_source, make_ray_cluster):
fake_version = namedtuple("FakeVersion", "major minor micro")(7, 12, 45)
with mock.patch("sys.version_info", fake_version):
setup_commands_result = ray_cluster._update_conda_requirements(
setup_commands_result = make_ray_cluster()._update_conda_requirements(
setup_commands_source
)

Expand Down

0 comments on commit dd691cd

Please sign in to comment.