Skip to content

Commit 895b0ae

Browse files
authored
Merge pull request #176 from StackStorm/check_installed_pack_version
Check installed pack version as expected
2 parents 217e4ea + b383417 commit 895b0ae

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

packs/tests/actions/chains/test_run_pack_tests_tool.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vars:
33
base_repo_url: "https://github.com/StackStorm"
44
# Note: Pack 1 should have no external dependencies beyond Python stdlib ones.
55
pack_to_install_1: "csv"
6-
pack_to_install_2: "xml"
6+
pack_to_install_2: "xml=0.3.0"
77
test_timeout: 180
88

99
chain:
@@ -18,8 +18,17 @@ chain:
1818
ST2_AUTH_TOKEN: "{{token}}"
1919
cmd: "st2 pack install {{ pack_to_install_1 }}"
2020
timeout: "{{test_timeout}}"
21+
on-success: test_installed_pack_1_version
22+
on-failure: error_handler
23+
24+
-
25+
name: test_installed_pack_1_version
26+
ref: tests.test_installed_pack_version
27+
params:
28+
installed_pack: "{{ pack_to_install_1 }}"
2129
on-success: install_pack_2
2230
on-failure: error_handler
31+
2332
-
2433
name: install_pack_2
2534
ref: core.local
@@ -31,8 +40,17 @@ chain:
3140
ST2_AUTH_TOKEN: "{{token}}"
3241
cmd: "st2 pack install {{ pack_to_install_2 }}"
3342
timeout: "{{test_timeout}}"
43+
on-success: test_installed_pack_2_version
44+
on-failure: error_handler
45+
46+
-
47+
name: test_installed_pack_2_version
48+
ref: tests.test_installed_pack_version
49+
params:
50+
installed_pack: "{{ pack_to_install_2 }}"
3451
on-success: run_pack_tests_without_creating_virtualenv
3552
on-failure: error_handler
53+
3654
-
3755
name: run_pack_tests_without_creating_virtualenv
3856
ref: core.local
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2019 Extreme Networks, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from st2common.constants.pack import PACK_VERSION_SEPARATOR
16+
from st2common.runners.base_action import Action
17+
from st2common.util.pack import get_pack_metadata
18+
from st2common.util.pack_management import get_repo_url
19+
20+
21+
class TesetInstalledPackVersionAction(Action):
22+
def run(self, installed_pack):
23+
"""
24+
:param installed_pack: Installed pack name with version
25+
:type: installed_pack: ``string``
26+
"""
27+
28+
if not installed_pack:
29+
return False, False
30+
31+
pack_and_version = installed_pack.split(PACK_VERSION_SEPARATOR)
32+
pack_name = pack_and_version[0]
33+
pack_version = pack_and_version[1] if len(pack_and_version) > 1 else None
34+
35+
# Pack version is not specified. Get pack version from index.json file.
36+
if not pack_version:
37+
try:
38+
_, pack_version = get_repo_url(pack_name, proxy_config=None)
39+
except Exception:
40+
print ('No record of the "%s" pack in the index.' % (pack_name))
41+
return False, False
42+
43+
# Get installed pack version from local pack metadata file.
44+
try:
45+
pack_dir = '/opt/stackstorm/packs/%s/' % (pack_name)
46+
pack_metadata = get_pack_metadata(pack_dir=pack_dir)
47+
local_pack_version = pack_metadata.get('version', None)
48+
except Exception:
49+
print ('Could not open pack.yaml file at location %s' % (pack_dir))
50+
return False, False
51+
52+
if pack_version == local_pack_version:
53+
return True, True
54+
else:
55+
return False, False
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: "test_installed_pack_version"
3+
runner_type: "python-script"
4+
description: "Test installed pack version."
5+
pack: tests
6+
enabled: true
7+
entry_point: "test_installed_pack_version.py"
8+
parameters:
9+
installed_pack:
10+
type: "string"
11+
description: "Name of pack to check"
12+
required: true

0 commit comments

Comments
 (0)