Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packs/tests/actions/chains/test_run_pack_tests_tool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ vars:
base_repo_url: "https://github.com/StackStorm"
# Note: Pack 1 should have no external dependencies beyond Python stdlib ones.
pack_to_install_1: "csv"
pack_to_install_2: "xml"
pack_to_install_2: "xml=0.3.0"
test_timeout: 180

chain:
Expand All @@ -18,8 +18,17 @@ chain:
ST2_AUTH_TOKEN: "{{token}}"
cmd: "st2 pack install {{ pack_to_install_1 }}"
timeout: "{{test_timeout}}"
on-success: test_installed_pack_1_version
on-failure: error_handler

-
name: test_installed_pack_1_version
ref: tests.test_installed_pack_version
params:
installed_pack: "{{ pack_to_install_1 }}"
on-success: install_pack_2
on-failure: error_handler

-
name: install_pack_2
ref: core.local
Expand All @@ -31,8 +40,17 @@ chain:
ST2_AUTH_TOKEN: "{{token}}"
cmd: "st2 pack install {{ pack_to_install_2 }}"
timeout: "{{test_timeout}}"
on-success: test_installed_pack_2_version
on-failure: error_handler

-
name: test_installed_pack_2_version
ref: tests.test_installed_pack_version
params:
installed_pack: "{{ pack_to_install_2 }}"
on-success: run_pack_tests_without_creating_virtualenv
on-failure: error_handler

-
name: run_pack_tests_without_creating_virtualenv
ref: core.local
Expand Down
55 changes: 55 additions & 0 deletions packs/tests/actions/test_installed_pack_version.py
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)
Copy link
Member

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 xml without 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.).

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
12 changes: 12 additions & 0 deletions packs/tests/actions/test_installed_pack_version.yaml
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