From 0cbd95d78b6ec400a77704a98d52a6969641ccd9 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Sun, 30 Oct 2016 11:02:18 +0000 Subject: [PATCH 01/21] Remake packs.info and its alias --- contrib/packs/actions/info.yaml | 1 - contrib/packs/actions/pack_mgmt/info.py | 55 ++++++++++++++++++------- contrib/packs/aliases/pack_info.yaml | 22 ++++++++++ 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/contrib/packs/actions/info.yaml b/contrib/packs/actions/info.yaml index 82d25983d7..152895eb3a 100644 --- a/contrib/packs/actions/info.yaml +++ b/contrib/packs/actions/info.yaml @@ -9,4 +9,3 @@ parameters: type: "string" description: "Name of pack to introspect" required: true - diff --git a/contrib/packs/actions/pack_mgmt/info.py b/contrib/packs/actions/pack_mgmt/info.py index 0d09b07a25..ef3df09250 100644 --- a/contrib/packs/actions/pack_mgmt/info.py +++ b/contrib/packs/actions/pack_mgmt/info.py @@ -14,41 +14,66 @@ # limitations under the License. import os -import json +import yaml + +from git.repo import Repo +from gitdb.exc import InvalidGitRepositoryError from st2common.runners.base_action import Action from st2common.content.utils import get_packs_base_paths -GITINFO_FILE = '.gitinfo' +MANIFEST_FILE = 'pack.yaml' class PackInfo(Action): def run(self, pack): packs_base_paths = get_packs_base_paths() - pack_git_info_path = None + metadata_file = None for packs_base_path in packs_base_paths: - git_info_path = os.path.join(packs_base_path, pack, GITINFO_FILE) + pack_path = os.path.join(packs_base_path, pack) + pack_yaml_path = os.path.join(pack_path, MANIFEST_FILE) - if os.path.isfile(git_info_path): - pack_git_info_path = git_info_path + if os.path.isfile(pack_yaml_path): + metadata_file = pack_yaml_path break - if not pack_git_info_path: - error = ('Pack "%s" doesn\'t exist or it doesn\'t contain a .gitinfo file' % (pack)) + if not metadata_file: + error = ('Pack "%s" doesn\'t exist or it doesn\'t contain pack.yaml.' % (pack)) raise Exception(error) try: - details = self._parse_git_info_file(git_info_path) + details = self._parse_yaml_file(metadata_file) except Exception as e: - error = ('Pack "%s" doesn\'t contain a valid .gitinfo file: %s' % (pack, str(e))) + error = ('Pack "%s" doesn\'t contain a valid pack.yaml file: %s' % (pack, str(e))) raise Exception(error) - return details + try: + repo = Repo(pack_path) + git_status = "Status:\n%s\n\nRemotes:\n%s" % ( + repo.git.status().split('\n')[0], + "\n".join([remote.url for remote in repo.remotes]) + ) - def _parse_git_info_file(self, file_path): - with open(file_path) as data_file: - details = json.load(data_file) - return details + ahead_behind = repo.git.rev_list( + '--left-right', '--count', 'HEAD...origin/master' + ).split() + # Dear god. + if ahead_behind != [u'0', u'0']: + git_status += "\n\n" + git_status += "%s commits ahead " if ahead_behind[0] != u'0' else "" + git_status += "and " if u'0' not in ahead_behind else "" + git_status += "%s commits behind " if ahead_behind[1] != u'0' else "" + git_status += "origin/master." + except InvalidGitRepositoryError: + git_status = None + + return {'pack': details, + 'git_status': git_status} + def _parse_yaml_file(self, file_path): + with open(file_path) as data_file: + # details = yaml.load(data_file) + # You know what? We'll just output yaml, it's pretty as it is. + details = data_file.read() return details diff --git a/contrib/packs/aliases/pack_info.yaml b/contrib/packs/aliases/pack_info.yaml index 479ab1a547..3701058e7a 100644 --- a/contrib/packs/aliases/pack_info.yaml +++ b/contrib/packs/aliases/pack_info.yaml @@ -4,3 +4,25 @@ action_ref: "packs.info" description: "Get StackStorm pack information via ChatOps" formats: - "pack info {{pack}}" +ack: + enabled: false +result: + format: | + {% if execution.status == "succeeded" %} + All the details on your pack: + ``` + {{ execution.result.pack }} + ``` + {% if execution.result.git_status %} + And here's what git says: + ``` + {{ execution.result.git_status }} + ``` + {% else %} + It does not appear to be a git repository though. + {% endif %} + {~} + {% else %} + Deployment failed for *{{execution.parameters.packs}}*.{~} + Please check {{ execution.id }} for details. + {% endif %} From a78bb42d8f3be4bda805cfac5558f293bcaa4815 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Sun, 30 Oct 2016 11:03:52 +0000 Subject: [PATCH 02/21] Packs.install alias --- contrib/packs/aliases/pack_install.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 contrib/packs/aliases/pack_install.yaml diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml new file mode 100644 index 0000000000..be26f3e709 --- /dev/null +++ b/contrib/packs/aliases/pack_install.yaml @@ -0,0 +1,22 @@ +--- +name: "pack_install" +action_ref: "packs.install" +pack: "packs" +description: "Install StackStorm packs (pack = name or git URL, gitref = tag/branch/commit)." +formats: + - display: "pack install [,]" + - display: "pack install #[,]" + representation: + - "pack install {{packs}}" +ack: + enabled: true + append_url: false + format: "Deploying the requested pack(s) for you." +result: + format: | + {% if execution.status == "succeeded" %} + Successful deployment of{% for pack in execution.result.packs %} *{{pack.name}}*{% endfor %}!{~} + {% else %} + Deployment failed for *{{execution.parameters.packs}}*.{~} + Please check {{ execution.id }} for details. + {% endif %} From 04f6fa56dca1b48a8d55c2ff359fb57c515cbe23 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Sun, 30 Oct 2016 11:04:36 +0000 Subject: [PATCH 03/21] Publish installed packs in packs.install --- contrib/packs/actions/workflows/install.yaml | 2 ++ contrib/packs/aliases/pack_install.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/packs/actions/workflows/install.yaml b/contrib/packs/actions/workflows/install.yaml index d29d4cfd72..264d0a7dc7 100644 --- a/contrib/packs/actions/workflows/install.yaml +++ b/contrib/packs/actions/workflows/install.yaml @@ -5,6 +5,8 @@ ref: "packs.download" parameters: packs: "{{packs}}" + publish: + installed_packs: "{{ __results['download pack'].result }}" on-success: "make a prerun" - name: "make a prerun" diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml index be26f3e709..4197b18e5e 100644 --- a/contrib/packs/aliases/pack_install.yaml +++ b/contrib/packs/aliases/pack_install.yaml @@ -15,7 +15,7 @@ ack: result: format: | {% if execution.status == "succeeded" %} - Successful deployment of{% for pack in execution.result.packs %} *{{pack.name}}*{% endfor %}!{~} + Successful deployment of{% for pack in execution.result.installed_packs %} *{{pack.name}}*{% endfor %}!{~} {% else %} Deployment failed for *{{execution.parameters.packs}}*.{~} Please check {{ execution.id }} for details. From 7efb676e42ae25f6acfb1b2a82a71d0f20b1f225 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Sun, 30 Oct 2016 11:05:12 +0000 Subject: [PATCH 04/21] Remove packs.deploy and the associated actions --- .../packs/actions/check_auto_deploy_repo.py | 47 ----- .../packs/actions/check_auto_deploy_repo.yaml | 18 -- contrib/packs/actions/deploy.yaml | 45 ----- contrib/packs/actions/expand_repo_name.py | 42 ----- contrib/packs/actions/expand_repo_name.yaml | 14 -- contrib/packs/actions/workflows/deploy.yaml | 178 ------------------ contrib/packs/aliases/pack_deploy.yaml | 27 --- contrib/packs/aliases/show_git_clone.yaml | 17 -- 8 files changed, 388 deletions(-) delete mode 100755 contrib/packs/actions/check_auto_deploy_repo.py delete mode 100644 contrib/packs/actions/check_auto_deploy_repo.yaml delete mode 100644 contrib/packs/actions/deploy.yaml delete mode 100755 contrib/packs/actions/expand_repo_name.py delete mode 100644 contrib/packs/actions/expand_repo_name.yaml delete mode 100644 contrib/packs/actions/workflows/deploy.yaml delete mode 100644 contrib/packs/aliases/pack_deploy.yaml delete mode 100644 contrib/packs/aliases/show_git_clone.yaml diff --git a/contrib/packs/actions/check_auto_deploy_repo.py b/contrib/packs/actions/check_auto_deploy_repo.py deleted file mode 100755 index 4ac2244d1e..0000000000 --- a/contrib/packs/actions/check_auto_deploy_repo.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python - -# Licensed to the StackStorm, Inc ('StackStorm') under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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.runners.base_action import Action - - -class CheckAutoDeployRepo(Action): - def run(self, branch, repo_name): - """Returns the required data to complete an auto deployment of a pack in repo_name. - - The branch is expected to be in the format _refs/heads/foo_, if - it's not then the comprassion will fail. - - Returns: A Dict with deployment_branch and notify_channel. - - Raises: - ValueError: If the repo_name should not be auto deployed or - config is not complete. - """ - results = {} - - try: - repo_config = self.config["repositories"][repo_name] - results['deployment_branch'] = repo_config["auto_deployment"]["branch"] - results['notify_channel'] = repo_config["auto_deployment"]["notify_channel"] - except KeyError: - raise ValueError("No repositories or auto_deployment config for '%s'" % repo_name) - else: - if branch == "refs/heads/%s" % results['deployment_branch']: - return results - else: - raise ValueError("Branch %s for %s should not be auto deployed" % - (branch, repo_name)) diff --git a/contrib/packs/actions/check_auto_deploy_repo.yaml b/contrib/packs/actions/check_auto_deploy_repo.yaml deleted file mode 100644 index 6b57f54e79..0000000000 --- a/contrib/packs/actions/check_auto_deploy_repo.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- - description: "Check if a given branch in a ST2 Pack's Git repository should be auto deployed" - enabled: true - entry_point: 'check_auto_deploy_repo.py' - name: "check_auto_deploy_repo" - pack: "packs" - - parameters: - branch: - type: "string" - description: "The branch in the ST2 Packs Git repository" - required: true - repo_name: - type: "string" - description: "The repo_name to check for auto deployment." - required: true - - runner_type: "python-script" diff --git a/contrib/packs/actions/deploy.yaml b/contrib/packs/actions/deploy.yaml deleted file mode 100644 index d281be6631..0000000000 --- a/contrib/packs/actions/deploy.yaml +++ /dev/null @@ -1,45 +0,0 @@ ---- - description: "Deploy StackStorm Pack(s)" - enabled: true - entry_point: 'workflows/deploy.yaml' - - name: "deploy" - pack: "packs" - - parameters: - skip_notify: - default: - - "expand_git_url" - - "packs_install" - - "deloyment_success" - repo_name: - type: "string" - description: "The name of the repository to expand into an Git URL." - required: true - branch: - type: "string" - description: "The Branch to deploy." - default: "master" - packs: - type: "array" - description: "The Pack(s) to deploy." - default: [] - auto_deploy: - type: "boolean" - description: "Should this pack and branch be evulated for auto deployment." - default: false - message: - type: "string" - description: "The message for the commit" - default: ~ - author: - type: "string" - description: "The author of the commit" - default: ~ - - workflow: - default: packs.deploy.entry - immutable: true - type: string - - runner_type: "mistral-v2" diff --git a/contrib/packs/actions/expand_repo_name.py b/contrib/packs/actions/expand_repo_name.py deleted file mode 100755 index c6bc55eb5d..0000000000 --- a/contrib/packs/actions/expand_repo_name.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -# Licensed to the StackStorm, Inc ('StackStorm') under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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.runners.base_action import Action - - -class ExpandRepoName(Action): - def run(self, repo_name): - """Returns the data required to install packs from repo_name. - - Keyword arguments: - repo_name -- The Reposistory name to look up in the Packs config.yaml. - - Returns: A Dict containing repo_url and subtree. - - Raises: - ValueError: If the supplied repo_name is present (or complete). - """ - # Set up the results object - results = {} - - try: - results['repo_url'] = self.config["repositories"][repo_name]["repo"] - results['subtree'] = self.config["repositories"][repo_name]["subtree"] - except KeyError: - raise ValueError("Missing repositories config for '%s'" % repo_name) - else: - return results diff --git a/contrib/packs/actions/expand_repo_name.yaml b/contrib/packs/actions/expand_repo_name.yaml deleted file mode 100644 index 84b23a6cbb..0000000000 --- a/contrib/packs/actions/expand_repo_name.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- - description: "For supplied ST2 pack Repo return the Git URL and if it has a subtree." - enabled: true - entry_point: 'expand_repo_name.py' - name: "expand_repo_name" - pack: "packs" - - parameters: - repo_name: - type: "string" - description: "The ST2 Git Repo Name to expanded to a full git URL" - required: true - - runner_type: "python-script" diff --git a/contrib/packs/actions/workflows/deploy.yaml b/contrib/packs/actions/workflows/deploy.yaml deleted file mode 100644 index 745258db2d..0000000000 --- a/contrib/packs/actions/workflows/deploy.yaml +++ /dev/null @@ -1,178 +0,0 @@ ---- -version: '2.0' -name: packs.deploy -description: A workflow to handle ST2 pack deloyments. - -workflows: - - entry: - type: direct - input: - - packs - - repo_name - - branch - - message - - author - - auto_deploy - - output: - repo_url: <% $.repo_url %> - branch: <% $.branch %> - packs: <% $.packs %> - - tasks: - auto_or_manual: - action: core.noop - - on-complete: - - do_auto_install: <% $.auto_deploy = true %> - - check_for_no_subtree: <% $.auto_deploy = false %> - - check_for_no_subtree: - action: core.noop - - # If packs has 0 len, call publish_packs so that packs is - # contains the right value. - on-complete: - - do_manual_install: <% len($.packs) != 0 %> - - publish_packs: <% len($.packs) = 0 %> - - publish_packs: - action: core.noop - - # If a pack is not contained in a subtree, we should replace - # the empty packs array with with an array that contains the - # repo_name. - publish: - packs: [ <% $.repo_name %> ] - - on-complete: - - do_manual_install - - do_manual_install: - workflow: install - - input: - repo_name: <% $.repo_name %> - branch: <% $.branch %> - packs: <% $.packs %> - - publish: - repo_url: <% task(do_manual_install).result.repo_url %> - pack: <% task(do_manual_install).result.pack %> - - do_auto_install: - workflow: auto_install - - input: - branch: <% $.branch %> - repo_name: <% $.repo_name %> - message: <% $.message %> - author: <% $.author %> - - publish: - repo_url: <% task(do_auto_install).result.repo_url %> - pack: <% task(do_auto_install).result.pack %> - - auto_install: - type: direct - input: - - branch - - repo_name - - message - - author - - output: - repo_url: <% $.repo_url %> - pack: <% $.pack %> - - tasks: - check_auto_deploy_repo: - # [365, 26] - action: packs.check_auto_deploy_repo - - input: - branch: <% $.branch %> - repo_name: <% $.repo_name %> - - publish: - notify_channel: <% task(check_auto_deploy_repo).result.result.notify_channel %> - deployment_branch: <% task(check_auto_deploy_repo).result.result.deployment_branch %> - - on-success: - - auto_deploy_install - - on-error: - - no_auto_deploy - - auto_deploy_install: - # [235, 128] - workflow: install - - input: - repo_name: <% $.repo_name %> - packs: [ <% $.repo_name %> ] - branch: <% $.deployment_branch %> - - publish: - repo_url: <% task(auto_deploy_install).result.repo_url %> - pack: <% task(auto_deploy_install).result.pack %> - - on-success: - - notify_success - on-error: - - notify_failure - - notify_failure: - # [365, 230] - action: chatops.post_message - input: - channel: <% $.notify_channel %> - message: "Failure in auto deployment of *<% $.repo_name %>* (branch: _<% $.deployment_branch %>_) triggered via commit by _<% $.author %>_!{~}```<% $.message %>```" - - notify_success: - # [105, 230] - action: chatops.post_message - input: - channel: <% $.notify_channel %> - message: "Auto deployment of *<% $.repo_name %>* (branch: _<% $.deployment_branch %>_) triggered via commit by _<% $.author %>_!{~}```<% $.message %>```" - - no_auto_deploy: - # [495, 128] - action: core.noop - - publish: - repo_url: ~ - pack: ~ - - install: - type: direct - input: - - repo_name - - branch - - packs - - output: - repo_url: <% $.repo_url %> - pack: <% $.packs %> - - tasks: - expand_repo_name: - action: packs.expand_repo_name - input: - repo_name: <% $.repo_name %> - - publish: - repo_url: <% task(expand_repo_name).result.result.repo_url %> - subtree: <% task(expand_repo_name).result.result.subtree %> - - on-success: - - packs_install - - packs_install: - action: packs.install - input: - packs: <% $.packs %> - repo_url: <% $.repo_url %> - branch: <% $.branch %> - subtree: <% $.subtree %> diff --git a/contrib/packs/aliases/pack_deploy.yaml b/contrib/packs/aliases/pack_deploy.yaml deleted file mode 100644 index edbbba4e01..0000000000 --- a/contrib/packs/aliases/pack_deploy.yaml +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: "pack_deploy" -action_ref: "packs.deploy" -pack: "packs" -description: "Download StackStorm packs via ChatOps" -formats: - - display: "pack deploy [packs ] [branch ]" - representation: - - "pack deploy {{repo_name}} packs {{packs}} branch {{branch}}" - - "pack deploy {{repo_name}} packs {{packs}}" - - display: "pack deploy [branch ]" - representation: - - "pack deploy {{repo_name}} branch {{branch=master}}" - - "pack deploy {{repo_name}}" -ack: - enabled: true - append_url: false - format: "Deploying the requested pack(s) from *{{execution.parameters.repo_name}}* for you...." -result: - format: | - {% if execution.status == "succeeded" %} - Successful deployment of {% for pack in execution.result.packs %}*{{pack}}* {% endfor %}!{~} - from {{ execution.result.repo_url }} (branch: _{{ execution.result.branch }}_). - {% else %} - Deployment failed of packs from *{{execution.parameters.repo_name}}*.{~} - Please check {{ execution.id }} for details. - {% endif %} diff --git a/contrib/packs/aliases/show_git_clone.yaml b/contrib/packs/aliases/show_git_clone.yaml deleted file mode 100644 index 4e09b63a08..0000000000 --- a/contrib/packs/aliases/show_git_clone.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: "show_git_clone" -pack: "packs" -description: "Show the Git clone command for a given pack" -action_ref: "packs.expand_repo_name" -formats: - - "show git clone {{repo_name}}" -ack: - enabled: false -result: - format: | - {% if execution.status == "succeeded" %} - The following will clone this Repository:{~} - ```git clone {{ execution.result.result.repo_url }}``` - {% else %} - Sorry I don't know about that Git Repository: `{{ execution.parameters.repo_name }}`.{~} - {% endif %} From f603dafd93d7ef32a2e02f69a4ac4fdac26e5c41 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Sun, 30 Oct 2016 11:05:35 +0000 Subject: [PATCH 05/21] Somehow there's an action from the linux pack here. Oh well. --- contrib/packs/linux/actions/sleep_until.yaml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 contrib/packs/linux/actions/sleep_until.yaml diff --git a/contrib/packs/linux/actions/sleep_until.yaml b/contrib/packs/linux/actions/sleep_until.yaml deleted file mode 100644 index 37f48cd9f7..0000000000 --- a/contrib/packs/linux/actions/sleep_until.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: "sleep_until" -pack: "linux" -description: "Sleeps until a specified time" -enabled: true - -runner_type: "local-shell-cmd" -entry_point: "" - -parameters: - time: - type: string - description: 'the time to wake up; must be smaller than the action timeout; must be parsable by "date -d" like "5pm today" or "Thu May 19 18:04:39 UTC 2016"' - required: true - cmd: - default: 'sleep $(expr `date -d "{{ time }}" +%s` - `date -d "now" +%s`)' - immutable: true From 2f6a734834903728bf25bce4e94de6160bd5f414 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Mon, 31 Oct 2016 15:25:31 +0700 Subject: [PATCH 06/21] Lookups --- contrib/packs/actions/lookup.meta.yaml | 21 ++++++ .../actions/{info.yaml => lookup_local.yaml} | 6 +- contrib/packs/actions/lookup_remote.yaml | 11 +++ .../pack_mgmt/{info.py => lookup_local.py} | 3 +- .../packs/actions/pack_mgmt/lookup_remote.py | 32 +++++++++ contrib/packs/actions/workflows/lookup.yaml | 21 ++++++ contrib/packs/aliases/pack_info.yaml | 28 -------- contrib/packs/aliases/pack_install.yaml | 2 +- contrib/packs/aliases/pack_show.yaml | 72 +++++++++++++++++++ 9 files changed, 162 insertions(+), 34 deletions(-) create mode 100644 contrib/packs/actions/lookup.meta.yaml rename contrib/packs/actions/{info.yaml => lookup_local.yaml} (56%) create mode 100644 contrib/packs/actions/lookup_remote.yaml rename contrib/packs/actions/pack_mgmt/{info.py => lookup_local.py} (98%) create mode 100644 contrib/packs/actions/pack_mgmt/lookup_remote.py create mode 100644 contrib/packs/actions/workflows/lookup.yaml delete mode 100644 contrib/packs/aliases/pack_info.yaml create mode 100644 contrib/packs/aliases/pack_show.yaml diff --git a/contrib/packs/actions/lookup.meta.yaml b/contrib/packs/actions/lookup.meta.yaml new file mode 100644 index 0000000000..3aac5c5151 --- /dev/null +++ b/contrib/packs/actions/lookup.meta.yaml @@ -0,0 +1,21 @@ +--- + name: "lookup" + runner_type: "action-chain" + description: "Will get pack information from the Exchange index and the list + of currently installed packs. This action is mostly meant to be + launched through its ChatOps alias." + enabled: true + entry_point: "workflows/lookup.yaml" + parameters: + pack: + type: "string" + description: "Pack name" + required: true + location: + type: "string" + description: "Primary source of information: installed packs or the pack + index." + enum: + - "available" + - "installed" + required: true diff --git a/contrib/packs/actions/info.yaml b/contrib/packs/actions/lookup_local.yaml similarity index 56% rename from contrib/packs/actions/info.yaml rename to contrib/packs/actions/lookup_local.yaml index 152895eb3a..3367e1fb03 100644 --- a/contrib/packs/actions/info.yaml +++ b/contrib/packs/actions/lookup_local.yaml @@ -1,9 +1,9 @@ --- -name: "info" +name: "lookup_local" runner_type: "python-script" -description: "Get currently deployed pack information" +description: "Get information about an installed pack" enabled: true -entry_point: "pack_mgmt/info.py" +entry_point: "pack_mgmt/lookup_local.py" parameters: pack: type: "string" diff --git a/contrib/packs/actions/lookup_remote.yaml b/contrib/packs/actions/lookup_remote.yaml new file mode 100644 index 0000000000..3335d512a0 --- /dev/null +++ b/contrib/packs/actions/lookup_remote.yaml @@ -0,0 +1,11 @@ +--- +name: "lookup_remote" +runner_type: "python-script" +description: "Get information about a pack in the StackStorm Exchange index" +enabled: true +entry_point: "pack_mgmt/lookup_remote.py" +parameters: + pack: + type: "string" + description: "Name of pack to introspect" + required: true diff --git a/contrib/packs/actions/pack_mgmt/info.py b/contrib/packs/actions/pack_mgmt/lookup_local.py similarity index 98% rename from contrib/packs/actions/pack_mgmt/info.py rename to contrib/packs/actions/pack_mgmt/lookup_local.py index ef3df09250..61e47b78d8 100644 --- a/contrib/packs/actions/pack_mgmt/info.py +++ b/contrib/packs/actions/pack_mgmt/lookup_local.py @@ -14,7 +14,6 @@ # limitations under the License. import os -import yaml from git.repo import Repo from gitdb.exc import InvalidGitRepositoryError @@ -25,7 +24,7 @@ MANIFEST_FILE = 'pack.yaml' -class PackInfo(Action): +class LookupLocal(Action): def run(self, pack): packs_base_paths = get_packs_base_paths() diff --git a/contrib/packs/actions/pack_mgmt/lookup_remote.py b/contrib/packs/actions/pack_mgmt/lookup_remote.py new file mode 100644 index 0000000000..be4282d433 --- /dev/null +++ b/contrib/packs/actions/pack_mgmt/lookup_remote.py @@ -0,0 +1,32 @@ +# Licensed to the StackStorm, Inc ('StackStorm') under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 yaml + +from st2common.runners.base_action import Action +from st2common.services.packs import get_pack_from_index + +MANIFEST_FILE = 'pack.yaml' + + +class LookupRemote(Action): + def run(self, pack): + index_pack = get_pack_from_index(pack) + return { + 'pack': index_pack, + # Would be nice to fetch the original pack.yaml from the index repo, + # but then we would lose support for user-created indexes. + 'pack_formatted': yaml.dump(index_pack) if index_pack else None + } diff --git a/contrib/packs/actions/workflows/lookup.yaml b/contrib/packs/actions/workflows/lookup.yaml new file mode 100644 index 0000000000..7ae1f3ff21 --- /dev/null +++ b/contrib/packs/actions/workflows/lookup.yaml @@ -0,0 +1,21 @@ +--- + chain: + - + name: "local lookup" + ref: "packs.local_lookup" + parameters: + pack: "{{pack}}" + publish: + pack: "{{ __results['local lookup'].result.pack }}" + git_status: "{{ __results['local lookup'].result.git_status }}" + on-success: "index lookup" + - + name: "index lookup" + ref: "packs.index_lookup" + parameters: + pack: "{{pack}}" + publish: + available: "{{ __results['index lookup'].result.pack_formatted }}" + repo_url: "{{ __results['index lookup'].result.pack.repo_url }}" + + default: "local lookup" diff --git a/contrib/packs/aliases/pack_info.yaml b/contrib/packs/aliases/pack_info.yaml deleted file mode 100644 index 3701058e7a..0000000000 --- a/contrib/packs/aliases/pack_info.yaml +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: "pack_info" -action_ref: "packs.info" -description: "Get StackStorm pack information via ChatOps" -formats: - - "pack info {{pack}}" -ack: - enabled: false -result: - format: | - {% if execution.status == "succeeded" %} - All the details on your pack: - ``` - {{ execution.result.pack }} - ``` - {% if execution.result.git_status %} - And here's what git says: - ``` - {{ execution.result.git_status }} - ``` - {% else %} - It does not appear to be a git repository though. - {% endif %} - {~} - {% else %} - Deployment failed for *{{execution.parameters.packs}}*.{~} - Please check {{ execution.id }} for details. - {% endif %} diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml index 4197b18e5e..71ca947cee 100644 --- a/contrib/packs/aliases/pack_install.yaml +++ b/contrib/packs/aliases/pack_install.yaml @@ -2,7 +2,7 @@ name: "pack_install" action_ref: "packs.install" pack: "packs" -description: "Install StackStorm packs (pack = name or git URL, gitref = tag/branch/commit)." +description: "Install/update StackStorm packs (pack = name or git URL, gitref = tag/branch/commit)." formats: - display: "pack install [,]" - display: "pack install #[,]" diff --git a/contrib/packs/aliases/pack_show.yaml b/contrib/packs/aliases/pack_show.yaml new file mode 100644 index 0000000000..5c8181b59b --- /dev/null +++ b/contrib/packs/aliases/pack_show.yaml @@ -0,0 +1,72 @@ +--- +name: "pack_show" +action_ref: "packs.lookup" +description: "Get information about a StackStorm pack, either installed or available through the Exchange" +formats: + - display: "pack show [available] {{ pack }}" + representation: + - "pack show {{ pack }}" + - "pack show available {{ pack }}({{ location="available" }}){0}" + +ack: + enabled: false +result: + format: | + {% if execution.status == "succeeded" %} + {% if execution.parameters.location == "installed" %} + Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} + {% if execution.result.pack %} + Full metadata: + ``` + {{ execution.result.pack }} + ``` + {% if execution.result.git_status %} + + Git status: + ``` + {{ execution.result.git_status }} + ``` + {% else %} + This pack does not appear to be a git repository though. + {% endif %} + {% else %} + Couldn't locate it in your installed packs. + {% if not execution.result.available %} + It's not on StackStorm Exchange either. What a sad world. + {% endif %} + {% endif %} + {% if execution.result.available %} + + StackStorm Exchange has an entry for this pack. You can take a look: + ``` + pack show available {{ execution.parameters.pack }} + ``` + {% if not execution.result.pack %} + Or ask me to install it for you right away: + ``` + pack install {{ execution.parameters.pack }} + ``` + {% endif %} + {% endif %} + {% else %} + Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} + {% if execution.result.available %} + Here's the full index entry for the pack: + ``` + {{ execution.result.available }} + ``` + Its source code is available at {{ execution.result.repo_url }}. + + To install the pack, just ask me: + ``` + pack install {{ execution.parameters.pack }} + ``` + If the pack is already installed, I will overwrite it with the latest version, keeping the config. + {% else %} + There's nothing like that on StackStorm Exchange. + I know how sad it is, but life goes on. Cheer up! + {% endif %} + {% endif %} + {% else %} + Couldn't locate *{{execution.parameters.pack}}*. :({~} + {% endif %} From b71db46bc860de3e0fecdbe6a824e3e76b7ad49f Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Mon, 31 Oct 2016 17:20:01 +0700 Subject: [PATCH 07/21] Getting yaml from the index --- .../packs/actions/pack_mgmt/lookup_remote.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/contrib/packs/actions/pack_mgmt/lookup_remote.py b/contrib/packs/actions/pack_mgmt/lookup_remote.py index be4282d433..805ff9f8ed 100644 --- a/contrib/packs/actions/pack_mgmt/lookup_remote.py +++ b/contrib/packs/actions/pack_mgmt/lookup_remote.py @@ -13,20 +13,33 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re + import yaml +import requests from st2common.runners.base_action import Action from st2common.services.packs import get_pack_from_index MANIFEST_FILE = 'pack.yaml' +EXCHANGE_REPO_URL_REGEX = r'(git@|https?://)github\.com[/:]StackStorm-Exchange/stackstorm-\S+' +EXCHANGE_YAML_PATH = 'https://index.stackstorm.org/v1/packs/%s.yaml' class LookupRemote(Action): def run(self, pack): - index_pack = get_pack_from_index(pack) + pack_meta = get_pack_from_index(pack) + pack_formatted = None + # Try to get the original yaml file because we know + # how it's stored in the Exchange, otherwise fall back + # to transforming json. + if pack_meta: + if re.match(EXCHANGE_REPO_URL_REGEX, pack_meta['repo_url'], re.IGNORECASE): + pack_formatted = requests.get(EXCHANGE_YAML_PATH % pack).text + else: + pack_formatted = yaml.dump(pack_meta) + return { - 'pack': index_pack, - # Would be nice to fetch the original pack.yaml from the index repo, - # but then we would lose support for user-created indexes. - 'pack_formatted': yaml.dump(index_pack) if index_pack else None + 'pack': pack_meta, + 'pack_formatted': pack_formatted } From cc598c61f4e5ce67fe8cbd2c9dbd3e591bfc3bc4 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Mon, 31 Oct 2016 18:09:02 +0700 Subject: [PATCH 08/21] Add action and alias for index search --- contrib/packs/actions/pack_mgmt/search.py | 23 +++++++++++++++ contrib/packs/actions/search.yaml | 11 ++++++++ contrib/packs/aliases/pack_install.yaml | 6 ++-- contrib/packs/aliases/pack_search.yaml | 34 +++++++++++++++++++++++ 4 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 contrib/packs/actions/pack_mgmt/search.py create mode 100644 contrib/packs/actions/search.yaml create mode 100644 contrib/packs/aliases/pack_search.yaml diff --git a/contrib/packs/actions/pack_mgmt/search.py b/contrib/packs/actions/pack_mgmt/search.py new file mode 100644 index 0000000000..ce334c474c --- /dev/null +++ b/contrib/packs/actions/pack_mgmt/search.py @@ -0,0 +1,23 @@ +# Licensed to the StackStorm, Inc ('StackStorm') under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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.runners.base_action import Action +from st2common.services.packs import search_pack_index + + +class PackSearch(Action): + def run(self, query): + # Yup. That's all folks! + return search_pack_index(query) diff --git a/contrib/packs/actions/search.yaml b/contrib/packs/actions/search.yaml new file mode 100644 index 0000000000..8a59547d39 --- /dev/null +++ b/contrib/packs/actions/search.yaml @@ -0,0 +1,11 @@ +--- +name: "search" +runner_type: "python-script" +description: "Get information about a pack in the StackStorm Exchange index" +enabled: true +entry_point: "pack_mgmt/search.py" +parameters: + query: + type: "string" + description: "A word or a phrase to search for." + required: true diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml index 71ca947cee..f063710e05 100644 --- a/contrib/packs/aliases/pack_install.yaml +++ b/contrib/packs/aliases/pack_install.yaml @@ -15,8 +15,8 @@ ack: result: format: | {% if execution.status == "succeeded" %} - Successful deployment of{% for pack in execution.result.installed_packs %} *{{pack.name}}*{% endfor %}!{~} + Successful deployment of{% for pack in execution.result.installed_packs %} *{{pack.name}}*{% endfor %}!{~} {% else %} - Deployment failed for *{{execution.parameters.packs}}*.{~} - Please check {{ execution.id }} for details. + Deployment failed for *{{execution.parameters.packs}}*.{~} + Please check {{ execution.id }} for details. {% endif %} diff --git a/contrib/packs/aliases/pack_search.yaml b/contrib/packs/aliases/pack_search.yaml new file mode 100644 index 0000000000..3bf90f2432 --- /dev/null +++ b/contrib/packs/aliases/pack_search.yaml @@ -0,0 +1,34 @@ +--- +name: "pack_search" +action_ref: "packs.search" +pack: "packs" +description: "Search for packs in the StackStorm Exchange index." +formats: + - display: "pack search " + representation: + - "pack search {{ query }}" +ack: + enabled: true + append_url: false + format: "Alright! Let me check if that matches anything in the pack index." +result: + format: | + {% if execution.status == "succeeded" %} + {% if execution.result %} + Got something for you!{~} + {% for pack in execution.result %} + • *{{ pack.name }}*: {{ pack.description }} + {% endfor %} + + I can tell you more about a particular pack, or even get it installed for you right away: + ``` + pack show available + pack install + ``` + {% else %} + I couldn't get any results for `{{ execution.parameters.query }}`, unfortunately. + {% endif %} + {% else %} + Search failed for `{{ execution.parameters.query }}`.{~} + Please check {{ execution.id }} for details. Index problems maybe? + {% endif %} From adac4422a033fa9875deca7ac833cdbeafed06f7 Mon Sep 17 00:00:00 2001 From: Edward Medvedev Date: Thu, 3 Nov 2016 20:44:09 +0700 Subject: [PATCH 09/21] Rewrite the descriptions --- contrib/packs/actions/install.meta.yaml | 13 +++++++++---- contrib/packs/actions/lookup.meta.yaml | 2 +- contrib/packs/actions/lookup_remote.yaml | 2 +- contrib/packs/actions/search.yaml | 2 +- contrib/packs/aliases/pack_install.yaml | 2 +- contrib/packs/aliases/pack_search.yaml | 2 +- contrib/packs/aliases/pack_show.yaml | 10 +++++----- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/contrib/packs/actions/install.meta.yaml b/contrib/packs/actions/install.meta.yaml index c2c4b6b612..7670d1645f 100644 --- a/contrib/packs/actions/install.meta.yaml +++ b/contrib/packs/actions/install.meta.yaml @@ -1,9 +1,10 @@ --- name: "install" runner_type: "action-chain" - description: "Installs a pack from StackStorm Exchange into local content repository. + description: "Installs or upgrades a pack into local content repository, either by + git URL or a short name matching an index entry. Will download pack, load the actions, sensors and rules from the pack. - Note that install require reboot of some st2 services." + Note that install requires reboot of some st2 services." enabled: true entry_point: "workflows/install.yaml" parameters: @@ -12,12 +13,16 @@ items: type: "string" required: true - description: "Name of the pack in Exchange or a git repo URL" + description: "Name of the pack in Exchange or a git repo URL." register: type: "string" default: "actions,aliases,sensors,triggers" description: "Possible options are all, triggers, sensors, actions, rules, aliases." + upgrade: + type: "boolean" + default: false + description: "Upgrade the pack if already installed." env: type: "object" - description: "Optional environment variables" + description: "Optional environment variables." required: false diff --git a/contrib/packs/actions/lookup.meta.yaml b/contrib/packs/actions/lookup.meta.yaml index 3aac5c5151..676d3408de 100644 --- a/contrib/packs/actions/lookup.meta.yaml +++ b/contrib/packs/actions/lookup.meta.yaml @@ -1,7 +1,7 @@ --- name: "lookup" runner_type: "action-chain" - description: "Will get pack information from the Exchange index and the list + description: "Will get information about a pack from both the index and the list of currently installed packs. This action is mostly meant to be launched through its ChatOps alias." enabled: true diff --git a/contrib/packs/actions/lookup_remote.yaml b/contrib/packs/actions/lookup_remote.yaml index 3335d512a0..007a0a80a6 100644 --- a/contrib/packs/actions/lookup_remote.yaml +++ b/contrib/packs/actions/lookup_remote.yaml @@ -1,7 +1,7 @@ --- name: "lookup_remote" runner_type: "python-script" -description: "Get information about a pack in the StackStorm Exchange index" +description: "Get detailed information about an available pack from the pack index" enabled: true entry_point: "pack_mgmt/lookup_remote.py" parameters: diff --git a/contrib/packs/actions/search.yaml b/contrib/packs/actions/search.yaml index 8a59547d39..32c549a260 100644 --- a/contrib/packs/actions/search.yaml +++ b/contrib/packs/actions/search.yaml @@ -1,7 +1,7 @@ --- name: "search" runner_type: "python-script" -description: "Get information about a pack in the StackStorm Exchange index" +description: "Search the index for a pack with any attribute matching the query." enabled: true entry_point: "pack_mgmt/search.py" parameters: diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml index f063710e05..3dc3e505a2 100644 --- a/contrib/packs/aliases/pack_install.yaml +++ b/contrib/packs/aliases/pack_install.yaml @@ -2,7 +2,7 @@ name: "pack_install" action_ref: "packs.install" pack: "packs" -description: "Install/update StackStorm packs (pack = name or git URL, gitref = tag/branch/commit)." +description: "Install/upgrade StackStorm packs (pack = name or git URL, gitref = tag/branch/commit)." formats: - display: "pack install [,]" - display: "pack install #[,]" diff --git a/contrib/packs/aliases/pack_search.yaml b/contrib/packs/aliases/pack_search.yaml index 3bf90f2432..92b745f216 100644 --- a/contrib/packs/aliases/pack_search.yaml +++ b/contrib/packs/aliases/pack_search.yaml @@ -2,7 +2,7 @@ name: "pack_search" action_ref: "packs.search" pack: "packs" -description: "Search for packs in the StackStorm Exchange index." +description: "Search for packs in StackStorm Exchange and other directories." formats: - display: "pack search " representation: diff --git a/contrib/packs/aliases/pack_show.yaml b/contrib/packs/aliases/pack_show.yaml index 5c8181b59b..632403d46e 100644 --- a/contrib/packs/aliases/pack_show.yaml +++ b/contrib/packs/aliases/pack_show.yaml @@ -1,7 +1,7 @@ --- name: "pack_show" action_ref: "packs.lookup" -description: "Get information about a StackStorm pack, either installed or available through the Exchange" +description: "Get information about a StackStorm pack: either installed or availble" formats: - display: "pack show [available] {{ pack }}" representation: @@ -30,14 +30,14 @@ result: This pack does not appear to be a git repository though. {% endif %} {% else %} - Couldn't locate it in your installed packs. + It looks like there is no installed pack with this name. {% if not execution.result.available %} It's not on StackStorm Exchange either. What a sad world. {% endif %} {% endif %} {% if execution.result.available %} - StackStorm Exchange has an entry for this pack. You can take a look: + This pack is available in the pack directory. You can take a look: ``` pack show available {{ execution.parameters.pack }} ``` @@ -61,9 +61,9 @@ result: ``` pack install {{ execution.parameters.pack }} ``` - If the pack is already installed, I will overwrite it with the latest version, keeping the config. + If the pack is already installed, I will upgrade it to the latest version, keeping the config. {% else %} - There's nothing like that on StackStorm Exchange. + There's nothing like that in the pack index. I know how sad it is, but life goes on. Cheer up! {% endif %} {% endif %} From 7a5c113bf407539efa60d70d415cbe14b248217f Mon Sep 17 00:00:00 2001 From: armab Date: Wed, 23 Nov 2016 18:49:06 +0200 Subject: [PATCH 10/21] Fix pack_show.yaml alias Jinja formatting error --- contrib/packs/aliases/pack_show.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/packs/aliases/pack_show.yaml b/contrib/packs/aliases/pack_show.yaml index 632403d46e..5e29a6334b 100644 --- a/contrib/packs/aliases/pack_show.yaml +++ b/contrib/packs/aliases/pack_show.yaml @@ -6,7 +6,7 @@ formats: - display: "pack show [available] {{ pack }}" representation: - "pack show {{ pack }}" - - "pack show available {{ pack }}({{ location="available" }}){0}" + - "pack show available {{ pack }}({{ location='available' }}){0}" ack: enabled: false From cd7203c07f995eb239631f2105ebeccdc3ddcf88 Mon Sep 17 00:00:00 2001 From: armab Date: Wed, 23 Nov 2016 22:09:42 +0200 Subject: [PATCH 11/21] Remove obsolete tests first --- contrib/packs/tests/test_action_aliases.py | 105 ------------------ .../test_action_check_auto_deploy_repo.py | 82 -------------- .../tests/test_action_expand_repo_name.py | 65 ----------- 3 files changed, 252 deletions(-) delete mode 100644 contrib/packs/tests/test_action_check_auto_deploy_repo.py delete mode 100644 contrib/packs/tests/test_action_expand_repo_name.py diff --git a/contrib/packs/tests/test_action_aliases.py b/contrib/packs/tests/test_action_aliases.py index e76bea4335..16ff4aab99 100644 --- a/contrib/packs/tests/test_action_aliases.py +++ b/contrib/packs/tests/test_action_aliases.py @@ -1,106 +1 @@ from st2tests.base import BaseActionAliasTestCase - - -class DeployActionAliasTestCase(BaseActionAliasTestCase): - action_alias_name = 'pack_deploy' - - def test_pack_deploy_alias(self): - # Includes packs - format_string = self.action_alias_db.formats[0]['representation'][0] - - # Command with branch - command = 'pack deploy StackStorm/st2contrib packs libcloud,aws branch master' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib', - 'packs': 'libcloud,aws', - 'branch': 'master' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - command = 'pack deploy StackStorm/st2contrib packs libcloud branch ma_branch' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib', - 'packs': 'libcloud', - 'branch': 'ma_branch' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - # Command without branch - format_string = self.action_alias_db.formats[0]['representation'][1] - command = 'pack deploy StackStorm/st2contrib packs libcloud,aws' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib', - 'packs': 'libcloud,aws' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - command = 'pack deploy StackStorm/st2contrib packs libcloud' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib', - 'packs': 'libcloud' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - # Doesnt include packs - format_string = self.action_alias_db.formats[1]['representation'][0] - command = 'pack deploy StackStorm/st2contrib branch trunk' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib', - 'branch': 'trunk' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - format_string = self.action_alias_db.formats[1]['representation'][1] - command = 'pack deploy StackStorm/st2contrib' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - -class PackInfoActionAliasTestCase(BaseActionAliasTestCase): - action_alias_name = 'pack_info' - - def test_pack_info_alias(self): - format_string = self.action_alias_db.formats[0] - command = 'pack info libcloud' - expected_parameters = { - 'pack': 'libcloud' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - command = 'pack info aws' - expected_parameters = { - 'pack': 'aws' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) - - -class ShowGitCloneActionAliasTestCase(BaseActionAliasTestCase): - action_alias_name = 'show_git_clone' - - def test_show_git_cline(self): - format_string = self.action_alias_db.formats[0] - command = 'show git clone StackStorm/st2contrib' - expected_parameters = { - 'repo_name': 'StackStorm/st2contrib' - } - self.assertExtractedParametersMatch(format_string=format_string, - command=command, - parameters=expected_parameters) diff --git a/contrib/packs/tests/test_action_check_auto_deploy_repo.py b/contrib/packs/tests/test_action_check_auto_deploy_repo.py deleted file mode 100644 index 9b1b8752b8..0000000000 --- a/contrib/packs/tests/test_action_check_auto_deploy_repo.py +++ /dev/null @@ -1,82 +0,0 @@ -import yaml - -from st2tests.base import BaseActionTestCase - -from check_auto_deploy_repo import CheckAutoDeployRepo - -__all__ = [ - 'CheckAutoDeployRepoActionTestCase' -] - -MOCK_DATA_1 = { "deployment_branch": "master", "notify_channel": "community" } - -MOCK_CONFIG_BLANK = "" - -MOCK_CONFIG_BLANK_REPOSITORIES = "repositories:" - -MOCK_CONFIG_FULL= """ -repositories: - st2contrib: - repo: "https://github.com/StackStorm/st2contrib.git" - subtree: true - auto_deployment: - branch: "master" - notify_channel: "community" - - st2incubator: - repo: "https://github.com/StackStorm/st2incubator.git" - subtree: true - auto_deployment: - branch: "master" - notify_channel: "community" -""" - -class CheckAutoDeployRepoActionTestCase(BaseActionTestCase): - action_cls = CheckAutoDeployRepo - - def test_run_config_blank(self): - config = yaml.safe_load(MOCK_CONFIG_BLANK) - action = self.get_action_instance(config=config) - - self.assertRaises(Exception, action.run, - branch="refs/heads/master", repo_name="st2contrib") - - def test_run_repositories_blank(self): - config = yaml.safe_load(MOCK_CONFIG_BLANK_REPOSITORIES) - action = self.get_action_instance(config=config) - - self.assertRaises(Exception, action.run, - branch="refs/heads/master", repo_name="st2contrib") - - def test_run_st2contrib_no_auto_deloy(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = self.get_action_instance(config=config) - - self.assertRaises(Exception, action.run, - branch="refs/heads/dev", repo_name="st2contrib") - - def test_run_st2contrib_auto_deloy(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = self.get_action_instance(config=config) - - expected = {'deployment_branch': 'master', 'notify_channel': 'community'} - - result = action.run(branch="refs/heads/master", repo_name="st2contrib") - self.assertEqual(result, expected) - - - def test_run_st2incubator_no_auto_deloy(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = CheckAutoDeployRepo(config) - - self.assertRaises(Exception, action.run, - branch="refs/heads/dev", repo_name="st2incubator") - - def test_run_st2incubator_auto_deloy(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = self.get_action_instance(config=config) - - expected = {'deployment_branch': 'master', 'notify_channel': 'community'} - - result = action.run(branch="refs/heads/master", repo_name="st2incubator") - self.assertEqual(result, expected) diff --git a/contrib/packs/tests/test_action_expand_repo_name.py b/contrib/packs/tests/test_action_expand_repo_name.py deleted file mode 100644 index c2d4088a79..0000000000 --- a/contrib/packs/tests/test_action_expand_repo_name.py +++ /dev/null @@ -1,65 +0,0 @@ -import yaml - -from st2tests.base import BaseActionTestCase - -from expand_repo_name import ExpandRepoName - -__all__ = [ - 'ExpandRepoNameTestCase' -] - -MOCK_CONFIG_BLANK = "" - -MOCK_CONFIG_BLANK_REPOSITORIES = "repositories:" - -MOCK_CONFIG_FULL= """ -repositories: - st2contrib: - repo: "https://github.com/StackStorm/st2contrib.git" - subtree: true - auto_deployment: - branch: "master" - notify_channel: "community" - - st2incubator: - repo: "https://github.com/StackStorm/st2incubator.git" - subtree: true - auto_deployment: - branch: "master" - notify_channel: "community" -""" - -class ExpandRepoNameTestCase(BaseActionTestCase): - action_cls = ExpandRepoName - - def test_run_config_blank(self): - config = yaml.safe_load(MOCK_CONFIG_BLANK) - action = self.get_action_instance(config=config) - - self.assertRaises(Exception, action.run, - repo_name="st2contrib") - - def test_run_repositories_blank(self): - config = yaml.safe_load(MOCK_CONFIG_BLANK_REPOSITORIES) - action = self.get_action_instance(config=config) - - self.assertRaises(Exception, action.run, - repo_name="st2contrib") - - def test_run_st2contrib_expands(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = self.get_action_instance(config=config) - - expected = {'repo_url': 'https://github.com/StackStorm/st2contrib.git', 'subtree': True} - - result = action.run(repo_name="st2contrib") - self.assertEqual(result, expected) - - def test_run_st2incubator_expands(self): - config = yaml.safe_load(MOCK_CONFIG_FULL) - action = self.get_action_instance(config=config) - - expected = {'repo_url': 'https://github.com/StackStorm/st2incubator.git', 'subtree': True} - - result = action.run(repo_name="st2incubator") - self.assertEqual(result, expected) From 77aefa67a5a422fd98f0e5e140c5728e15f13a8a Mon Sep 17 00:00:00 2001 From: armab Date: Wed, 23 Nov 2016 22:11:52 +0200 Subject: [PATCH 12/21] Bump pack version --- contrib/packs/pack.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/packs/pack.yaml b/contrib/packs/pack.yaml index 54a6856622..b1c3bc8336 100644 --- a/contrib/packs/pack.yaml +++ b/contrib/packs/pack.yaml @@ -1,6 +1,6 @@ --- name : packs -description : st2 content pack containing pack management functionality. -version : 0.1.0 +description : core st2 content pack containing pack management functionality. +version : 0.2.0 author : st2-dev email : info@stackstorm.com From f4db2cd8cd888ac01fbaaa8e681a0a7555f7ed1b Mon Sep 17 00:00:00 2001 From: armab Date: Wed, 23 Nov 2016 22:45:19 +0200 Subject: [PATCH 13/21] Touch pack descriptions --- contrib/packs/actions/lookup.meta.yaml | 8 +++----- contrib/packs/actions/lookup_remote.yaml | 2 +- contrib/packs/actions/pack_mgmt/lookup_remote.py | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/contrib/packs/actions/lookup.meta.yaml b/contrib/packs/actions/lookup.meta.yaml index 676d3408de..23e92cde78 100644 --- a/contrib/packs/actions/lookup.meta.yaml +++ b/contrib/packs/actions/lookup.meta.yaml @@ -1,9 +1,8 @@ --- name: "lookup" runner_type: "action-chain" - description: "Will get information about a pack from both the index and the list - of currently installed packs. This action is mostly meant to be - launched through its ChatOps alias." + description: "Get information about both locally installed and remotely available packs. + Used for ChatOps alias." enabled: true entry_point: "workflows/lookup.yaml" parameters: @@ -13,8 +12,7 @@ required: true location: type: "string" - description: "Primary source of information: installed packs or the pack - index." + description: "Primary source of information: installed packs or the pack index." enum: - "available" - "installed" diff --git a/contrib/packs/actions/lookup_remote.yaml b/contrib/packs/actions/lookup_remote.yaml index 007a0a80a6..702c01d362 100644 --- a/contrib/packs/actions/lookup_remote.yaml +++ b/contrib/packs/actions/lookup_remote.yaml @@ -1,7 +1,7 @@ --- name: "lookup_remote" runner_type: "python-script" -description: "Get detailed information about an available pack from the pack index" +description: "Get detailed information about an available pack from the pack index." enabled: true entry_point: "pack_mgmt/lookup_remote.py" parameters: diff --git a/contrib/packs/actions/pack_mgmt/lookup_remote.py b/contrib/packs/actions/pack_mgmt/lookup_remote.py index 805ff9f8ed..09121a8828 100644 --- a/contrib/packs/actions/pack_mgmt/lookup_remote.py +++ b/contrib/packs/actions/pack_mgmt/lookup_remote.py @@ -27,6 +27,7 @@ class LookupRemote(Action): + """Get detailed information about an available pack from the pack index""" def run(self, pack): pack_meta = get_pack_from_index(pack) pack_formatted = None From 6cc8fd097eec562ca2236cabddcf06636c67b35a Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 00:11:10 +0200 Subject: [PATCH 14/21] Simplify packs.lookup_remote action --- .../packs/actions/pack_mgmt/lookup_remote.py | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/contrib/packs/actions/pack_mgmt/lookup_remote.py b/contrib/packs/actions/pack_mgmt/lookup_remote.py index 09121a8828..de6cda8089 100644 --- a/contrib/packs/actions/pack_mgmt/lookup_remote.py +++ b/contrib/packs/actions/pack_mgmt/lookup_remote.py @@ -13,34 +13,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import re - -import yaml -import requests - from st2common.runners.base_action import Action from st2common.services.packs import get_pack_from_index -MANIFEST_FILE = 'pack.yaml' -EXCHANGE_REPO_URL_REGEX = r'(git@|https?://)github\.com[/:]StackStorm-Exchange/stackstorm-\S+' -EXCHANGE_YAML_PATH = 'https://index.stackstorm.org/v1/packs/%s.yaml' - class LookupRemote(Action): - """Get detailed information about an available pack from the pack index""" + """Get detailed information about an available pack from the StackStorm Exchange index""" def run(self, pack): - pack_meta = get_pack_from_index(pack) - pack_formatted = None - # Try to get the original yaml file because we know - # how it's stored in the Exchange, otherwise fall back - # to transforming json. - if pack_meta: - if re.match(EXCHANGE_REPO_URL_REGEX, pack_meta['repo_url'], re.IGNORECASE): - pack_formatted = requests.get(EXCHANGE_YAML_PATH % pack).text - else: - pack_formatted = yaml.dump(pack_meta) - + """ + :param pack: Pack Name to get info about + :type pack: ``str`` + """ return { - 'pack': pack_meta, - 'pack_formatted': pack_formatted + 'pack': get_pack_from_index(pack) } From f96beda6b5284a30694a2d2458d30fba4fda1bbc Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 18:31:08 +0200 Subject: [PATCH 15/21] Follow the CLI naming for consistency - `!pack get` - get info about installed pack - `!pack show` - show remote StackStorm Exchange pack - polished & working `!pack show` --- contrib/packs/actions/get.yaml | 11 +++ contrib/packs/actions/lookup.meta.yaml | 19 ----- contrib/packs/actions/lookup_local.yaml | 11 --- contrib/packs/actions/lookup_remote.yaml | 11 --- .../{lookup_local.py => get_installed.py} | 2 +- .../{lookup_remote.py => show_remote.py} | 2 +- contrib/packs/actions/show.yaml | 11 +++ contrib/packs/actions/workflows/lookup.yaml | 21 ------ contrib/packs/aliases/pack_get.yaml | 34 +++++++++ contrib/packs/aliases/pack_show.yaml | 73 ++++--------------- 10 files changed, 72 insertions(+), 123 deletions(-) create mode 100644 contrib/packs/actions/get.yaml delete mode 100644 contrib/packs/actions/lookup.meta.yaml delete mode 100644 contrib/packs/actions/lookup_local.yaml delete mode 100644 contrib/packs/actions/lookup_remote.yaml rename contrib/packs/actions/pack_mgmt/{lookup_local.py => get_installed.py} (99%) rename contrib/packs/actions/pack_mgmt/{lookup_remote.py => show_remote.py} (97%) create mode 100644 contrib/packs/actions/show.yaml delete mode 100644 contrib/packs/actions/workflows/lookup.yaml create mode 100644 contrib/packs/aliases/pack_get.yaml diff --git a/contrib/packs/actions/get.yaml b/contrib/packs/actions/get.yaml new file mode 100644 index 0000000000..98cc0f5a07 --- /dev/null +++ b/contrib/packs/actions/get.yaml @@ -0,0 +1,11 @@ +--- +name: "get" +runner_type: "python-script" +description: "Get information about installed pack." +enabled: true +entry_point: "pack_mgmt/get_installed.py" +parameters: + pack: + type: "string" + description: "Name of pack to lookup" + required: true diff --git a/contrib/packs/actions/lookup.meta.yaml b/contrib/packs/actions/lookup.meta.yaml deleted file mode 100644 index 23e92cde78..0000000000 --- a/contrib/packs/actions/lookup.meta.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- - name: "lookup" - runner_type: "action-chain" - description: "Get information about both locally installed and remotely available packs. - Used for ChatOps alias." - enabled: true - entry_point: "workflows/lookup.yaml" - parameters: - pack: - type: "string" - description: "Pack name" - required: true - location: - type: "string" - description: "Primary source of information: installed packs or the pack index." - enum: - - "available" - - "installed" - required: true diff --git a/contrib/packs/actions/lookup_local.yaml b/contrib/packs/actions/lookup_local.yaml deleted file mode 100644 index 3367e1fb03..0000000000 --- a/contrib/packs/actions/lookup_local.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: "lookup_local" -runner_type: "python-script" -description: "Get information about an installed pack" -enabled: true -entry_point: "pack_mgmt/lookup_local.py" -parameters: - pack: - type: "string" - description: "Name of pack to introspect" - required: true diff --git a/contrib/packs/actions/lookup_remote.yaml b/contrib/packs/actions/lookup_remote.yaml deleted file mode 100644 index 702c01d362..0000000000 --- a/contrib/packs/actions/lookup_remote.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: "lookup_remote" -runner_type: "python-script" -description: "Get detailed information about an available pack from the pack index." -enabled: true -entry_point: "pack_mgmt/lookup_remote.py" -parameters: - pack: - type: "string" - description: "Name of pack to introspect" - required: true diff --git a/contrib/packs/actions/pack_mgmt/lookup_local.py b/contrib/packs/actions/pack_mgmt/get_installed.py similarity index 99% rename from contrib/packs/actions/pack_mgmt/lookup_local.py rename to contrib/packs/actions/pack_mgmt/get_installed.py index 61e47b78d8..b0535566e0 100644 --- a/contrib/packs/actions/pack_mgmt/lookup_local.py +++ b/contrib/packs/actions/pack_mgmt/get_installed.py @@ -24,7 +24,7 @@ MANIFEST_FILE = 'pack.yaml' -class LookupLocal(Action): +class GetInstalled(Action): def run(self, pack): packs_base_paths = get_packs_base_paths() diff --git a/contrib/packs/actions/pack_mgmt/lookup_remote.py b/contrib/packs/actions/pack_mgmt/show_remote.py similarity index 97% rename from contrib/packs/actions/pack_mgmt/lookup_remote.py rename to contrib/packs/actions/pack_mgmt/show_remote.py index de6cda8089..c049725011 100644 --- a/contrib/packs/actions/pack_mgmt/lookup_remote.py +++ b/contrib/packs/actions/pack_mgmt/show_remote.py @@ -17,7 +17,7 @@ from st2common.services.packs import get_pack_from_index -class LookupRemote(Action): +class ShowRemote(Action): """Get detailed information about an available pack from the StackStorm Exchange index""" def run(self, pack): """ diff --git a/contrib/packs/actions/show.yaml b/contrib/packs/actions/show.yaml new file mode 100644 index 0000000000..028d64db34 --- /dev/null +++ b/contrib/packs/actions/show.yaml @@ -0,0 +1,11 @@ +--- +name: "show" +runner_type: "python-script" +description: "Get detailed information about pack from the remote StackStorm exchange index." +enabled: true +entry_point: "pack_mgmt/show_remote.py" +parameters: + pack: + type: "string" + description: "Name of pack to lookup" + required: true diff --git a/contrib/packs/actions/workflows/lookup.yaml b/contrib/packs/actions/workflows/lookup.yaml deleted file mode 100644 index 7ae1f3ff21..0000000000 --- a/contrib/packs/actions/workflows/lookup.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- - chain: - - - name: "local lookup" - ref: "packs.local_lookup" - parameters: - pack: "{{pack}}" - publish: - pack: "{{ __results['local lookup'].result.pack }}" - git_status: "{{ __results['local lookup'].result.git_status }}" - on-success: "index lookup" - - - name: "index lookup" - ref: "packs.index_lookup" - parameters: - pack: "{{pack}}" - publish: - available: "{{ __results['index lookup'].result.pack_formatted }}" - repo_url: "{{ __results['index lookup'].result.pack.repo_url }}" - - default: "local lookup" diff --git a/contrib/packs/aliases/pack_get.yaml b/contrib/packs/aliases/pack_get.yaml new file mode 100644 index 0000000000..deb74a3da2 --- /dev/null +++ b/contrib/packs/aliases/pack_get.yaml @@ -0,0 +1,34 @@ +--- +name: "pack_get" +action_ref: "packs.get" +description: "Get information about installed StackStorm pack." +formats: + - display: "pack get " + representation: + - "pack get {{ pack }}" + +ack: + enabled: false +result: + format: | + {% if execution.status == "succeeded" %} + Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} + {% if execution.result.pack %} + Here's the full index entry for the pack: + ``` + {{ execution.result.pack }} + ``` + Its source code is available at {{ execution.result.pack.repo_url }}. + + To install the pack: + ``` + pack install {{ execution.parameters.pack }} + ``` + If the pack is already installed, I will upgrade it to the latest version, keeping the config. + {% else %} + There's nothing like that in the pack index. + I know how sad it is, but life goes on. Cheer up! + {% endif %} + {% else %} + Couldn't locate *{{execution.parameters.pack}}*. :({~} + {% endif %} diff --git a/contrib/packs/aliases/pack_show.yaml b/contrib/packs/aliases/pack_show.yaml index 5e29a6334b..c7410edcc0 100644 --- a/contrib/packs/aliases/pack_show.yaml +++ b/contrib/packs/aliases/pack_show.yaml @@ -1,72 +1,27 @@ --- name: "pack_show" -action_ref: "packs.lookup" -description: "Get information about a StackStorm pack: either installed or availble" +action_ref: "packs.show" +description: "Show information about the pack from StackStorm Exchange." formats: - - display: "pack show [available] {{ pack }}" + - display: "pack show " representation: - "pack show {{ pack }}" - - "pack show available {{ pack }}({{ location='available' }}){0}" ack: enabled: false result: format: | {% if execution.status == "succeeded" %} - {% if execution.parameters.location == "installed" %} - Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} - {% if execution.result.pack %} - Full metadata: - ``` - {{ execution.result.pack }} - ``` - {% if execution.result.git_status %} - - Git status: - ``` - {{ execution.result.git_status }} - ``` - {% else %} - This pack does not appear to be a git repository though. - {% endif %} - {% else %} - It looks like there is no installed pack with this name. - {% if not execution.result.available %} - It's not on StackStorm Exchange either. What a sad world. - {% endif %} - {% endif %} - {% if execution.result.available %} - - This pack is available in the pack directory. You can take a look: - ``` - pack show available {{ execution.parameters.pack }} - ``` - {% if not execution.result.pack %} - Or ask me to install it for you right away: - ``` - pack install {{ execution.parameters.pack }} - ``` - {% endif %} - {% endif %} - {% else %} - Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} - {% if execution.result.available %} - Here's the full index entry for the pack: - ``` - {{ execution.result.available }} - ``` - Its source code is available at {{ execution.result.repo_url }}. - - To install the pack, just ask me: - ``` - pack install {{ execution.parameters.pack }} - ``` - If the pack is already installed, I will upgrade it to the latest version, keeping the config. - {% else %} - There's nothing like that in the pack index. - I know how sad it is, but life goes on. Cheer up! - {% endif %} - {% endif %} + Getting back to you about the `{{ execution.parameters.pack }}` pack: {~} + {% if execution.result.result.pack %} + Here's the full index entry at StackStorm Exchange: ```{{ execution.result.result.pack|to_yaml_string }}``` + To install the pack: `pack install {{ execution.parameters.pack }}` + If the pack is already installed, I will upgrade it to the latest version, keeping the config. + {% else %} + There's nothing like that in the pack index. + https://exchange.stackstorm.org/ + {% endif %} {% else %} - Couldn't locate *{{execution.parameters.pack}}*. :({~} + Couldn't locate `{{execution.parameters.pack}}`.{~} + {% if execution.result.stderr %}*Stderr:* ```{{ execution.result.stderr }}```{% endif %} {% endif %} From c9745b865bb54d3a492177bb7ff2272683bf71f8 Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 18:56:00 +0200 Subject: [PATCH 16/21] Fix & Polish `!pack search` Action Alias --- contrib/packs/actions/pack_mgmt/search.py | 6 ++++- contrib/packs/aliases/pack_search.yaml | 33 ++++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/contrib/packs/actions/pack_mgmt/search.py b/contrib/packs/actions/pack_mgmt/search.py index ce334c474c..6bcbdfc48d 100644 --- a/contrib/packs/actions/pack_mgmt/search.py +++ b/contrib/packs/actions/pack_mgmt/search.py @@ -18,6 +18,10 @@ class PackSearch(Action): + """"Search for packs in StackStorm Exchange and other directories.""" def run(self, query): - # Yup. That's all folks! + """ + :param query: A word or a phrase to search for + :type query: ``str`` + """ return search_pack_index(query) diff --git a/contrib/packs/aliases/pack_search.yaml b/contrib/packs/aliases/pack_search.yaml index 92b745f216..c1e999a510 100644 --- a/contrib/packs/aliases/pack_search.yaml +++ b/contrib/packs/aliases/pack_search.yaml @@ -10,25 +10,26 @@ formats: ack: enabled: true append_url: false - format: "Alright! Let me check if that matches anything in the pack index." + format: "Alright! Let me check if that matches anything in the StackStorm Exchange index." result: format: | {% if execution.status == "succeeded" %} - {% if execution.result %} - Got something for you!{~} - {% for pack in execution.result %} - • *{{ pack.name }}*: {{ pack.description }} - {% endfor %} + {% if execution.result.result | length %} + Got something for you matching `{{ execution.parameters.query }}`!{~} + {% for pack in execution.result.result %} + • *{{ pack.name }}*: {{ pack.description }} + {% endfor %} - I can tell you more about a particular pack, or even get it installed for you right away: - ``` - pack show available - pack install - ``` - {% else %} - I couldn't get any results for `{{ execution.parameters.query }}`, unfortunately. - {% endif %} + I can tell you more about a particular pack, or even get it installed for you right away: + ``` + pack show + pack install + ``` {% else %} - Search failed for `{{ execution.parameters.query }}`.{~} - Please check {{ execution.id }} for details. Index problems maybe? + Unfortunately I couldn't find any results for `{{ execution.parameters.query }}` in pack index. + {% endif %} + {% else %} + Search failed for `{{ execution.parameters.query }}`.{~} + Please check {{ execution.id }} for details. Index problems maybe? + {% if execution.result.stderr %}*Stderr:* ```{{ execution.result.stderr }}```{% endif %} {% endif %} From 17eeffbd4e5d59ad671e267bcb5f005e234036bd Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 21:12:24 +0200 Subject: [PATCH 17/21] Fix & Polish `!pack install` Action Alias --- contrib/packs/aliases/pack_install.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/packs/aliases/pack_install.yaml b/contrib/packs/aliases/pack_install.yaml index 99f19a2d29..9c79cc695f 100644 --- a/contrib/packs/aliases/pack_install.yaml +++ b/contrib/packs/aliases/pack_install.yaml @@ -7,16 +7,16 @@ formats: - display: "pack install [,]" - display: "pack install #[,]" representation: - - "pack install {{packs}}" + - "pack install {{ packs }}" ack: enabled: true append_url: false - format: "Deploying the requested pack(s) for you." + format: "Installing the requested pack(s) for you." result: format: | {% if execution.status == "succeeded" %} - Successful deployment of{% for pack in execution.result.packs_status %} *{{pack.name}}*{% endfor %}!{~} + Successful deployment of *{{ execution.parameters.packs | join('*, *') }}* pack{% if execution.parameters.packs | length > 1 %}s{% endif %}! {% else %} - Deployment failed for *{{execution.parameters.packs}}*.{~} - Please check {{ execution.id }} for details. + Failed to install `{{ execution.parameters.packs | join('`, `') }}` pack{% if execution.parameters.packs | length > 1 %}s{% endif %}.{~} + Please check `{{ execution.id }}` for details. {% endif %} From 60a88a1e7f4e2690034150550a3b5bb8817b364a Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 21:46:15 +0200 Subject: [PATCH 18/21] Fix force=true parameter for packs.download --- contrib/packs/actions/workflows/install.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/packs/actions/workflows/install.yaml b/contrib/packs/actions/workflows/install.yaml index 6ca4c557a7..e8373d6da3 100644 --- a/contrib/packs/actions/workflows/install.yaml +++ b/contrib/packs/actions/workflows/install.yaml @@ -5,7 +5,6 @@ ref: "packs.download" parameters: packs: "{{packs}}" - publish: force: "{{force}}" on-success: "make a prerun" - From 5cd04e4ef96c6a34e614cb82ec9286535f44356d Mon Sep 17 00:00:00 2001 From: armab Date: Thu, 24 Nov 2016 23:14:14 +0200 Subject: [PATCH 19/21] Fix & Polish `!pack get` Action Alias --- .../packs/actions/pack_mgmt/get_installed.py | 33 +++++++++++++------ contrib/packs/aliases/pack_get.yaml | 30 +++++++---------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/contrib/packs/actions/pack_mgmt/get_installed.py b/contrib/packs/actions/pack_mgmt/get_installed.py index b0535566e0..f768172cba 100644 --- a/contrib/packs/actions/pack_mgmt/get_installed.py +++ b/contrib/packs/actions/pack_mgmt/get_installed.py @@ -14,31 +14,44 @@ # limitations under the License. import os +import yaml from git.repo import Repo -from gitdb.exc import InvalidGitRepositoryError +from git.exc import InvalidGitRepositoryError from st2common.runners.base_action import Action from st2common.content.utils import get_packs_base_paths - -MANIFEST_FILE = 'pack.yaml' +from st2common.constants.pack import MANIFEST_FILE_NAME class GetInstalled(Action): + """"Get information about installed pack.""" def run(self, pack): + """ + :param pack: Installed Pack Name to get info about + :type pack: ``str`` + """ packs_base_paths = get_packs_base_paths() + pack_path = None metadata_file = None for packs_base_path in packs_base_paths: pack_path = os.path.join(packs_base_path, pack) - pack_yaml_path = os.path.join(pack_path, MANIFEST_FILE) + pack_yaml_path = os.path.join(pack_path, MANIFEST_FILE_NAME) if os.path.isfile(pack_yaml_path): metadata_file = pack_yaml_path break + # Pack doesn't exist, finish execution normally with empty metadata + if not os.path.isdir(pack_path): + return { + 'pack': None, + 'git_status': None + } + if not metadata_file: - error = ('Pack "%s" doesn\'t exist or it doesn\'t contain pack.yaml.' % (pack)) + error = ('Pack "%s" doesn\'t contain pack.yaml file.' % (pack)) raise Exception(error) try: @@ -67,12 +80,12 @@ def run(self, pack): except InvalidGitRepositoryError: git_status = None - return {'pack': details, - 'git_status': git_status} + return { + 'pack': details, + 'git_status': git_status + } def _parse_yaml_file(self, file_path): with open(file_path) as data_file: - # details = yaml.load(data_file) - # You know what? We'll just output yaml, it's pretty as it is. - details = data_file.read() + details = yaml.load(data_file) return details diff --git a/contrib/packs/aliases/pack_get.yaml b/contrib/packs/aliases/pack_get.yaml index deb74a3da2..a0414d4951 100644 --- a/contrib/packs/aliases/pack_get.yaml +++ b/contrib/packs/aliases/pack_get.yaml @@ -12,23 +12,17 @@ ack: result: format: | {% if execution.status == "succeeded" %} - Getting back to you about the `{{ execution.parameters.pack }}` pack:{~} - {% if execution.result.pack %} - Here's the full index entry for the pack: - ``` - {{ execution.result.pack }} - ``` - Its source code is available at {{ execution.result.pack.repo_url }}. - - To install the pack: - ``` - pack install {{ execution.parameters.pack }} - ``` - If the pack is already installed, I will upgrade it to the latest version, keeping the config. - {% else %} - There's nothing like that in the pack index. - I know how sad it is, but life goes on. Cheer up! - {% endif %} + {% if execution.result.result.pack %} + Getting back to you about the installed `{{ execution.parameters.pack }}` pack:{~} + Here's the full entry: ```{{ execution.result.result.pack|to_yaml_string }}``` + {% if execution.result.result.git_status %} + Git status: ```{{ execution.result.result.git_status }}``` + {% endif %} + {% else %} + The requested pack is not present in your StackStorm installation. + To install the pack: `pack install {{ execution.parameters.pack }}` + {% endif %} {% else %} - Couldn't locate *{{execution.parameters.pack}}*. :({~} + Couldn't locate *{{execution.parameters.pack}}*. :({~} + {% if execution.result.stderr %}*Stderr:* ```{{ execution.result.stderr }}```{% endif %} {% endif %} From 16f5249cae8762c4efb4d99b6c638e02bca60009 Mon Sep 17 00:00:00 2001 From: armab Date: Fri, 25 Nov 2016 00:05:06 +0200 Subject: [PATCH 20/21] Remove obsolete config settings for `packs` pack --- contrib/packs/config.yaml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/contrib/packs/config.yaml b/contrib/packs/config.yaml index 5662447e23..ed97d539c0 100644 --- a/contrib/packs/config.yaml +++ b/contrib/packs/config.yaml @@ -1,24 +1 @@ --- -repositories: - - # To deploy a pack from a forked st2contrib on GitHub update & uncomment the following - # ! packs deploy me/st2contrib/ - #/st2contrib: - # repo: "https://github.com//st2contrib.git" - # subtree: true - - #If you have your own ST2 Pack - #my-st2: - # repo: "https://github.com//my-st2.git" - # subtree: false - # auto_deployment: - # branch: "master" - # notify_channel: "my-chatops-channel" - - st2incubator: - repo: "https://github.com/StackStorm/st2incubator.git" - subtree: true - - st2contrib: - repo: "https://github.com/StackStorm/st2contrib.git" - subtree: true From 4ddbe996ce6cadeff13aebe8786ad8bbd81b327a Mon Sep 17 00:00:00 2001 From: armab Date: Fri, 25 Nov 2016 15:22:01 +0200 Subject: [PATCH 21/21] Remove upgrade flag for packs.install action --- contrib/packs/actions/install.meta.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/packs/actions/install.meta.yaml b/contrib/packs/actions/install.meta.yaml index 332fbccd4a..a8e65e6640 100644 --- a/contrib/packs/actions/install.meta.yaml +++ b/contrib/packs/actions/install.meta.yaml @@ -18,10 +18,6 @@ type: "string" default: "actions,aliases,sensors,triggers" description: "Possible options are all, triggers, sensors, actions, rules, aliases." - upgrade: - type: "boolean" - default: false - description: "Upgrade the pack if already installed." env: type: "object" description: "Optional environment variables."