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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ in development
* Add support for caching of the retrieved auth tokens to the CLI. (new-feature)
* Throw a more-user friendly exception when enforcing a rule if an action referenced inside
the rule definition doesn't exist. (improvement)
* Fix a bug with the rule evaluation failing if the trigger payload contained a key with a
dot in the name. (bug-fix)

v0.9.0 - April 29, 2015
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pylint: requirements .pylint
echo "==========================================================="; \
echo "Running pylint on" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./.pylintrc --load-plugins=pylint_plugins.api_models $$component/$$component; \
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./.pylintrc --load-plugins=pylint_plugins.api_models $$component/$$component || exit 1; \
done

.PHONY: flake8
Expand Down
2 changes: 1 addition & 1 deletion st2actions/st2actions/resultstracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def start(self, wait=False):

def wait(self):
super(ResultsTracker, self).wait()
for thread in self._query_threads():
for thread in self._query_threads:
thread.wait()

def shutdown(self):
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/models/db/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class TriggerInstanceDB(stormbase.StormFoundationDB):
occurrence_time (datetime): time of occurrence of the trigger.
"""
trigger = me.StringField()
payload = me.DictField()
payload = stormbase.EscapedDictField()
occurrence_time = me.DateTimeField()


Expand Down
29 changes: 24 additions & 5 deletions st2reactor/tests/unit/test_rule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


class RuleMatcherTest(DbTestCase):
rules = []

def test_get_matching_rules(self):
self._setup_sample_trigger('st2.test.trigger1')
Expand All @@ -40,6 +41,22 @@ def test_get_matching_rules(self):
self.assertTrue(matching_rules is not None)
self.assertEqual(len(matching_rules), 1)

def test_trigger_instance_payload_with_special_values(self):
# Test a rule where TriggerInstance payload contains a dot (".") and $
self._setup_sample_trigger('st2.test.trigger2')
trigger_instance = container_utils.create_trigger_instance(
'dummy_pack_1.st2.test.trigger2',
{'k1': 't1_p_v', 'k2.k2': 'v2', 'k3.more.nested.deep': 'some.value',
'k4.even.more.nested$': 'foo', 'yep$aaa': 'b'},
datetime.datetime.utcnow()
)
trigger = get_trigger_db_by_ref(trigger_instance.trigger)
rules = self._get_sample_rules()
rules_matcher = RulesMatcher(trigger_instance, trigger, rules)
matching_rules = rules_matcher.get_matching_rules()
self.assertTrue(matching_rules is not None)
self.assertEqual(len(matching_rules), 1)

def _setup_sample_trigger(self, name):
trigtype = TriggerTypeDB()
trigtype.name = name
Expand All @@ -58,7 +75,9 @@ def _setup_sample_trigger(self, name):
Trigger.add_or_update(created)

def _get_sample_rules(self):
rules = []
if self.rules:
# Make sure rules are created only once
return self.rules

RULE_1 = {
'enabled': True,
Expand All @@ -85,7 +104,7 @@ def _get_sample_rules(self):
rule_api = RuleAPI(**RULE_1)
rule_db = RuleAPI.to_model(rule_api)
rule_db = Rule.add_or_update(rule_db)
rules.append(rule_db)
self.rules.append(rule_db)

RULE_2 = { # Rule should match.
'enabled': True,
Expand All @@ -112,7 +131,7 @@ def _get_sample_rules(self):
rule_api = RuleAPI(**RULE_2)
rule_db = RuleAPI.to_model(rule_api)
rule_db = Rule.add_or_update(rule_db)
rules.append(rule_db)
self.rules.append(rule_db)

RULE_3 = {
'enabled': False, # Disabled rule shouldn't match.
Expand All @@ -139,6 +158,6 @@ def _get_sample_rules(self):
rule_api = RuleAPI(**RULE_3)
rule_db = RuleAPI.to_model(rule_api)
rule_db = Rule.add_or_update(rule_db)
rules.append(rule_db)
self.rules.append(rule_db)

return rules
return self.rules