mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 09:29:05 +08:00
a24d117c68
* wip refactor * add util * wip * fix * fix * remove * remove extraneous string type for sg
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import jsonschema
|
|
import os
|
|
import unittest
|
|
import yaml
|
|
import urllib
|
|
import tempfile
|
|
|
|
from ray.autoscaler.util import fillout_defaults, validate_config
|
|
from ray.test_utils import recursive_fnmatch
|
|
|
|
RAY_PATH = os.path.abspath(os.path.join(__file__, "../../"))
|
|
CONFIG_PATHS = recursive_fnmatch(
|
|
os.path.join(RAY_PATH, "autoscaler"), "*.yaml")
|
|
|
|
CONFIG_PATHS += recursive_fnmatch(
|
|
os.path.join(RAY_PATH, "tune/examples/"), "*.yaml")
|
|
|
|
|
|
class AutoscalingConfigTest(unittest.TestCase):
|
|
def testValidateDefaultConfig(self):
|
|
for config_path in CONFIG_PATHS:
|
|
with open(config_path) as f:
|
|
config = yaml.safe_load(f)
|
|
config = fillout_defaults(config)
|
|
try:
|
|
validate_config(config)
|
|
except Exception:
|
|
self.fail("Config did not pass validation test!")
|
|
|
|
def testValidateNetworkConfig(self):
|
|
web_yaml = "https://raw.githubusercontent.com/ray-project/ray/" \
|
|
"master/python/ray/autoscaler/aws/example-full.yaml"
|
|
response = urllib.request.urlopen(web_yaml, timeout=5)
|
|
content = response.read()
|
|
with tempfile.TemporaryFile() as f:
|
|
f.write(content)
|
|
f.seek(0)
|
|
config = yaml.safe_load(f)
|
|
config = fillout_defaults(config)
|
|
try:
|
|
validate_config(config)
|
|
except Exception:
|
|
self.fail("Config did not pass validation test!")
|
|
|
|
def _test_invalid_config(self, config_path):
|
|
with open(os.path.join(RAY_PATH, config_path)) as f:
|
|
config = yaml.safe_load(f)
|
|
try:
|
|
validate_config(config)
|
|
self.fail("Expected validation to fail for {}".format(config_path))
|
|
except jsonschema.ValidationError:
|
|
pass
|
|
|
|
def testInvalidConfig(self):
|
|
self._test_invalid_config("tests/additional_property.yaml")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import pytest
|
|
import sys
|
|
sys.exit(pytest.main(["-v", __file__]))
|