-
-
Notifications
You must be signed in to change notification settings - Fork 777
Pack dependency management #4769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d47e267
Pack dependency management
jinpingh 754f632
Add unit test cases for Pack dependency management
jinpingh 6bb6512
Add pack `ref` in pack install/remove command output
jinpingh 2f4e361
Code improvement and simplify getting dependencies code
jinpingh 1a9c026
Check conflict between dependency packs
jinpingh 925794d
Rename --no_deps parameter to --skip-dependencies
blag 1f4ecc6
Use Python's print function
blag bdb4aa9
Use one return statement in try/except/finally blocks
blag b506787
Simplify install workflow
blag a8166d4
Explicitly fail
blag 6560d36
Fixup pack_management.py to handle tags that aren't on branches
blag fc6a9ea
Further simplify install workflow
blag 9b13162
Merge remote-tracking branch 'origin/master' into issue-354/pack_mana…
blag fb29321
Fix overzealous simplification
blag b91a05a
Fix version comparisons
blag 1c3b243
Bump packs pack version
blag b8b480f
Handle pack versions that are None
blag 105c588
Add dependencies list example to hello_st2/pack.yaml
blag 32ad61f
Betterize error messages and add a core.error action
blag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
|
|
||
|
|
||
| --- | ||
| name: "get_pack_dependencies" | ||
| runner_type: "python-script" | ||
| description: "Get pack dependencies specified in pack.yaml" | ||
| enabled: true | ||
| pack: packs | ||
| entry_point: "pack_mgmt/get_pack_dependencies.py" | ||
| parameters: | ||
| packs_status: | ||
| type: object | ||
| description: Name of the pack in Exchange or a git repo URL and download status. | ||
| required: true | ||
| default: null | ||
| nested: | ||
| type: integer | ||
| description: Nested level of dependencies to prevent infinite or really long download loops. | ||
| required: true | ||
| default: 3 | ||
jinpingh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
contrib/packs/actions/pack_mgmt/get_pack_dependencies.py
This file contains hidden or 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,133 @@ | ||
| # Copyright 2019 Extreme Networks, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import six | ||
|
|
||
| from st2common.constants.pack import PACK_VERSION_SEPARATOR | ||
| from st2common.content.utils import get_pack_base_path | ||
| from st2common.runners.base_action import Action | ||
| from st2common.util.pack import get_pack_metadata | ||
|
|
||
| STACKSTORM_EXCHANGE_PACK = 'StackStorm-Exchange/stackstorm-' | ||
jinpingh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| LOCAL_FILE_PREFIX = 'file://' | ||
|
|
||
|
|
||
| class GetPackDependencies(Action): | ||
| def __init__(self, config=None, action_service=None): | ||
| self.dependency_list = [] | ||
| self.conflict_list = [] | ||
|
|
||
| def run(self, packs_status, nested): | ||
| """ | ||
| :param packs_status: Name of the pack in Exchange or a git repo URL and download status. | ||
| :type: packs_status: ``dict`` | ||
| :param nested: Nested level of dependencies to prevent infinite or really | ||
| long download loops. | ||
| :type nested: ``integer`` | ||
| """ | ||
| result = {} | ||
|
|
||
| if not packs_status or nested == 0: | ||
| return result | ||
|
|
||
| for pack, status in six.iteritems(packs_status): | ||
| if 'success' not in status.lower(): | ||
| continue | ||
|
|
||
| dependency_packs = get_dependency_list(pack) | ||
| if not dependency_packs: | ||
| continue | ||
|
|
||
| for dependency_pack in dependency_packs: | ||
| pack_and_version = dependency_pack.split(PACK_VERSION_SEPARATOR) | ||
| name_or_url = pack_and_version[0] | ||
| pack_version = pack_and_version[1] if len(pack_and_version) > 1 else None | ||
|
|
||
| if name_or_url.startswith(LOCAL_FILE_PREFIX): | ||
jinpingh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.get_local_pack_dependencies(name_or_url, pack_version, dependency_pack) | ||
| elif (len(name_or_url.split('/')) == 1 and STACKSTORM_EXCHANGE_PACK not in | ||
| name_or_url) or STACKSTORM_EXCHANGE_PACK in name_or_url: | ||
| self.get_exchange_pack_dependencies(name_or_url, pack_version, dependency_pack) | ||
| else: | ||
| self.get_none_exchange_pack_dependencies(name_or_url, pack_version, | ||
| dependency_pack) | ||
|
|
||
| result['dependency_list'] = self.dependency_list | ||
| result['conflict_list'] = self.conflict_list | ||
| result['nested'] = nested - 1 | ||
|
|
||
| return result | ||
|
|
||
| # For StackStorm Exchange packs. E.g. | ||
| # https://github.com/StackStorm-Exchange/stackstorm-email | ||
| # https://github.com/StackStorm-Exchange/stackstorm-email.git | ||
| def get_exchange_pack_dependencies(self, name_or_url, pack_version, dependency_pack): | ||
| if len(name_or_url.split('/')) == 1: | ||
| pack_name = name_or_url | ||
| else: | ||
| name_or_git = name_or_url.split(STACKSTORM_EXCHANGE_PACK)[-1] | ||
| pack_name = name_or_git if '.git' not in name_or_git else name_or_git.split('.')[0] | ||
jinpingh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| existing_pack_version = get_pack_version(pack_name) | ||
| self.check_conflict(dependency_pack, pack_version, existing_pack_version) | ||
|
|
||
| # For None StackStorm Exchange packs. E.g. | ||
| # https://github.com/EncoreTechnologies/stackstorm-freeipa.git | ||
| # https://github.com/EncoreTechnologies/stackstorm-freeipa | ||
| # https://github.com/EncoreTechnologies/pack.git | ||
| def get_none_exchange_pack_dependencies(self, name_or_url, pack_version, dependency_pack): | ||
jinpingh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name_or_git = name_or_url.split('/')[-1] | ||
| name = name_or_git if '.git' not in name_or_git else name_or_git.split('.')[0] | ||
| pack_name = name.split('-')[-1] if "stackstorm-" in name else name | ||
jinpingh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| existing_pack_version = get_pack_version(pack_name) | ||
| self.check_conflict(dependency_pack, pack_version, existing_pack_version) | ||
|
|
||
| # For local file. E.g | ||
| # file:///opt/stackstorm/st2/lib/python3.6/site-packages/st2tests/fixtures/packs/dummy_pack_3 | ||
| def get_local_pack_dependencies(self, name_or_url, pack_version, dependency_pack): | ||
| pack_name = name_or_url.split("/")[-1] | ||
|
|
||
| existing_pack_version = get_pack_version(pack_name) | ||
| self.check_conflict(dependency_pack, pack_version, existing_pack_version) | ||
|
|
||
| def check_conflict(self, pack, version, existing_version): | ||
| if existing_version: | ||
| existing_version = 'v' + existing_version | ||
| if version and existing_version != version and pack not in self.conflict_list: | ||
| self.conflict_list.append(pack) | ||
| elif pack not in self.dependency_list: | ||
| self.dependency_list.append(pack) | ||
|
|
||
|
|
||
| def get_pack_version(pack=None): | ||
| pack_path = get_pack_base_path(pack) | ||
| try: | ||
| pack_metadata = get_pack_metadata(pack_dir=pack_path) | ||
| return pack_metadata.get('version', None) | ||
| except Exception: | ||
| return None | ||
|
|
||
|
|
||
| def get_dependency_list(pack=None): | ||
| pack_path = get_pack_base_path(pack) | ||
|
|
||
| try: | ||
| pack_metadata = get_pack_metadata(pack_dir=pack_path) | ||
| return pack_metadata.get('dependencies', None) | ||
| except Exception: | ||
| print ('Could not open pack.yaml at location %s' % pack_path) | ||
| return None | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.