Skip to content

Commit

Permalink
Merge pull request #1 from meirwah/add_tests_for_csr
Browse files Browse the repository at this point in the history
Add tests for csr
  • Loading branch information
Meir Wahnon committed Jun 8, 2015
2 parents 014bad4 + c87ccb6 commit 1eec258
Show file tree
Hide file tree
Showing 111 changed files with 2,413 additions and 253 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Changelog
in development
--------------

* Add support for script arguments to the Windows script runner. (new feature)
[James Sigurðarson]
* Allow user to filter executions on trigger instance id.
[Sayli Karmarkar]

0.11 - June 5, 2015
-------------------

* Allow user to configure the CLI using an ini style config file located at ``~/.st2rc``.
(new-feature)
* Add support for caching of the retrieved auth tokens to the CLI. (new-feature)
Expand All @@ -20,9 +28,16 @@ in development
(new-feature)
* Rules should be part of a pack. (improvement)
* Update Windows runner code so it also works with a newer versions of winexe (> 1.0).
(improvements)
(improvement)
[James Sigurðarson]
* CLI now has ``get`` and ``list`` commands for triggerinstance. (new-feature)
* Validate parameters during rule creation for system triggers. (improvement)
* CLI now has ``re-emit`` command for triggerinstance. (new-feature)

v0.9.2 - May 26, 2015
---------------------

* Fix broken ``packs.download`` action. (bug-fix)

v0.9.1 - May 12, 2015
---------------------
Expand Down
7 changes: 6 additions & 1 deletion contrib/core/actions/send_mail/send_mail
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ TO=$1
shift
SUBJECT=$1
shift
SEND_EMPTY_BODY=$1
shift
BODY="$@"

${MAIL} <<EOF
if [[ -z "${BODY// }" && $SEND_EMPTY_BODY == 'True' ]] || [[ -n $BODY ]]; then
${MAIL} <<EOF
TO: ${TO}
FROM: ${FROM}
SUBJECT: ${SUBJECT}
Expand All @@ -23,6 +26,8 @@ ${FOOTER}
EOF

fi

if [ $? -ne 0 ]; then
echo "Failed to send mail to ${TO}"
exit 2
Expand Down
8 changes: 7 additions & 1 deletion contrib/core/actions/sendmail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: sendmail
parameters:
body:
description: Body of the email.
position: 2
position: 3
required: true
type: string
subject:
Expand All @@ -21,4 +21,10 @@ parameters:
position: 0
required: true
type: string
send_empty_body:
description: Send a message even if the body is empty.
position: 2
required: false
type: boolean
default: True
runner_type: "local-shell-script"
10 changes: 1 addition & 9 deletions contrib/examples/actions/chains/mistral_examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
params:
cmd: "hostname"
on-success: "mistral-handle-error"
on-failure: "mistral-handle-error"
-
name: "mistral-handle-error"
ref: "examples.mistral-handle-error"
params: {}
on-success: "mistral-handle-retry"
on-failure: "mistral-handle-retry"
-
name: "mistral-handle-retry"
ref: "examples.mistral-handle-retry"
params: {}
on-success: "mistral-repeat-with-items"
on-failure: "mistral-repeat-with-items"
-
name: "mistral-repeat-with-items"
ref: "examples.mistral-repeat-with-items"
Expand All @@ -27,36 +24,31 @@
- "hostname"
- "date"
on-success: "mistral-repeat"
on-failure: "mistral-repeat"
-
name: "mistral-repeat"
ref: "examples.mistral-repeat"
params:
cmd: "hostname"
on-success: "mistral-workbook-basic"
on-failure: "mistral-workbook-basic"
-
name: "mistral-workbook-basic"
ref: "examples.mistral-workbook-basic"
params:
cmd: "hostname"
on-success: "mistral-workbook-complex"
on-failure: "mistral-workbook-complex"
-
name: "mistral-workbook-complex"
ref: "examples.mistral-workbook-complex"
params:
vm_name: "fake-host-1"
on-success: "mistral-workbook-multiple-subflows"
on-failure: "mistral-workbook-multiple-subflows"
-
name: "mistral-workbook-multiple-subflows"
ref: "examples.mistral-workbook-multiple-subflows"
params: {}
on-success: "mistral-workbook-subflows"
on-failure: "mistral-workbook-subflows"
-
name: "mistral-workbook-subflows"
ref: "examples.mistral-workbook-subflows"
params: {}
default: "mistral-basic"
default: "mistral-basic"
2 changes: 1 addition & 1 deletion contrib/examples/actions/echochain.meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parameters:
default:
- c2
notify:
on_complete:
on-complete:
message: "\"@channel: Action succeeded.\""
channels:
- "slack"
2 changes: 1 addition & 1 deletion contrib/examples/actions/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enabled: true
entry_point: ''
name: local-notify
notify:
on_complete:
on-complete:
channels:
- slack
message: '"@channel: Action succeeded."'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parameters:
immutable: true
type: string
notify:
on_complete:
on-complete:
message: "\"@channel: Action succeeded.\""
channels:
- "slack"
5 changes: 4 additions & 1 deletion contrib/packs/actions/download.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
type: "string"
repo_url:
type: "string"
default: "https:/StackStorm/st2contrib.git"
default: "StackStorm/st2contrib"
branch:
type: "string"
default: "master"
abs_repo_base:
type: "string"
default: "/opt/stackstorm/packs/"
immutable: true
subtree:
type: "boolean"
default: false
verifyssl:
type: "boolean"
default: true
12 changes: 12 additions & 0 deletions contrib/packs/actions/info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: "info"
runner_type: "python-script"
description: "Get currently deployed pack information"
enabled: true
entry_point: "pack_mgmt/info.py"
parameters:
pack:
type: "string"
description: "Name of pack to introspect"
required: true

61 changes: 56 additions & 5 deletions contrib/packs/actions/pack_mgmt/download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import shutil
import hashlib
import re
import json

import six
from git.repo import Repo
Expand All @@ -11,20 +13,30 @@
ALL_PACKS = '*'
PACK_REPO_ROOT = 'packs'
MANIFEST_FILE = 'pack.yaml'
CONFIG_FILE = 'config.yaml'
GITINFO_FILE = '.gitinfo'
PACK_RESERVE_CHARACTER = '.'


class InstallGitRepoAction(Action):
def run(self, packs, repo_url, abs_repo_base, verifyssl=True, branch='master'):
repo_name = repo_url[repo_url.rfind('/') + 1: repo_url.rfind('.')]
def run(self, packs, repo_url, abs_repo_base, verifyssl=True, branch='master', subtree=False):
self._subtree = self._eval_subtree(repo_url, subtree)
self._repo_url = self._eval_repo_url(repo_url)

repo_name = self._repo_url[self._repo_url.rfind('/') + 1: self._repo_url.rfind('.')]
lock_name = hashlib.md5(repo_name).hexdigest() + '.lock'

with LockFile('/tmp/%s' % (lock_name)):
abs_local_path = self._clone_repo(repo_url=repo_url, verifyssl=verifyssl,
abs_local_path = self._clone_repo(repo_url=self._repo_url, verifyssl=verifyssl,
branch=branch)
try:
# st2-contrib repo has a top-level packs folder that actually contains the
pack_abs_local_path = os.path.join(abs_local_path, PACK_REPO_ROOT)
if self._subtree:
# st2-contrib repo has a top-level packs folder that actually contains the
pack_abs_local_path = os.path.join(abs_local_path, PACK_REPO_ROOT)
else:
pack_abs_local_path = abs_local_path

self._tag_pack(pack_abs_local_path, packs, self._subtree)
result = self._move_packs(abs_repo_base, packs, pack_abs_local_path)
finally:
self._cleanup_repo(abs_local_path)
Expand Down Expand Up @@ -58,6 +70,10 @@ def _move_packs(self, abs_repo_base, packs, abs_local_path):
if os.path.exists(dest_pack_path):
self.logger.debug('Removing existing pack %s in %s to replace.', pack,
dest_pack_path)
# Ensure to preserve any existing configuration
old_config_file = os.path.join(dest_pack_path, CONFIG_FILE)
new_config_file = os.path.join(abs_pack_temp_location, CONFIG_FILE)
shutil.move(old_config_file, new_config_file)
shutil.rmtree(dest_pack_path)
self.logger.debug('Moving pack from %s to %s.', abs_pack_temp_location, to)
shutil.move(abs_pack_temp_location, to)
Expand Down Expand Up @@ -115,3 +131,38 @@ def _validate_result(result, packs, repo_url):
raise Exception(message)

return sanitized_result

@staticmethod
def _eval_subtree(repo_url, subtree):
st2_repos = re.compile("st2(contrib|incubator)")
match = True if st2_repos.search(repo_url) else False
return subtree ^ match

@staticmethod
def _eval_repo_url(repo_url):
"""Allow passing short GitHub style URLs"""
if len(repo_url.split('/')) == 2 and not "git@" in repo_url:
return "https:/{}.git".format(repo_url)
else:
return "{}.git".format(repo_url)

@staticmethod
def _tag_pack(pack_dir, packs, subtree):
"""Add git information to pack directory for retrieval later"""
for pack in packs:
repo = Repo(pack_dir)
payload = {
"branch": repo.active_branch.name,
"ref": repo.head.commit.hexsha
}

if subtree:
info_file = os.path.join(pack_dir, pack, GITINFO_FILE)
else:
info_file = os.path.join(pack_dir, GITINFO_FILE)

try:
gitinfo = open(info_file, "w")
gitinfo.write(json.dumps(payload))
finally:
gitinfo.close()
16 changes: 16 additions & 0 deletions contrib/packs/actions/pack_mgmt/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from st2actions.runners.pythonrunner import Action
import json
import os

GITINFO_FILE = '.gitinfo'


class PackInfo(Action):
def run(self, pack, pack_dir="/opt/stackstorm/packs"):
gitinfo = os.path.join(pack_dir, pack, GITINFO_FILE)
try:
with open(gitinfo) as data_file:
details = json.load(data_file)
return details
except:
print "Unable to load git info for {}".format(pack)
7 changes: 7 additions & 0 deletions contrib/packs/aliases/pack_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "deploy_pack"
action_ref: "packs.install"
description: "Download StackStorm packs via ChatOps"
formats:
- "pack deploy {{packs}}"
- "pack deploy {{packs}} from {{repo_url}}"
6 changes: 6 additions & 0 deletions contrib/packs/aliases/pack_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: "pack_info"
action_ref: "packs.info"
description: "Get StackStorm pack information via ChatOps"
formats:
- "pack info {{pack}}"
7 changes: 7 additions & 0 deletions docs/source/rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ get details about a trigger instance by using ``get``.
st2 triggerinstance get 556e135232ed35569ff23238
Something that might be useful in debugging a rule is to re-send a trigger instance into |st2|. You
can use the ``re-emit`` command for that.
.. code-block:: bash
st2 triggerinstance re-emit 556e135232ed35569ff23238
Timers
------
Expand Down
Loading

0 comments on commit 1eec258

Please sign in to comment.