Added app-id override for package install.
- Modified package install to preserve existing app labels. - Integration tests.
This commit is contained in:
committed by
Connor Doyle
parent
9184059d52
commit
eae83f4878
@@ -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
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
Usage:
|
||||
dcos package describe <package_name>
|
||||
dcos package info
|
||||
dcos package install [--options=<options_file>] <package_name>
|
||||
dcos package install [--options=<options_file> --app-id=<app_id>]
|
||||
<package_name>
|
||||
dcos package list
|
||||
dcos package search <query>
|
||||
dcos package sources
|
||||
@@ -94,7 +95,7 @@ def _cmds():
|
||||
|
||||
cmds.Command(
|
||||
hierarchy=['install'],
|
||||
arg_keys=['<package_name>', '--options'],
|
||||
arg_keys=['<package_name>', '--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:
|
||||
|
||||
@@ -8,7 +8,8 @@ def test_package():
|
||||
assert stdout == b"""Usage:
|
||||
dcos package describe <package_name>
|
||||
dcos package info
|
||||
dcos package install [--options=<options_file>] <package_name>
|
||||
dcos package install [--options=<options_file> --app-id=<app_id>]
|
||||
<package_name>
|
||||
dcos package list
|
||||
dcos package search <query>
|
||||
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'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user