From bad083be567dd93e3ac42320b38413bcc3d757f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Armando=20Garc=C3=ADa=20Sancio?= Date: Wed, 4 Mar 2015 13:43:09 -0800 Subject: [PATCH] Remove the marathon command line --- dcos/cli/marathon/__init__.py | 0 dcos/cli/marathon/main.py | 218 ------------------------------ integrations/cli/test_help.py | 1 - integrations/cli/test_marathon.py | 168 ----------------------- integrations/cli/test_package.py | 2 +- setup.py | 1 - 6 files changed, 1 insertion(+), 389 deletions(-) delete mode 100644 dcos/cli/marathon/__init__.py delete mode 100644 dcos/cli/marathon/main.py delete mode 100644 integrations/cli/test_marathon.py diff --git a/dcos/cli/marathon/__init__.py b/dcos/cli/marathon/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/dcos/cli/marathon/main.py b/dcos/cli/marathon/main.py deleted file mode 100644 index 998298e..0000000 --- a/dcos/cli/marathon/main.py +++ /dev/null @@ -1,218 +0,0 @@ -""" -Usage: - dcos marathon describe [--json] - dcos marathon info - dcos marathon list - dcos marathon remove [--force] - dcos marathon scale [--force] - dcos marathon start - dcos marathon suspend [--force] - -Options: - -h, --help Show this screen - --version Show version - --force This flag disable checks in Marathon during update - operations. - --json Outputs JSON format instead of default (TOML) format -""" - -import json -import os - -import docopt -import toml -from dcos.api import config, constants, marathon, options, util - - -def main(): - error = util.configure_logger_from_environ() - if error is not None: - print(error.error()) - return 1 - - config_path = os.environ[constants.DCOS_CONFIG_ENV] - args = docopt.docopt( - __doc__, - version='dcos-marathon version {}'.format(constants.version)) - - if args['marathon'] and args['info']: - return _info() - elif args['marathon'] and args['list']: - toml_config = config.load_from_path(config_path) - return _list(toml_config) - elif args['marathon'] and args['describe']: - toml_config = config.load_from_path(config_path) - return _describe(args[''], args['--json'], toml_config) - elif args['marathon'] and args['start']: - toml_config = config.load_from_path(config_path) - return _start(args[''], toml_config) - elif args['marathon'] and args['scale']: - toml_config = config.load_from_path(config_path) - return _scale(args[''], - args[''], - args['--force'], - toml_config) - elif args['marathon'] and args['suspend']: - toml_config = config.load_from_path(config_path) - return _suspend(args[''], args['--force'], toml_config) - elif args['marathon'] and args['remove']: - toml_config = config.load_from_path(config_path) - return _remove(args[''], args['--force'], toml_config) - else: - print(options.make_generic_usage_error(__doc__)) - return 1 - - -def _info(): - """Print marathon cli information. - - :returns: Process status - :rtype: int - """ - - print('Deploy and manage applications on Apache Mesos') - return 0 - - -def _list(config): - """Lists known Marathon applications. - - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - apps, err = client.get_apps() - if err is not None: - print(err.error()) - return 1 - - if not apps: - print("No applications to list.") - - for app in apps: - print(app['id']) - - return 0 - - -def _describe(app_id, is_json, config): - """Show details of a Marathon application. - - :param app_id: ID of the app to suspend - :type app_id: str - :param is_json: Whether to print in JSON format or TOML - :type is_json: bool - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - app, err = client.get_app(app_id) - if err is not None: - print(err.error()) - return 1 - - if is_json: - print(json.dumps(app, sort_keys=True, indent=2)) - else: - print(toml.dumps(app)) - - return 0 - - -def _start(app_resource_path, config): - """Starts an application with Marathon - - :param app_resource_path: Path to the application resource - :type app_resource_path: str - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - with open(app_resource_path) as app_resource_file: - _, err = client.add_app(app_resource_file) - if err is not None: - print(err.error()) - return 1 - - return 0 - - -def _scale(app_id, instances, force, config): - """Suspends a running Marathon application. - - :param app_id: ID of the app to suspend - :type app_id: str - :param instances: The requested number of instances. - :type instances: int - :param force: Whether to override running deployments. - :type force: bool - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - deployment, err = client.scale_app(app_id, instances, force) - if err is not None: - print(err.error()) - return 1 - - print('Created deployment {}'.format(deployment)) - - return 0 - - -def _suspend(app_id, force, config): - """Suspends a running Marathon application. - - :param app_id: ID of the app to suspend - :type app_id: str - :param force: Whether to override running deployments. - :type force: bool - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - deployment, err = client.stop_app(app_id, force) - if err is not None: - print(err.error()) - return 1 - - print('Created deployment {}'.format(deployment)) - - return 0 - - -def _remove(app_id, force, config): - """Remove a Marathon application. - - :param app_id: ID of the app to remove - :type app_id: str - :param force: Whether to override running deployments. - :type force: bool - :param config: Configuration dictionary - :type config: config.Toml - :returns: Process status - :rtype: int - """ - client = marathon.create_client(config) - - err = client.remove_app(app_id, force) - if err is not None: - print(err.error()) - return 1 - - return 0 diff --git a/integrations/cli/test_help.py b/integrations/cli/test_help.py index 9c91a41..8f6ed32 100644 --- a/integrations/cli/test_help.py +++ b/integrations/cli/test_help.py @@ -49,7 +49,6 @@ Available DCOS commands in '{}': \tapp \tDeploy and manage applications on the DCOS \tconfig \tGet and set DCOS command line options \thelp \tDisplay usage information -\tmarathon \tDeploy and manage applications on Apache Mesos \tpackage \tInstall and manage DCOS software packages Get detailed command description with 'dcos --help'. diff --git a/integrations/cli/test_marathon.py b/integrations/cli/test_marathon.py deleted file mode 100644 index d31705b..0000000 --- a/integrations/cli/test_marathon.py +++ /dev/null @@ -1,168 +0,0 @@ -import json -from common import exec_command - - -def test_help(): - returncode, stdout, stderr = exec_command(['dcos', 'marathon', '--help']) - - assert returncode == 0 - assert stdout == b"""Usage: - dcos marathon describe [--json] - dcos marathon info - dcos marathon list - dcos marathon remove [--force] - dcos marathon scale [--force] - dcos marathon start - dcos marathon suspend [--force] - -Options: - -h, --help Show this screen - --version Show version - --force This flag disable checks in Marathon during update - operations. - --json Outputs JSON format instead of default (TOML) format -""" - - -def test_version(): - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', '--version']) - - assert returncode == 0 - assert stdout == b'dcos-marathon version 0.1.0\n' - assert stderr == b'' - - -def test_info(): - returncode, stdout, stderr = exec_command(['dcos', 'marathon', 'info']) - - assert returncode == 0 - assert stdout == b'Deploy and manage applications on Apache Mesos\n' - assert stderr == b'' - - -def test_empty_list(): - _list_apps() - - -def test_start_app(): - _start_app('tests/data/marathon/sleep.json') - _list_apps('test-app') - _remove_app('test-app') - - -def test_remove_app(): - _start_app('tests/data/marathon/sleep.json') - _remove_app('test-app') - _list_apps() - - -# TODO: Let's improve this once we have a fixed version of toml -def test_describe_app(): - _start_app('tests/data/marathon/sleep.json') - - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'describe', 'test-app']) - - assert returncode == 0 - assert stdout != b'' - assert stderr == b'' - - _remove_app('test-app') - - -def test_describe_app_in_json(): - _start_app('tests/data/marathon/sleep.json') - - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'describe', '--json', 'test-app']) - - result = json.loads(stdout.decode('utf-8')) - - assert returncode == 0 - assert isinstance(result, dict) - assert result['id'] == '/test-app' - assert stderr == b'' - - _remove_app('test-app') - - -def test_scale_app(): - _start_app('tests/data/marathon/zero_instance_sleep.json') - - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'scale', 'zero-instance-app', '2']) - - assert returncode == 0 - assert stdout.decode('utf-8').startswith('Created deployment ') - assert stderr == b'' - - _remove_app('zero-instance-app') - - -def test_force_scale_appp(): - _start_app('tests/data/marathon/sleep.json') - - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'scale', '--force', 'test-app', '2']) - - assert returncode == 0 - assert stdout.decode('utf-8').startswith('Created deployment ') - assert stderr == b'' - - _remove_app('test-app') - - -def test_suspend_app(): - _start_app('tests/data/marathon/zero_instance_sleep.json') - - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'suspend', 'zero-instance-app']) - - assert returncode == 0 - assert stdout.decode('utf-8').startswith('Created deployment ') - assert stderr == b'' - - _remove_app('zero-instance-app') - - -def test_remove_missing_app(): - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'remove', 'missing-id']) - - assert returncode == 1 - assert stdout == b"Error: App '/missing-id' does not exist\n" - assert stderr == b'' - - -def _start_app(file_path): - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'start', file_path]) - - assert returncode == 0 - assert stdout == b'' - assert stderr == b'' - - -def _list_apps(app_id=None): - returncode, stdout, stderr = exec_command(['dcos', 'marathon', 'list']) - - if app_id is None: - result = b'No applications to list.\n' - elif isinstance(app_id, str): - result = '/{}\n'.format(app_id).encode('utf-8') - else: - assert False - - assert returncode == 0 - assert stdout == result - assert stderr == b'' - - -def _remove_app(app_id): - returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'remove', app_id]) - - assert returncode == 0 - assert stdout == b'' - assert stderr == b'' diff --git a/integrations/cli/test_package.py b/integrations/cli/test_package.py index cadbe99..6c83dd5 100644 --- a/integrations/cli/test_package.py +++ b/integrations/cli/test_package.py @@ -141,7 +141,7 @@ def test_search(): def test_cleanup(): returncode, stdout, stderr = exec_command( - ['dcos', 'marathon', 'remove', 'mesos-dns']) + ['dcos', 'app', 'remove', 'mesos-dns']) assert returncode == 0 assert stdout == b'' diff --git a/setup.py b/setup.py index 0d2b3f8..df2f66f 100644 --- a/setup.py +++ b/setup.py @@ -109,7 +109,6 @@ setup( 'dcos=dcos.cli.main:main', 'dcos-help=dcos.cli.help.main:main', 'dcos-config=dcos.cli.config.main:main', - 'dcos-marathon=dcos.cli.marathon.main:main', 'dcos-app=dcos.cli.app.main:main', 'dcos-package=dcos.cli.package.main:main', ],