def nmrc_path(tmp_path: Path, token: str, auth_config: _AuthConfig) -> Path: nmrc_path = tmp_path / "conftest.nmrc" cluster_config = _ClusterConfig.create( registry_url=URL("https://registry-dev.neu.ro"), storage_url=URL("https://storage-dev.neu.ro"), users_url=URL("https://users-dev.neu.ro"), monitoring_url=URL("https://monitoring-dev.neu.ro"), resource_presets={ "gpu-small": Preset(cpu=7, memory_mb=30 * 1024, gpu=1, gpu_model="nvidia-tesla-k80"), "gpu-large": Preset(cpu=7, memory_mb=60 * 1024, gpu=1, gpu_model="nvidia-tesla-v100"), "cpu-small": Preset(cpu=7, memory_mb=2 * 1024), "cpu-large": Preset(cpu=7, memory_mb=14 * 1024), }, ) config = _Config( auth_config=auth_config, auth_token=_AuthToken.create_non_expiring(token), cluster_config=cluster_config, pypi=_PyPIVersion.create_uninitialized(), url=URL("https://dev.neu.ro/api/v1"), cookie_session=_CookieSession.create_uninitialized(), version=neuromation.__version__, ) Factory(nmrc_path)._save(config) return nmrc_path
def test_is_initialized__no_resource_presets(self) -> None: cluster_config = _ClusterConfig.create( registry_url=URL("value"), storage_url=URL("value"), users_url=URL("value"), monitoring_url=URL("value"), resource_presets={}, ) assert cluster_config.is_initialized() is False
def test_is_initialized__no_monitoring_url(self) -> None: cluster_config = _ClusterConfig.create( registry_url=URL("value"), storage_url=URL("value"), users_url=URL("value"), monitoring_url=URL(), resource_presets={"default": Preset(cpu=1, memory_mb=2 * 1024)}, ) assert cluster_config.is_initialized() is False
async def test_get_server_config(aiohttp_server: _TestServerFactory) -> None: auth_url = "https://dev-neuromation.auth0.com/authorize" token_url = "https://dev-neuromation.auth0.com/oauth/token" client_id = "this_is_client_id" audience = "https://platform.dev.neuromation.io" headless_callback_url = "https://dev.neu.ro/oauth/show-code" callback_urls = [ "http://127.0.0.1:54540", "http://127.0.0.1:54541", "http://127.0.0.1:54542", ] success_redirect_url = "https://platform.neuromation.io" JSON = { "auth_url": auth_url, "token_url": token_url, "client_id": client_id, "audience": audience, "callback_urls": callback_urls, "success_redirect_url": success_redirect_url, "headless_callback_url": headless_callback_url, } async def handler(request: web.Request) -> web.Response: assert "Authorization" not in request.headers return web.json_response(JSON) app = web.Application() app.router.add_get("/config", handler) srv = await aiohttp_server(app) async with aiohttp.TCPConnector() as connector: config = await get_server_config(connector, srv.make_url("/")) assert config == _ServerConfig( auth_config=_AuthConfig( auth_url=URL(auth_url), token_url=URL(token_url), client_id=client_id, audience=audience, headless_callback_url=URL(headless_callback_url), callback_urls=tuple(URL(u) for u in callback_urls), success_redirect_url=URL(success_redirect_url), ), cluster_config=_ClusterConfig.create( registry_url=URL(), storage_url=URL(), users_url=URL(), monitoring_url=URL(), resource_presets={}, ), )
def cluster_config() -> _ClusterConfig: return _ClusterConfig.create( registry_url=URL("https://registry-dev.neu.ro"), storage_url=URL("https://storage-dev.neu.ro"), users_url=URL("https://users-dev.neu.ro"), monitoring_url=URL("https://monitoring-dev.neu.ro"), resource_presets={ "gpu-small": Preset( cpu=7, memory_mb=30 * 1024, gpu=1, gpu_model="nvidia-tesla-k80" ), "gpu-large": Preset( cpu=7, memory_mb=60 * 1024, gpu=1, gpu_model="nvidia-tesla-v100" ), "cpu-small": Preset(cpu=7, memory_mb=2 * 1024), "cpu-large": Preset(cpu=7, memory_mb=14 * 1024), "cpu-large-p": Preset(cpu=7, memory_mb=14 * 1024, is_preemptible=True), }, )
async def test_get_server_config_with_token( aiohttp_server: _TestServerFactory) -> None: registry_url = "https://registry.dev.neuromation.io" storage_url = "https://storage.dev.neuromation.io" users_url = "https://dev.neuromation.io/users" monitoring_url = "https://dev.neuromation.io/monitoring" auth_url = "https://dev-neuromation.auth0.com/authorize" token_url = "https://dev-neuromation.auth0.com/oauth/token" client_id = "this_is_client_id" audience = "https://platform.dev.neuromation.io" headless_callback_url = "https://dev.neu.ro/oauth/show-code" success_redirect_url = "https://platform.neuromation.io" JSON = { "registry_url": registry_url, "storage_url": storage_url, "users_url": users_url, "monitoring_url": monitoring_url, "auth_url": auth_url, "token_url": token_url, "client_id": client_id, "audience": audience, "headless_callback_url": headless_callback_url, "success_redirect_url": success_redirect_url, "resource_presets": [ { "name": "gpu-small", "cpu": 7, "memory_mb": 30 * 1024, "gpu": 1, "gpu_model": "nvidia-tesla-k80", }, { "name": "gpu-large", "cpu": 7, "memory_mb": 60 * 1024, "gpu": 1, "gpu_model": "nvidia-tesla-v100", }, { "name": "cpu-small", "cpu": 2, "memory_mb": 2 * 1024 }, { "name": "cpu-large", "cpu": 3, "memory_mb": 14 * 1024 }, ], } async def handler(request: web.Request) -> web.Response: assert request.headers["Authorization"] == "Bearer bananatoken" return web.json_response(JSON) app = web.Application() app.router.add_get("/config", handler) srv = await aiohttp_server(app) async with aiohttp.TCPConnector() as connector: config = await get_server_config(connector, srv.make_url("/"), token="bananatoken") assert config == _ServerConfig( auth_config=_AuthConfig( auth_url=URL(auth_url), token_url=URL(token_url), client_id=client_id, audience=audience, headless_callback_url=URL(headless_callback_url), success_redirect_url=URL(success_redirect_url), ), cluster_config=_ClusterConfig.create( registry_url=URL(registry_url), storage_url=URL(storage_url), users_url=URL(users_url), monitoring_url=URL(monitoring_url), resource_presets={ "gpu-small": Preset(cpu=7, memory_mb=30 * 1024, gpu=1, gpu_model="nvidia-tesla-k80"), "gpu-large": Preset(cpu=7, memory_mb=60 * 1024, gpu=1, gpu_model="nvidia-tesla-v100"), "cpu-small": Preset(cpu=2, memory_mb=2 * 1024), "cpu-large": Preset(cpu=3, memory_mb=14 * 1024), }, ), )