-
Notifications
You must be signed in to change notification settings - Fork 12
Check installed pack version as expected #176
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
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,55 @@ | ||
| # 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 st2common.constants.pack import PACK_VERSION_SEPARATOR | ||
| from st2common.runners.base_action import Action | ||
| from st2common.util.pack import get_pack_metadata | ||
| from st2common.util.pack_management import get_repo_url | ||
|
|
||
|
|
||
| class TesetInstalledPackVersionAction(Action): | ||
| def run(self, installed_pack): | ||
| """ | ||
| :param installed_pack: Installed pack name with version | ||
| :type: installed_pack: ``string`` | ||
| """ | ||
|
|
||
| if not installed_pack: | ||
| return False, False | ||
|
|
||
| pack_and_version = installed_pack.split(PACK_VERSION_SEPARATOR) | ||
| pack_name = pack_and_version[0] | ||
| pack_version = pack_and_version[1] if len(pack_and_version) > 1 else None | ||
|
|
||
| # Pack version is not specified. Get pack version from index.json file. | ||
| if not pack_version: | ||
| try: | ||
| _, pack_version = get_repo_url(pack_name, proxy_config=None) | ||
| except Exception: | ||
| print ('No record of the "%s" pack in the index.' % (pack_name)) | ||
| return False, False | ||
|
|
||
| # Get installed pack version from local pack metadata file. | ||
| try: | ||
| pack_dir = '/opt/stackstorm/packs/%s/' % (pack_name) | ||
| pack_metadata = get_pack_metadata(pack_dir=pack_dir) | ||
| local_pack_version = pack_metadata.get('version', None) | ||
| except Exception: | ||
| print ('Could not open pack.yaml file at location %s' % (pack_dir)) | ||
| return False, False | ||
|
|
||
| if pack_version == local_pack_version: | ||
| return True, True | ||
| else: | ||
| return False, False | ||
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,12 @@ | ||
| --- | ||
| name: "test_installed_pack_version" | ||
| runner_type: "python-script" | ||
| description: "Test installed pack version." | ||
| pack: tests | ||
| enabled: true | ||
| entry_point: "test_installed_pack_version.py" | ||
| parameters: | ||
| installed_pack: | ||
| type: "string" | ||
| description: "Name of pack to check" | ||
| required: true |
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.
Hm, I think there is a possible race condition here.
Let's say user installs pack
xmlwithout specifying a version when a latest version in index and git repo is v3.0.0. After the installation, but before running this check, new version is published to the index.In such scenario, this check would (incorrectly) fail. I know the time window when this can happen is relatively small, but still something to keep in mind.
To avoid such issues, we should use some other test packs for testing such functionality, ones which rarely change (we already have some test packs for testing other pack related functionality,
stackstorm-test,stackstorm-test2, etc.).