-
-
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 all commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| description: Action that executes the Linux echo command (to stderr) on the localhost. | ||
| runner_type: "local-shell-cmd" | ||
| enabled: true | ||
| entry_point: '' | ||
| name: error | ||
| parameters: | ||
| message: | ||
| description: The message that the command will echo to stderr. | ||
| type: string | ||
| required: true | ||
| cmd: | ||
| description: Arbitrary Linux command to be executed on the local host. | ||
| required: true | ||
| type: string | ||
| default: '>&2 echo "{{message}}"' | ||
| immutable: true | ||
| kwarg_op: | ||
| immutable: true | ||
| sudo: | ||
| default: false | ||
| immutable: true | ||
| sudo_password: | ||
| immutable: true |
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
131 changes: 131 additions & 0 deletions
131
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,131 @@ | ||
| # 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. | ||
| from __future__ import print_function | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| class GetPackDependencies(Action): | ||
| 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 = {} | ||
| dependency_list = [] | ||
| conflict_list = [] | ||
|
|
||
| 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 dep_pack in dependency_packs: | ||
| name_or_url, pack_version = self.get_name_and_version(dep_pack) | ||
|
|
||
| if len(name_or_url.split('/')) == 1: | ||
| pack_name = name_or_url | ||
| else: | ||
| name_or_git = name_or_url.split("/")[-1] | ||
| pack_name = name_or_git if '.git' not in name_or_git else \ | ||
| name_or_git.split('.')[0] | ||
|
|
||
| # Check existing pack by pack name | ||
| existing_pack_version = get_pack_version(pack_name) | ||
|
|
||
| # Try one more time to get existing pack version by name if 'stackstorm-' is in | ||
| # pack name | ||
| if not existing_pack_version and 'stackstorm-' in pack_name.lower(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad assumption thinking that OK about this for now, could be improved in future. |
||
| existing_pack_version = get_pack_version(pack_name.split('stackstorm-')[-1]) | ||
|
|
||
| if existing_pack_version: | ||
| if existing_pack_version and not existing_pack_version.startswith('v'): | ||
| existing_pack_version = 'v' + existing_pack_version | ||
| if pack_version and not pack_version.startswith('v'): | ||
| pack_version = 'v' + pack_version | ||
| if pack_version and existing_pack_version != pack_version \ | ||
| and dep_pack not in conflict_list: | ||
| conflict_list.append(dep_pack) | ||
| else: | ||
| conflict = self.check_dependency_list_for_conflict(name_or_url, pack_version, | ||
| dependency_list) | ||
| if conflict: | ||
| conflict_list.append(dep_pack) | ||
| elif dep_pack not in dependency_list: | ||
| dependency_list.append(dep_pack) | ||
|
|
||
| result['dependency_list'] = dependency_list | ||
| result['conflict_list'] = conflict_list | ||
| result['nested'] = nested - 1 | ||
|
|
||
| return result | ||
|
|
||
| def check_dependency_list_for_conflict(self, name, version, dependency_list): | ||
| conflict = False | ||
|
|
||
| for pack in dependency_list: | ||
| name_or_url, pack_version = self.get_name_and_version(pack) | ||
| if name == name_or_url: | ||
| if version != pack_version: | ||
| conflict = True | ||
| break | ||
|
|
||
| return conflict | ||
|
|
||
| @staticmethod | ||
| def get_name_and_version(pack): | ||
| pack_and_version = 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 | ||
|
|
||
| return name_or_url, pack_version | ||
|
|
||
|
|
||
| def get_pack_version(pack=None): | ||
| pack_path = get_pack_base_path(pack) | ||
| try: | ||
| pack_metadata = get_pack_metadata(pack_dir=pack_path) | ||
| result = pack_metadata.get('version', None) | ||
| except Exception: | ||
| result = None | ||
| finally: | ||
| return result | ||
|
|
||
|
|
||
| def get_dependency_list(pack=None): | ||
| pack_path = get_pack_base_path(pack) | ||
|
|
||
| try: | ||
| pack_metadata = get_pack_metadata(pack_dir=pack_path) | ||
| result = pack_metadata.get('dependencies', None) | ||
| except Exception: | ||
| print('Could not open pack.yaml at location %s' % pack_path) | ||
| result = None | ||
| finally: | ||
| return result | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog message could be improved for this new functionality.