This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
forked from ansible/mazer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --collections-lock art to a 'collections lock'
Add support for 'collection lockfiles'. A collections lock specifies a set of collections to install and the version specs to match. Fixes ansible#173 Add collections_lock and collections_lockfile models. Add ansible_galaxy.collections_lockfile with a yaml loader for a collections lockfile. Update cli and install action to use the collections lockfile. The contents of collections lock file is a yaml file, containing a dictionary. The dictitionary is the same format as the 'dependencies' dict in galaxy.yml. ie, The keys are collection labels (the namespace and name dot separated ala 'alikins.collection_inspect'). The values is a version spec string. ie "*" or "==1.0.0". Example contents of a collections lock file: alikins.collection_inspect: "1.0.0" alikins.collection_ntp: ">0.0.1,!=0.0.2"
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import logging | ||
|
||
import yaml | ||
|
||
from ansible_galaxy import exceptions | ||
from ansible_galaxy.models.collections_lockfile import CollectionsLockfile | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
# TODO: replace with a generic version for cases | ||
# where SomeClass(**dict_from_yaml) works | ||
def load(data_or_file_object): | ||
data_dict = yaml.safe_load(data_or_file_object) | ||
|
||
log.debug('data_dict: %s', data_dict) | ||
|
||
try: | ||
collections_lockfile = CollectionsLockfile(dependencies=data_dict) | ||
except ValueError: | ||
raise | ||
except Exception as exc: | ||
log.exception(exc) | ||
raise exceptions.GalaxyClientError("Error parsing collections lockfile: %s" % str(exc)) | ||
|
||
return collections_lockfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
import attr | ||
|
||
|
||
@attr.s(frozen=True) | ||
class CollectionsLock(object): | ||
'''The collections "lock" (ie, manifest) used with --colleections-lock''' | ||
|
||
dependencies = attr.ib(factory=list, validator=attr.validators.instance_of(list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from ansible_galaxy.utils import attr_utils | ||
import attr | ||
|
||
|
||
@attr.s(frozen=True) | ||
class CollectionsLockfile(object): | ||
'''Represents the data in a collections lock yaml file.''' | ||
|
||
dependencies = attr.ib(factory=dict, | ||
validator=attr.validators.instance_of(dict), | ||
converter=attr_utils.convert_none_to_empty_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/ansible_galaxy/models/test_collections_lock_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
from ansible_galaxy.models import collections_lock | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def test_init(): | ||
res = collections_lock.CollectionsLock() | ||
|
||
assert isinstance(res, collections_lock.CollectionsLock) | ||
assert isinstance(res.dependencies, list) | ||
assert res.dependencies == [] | ||
|
||
|
||
def test_init_deps_dict(): | ||
not_a_list = {'foo': 'bar'} | ||
with pytest.raises(TypeError, match='.*dependencies.*') as exc_info: | ||
collections_lock.CollectionsLock(dependencies=not_a_list) | ||
|
||
log.debug('exc_info: %s', exc_info) |
31 changes: 31 additions & 0 deletions
31
tests/ansible_galaxy/models/test_collections_lockfile_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
from ansible_galaxy.models import collections_lockfile | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def test_init(): | ||
res = collections_lockfile.CollectionsLockfile() | ||
|
||
assert isinstance(res, collections_lockfile.CollectionsLockfile) | ||
assert isinstance(res.dependencies, dict) | ||
assert res.dependencies == {} | ||
|
||
|
||
def test_init_deps_none(): | ||
res = collections_lockfile.CollectionsLockfile(dependencies=None) | ||
|
||
assert isinstance(res, collections_lockfile.CollectionsLockfile) | ||
assert isinstance(res.dependencies, dict) | ||
assert res.dependencies == {} | ||
|
||
|
||
def test_init_deps_dict(): | ||
not_a_dict = ['foo', 'bar'] | ||
with pytest.raises(TypeError, match='.*dependencies.*') as exc_info: | ||
collections_lockfile.CollectionsLockfile(dependencies=not_a_dict) | ||
|
||
log.debug('exc_info: %s', exc_info) |