From 73b5259436dc504444f30d1138a614dfbb60488e Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 23 May 2024 15:57:46 -0500 Subject: [PATCH 1/4] pants: fix running test_util_file_system test --- st2common/tests/unit/test_util_file_system.py | 12 ++++++------ st2tests/st2tests/policies/meta/BUILD | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/st2common/tests/unit/test_util_file_system.py b/st2common/tests/unit/test_util_file_system.py index f45498702b..58f7bf6473 100644 --- a/st2common/tests/unit/test_util_file_system.py +++ b/st2common/tests/unit/test_util_file_system.py @@ -27,21 +27,21 @@ class FileSystemUtilsTestCase(unittest.TestCase): def test_get_file_list(self): + # NB: Make sure to exclude BUILD files as pants will not include them in the sandbox, + # but the BUILD files will be present if you directly run the tests. + basic_excludes = ["*.pyc", "__pycache__", "*BUILD"] + # Standard exclude pattern directory = os.path.join(ST2TESTS_DIR, "policies") expected = [ - "BUILD", "mock_exception.py", "concurrency.py", "__init__.py", - "meta/BUILD", "meta/mock_exception.yaml", "meta/concurrency.yaml", "meta/__init__.py", ] - result = get_file_list( - directory=directory, exclude_patterns=["*.pyc", "__pycache__"] - ) + result = get_file_list(directory=directory, exclude_patterns=basic_excludes) # directory listings are sorted because the item order must be exact for assert # to validate equivalence. Directory item order doesn't matter in general and may # even change on different platforms or locales. @@ -55,7 +55,7 @@ def test_get_file_list(self): "meta/__init__.py", ] result = get_file_list( - directory=directory, exclude_patterns=["*.pyc", "*.yaml", "*BUILD"] + directory=directory, exclude_patterns=["*.yaml"] + basic_excludes ) # directory listings are sorted because the item order must be exact for assert # to validate equivalence. Directory item order doesn't matter in general and may diff --git a/st2tests/st2tests/policies/meta/BUILD b/st2tests/st2tests/policies/meta/BUILD index 0700f34cd5..53560669a3 100644 --- a/st2tests/st2tests/policies/meta/BUILD +++ b/st2tests/st2tests/policies/meta/BUILD @@ -1,3 +1,9 @@ resources( - sources=["*.yaml"], + sources=[ + "*.yaml", + # pants ignores empty __init__.py files. + # However, the tests for st2common.util.file_system need it to be present, + # so we treat it as a resource instead of a python source file. + "__init__.py", + ], ) From 784bb618b26722bab19efb8d62818af299e92e21 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 23 May 2024 22:21:23 -0500 Subject: [PATCH 2/4] pants: fix running services/test_packs tests --- contrib/core/BUILD | 6 +++++- contrib/core/actions/send_mail/BUILD | 5 +++-- st2common/tests/unit/services/test_packs.py | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/contrib/core/BUILD b/contrib/core/BUILD index 7db2dc9d25..59673bd746 100644 --- a/contrib/core/BUILD +++ b/contrib/core/BUILD @@ -8,5 +8,9 @@ python_requirements( ) python_sources( - dependencies=[":metadata"], + dependencies=[ + ":metadata", + "./actions", + "./actions/send_mail:send_mail_resources", + ], ) diff --git a/contrib/core/actions/send_mail/BUILD b/contrib/core/actions/send_mail/BUILD index f27e7c10ec..94280e6e49 100644 --- a/contrib/core/actions/send_mail/BUILD +++ b/contrib/core/actions/send_mail/BUILD @@ -1,4 +1,5 @@ -shell_source( - source="send_mail", +st2_shell_sources_and_resources( + name="send_mail", + sources=["send_mail"], skip_shellcheck=True, ) diff --git a/st2common/tests/unit/services/test_packs.py b/st2common/tests/unit/services/test_packs.py index 69152a8398..668137e9cb 100644 --- a/st2common/tests/unit/services/test_packs.py +++ b/st2common/tests/unit/services/test_packs.py @@ -43,6 +43,7 @@ from st2tests.fixtures.packs.orquesta_tests.fixture import ( PACK_NAME as TEST_SOURCE_WORKFLOW_PACK, ) +import st2tests.config as tests_config SOURCE_ACTION_WITH_PYTHON_SCRIPT_RUNNER = { "description": "Action which injects a new trigger in the system.", @@ -416,6 +417,8 @@ def test_exception_to_remove_resource_metadata_file(self, remove): class CloneActionDBAndFilesTestCase(unittest.TestCase): @classmethod def setUpClass(cls): + super().setUpClass() + tests_config.parse_args() action_files_path = os.path.join(TEST_DEST_PACK_PATH, "actions") workflow_files_path = os.path.join(action_files_path, "workflows") if not os.path.isdir(action_files_path): @@ -588,6 +591,11 @@ def test_workflows_directory_created_if_does_not_exist(self): class CloneActionFilesBackupTestCase(unittest.TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + tests_config.parse_args() + @classmethod def tearDownClass(cls): action_files_path = os.path.join(TEST_DEST_PACK_PATH, "actions") From 96217fc2fb323bbc1999483a78b6ee1c37be2fbe Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 25 Sep 2024 22:50:00 -0500 Subject: [PATCH 3/4] update changelog entry --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9c7667727d..9e9a2ddf6b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -59,7 +59,7 @@ Added * Continue introducing `pants `_ to improve DX (Developer Experience) working on StackStorm, improve our security posture, and improve CI reliability thanks in part to pants' use of PEX lockfiles. This is not a user-facing addition. - #6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 + #6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253 Contributed by @cognifloyd * Build of ST2 EL9 packages #6153 Contributed by @amanda11 From ddc00ce8892ac5680a46480d3eeea7f1b4bbc4f2 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Thu, 26 Sep 2024 00:55:28 -0500 Subject: [PATCH 4/4] review feedback: fix typo in comment --- st2common/tests/unit/test_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2common/tests/unit/test_db.py b/st2common/tests/unit/test_db.py index 496db3b0fa..f403d856b9 100644 --- a/st2common/tests/unit/test_db.py +++ b/st2common/tests/unit/test_db.py @@ -112,7 +112,7 @@ def tearDown(self): @classmethod def tearDownClass(cls): # since tearDown discconnects, dropping the database in tearDownClass - # fails withotu establishing a new connection. + # fails without establishing a new connection. cls._establish_connection_and_re_create_db() super().tearDownClass()