...
 
Commits (3)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
import click
import logging
import six
import simplejson as json
from beat.core.dock import Host
from . import common
from .click_helper import AliasedGroup
logger = logging.getLogger(__name__)
def get_remote_environments(ctx):
config = ctx.meta.get("config")
with common.make_webapi(config) as webapi:
status, answer = webapi.get("/api/v1/backend/environments/")
if status != six.moves.http_client.OK:
logger.error(
"failed to retrieve environment list on {}, reason: {}".format(
webapi.platform, six.moves.http_client.responses[status]
)
)
return {}
else:
return json.loads(answer)
def get_docker_environments():
host = Host(raise_on_errors=False)
return host.images_cache
@click.group(cls=AliasedGroup)
@click.pass_context
def environments(ctx):
"""Execution environment related commands"""
@environments.command()
@click.option(
"--type",
"-t",
"type_",
type=click.Choice(["docker", "remote", "all"], case_sensitive=False),
default="all",
)
@click.option("--output", "-o", type=click.Path(), default=None)
@click.pass_context
def list(ctx, type_, output):
"""List available execution environments"""
data = {}
if type_ in ["remote", "all"]:
data["remote"] = get_remote_environments(ctx)
if type_ in ["docker", "all"]:
data["docker"] = get_docker_environments()
data_str = json.dumps(data, indent=4)
if output is not None:
with open(output, "wt") as file:
click.echo(data_str, file=file)
else:
click.echo(data_str)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
# Basic tests for the command line beat program: environments
import nose.tools
import simplejson as json
from click.testing import CliRunner
from beat.core.test.utils import slow, cleanup, skipif
from beat.cmdline.scripts import main_cli
from . import platform, disconnected, prefix, user, token
def call(*args, **kwargs):
"""A central mechanism to call the main routine with the right parameters"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", platform)
use_cache = kwargs.get("cache", "cache")
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
[
"--platform",
use_platform,
"--user",
user,
"--token",
token,
"--prefix",
use_prefix,
"--cache",
use_cache,
"--test-mode",
"environments",
]
+ list(args),
catch_exceptions=False,
)
return result.exit_code, result.output
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_all_list():
exit_code, output = call("list", "-t", "all")
nose.tools.eq_(exit_code, 0, msg=output)
output_data = json.loads(output)
nose.tools.assert_true(all(key in output_data for key in ["remote", "docker"]))
nose.tools.assert_not_equals(len(output_data["remote"]), 0)
nose.tools.assert_not_equals(len(output_data["docker"]), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
@skipif(disconnected, "missing test platform (%s)" % platform)
def test_remote_list():
exit_code, output = call("list", "-t", "remote")
nose.tools.eq_(exit_code, 0, msg=output)
output_data = json.loads(output)
nose.tools.assert_true("remote" in output_data)
nose.tools.assert_not_equals(len(output_data["remote"]), 0)
@slow
@nose.tools.with_setup(teardown=cleanup)
def test_docker_list():
exit_code, output = call("list", "-t", "docker")
nose.tools.eq_(exit_code, 0, msg=output)
output_data = json.loads(output)
nose.tools.assert_true("docker" in output_data)
nose.tools.assert_not_equals(len(output_data["docker"]), 0)
......@@ -18,6 +18,8 @@ build:
- plotterparameters = beat.cmdline.plotterparameters:plotterparameters
- toolchains = beat.cmdline.toolchains:toolchains
- experiments = beat.cmdline.experiments:experiments
- environments = beat.cmdline.environments:environments
number: {{ environ.get('BOB_BUILD_NUMBER', 0) }}
run_exports:
- {{ pin_subpackage(name) }}
......@@ -79,6 +81,7 @@ test:
- beat plotterparameters --help
- beat toolchains --help
- beat experiments --help
- beat environments --help
- nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
- sphinx-build -aEW ${PREFIX}/share/doc/{{ name }}/doc sphinx
- if [ -n "${CI_PROJECT_DIR}" ]; then mv sphinx "${CI_PROJECT_DIR}/"; fi
......
......@@ -73,6 +73,7 @@ setup(
"protocoltemplates = beat.cmdline.protocoltemplates:protocoltemplates",
"toolchains = beat.cmdline.toolchains:toolchains",
"experiments = beat.cmdline.experiments:experiments",
"environments = beat.cmdline.environments:environments",
],
"beat.config.cli": [
"show = beat.cmdline.config:show",
......@@ -202,7 +203,13 @@ setup(
"rm = beat.cmdline.experiments:rm",
"draw = beat.cmdline.experiments:draw",
"plot = beat.cmdline.experiments:plot",
"start = beat.cmdline.experiments:start",
"cancel = beat.cmdline.experiments:cancel",
"reset = beat.cmdline.experiments:reset",
"runstatus = beat.cmdline.experiments:runstatus",
"monitor = beat.cmdline.experiments:monitor",
],
"beat.environments.cli": ["list = beat.cmdline.environments:list"],
},
classifiers=[
"Framework :: BEAT",
......