mirror of
https://github.com/wassname/ray.git
synced 2026-07-06 05:16:30 +08:00
[autoscaler] Enforce CommandRunnerInterface abstractions (#10822)
Co-authored-by: root <root@ip-172-31-28-155.us-west-2.compute.internal> Co-authored-by: Ameer Haj Ali <ameerhajali@Ameers-MacBook-Pro.local>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import pytest
|
||||
from ray.tests.test_autoscaler import MockProvider, MockProcessRunner
|
||||
from ray.autoscaler.command_runner import SSHCommandRunner, \
|
||||
_with_environment_variables, DockerCommandRunner, KubernetesCommandRunner
|
||||
from ray.autoscaler.command_runner import CommandRunnerInterface, \
|
||||
SSHCommandRunner, _with_environment_variables, DockerCommandRunner, \
|
||||
KubernetesCommandRunner
|
||||
from ray.autoscaler.docker import DOCKER_MOUNT_PREFIX
|
||||
from getpass import getuser
|
||||
import hashlib
|
||||
@@ -27,6 +28,33 @@ def test_environment_variable_encoder_dict():
|
||||
assert res == expected
|
||||
|
||||
|
||||
def test_command_runner_interface_abstraction_violation():
|
||||
"""Enforces the CommandRunnerInterface functions on the subclasses.
|
||||
|
||||
This is important to make sure the subclasses do not violate the
|
||||
function abstractions. If you need to add a new function to one of
|
||||
the CommandRunnerInterface subclasses, you have to add it to
|
||||
CommandRunnerInterface and all of its subclasses.
|
||||
"""
|
||||
|
||||
cmd_runner_interface_public_functions = dir(CommandRunnerInterface)
|
||||
allowed_public_interface_functions = {
|
||||
func
|
||||
for func in cmd_runner_interface_public_functions
|
||||
if not func.startswith("_")
|
||||
}
|
||||
for subcls in [
|
||||
SSHCommandRunner, DockerCommandRunner, KubernetesCommandRunner
|
||||
]:
|
||||
subclass_available_functions = dir(subcls)
|
||||
subclass_public_functions = {
|
||||
func
|
||||
for func in subclass_available_functions
|
||||
if not func.startswith("_")
|
||||
}
|
||||
assert allowed_public_interface_functions == subclass_public_functions
|
||||
|
||||
|
||||
def test_ssh_command_runner():
|
||||
process_runner = MockProcessRunner()
|
||||
provider = MockProvider()
|
||||
|
||||
Reference in New Issue
Block a user