From eae83f48789246cd082d3f649b251467ce9ebfad Mon Sep 17 00:00:00 2001 From: Connor Doyle Date: Mon, 16 Mar 2015 17:38:18 -0700 Subject: [PATCH] Added app-id override for package install. - Modified package install to preserve existing app labels. - Integration tests. --- dcos/api/package.py | 18 ++++++++++++++++-- dcos/cli/package/main.py | 10 +++++++--- integrations/cli/test_package.py | 24 +++++++++++++++++++++++- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/dcos/api/package.py b/dcos/api/package.py index 2f182d3..70b24ab 100644 --- a/dcos/api/package.py +++ b/dcos/api/package.py @@ -33,7 +33,7 @@ PACKAGE_SOURCE_KEY = 'DCOS_PACKAGE_SOURCE' PACKAGE_FRAMEWORK_KEY = 'DCOS_PACKAGE_IS_FRAMEWORK' -def install(pkg, version, init_client, user_options, cfg): +def install(pkg, version, init_client, user_options, app_id, cfg): """Installs a package. :param pkg: The package to install @@ -44,6 +44,8 @@ def install(pkg, version, init_client, user_options, cfg): :type init_client: object :param user_options: Package parameters :type user_options: dict + :param app_id: App ID for installation of this package + :type app_id: str :param cfg: Configuration dictionary :type cfg: dcos.api.config.Toml :rtype: Error @@ -88,13 +90,25 @@ def install(pkg, version, init_client, user_options, cfg): if not is_framework: is_framework = False - init_desc['labels'] = { + package_labels = { PACKAGE_NAME_KEY: metadata['name'], PACKAGE_VERSION_KEY: metadata['version'], PACKAGE_SOURCE_KEY: pkg.registry.source.url, PACKAGE_FRAMEWORK_KEY: str(is_framework) } + # Preserve existing labels + labels = init_desc.get('labels', {}) + + labels.update(package_labels) + init_desc['labels'] = labels + + if app_id is not None: + logger.debug('Setting app ID to "%s" (was "%s")', + app_id, + init_desc['id']) + init_desc['id'] = app_id + # Send the descriptor to init _, err = init_client.add_app(init_desc) return err diff --git a/dcos/cli/package/main.py b/dcos/cli/package/main.py index 29dc7f4..705897d 100644 --- a/dcos/cli/package/main.py +++ b/dcos/cli/package/main.py @@ -2,7 +2,8 @@ Usage: dcos package describe dcos package info - dcos package install [--options=] + dcos package install [--options= --app-id=] + dcos package list dcos package search dcos package sources @@ -94,7 +95,7 @@ def _cmds(): cmds.Command( hierarchy=['install'], - arg_keys=['', '--options'], + arg_keys=['', '--options', '--app-id'], function=_install), cmds.Command( @@ -214,13 +215,15 @@ def _describe(package_name): return 0 -def _install(package_name, options_file): +def _install(package_name, options_file, app_id): """Install the specified package. :param package_name: The package to install :type package_name: str :param options_file: Path to file containing option values :type options_file: str + :param app_id: App ID for installation of this package + :type app_id: str :returns: Process status :rtype: int """ @@ -257,6 +260,7 @@ def _install(package_name, options_file): pkg_version, init_client, options_json, + app_id, config) if install_error is not None: diff --git a/integrations/cli/test_package.py b/integrations/cli/test_package.py index 58f8e20..cf5fb1d 100644 --- a/integrations/cli/test_package.py +++ b/integrations/cli/test_package.py @@ -8,7 +8,8 @@ def test_package(): assert stdout == b"""Usage: dcos package describe dcos package info - dcos package install [--options=] + dcos package install [--options= --app-id=] + dcos package list dcos package search dcos package sources @@ -108,6 +109,27 @@ def test_install(): assert stderr == b'' +def test_install_with_id(): + returncode, stdout, stderr = exec_command( + ['dcos', + 'package', + 'install', + 'mesos-dns', + '--options=tests/data/package/mesos-dns-config.json', + '--app-id=dns']) + + assert returncode == 0 + assert stdout == b'' + assert stderr == b'' + + returncode, stdout, stderr = exec_command( + ['dcos', 'marathon', 'app', 'remove', 'dns']) + + assert returncode == 0 + assert stdout == b'' + assert stderr == b'' + + def test_list(): returncode, stdout, stderr = exec_command(['dcos', 'package', 'list'])