Skip to content

Commit

Permalink
Make upgrade a required argument for install_collections and _resolve…
Browse files Browse the repository at this point in the history
…_depenency_map and fix the order
  • Loading branch information
s-hertel committed Feb 2, 2021
1 parent 12a5529 commit ded81d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
3 changes: 1 addition & 2 deletions lib/ansible/cli/galaxy.py
Expand Up @@ -1197,10 +1197,9 @@ def _execute_install_collection(

install_collections(
requirements, output_path, self.api_servers, ignore_errors,
no_deps, force, force_with_deps,
no_deps, force, force_with_deps, upgrade,
allow_pre_release=allow_pre_release,
artifacts_manager=artifacts_manager,
upgrade=upgrade,
)

return 0
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/galaxy/collection/__init__.py
Expand Up @@ -407,9 +407,9 @@ def install_collections(
no_deps, # type: bool
force, # type: bool
force_deps, # type: bool
upgrade, # type: bool
allow_pre_release, # type: bool
artifacts_manager, # type: ConcreteArtifactsManager
upgrade=False, # type: bool
): # type: (...) -> None
"""Install Ansible collections to the path specified.
Expand Down Expand Up @@ -1255,7 +1255,7 @@ def _resolve_depenency_map(
preferred_candidates, # type: Optional[Iterable[Candidate]]
no_deps, # type: bool
allow_pre_release, # type: bool
upgrade=False, # type: bool
upgrade, # type: bool
): # type: (...) -> Dict[str, Candidate]
"""Return the resolved dependency map."""
collection_dep_resolver = build_collection_dependency_resolver(
Expand Down
32 changes: 17 additions & 15 deletions test/units/galaxy/test_collection_install.py
Expand Up @@ -392,7 +392,7 @@ def test_build_requirement_from_name(galaxy_server, monkeypatch, tmp_path_factor
requirements = cli._require_one_of_collections_requirements(
collections, requirements_file, artifacts_manager=concrete_artifact_cm
)['collections']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand All @@ -419,7 +419,7 @@ def test_build_requirement_from_name_with_prerelease(galaxy_server, monkeypatch,
requirements = cli._require_one_of_collections_requirements(
['namespace.collection'], None, artifacts_manager=concrete_artifact_cm
)['collections']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_build_requirment_from_name_with_prerelease_explicit(galaxy_server, monk
requirements = cli._require_one_of_collections_requirements(
['namespace.collection:2.0.1-beta.1'], None, artifacts_manager=concrete_artifact_cm
)['collections']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, True, False, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -480,7 +480,9 @@ def test_build_requirement_from_name_second_server(galaxy_server, monkeypatch, t
requirements = cli._require_one_of_collections_requirements(
['namespace.collection:>1.0.1'], None, artifacts_manager=concrete_artifact_cm
)['collections']
actual = collection._resolve_depenency_map(requirements, [broken_server, galaxy_server], concrete_artifact_cm, None, True, False)['namespace.collection']
actual = collection._resolve_depenency_map(
requirements, [broken_server, galaxy_server], concrete_artifact_cm, None, True, False, False
)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -510,7 +512,7 @@ def test_build_requirement_from_name_missing(galaxy_server, monkeypatch, tmp_pat

expected = "Failed to resolve the requested dependencies map. Could not satisfy the following requirements:\n* namespace.collection:* (direct request)"
with pytest.raises(AnsibleError, match=re.escape(expected)):
collection._resolve_depenency_map(requirements, [galaxy_server, galaxy_server], concrete_artifact_cm, None, False, True)
collection._resolve_depenency_map(requirements, [galaxy_server, galaxy_server], concrete_artifact_cm, None, False, True, False)


def test_build_requirement_from_name_401_unauthorized(galaxy_server, monkeypatch, tmp_path_factory):
Expand All @@ -530,7 +532,7 @@ def test_build_requirement_from_name_401_unauthorized(galaxy_server, monkeypatch

expected = "error (HTTP Code: 401, Message: msg)"
with pytest.raises(api.GalaxyError, match=re.escape(expected)):
collection._resolve_depenency_map(requirements, [galaxy_server, galaxy_server], concrete_artifact_cm, None, False, False)
collection._resolve_depenency_map(requirements, [galaxy_server, galaxy_server], concrete_artifact_cm, None, False, False, False)


def test_build_requirement_from_name_single_version(galaxy_server, monkeypatch, tmp_path_factory):
Expand All @@ -557,7 +559,7 @@ def test_build_requirement_from_name_single_version(galaxy_server, monkeypatch,
['namespace.collection:==2.0.0'], None, artifacts_manager=concrete_artifact_cm
)['collections']

actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -593,7 +595,7 @@ def test_build_requirement_from_name_multiple_versions_one_match(galaxy_server,
['namespace.collection:>=2.0.1,<2.0.2'], None, artifacts_manager=concrete_artifact_cm
)['collections']

actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -634,7 +636,7 @@ def test_build_requirement_from_name_multiple_version_results(galaxy_server, mon
['namespace.collection:!=2.0.2'], None, artifacts_manager=concrete_artifact_cm
)['collections']

actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True)['namespace.collection']
actual = collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True, False)['namespace.collection']

assert actual.namespace == u'namespace'
assert actual.name == u'collection'
Expand Down Expand Up @@ -668,7 +670,7 @@ def test_candidate_with_conflict(monkeypatch, tmp_path_factory, galaxy_server):
expected = "Failed to resolve the requested dependencies map. Could not satisfy the following requirements:\n"
expected += "* namespace.collection:!=2.0.5 (direct request)"
with pytest.raises(AnsibleError, match=re.escape(expected)):
collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True)
collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True, False)


def test_dep_candidate_with_conflict(monkeypatch, tmp_path_factory, galaxy_server):
Expand All @@ -693,7 +695,7 @@ def test_dep_candidate_with_conflict(monkeypatch, tmp_path_factory, galaxy_serve
expected = "Failed to resolve the requested dependencies map. Could not satisfy the following requirements:\n"
expected += "* namespace.collection:!=1.0.0 (dependency of parent.collection:2.0.5)"
with pytest.raises(AnsibleError, match=re.escape(expected)):
collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True)
collection._resolve_depenency_map(requirements, [galaxy_server], concrete_artifact_cm, None, False, True, False)


def test_install_installed_collection(monkeypatch, tmp_path_factory, galaxy_server):
Expand Down Expand Up @@ -804,7 +806,7 @@ def test_install_collections_from_tar(collection_artifact, monkeypatch):
concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(temp_path, validate_certs=False)

requirements = [Requirement('ansible_namespace.collection', '0.1.0', to_text(collection_tar), 'file')]
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, concrete_artifact_cm)
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, False, concrete_artifact_cm)

assert os.path.isdir(collection_path)

Expand Down Expand Up @@ -840,7 +842,7 @@ def test_install_collections_existing_without_force(collection_artifact, monkeyp
assert os.path.isdir(collection_path)

requirements = [Requirement('ansible_namespace.collection', '0.1.0', to_text(collection_tar), 'file')]
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, concrete_artifact_cm)
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, False, concrete_artifact_cm)

assert os.path.isdir(collection_path)

Expand Down Expand Up @@ -872,7 +874,7 @@ def test_install_missing_metadata_warning(collection_artifact, monkeypatch):

concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(temp_path, validate_certs=False)
requirements = [Requirement('ansible_namespace.collection', '0.1.0', to_text(collection_tar), 'file')]
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, concrete_artifact_cm)
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, False, concrete_artifact_cm)

display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1]

Expand All @@ -893,7 +895,7 @@ def test_install_collection_with_circular_dependency(collection_artifact, monkey

concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(temp_path, validate_certs=False)
requirements = [Requirement('ansible_namespace.collection', '0.1.0', to_text(collection_tar), 'file')]
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, concrete_artifact_cm)
collection.install_collections(requirements, to_text(temp_path), [], False, False, False, False, False, False, concrete_artifact_cm)

assert os.path.isdir(collection_path)

Expand Down

0 comments on commit ded81d9

Please sign in to comment.