Beispiel #1
0
 def test_non_matching_trigger_from_file(self):
     rule_file_path = os.path.join(BASE_PATH, '../fixtures/rule.yaml')
     trigger_instance_file_path = os.path.join(BASE_PATH, '../fixtures/trigger_instance_2.yaml')
     tester = RuleTester(rule_file_path=rule_file_path,
                         trigger_instance_file_path=trigger_instance_file_path)
     matching = tester.evaluate()
     self.assertFalse(matching)
Beispiel #2
0
 def test_matching_trigger_from_file(self):
     FixturesLoader().save_fixtures_to_db(fixtures_pack=FIXTURES_PACK,
                                          fixtures_dict=TEST_MODELS_ACTIONS)
     rule_file_path = os.path.join(BASE_PATH, '../fixtures/rule.yaml')
     trigger_instance_file_path = os.path.join(BASE_PATH, '../fixtures/trigger_instance_1.yaml')
     tester = RuleTester(rule_file_path=rule_file_path,
                         trigger_instance_file_path=trigger_instance_file_path)
     matching = tester.evaluate()
     self.assertTrue(matching)
Beispiel #3
0
 def test_non_matching_trigger_from_db(self):
     models = FixturesLoader().save_fixtures_to_db(fixtures_pack=FIXTURES_PACK,
                                                   fixtures_dict=TEST_MODELS_TRIGGERS)
     trigger_instance_db = models['triggerinstances']['trigger_instance_1.yaml']
     models = FixturesLoader().save_fixtures_to_db(fixtures_pack=FIXTURES_PACK,
                                                   fixtures_dict=TEST_MODELS_RULES)
     rule_db = models['rules']['rule1.yaml']
     tester = RuleTester(rule_ref=rule_db.ref,
                         trigger_instance_id=str(trigger_instance_db.id))
     matching = tester.evaluate()
     self.assertFalse(matching)
Beispiel #4
0
 def test_matching_trigger_from_db(self):
     FixturesLoader().save_fixtures_to_db(
         fixtures_pack=FIXTURES_PACK, fixtures_dict=TEST_MODELS_ACTIONS
     )
     models = FixturesLoader().save_fixtures_to_db(
         fixtures_pack=FIXTURES_PACK, fixtures_dict=TEST_MODELS_TRIGGERS
     )
     trigger_instance_db = models["triggerinstances"]["trigger_instance_2.yaml"]
     models = FixturesLoader().save_fixtures_to_db(
         fixtures_pack=FIXTURES_PACK, fixtures_dict=TEST_MODELS_RULES
     )
     rule_db = models["rules"]["rule1.yaml"]
     tester = RuleTester(
         rule_ref=rule_db.ref, trigger_instance_id=str(trigger_instance_db.id)
     )
     matching = tester.evaluate()
     self.assertTrue(matching)
Beispiel #5
0
def main():
    _register_cli_opts()
    common_setup(config=config, setup_db=True, register_mq_exchanges=False)

    try:
        tester = RuleTester(rule_file_path=cfg.CONF.rule,
                            rule_ref=cfg.CONF.rule_ref,
                            trigger_instance_file_path=cfg.CONF.trigger_instance,
                            trigger_instance_id=cfg.CONF.trigger_instance_id)
        matches = tester.evaluate()
    finally:
        common_teardown()

    if matches:
        LOG.info('=== RULE MATCHES ===')
        sys.exit(0)
    else:
        LOG.info('=== RULE DOES NOT MATCH ===')
        sys.exit(1)
Beispiel #6
0
def main():
    _register_cli_opts()
    common_setup(config=config, setup_db=True, register_mq_exchanges=False)

    try:
        tester = RuleTester(rule_file_path=cfg.CONF.rule,
                            rule_ref=cfg.CONF.rule_ref,
                            trigger_instance_file_path=cfg.CONF.trigger_instance,
                            trigger_instance_id=cfg.CONF.trigger_instance_id)
        matches = tester.evaluate()
    finally:
        common_teardown()

    if matches:
        LOG.info('=== RULE MATCHES ===')
        sys.exit(0)
    else:
        LOG.info('=== RULE DOES NOT MATCH ===')
        sys.exit(1)
Beispiel #7
0
def main():
    args = _parse_args()
    if args.verbose:
        _setup_logging()
        output = logging.getLogger(__name__).info
    else:
        output = pprint.pprint

    rule_file_path = os.path.realpath(args.rule)
    trigger_instance_file_path = os.path.realpath(args.trigger_instance)

    tester = RuleTester(rule_file_path=rule_file_path,
                        trigger_instance_file_path=trigger_instance_file_path)
    matches = tester.evaluate()

    if matches:
        output('=== RULE MATCHES ===')
        sys.exit(0)
    else:
        output('=== RULE DOES NOT MATCH ===')
        sys.exit(1)
Beispiel #8
0
def main():
    args = _parse_args()
    if args.verbose:
        _setup_logging()
        output = logging.getLogger(__name__).info
    else:
        output = pprint.pprint

    rule_file_path = os.path.realpath(args.rule)
    trigger_instance_file_path = os.path.realpath(args.trigger_instance)

    tester = RuleTester(rule_file_path=rule_file_path,
                        trigger_instance_file_path=trigger_instance_file_path)
    matches = tester.evaluate()

    if matches:
        output('=== RULE MATCHES ===')
        sys.exit(0)
    else:
        output('=== RULE DOES NOT MATCH ===')
        sys.exit(1)