diff --git a/cli/dcoscli/package/main.py b/cli/dcoscli/package/main.py index c50b7dd..3dd1cd6 100644 --- a/cli/dcoscli/package/main.py +++ b/cli/dcoscli/package/main.py @@ -3,7 +3,7 @@ Usage: dcos package --config-schema dcos package --info - dcos package describe + dcos package describe [--app --options= --cli] dcos package info dcos package install [--cli | [--app --app-id=] @@ -96,7 +96,7 @@ def _cmds(): cmds.Command( hierarchy=['package', 'describe'], - arg_keys=[''], + arg_keys=['', '--cli', '--app', '--options'], function=_describe), cmds.Command( @@ -205,7 +205,7 @@ def _update(validate): return 0 -def _describe(package_name): +def _describe(package_name, cli, app, options_path): """Describe the specified package. :param package_name: The package to describe @@ -243,15 +243,54 @@ def _describe(package_name): emitter.publish(version_error) return 1 - versions = [version_map[pkg_ver] for pkg_ver in version_map] + versions = [version_map[key] for key in version_map] del pkg_json['version'] pkg_json['versions'] = versions + + if cli or app: + user_options, err = _user_options(options_path) + if err is not None: + emitter.publish(err) + return 1 + + options, err = pkg.options(pkg_version, user_options) + if err is not None: + emitter.publish(err) + return 1 + + if cli: + command_json, err = pkg.command_json(pkg_version, options) + if err is not None: + emitter.publish(err) + return 1 + + pkg_json['command'] = command_json + + if app: + marathon_json, err = pkg.marathon_json(pkg_version, options) + if err is not None: + emitter.publish(err) + return 1 + + pkg_json['app'] = marathon_json + emitter.publish(pkg_json) return 0 +def _user_options(path): + if path is None: + return ({}, None) + else: + with open(path) as options_file: + user_options, err = util.load_json(options_file) + if err is not None: + return (None, err) + return (user_options, None) + + def _install(package_name, options_path, app_id, cli, app): """Install the specified package. @@ -297,14 +336,10 @@ def _install(package_name, options_path, app_id, cli, app): emitter.publish(version_error) return 1 - if options_path is None: - user_options = {} - else: - with open(options_path) as options_file: - user_options, err = util.load_json(options_file) - if err is not None: - emitter.publish(err) - return 1 + user_options, err = _user_options(options_path) + if err is not None: + emitter.publish(err) + return 1 try: options, err = pkg.options(pkg_version, user_options) diff --git a/cli/tests/data/package/marathon.json b/cli/tests/data/package/marathon.json new file mode 100644 index 0000000..276dca0 --- /dev/null +++ b/cli/tests/data/package/marathon.json @@ -0,0 +1,5 @@ +{ + "marathon": { + "zk": "zk://localhost:2181/mesos" + } +} diff --git a/cli/tests/integrations/cli/test_package.py b/cli/tests/integrations/cli/test_package.py index e70df0a..f3061db 100644 --- a/cli/tests/integrations/cli/test_package.py +++ b/cli/tests/integrations/cli/test_package.py @@ -13,7 +13,7 @@ def test_package(): Usage: dcos package --config-schema dcos package --info - dcos package describe + dcos package describe [--app --options= --cli] dcos package info dcos package install [--cli | [--app --app-id=] @@ -108,23 +108,114 @@ def test_describe_nonexistent(): def test_describe(): stdout = b"""\ { - "description": "DNS-based service discovery for Mesos.", + "description": "A cluster-wide init and control system for services in \ +cgroups or Docker containers.", + "framework": true, + "images": { + "icon-large": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-large.png", + "icon-medium": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-medium.png", + "icon-small": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-small.png" + }, "maintainer": "support@mesosphere.io", - "name": "mesos-dns", - "postInstallNotes": "Please refer to the tutorial instructions for further \ -setup requirements: http://mesosphere.github.io/mesos-dns/docs/\ -tutorial-gce.html", - "scm": "https://github.com/mesosphere/mesos-dns.git", + "name": "marathon", + "scm": "https://github.com/mesosphere/marathon.git", "tags": [ - "mesosphere" + "mesosphere", + "framework" ], "versions": [ - "alpha" - ], - "website": "http://mesosphere.github.io/mesos-dns" + "0.8.1" + ] } """ - assert_command(['dcos', 'package', 'describe', 'mesos-dns'], + assert_command(['dcos', 'package', 'describe', 'marathon'], + stdout=stdout) + + stdout = b"""\ +{ + "command": { + "pip": [ + "http://downloads.mesosphere.io/dcos-cli/\ +dcos-0.1.0-py2.py3-none-any.whl", + "git+https://github.com/mesosphere/\ +dcos-helloworld.git#dcos-helloworld=0.1.0" + ] + }, + "description": "Example DCOS application package", + "maintainer": "support@mesosphere.io", + "name": "helloworld", + "tags": [ + "mesosphere", + "example", + "subcommand" + ], + "versions": [ + "0.1.0" + ], + "website": "https://github.com/mesosphere/dcos-helloworld" +} +""" + assert_command(['dcos', 'package', 'describe', '--cli', 'helloworld'], + stdout=stdout) + + stdout = b"""\ +{ + "app": { + "cmd": "LIBPROCESS_PORT=$PORT1 && ./bin/start --master zk://master\ +.mesos:2181/mesos --checkpoint --failover_timeout 604800 --framework_\ +name marathon-user --ha --zk zk://localhost:2181/mesos/\ +marathon-user --http_port $PORT0 ", + "constraints": [ + [ + "hostname", + "UNIQUE" + ] + ], + "container": { + "docker": { + "image": "mesosphere/marathon:v0.8.1", + "network": "HOST" + }, + "type": "DOCKER" + }, + "cpus": 1.0, + "id": "marathon-user", + "instances": 1, + "mem": 512.0, + "ports": [ + 0, + 0 + ], + "uris": [] + }, + "description": "A cluster-wide init and control system for services \ +in cgroups or Docker containers.", + "framework": true, + "images": { + "icon-large": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-large.png", + "icon-medium": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-medium.png", + "icon-small": "https://downloads.mesosphere.io/marathon/assets/\ +icon-service-marathon-small.png" + }, + "maintainer": "support@mesosphere.io", + "name": "marathon", + "scm": "https://github.com/mesosphere/marathon.git", + "tags": [ + "mesosphere", + "framework" + ], + "versions": [ + "0.8.1" + ] +} +""" + assert_command(['dcos', 'package', 'describe', '--app', '--options', + 'tests/data/package/marathon.json', 'marathon'], stdout=stdout)