Skip to content
Open
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
6 changes: 1 addition & 5 deletions irods/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ class RuleExec(Model):
last_exe_time = Column(DateTime, "RULE_EXEC_LAST_EXE_TIME", 1010)
frequency = Column(String, "RULE_EXEC_FREQUENCY", 1006)
priority = Column(String, "RULE_EXEC_PRIORITY", 1007)


# # If needed in 4.2.9, we can update the Query class to dynamically
# # attach this field based on server version:
# context = Column(String, 'RULE_EXEC_CONTEXT', 1012)
context = Column(String, 'RULE_EXEC_CONTEXT', 1012, min_version=(4, 3, 0))

# # These are either unused or usually absent:
# exec_status = Column(String,'RULE_EXEC_STATUS', 1011)
Expand Down
32 changes: 31 additions & 1 deletion irods/test/rule_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import random
import time
import textwrap
import unittest
from irods.models import DataObject
from irods.column import Like
from irods.models import DataObject, RuleExec
from irods.exception import (
FAIL_ACTION_ENCOUNTERED_ERR,
RULE_ENGINE_ERROR,
UnknowniRODSError,
)
import irods.test.helpers as helpers
from irods.rule import Rule
from io import open as io_open
import io

Check failure on line 20 in irods/test/rule_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff unsorted-imports

unsorted-imports: Import block is un-sorted or un-formatted [check:unsorted-imports]


RE_Plugins_installed_run_condition_args = (
Expand Down Expand Up @@ -436,7 +438,35 @@
self.assertRegex(lines[0], r"\[INTEGER\]\[5\]")
self.assertRegex(lines[1], r"\[STRING\]\[A String\]")


def test_rule_exec_context(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use more words to describe what the test is about. For example:

def test_RULE_EXEC_CONTEXT_column_is_available_via_genquery1(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing issue number.

if self.sess.server_version < (4, 3):
self.skipTest("""RuleExec's "context" attribute not available before 4.3.0""")

Comment on lines +443 to +445

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check isn't necessary since iRODS 4.2 is EOL.

Assume the iRODS server is 4.3.0 or later.

rule_id = -1

try:
# Schedule a delayed rule.
n_minutes = 15
random_int = random.randint(1<<30, (1<<31)-1)

Check failure on line 451 in irods/test/rule_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff suspicious-non-cryptographic-random-usage

suspicious-non-cryptographic-random-usage: Standard pseudo-random generators are not suitable for cryptographic purposes [check:suspicious-non-cryptographic-random-usage]
r = Rule(
self.sess,
body=f'''delay("<PLUSET>{n_minutes}m</PLUSET>") {{writeLine("serverLog","{random_int}")}}'''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body=f'''delay("<PLUSET>{n_minutes}m</PLUSET>") {{writeLine("serverLog","{random_int}")}}'''
body=f'''delay("<PLUSET>{n_minutes}m</PLUSET>") {{ writeLine("serverLog","{random_int}") }}'''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider specifying the value to <PLUSET> as seconds instead of using the minutes (m) suffix.

)
r.execute()

# Get the delayed rule's ID, needed for cancellation.
l = list(self.sess.query(RuleExec).filter(Like(RuleExec.name,f'%"{random_int}"%')))

Check failure on line 459 in irods/test/rule_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-format

Ruff format

Improper formatting

Check failure on line 459 in irods/test/rule_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff ambiguous-variable-name

ambiguous-variable-name: Ambiguous variable name: `l` [check:ambiguous-variable-name]
rule_id = l[0][RuleExec.id]

# Assert context exists, is of string type, and is not empty.
self.assertGreater(l[0][RuleExec.context], "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also assert that RULE_EXEC_CONTEXT is parsable as a JSON string since that is how it is stored in the database.

finally:
# Remove the delayed rule from the queue.
if rule_id >= 0:
r.remove_by_id(rule_id)


if __name__ == "__main__":
# let the tests find the parent irods lib
sys.path.insert(0, os.path.abspath("../.."))
Expand Down
Loading