Skip to content

Commit d284f84

Browse files
authored
Enable completely offline st2-rule-tester (#6208)
1 parent 79f55ec commit d284f84

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Added
7070
Contributed by @amanda11
7171
* Ensure `.pth` files in the st2 virtualenv get loaded by pack virtualenvs. #6183
7272
Contributed by @cognifloyd
73+
* Allow `st2-rule-tester` to run without a mongo connection if user is testing against local `rule`/`trigger-instance` files. #6208
74+
Contributed by @jk464
7375

7476
* Added a `get_result` method to the `ExecutionResourceManager` Class for st2client
7577
Contributed by @skiedude

st2reactor/st2reactor/cmd/rule_tester.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from st2common import config
2222
from st2common import log as logging
2323
from st2common.config import do_register_cli_opts
24+
from st2common.service_setup import db_setup
2425
from st2common.script_setup import setup as common_setup
2526
from st2common.script_setup import teardown as common_teardown
2627
from st2reactor.rules.tester import RuleTester
@@ -46,13 +47,29 @@ def _register_cli_opts():
4647
default=None,
4748
help="Id of the Trigger Instance to use for validation.",
4849
),
50+
cfg.BoolOpt(
51+
"offline",
52+
default=False,
53+
help="Run st2-rule-tester without DB connection - can only be used in connection with 'rule' and 'trigger-instance' options",
54+
),
4955
]
5056
do_register_cli_opts(cli_opts)
5157

5258

5359
def main():
5460
_register_cli_opts()
55-
common_setup(config=config, setup_db=True, register_mq_exchanges=False)
61+
62+
common_setup(config=config, setup_db=False, register_mq_exchanges=False)
63+
64+
# Setup DB if not running offline
65+
if not cfg.CONF.offline:
66+
db_setup()
67+
# If running offline check that neither rule_ref or trigger_instance_id are provided as they require the DB.
68+
elif cfg.CONF.rule_ref or cfg.CONF.trigger_instance_id:
69+
LOG.critical(
70+
"'rule-ref' and/or 'trigger-instance-id' cannot be used in 'offline' mode"
71+
)
72+
sys.exit(2)
5673

5774
try:
5875
tester = RuleTester(

0 commit comments

Comments
 (0)