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'
|
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.
|
"""Installs a package.
|
||||||
|
|
||||||
:param pkg: The package to install
|
:param pkg: The package to install
|
||||||
@@ -44,6 +44,8 @@ def install(pkg, version, init_client, user_options, cfg):
|
|||||||
:type init_client: object
|
:type init_client: object
|
||||||
:param user_options: Package parameters
|
:param user_options: Package parameters
|
||||||
:type user_options: dict
|
:type user_options: dict
|
||||||
|
:param app_id: App ID for installation of this package
|
||||||
|
:type app_id: str
|
||||||
:param cfg: Configuration dictionary
|
:param cfg: Configuration dictionary
|
||||||
:type cfg: dcos.api.config.Toml
|
:type cfg: dcos.api.config.Toml
|
||||||
:rtype: Error
|
:rtype: Error
|
||||||
@@ -88,13 +90,25 @@ def install(pkg, version, init_client, user_options, cfg):
|
|||||||
if not is_framework:
|
if not is_framework:
|
||||||
is_framework = False
|
is_framework = False
|
||||||
|
|
||||||
init_desc['labels'] = {
|
package_labels = {
|
||||||
PACKAGE_NAME_KEY: metadata['name'],
|
PACKAGE_NAME_KEY: metadata['name'],
|
||||||
PACKAGE_VERSION_KEY: metadata['version'],
|
PACKAGE_VERSION_KEY: metadata['version'],
|
||||||
PACKAGE_SOURCE_KEY: pkg.registry.source.url,
|
PACKAGE_SOURCE_KEY: pkg.registry.source.url,
|
||||||
PACKAGE_FRAMEWORK_KEY: str(is_framework)
|
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
|
# Send the descriptor to init
|
||||||
_, err = init_client.add_app(init_desc)
|
_, err = init_client.add_app(init_desc)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
Usage:
|
Usage:
|
||||||
dcos package describe <package_name>
|
dcos package describe <package_name>
|
||||||
dcos package info
|
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 list
|
||||||
dcos package search <query>
|
dcos package search <query>
|
||||||
dcos package sources
|
dcos package sources
|
||||||
@@ -94,7 +95,7 @@ def _cmds():
|
|||||||
|
|
||||||
cmds.Command(
|
cmds.Command(
|
||||||
hierarchy=['install'],
|
hierarchy=['install'],
|
||||||
arg_keys=['<package_name>', '--options'],
|
arg_keys=['<package_name>', '--options', '--app-id'],
|
||||||
function=_install),
|
function=_install),
|
||||||
|
|
||||||
cmds.Command(
|
cmds.Command(
|
||||||
@@ -214,13 +215,15 @@ def _describe(package_name):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def _install(package_name, options_file):
|
def _install(package_name, options_file, app_id):
|
||||||
"""Install the specified package.
|
"""Install the specified package.
|
||||||
|
|
||||||
:param package_name: The package to install
|
:param package_name: The package to install
|
||||||
:type package_name: str
|
:type package_name: str
|
||||||
:param options_file: Path to file containing option values
|
:param options_file: Path to file containing option values
|
||||||
:type options_file: str
|
:type options_file: str
|
||||||
|
:param app_id: App ID for installation of this package
|
||||||
|
:type app_id: str
|
||||||
:returns: Process status
|
:returns: Process status
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
@@ -257,6 +260,7 @@ def _install(package_name, options_file):
|
|||||||
pkg_version,
|
pkg_version,
|
||||||
init_client,
|
init_client,
|
||||||
options_json,
|
options_json,
|
||||||
|
app_id,
|
||||||
config)
|
config)
|
||||||
|
|
||||||
if install_error is not None:
|
if install_error is not None:
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ def test_package():
|
|||||||
assert stdout == b"""Usage:
|
assert stdout == b"""Usage:
|
||||||
dcos package describe <package_name>
|
dcos package describe <package_name>
|
||||||
dcos package info
|
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 list
|
||||||
dcos package search <query>
|
dcos package search <query>
|
||||||
dcos package sources
|
dcos package sources
|
||||||
@@ -108,6 +109,27 @@ def test_install():
|
|||||||
assert stderr == b''
|
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():
|
def test_list():
|
||||||
returncode, stdout, stderr = exec_command(['dcos', 'package', 'list'])
|
returncode, stdout, stderr = exec_command(['dcos', 'package', 'list'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user