Skip to content

Commit

Permalink
Pants: Add BUILD metadata for integration tests (#6275)
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd authored Nov 16, 2024
2 parents 6ee7ed7 + 098759f commit e51fe93
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Added
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 #6253
#6254 #6258 #6259 #6260 #6269
#6254 #6258 #6259 #6260 #6269 #6275
Contributed by @cognifloyd
* Build of ST2 EL9 packages #6153
Contributed by @amanda11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import absolute_import
import os
import unittest
import uuid

import mock
Expand Down Expand Up @@ -45,6 +46,8 @@

__all__ = ["LocalShellCommandRunnerTestCase", "LocalShellScriptRunnerTestCase"]

ST2_CI = os.environ.get("ST2_CI", "false").lower() == "true"

MOCK_EXECUTION = mock.Mock()
MOCK_EXECUTION.id = "598dbf0c0640fd54bffc688b"

Expand Down Expand Up @@ -94,6 +97,11 @@ def test_shell_command_action_basic(self):
self.assertEqual(output_dbs[0].output_type, "stdout")
self.assertEqual(output_dbs[0].data, "10\n")

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_timeout(self):
models = self.fixtures_loader.load_models(
fixtures_pack=GENERIC_PACK, fixtures_dict={"actions": ["local.yaml"]}
Expand Down Expand Up @@ -141,8 +149,13 @@ def test_common_st2_env_vars_are_available_to_the_action(self):
self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
self.assertEqual(result["stdout"].strip(), "mock-token")

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_sudo_and_env_variable_preservation(self):
# Verify that the environment environment are correctly preserved when running as a
# Verify that the environment vars are correctly preserved when running as a
# root / non-system user
# Note: This test will fail if SETENV option is not present in the sudoers file
models = self.fixtures_loader.load_models(
Expand Down Expand Up @@ -297,6 +310,11 @@ def test_action_stdout_and_stderr_is_stored_in_the_db_short_running_action(
self.assertEqual(output_dbs[db_index_1].data, mock_stderr[0])
self.assertEqual(output_dbs[db_index_2].data, mock_stderr[1])

# This test depends on passwordless sudo. Don't require that for local development.
@unittest.skipIf(
not ST2_CI,
'Skipping tests because ST2_CI environment variable is not set to "true"',
)
def test_shell_command_sudo_password_is_passed_to_sudo_binary(self):
# Verify that sudo password is correctly passed to sudo binary via stdin
models = self.fixtures_loader.load_models(
Expand Down
2 changes: 1 addition & 1 deletion contrib/runners/orquesta_runner/tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ __defaults__(

python_tests(
name="tests",
uses=["redis"],
uses=["mongo", "rabbitmq", "redis", "system_user"],
)
7 changes: 7 additions & 0 deletions pants.ci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ remote_provider = "experimental-github-actions-cache"
remote_cache_read = true
remote_cache_write = true

# https://www.pantsbuild.org/stable/reference/global-options#ignore_warnings
ignore_warnings = [
# remote cache errors caused by GitHub rate-limits are not helpful
"Failed to read from remote cache",
"Failed to write to remote cache",
]

[stats]
# "print metrics of your cache's performance at the end of the run,
# including the number of cache hits and the total time saved thanks
Expand Down
2 changes: 2 additions & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ extra_env_vars = [
"ST2TESTS_REDIS_HOST",
"ST2TESTS_REDIS_PORT",
]
# 10 min should be more than enough even for integration tests.
timeout_default = 600 # seconds

[twine]
install_from_resolve = "twine"
Expand Down
4 changes: 4 additions & 0 deletions st2actions/tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ __defaults__(

python_tests(
name="tests",
uses=["rabbitmq"],
stevedore_namespaces=[
"st2common.metrics.driver",
],
)
8 changes: 8 additions & 0 deletions st2api/tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ python_tests(
name="tests",
dependencies=[
"conf/st2.tests.conf:st2_tests_conf",
"st2api/st2api/wsgi.py",
"st2auth/st2auth/wsgi.py",
],
stevedore_namespaces=[
"st2auth.sso.backends",
"st2common.metrics.driver",
"st2common.rbac.backend",
],
uses=["mongo", "rabbitmq", "redis"],
)
3 changes: 2 additions & 1 deletion st2common/tests/fixtures/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
python_sources()

shell_sources(
st2_shell_sources_and_resources(
name="shell",
sources=["*.sh"],
)
37 changes: 32 additions & 5 deletions st2common/tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,46 @@ __defaults__(

python_tests(
name="tests",
dependencies=[
# used by test_register_content_script
"conf/st2.tests.conf:st2_tests_conf",
"conf/st2.tests1.conf:st2_tests_conf",
],
stevedore_namespaces=[
"orquesta.expressions.functions",
"st2common.runners.runner",
"st2common.rbac.backend",
"st2common.metrics.driver",
],
uses=["mongo", "rabbitmq", "redis"],
overrides={
"test_logging.py": dict(
dependencies=[
"./log_unicode_data.py",
],
),
"test_register_content_script.py": dict(
dependencies=[
"conf/st2.tests.conf:st2_tests_conf",
"conf/st2.tests1.conf:st2_tests_conf",
"st2common/bin/st2-register-content",
],
),
"test_service_setup_log_level_filtering.py": dict(
dependencies=[
"st2api/bin/st2api",
],
),
"test_util_green.py": dict(
dependencies=[
"st2common/tests/fixtures/print_to_stdout_stderr_sleep.sh:shell_resources",
],
),
},
)

python_test_utils(
sources=["*.py", "!test_*.py"],
overrides={
"log_unicode_data.py": dict(
dependencies=[
"st2tests/st2tests/fixtures/conf:st2.tests.conf",
],
),
},
)
48 changes: 44 additions & 4 deletions st2reactor/tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,50 @@ __defaults__(
extend=True,
)

_conf_deps = [
"conf/st2.tests.conf:st2_tests_conf",
"conf/st2.tests2.conf:st2_tests_conf",
]

python_tests(
name="tests",
dependencies=[
"conf/st2.tests.conf:st2_tests_conf",
"conf/st2.tests2.conf:st2_tests_conf",
],
dependencies=_conf_deps,
uses=["mongo", "rabbitmq", "redis"],
overrides={
"test_garbage_collector.py": dict(
dependencies=[
*_conf_deps,
"st2reactor/bin/st2garbagecollector",
],
stevedore_namespaces=[
"st2common.metrics.driver",
],
entry_point_dependencies={
"contrib/runners/inquirer_runner": ["st2common.runners.runner"],
},
),
"test_rules_engine.py": dict(
dependencies=[
*_conf_deps,
"st2reactor/bin/st2timersengine",
],
stevedore_namespaces=[
"st2common.metrics.driver",
],
),
"test_sensor_container.py": dict(
dependencies=[
*_conf_deps,
"st2reactor/bin/st2sensorcontainer",
"contrib/examples/sensors",
"contrib/examples:metadata",
],
stevedore_namespaces=[
"st2common.metrics.driver",
],
),
"test_sensor_watcher.py": dict(
uses=["rabbitmq"],
),
},
)
2 changes: 1 addition & 1 deletion st2tests/integration/orquesta/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
python_tests(
name="tests",
uses=["redis"],
uses=["mongo", "rabbitmq", "redis", "system_user"],
)

python_test_utils(
Expand Down

0 comments on commit e51fe93

Please sign in to comment.