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
108 changes: 32 additions & 76 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ install-runners:
@echo ""
# NOTE: We use xargs to speed things up by installing runners in parallel
echo -e "$(COMPONENTS_RUNNERS)" | tr -d "\n" | xargs -P $(XARGS_CONCURRENCY) -d " " -n1 -i bash -c "set -x; . $(VIRTUALENV_DIR)/bin/activate; cd $$(pwd)/{} ; $(PYBIN) -m pip install --editable . --no-deps"
#@for component in $(COMPONENTS_RUNNERS); do \
# echo "==========================================================="; \
# echo "Installing runner:" $$component; \
# echo "==========================================================="; \
# #(. $(VIRTUALENV_DIR)/bin/activate; cd $$component; python -m pip install --editable . --no-deps); \
#done

.PHONY: install-mock-runners
install-mock-runners:
Expand All @@ -198,12 +192,6 @@ install-mock-runners:
@echo ""
# NOTE: We use xargs to speed things up by installing runners in parallel
echo -e "$(MOCK_RUNNERS)" | tr -d "\n" | xargs -P $(XARGS_CONCURRENCY) -d " " -n1 -i sh -c ". $(VIRTUALENV_DIR)/bin/activate; cd $$(pwd)/{} ; $(PYBIN) -m pip install --editable . --no-deps"
#@for component in $(MOCK_RUNNERS); do \
# echo "==========================================================="; \
# echo "Installing mock runner:" $$component; \
# echo "==========================================================="; \
# (. $(VIRTUALENV_DIR)/bin/activate; cd $$component; python -m pip install --editable . --no-deps); \
#done

.PHONY: check-requirements
.check-requirements:
Expand Down Expand Up @@ -262,12 +250,12 @@ check-python-packages:
@echo "================== CHECK PYTHON PACKAGES ===================="
@echo ""
test -f $(VIRTUALENV_COMPONENTS_DIR)/bin/activate || $(PYBIN) -m venv $(VIRTUALENV_COMPONENTS_DIR) --system-site-packages
$(VIRTUALENV_COMPONENTS_DIR)/bin/pip install --quiet "setuptools==$(SETUPTOOLS_VERSION)"
$(VIRTUALENV_COMPONENTS_DIR)/bin/pip install --quiet "setuptools==$(SETUPTOOLS_VERSION)" setuptools_scm
@for component in $(COMPONENTS_WITHOUT_ST2TESTS); do \
echo "==========================================================="; \
echo "Checking component:" $$component; \
echo "==========================================================="; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) setup.py --version) || exit 1; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) -m setuptools_scm) || exit 1; \
done

.PHONY: check-python-packages-nightly
Expand All @@ -279,13 +267,13 @@ check-python-packages-nightly:
@echo ""

test -f $(VIRTUALENV_COMPONENTS_DIR)/bin/activate || $(PYBIN) -m venv $(VIRTUALENV_COMPONENTS_DIR) --system-site-packages
$(VIRTUALENV_COMPONENTS_DIR)/bin/pip install --quiet "setuptools==$(SETUPTOOLS_VERSION)" wheel
$(VIRTUALENV_COMPONENTS_DIR)/bin/pip install --quiet "setuptools==$(SETUPTOOLS_VERSION)" setuptools_scm wheel
@for component in $(COMPONENTS_WITHOUT_ST2TESTS); do \
echo "==========================================================="; \
echo "Checking component:" $$component; \
echo "==========================================================="; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) setup.py --version) || exit 1; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) setup.py sdist bdist_wheel) || exit 1; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) -m setuptools_scm) || exit 1; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) -m build) || exit 1; \
(set -e; cd $$component; ../$(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) -m pip install --editable . --no-deps) || exit 1; \
($(VIRTUALENV_COMPONENTS_DIR)/bin/$(PYBIN) -c "import $$component") || exit 1; \
(set -e; cd $$component; rm -rf dist/; rm -rf $$component.egg-info) || exit 1; \
Expand Down Expand Up @@ -662,13 +650,6 @@ distclean: clean
scripts/write-headers.sh $$component/dist_utils.py || break;\
done

# Copy over CHANGELOG.RST, CONTRIBUTING.RST and LICENSE file to each component directory
#@for component in $(COMPONENTS_TEST); do\
# test -s $$component/README.rst || cp -f README.rst $$component/; \
# cp -f CONTRIBUTING.rst $$component/; \
# cp -f LICENSE $$component/; \
#done

.PHONY: .requirements
.requirements: virtualenv
$(VIRTUALENV_DIR)/bin/$(PYBIN) -m pip install --upgrade "pip==$(PIP_VERSION)"
Expand All @@ -681,16 +662,10 @@ distclean: clean
# Remove any *.egg-info files which polute PYTHONPATH
rm -rf *.egg-info*

# Generate finall requirements.txt file for each component
# Generate final requirements.txt file for each component
# NOTE: We use xargs to speed things up by running commands in parallel
echo -e "$(COMPONENTS_WITH_RUNNERS)" | tr -d "\n" | xargs -P $(XARGS_CONCURRENCY) -d " " -n1 -i sh -c "$(VIRTUALENV_DIR)/bin/$(PYBIN) scripts/fixate-requirements.py --skip=virtualenv,virtualenv-osx -s {}/in-requirements.txt -f fixed-requirements.txt -o {}/requirements.txt"

#@for component in $(COMPONENTS_WITH_RUNNERS); do\
# echo "==========================================================="; \
# echo "Generating requirements.txt for" $$component; \
# $(VIRTUALENV_DIR)/bin/python scripts/fixate-requirements.py --skip=virtualenv,virtualenv-osx -s $$component/in-requirements.txt -f fixed-requirements.txt -o $$component/requirements.txt; \
#done

@echo "==========================================================="

.PHONY: requirements
Expand Down Expand Up @@ -781,21 +756,6 @@ endif
echo 'export PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate
touch $(VIRTUALENV_DIR)/bin/activate

# Setup PYTHONPATH in fish activate script...
#echo '' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo 'set -gx _OLD_PYTHONPATH $$PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo 'set -gx PYTHONPATH $$_OLD_PYTHONPATH $(COMPONENT_PYTHONPATH)' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo 'functions -c deactivate old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo 'function deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' if test -n $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' set -gx PYTHONPATH $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' set -e _OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' end' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo ' functions -e old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
#echo 'end' >> $(VIRTUALENV_DIR)/bin/activate.fish
#touch $(VIRTUALENV_DIR)/bin/activate.fish

# debug pip installed packages
$(VIRTUALENV_DIR)/bin/pip list

Expand Down Expand Up @@ -867,7 +827,7 @@ endif
@echo
@echo "----- Dropping st2-test db -----"
@mongosh st2-test --eval "db.dropDatabase();"
failed=0; \
failed=(); \
for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
Expand All @@ -878,13 +838,13 @@ endif
ST2TESTS_REDIS_PORT=$(ST2TESTS_REDIS_PORT) \
COVERAGE_FILE=.coverage.unit.$$(echo $$component | tr '/' '.') \
pytest --verbose $(PYTEST_OPTS) --cov=$$component --cov-branch \
$$component/tests/unit || ((failed+=1)); \
$$component/tests/unit || failed+=($$component); \
echo "-----------------------------------------------------------"; \
echo "Done running tests in" $$component; \
echo "==========================================================="; \
done; \
echo pytest runs failed=$$failed; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi

.PHONY: .combine-unit-tests-coverage
.combine-unit-tests-coverage: .run-unit-tests-coverage
Expand Down Expand Up @@ -929,21 +889,21 @@ itests: requirements .itests
@echo
@echo "----- Dropping st2-test db -----"
@mongosh st2-test --eval "db.dropDatabase();"
@failed=0; \
@failed=(); \
for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running integration tests in" $$component; \
echo "-----------------------------------------------------------"; \
. $(VIRTUALENV_DIR)/bin/activate; \
EVENTLET_TESTS=1 \
pytest --capture=no --verbose $(PYTEST_OPTS) \
$$component/tests/integration || ((failed+=1)); \
$$component/tests/integration || failed+=($$component); \
echo "-----------------------------------------------------------"; \
echo "Done running integration tests in" $$component; \
echo "==========================================================="; \
done; \
echo pytest runs failed=$$failed; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi

.PHONY: .run-integration-tests-coverage
ifdef INCLUDE_TESTS_IN_COVERAGE
Expand All @@ -955,7 +915,7 @@ endif
@echo
@echo "----- Dropping st2-test db -----"
@mongosh st2-test --eval "db.dropDatabase();"
@failed=0; \
@failed=(); \
for component in $(COMPONENTS_TEST); do\
echo "==========================================================="; \
echo "Running integration tests in" $$component; \
Expand All @@ -964,13 +924,13 @@ endif
EVENTLET_TESTS=1 \
COVERAGE_FILE=.coverage.integration.$$(echo $$component | tr '/' '.') \
pytest --capture=no --verbose $(PYTEST_OPTS) --cov=$$component --cov-branch \
$$component/tests/integration || ((failed+=1)); \
$$component/tests/integration || failed+=($$component); \
echo "-----------------------------------------------------------"; \
echo "Done integration running tests in" $$component; \
echo "==========================================================="; \
done; \
echo pytest runs failed=$$failed; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi
# NOTE: If you also want to run orquesta tests which seem to have a bunch of race conditions, use
# ci-integration-full target
# @echo
Expand Down Expand Up @@ -1039,13 +999,6 @@ endif
make .coverage-combine; \
fi

# @for coverage_result in $(COVERAGE_GLOBS); do \
# [ -e $${coverage_result} ] || echo "$${coverage_result} does not exist." && continue; \
# echo "Combining data from $${coverage_result}"; \
# . $(VIRTUALENV_DIR)/bin/activate; coverage combine $${coverage_result}; \
# done || \
# (echo "Running .coverage-combine"; make .coverage-combine)

.PHONY: .coverage-report
.coverage-report: .coverage
. $(VIRTUALENV_DIR)/bin/activate; coverage report
Expand Down Expand Up @@ -1096,14 +1049,16 @@ runners-tests: requirements .runners-tests
@echo
@echo "----- Dropping st2-test db -----"
@mongosh st2-test --eval "db.dropDatabase();"
@failed=0; \
@failed=(); \
for component in $(COMPONENTS_RUNNERS); do\
echo "==========================================================="; \
echo "Running tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; pytest --capture=no --verbose $(PYTEST_OPTS) $$component/tests/unit || ((failed+=1)); \
. $(VIRTUALENV_DIR)/bin/activate; \
pytest --capture=no --verbose $(PYTEST_OPTS) $$component/tests/unit || failed+=($$component); \
done; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi

.PHONY: runners-itests
runners-itests: requirements .runners-itests
Expand All @@ -1114,32 +1069,33 @@ runners-itests: requirements .runners-itests
@echo "==================== runners-itests ===================="
@echo
@echo "----- Dropping st2-test db -----"
@failed=0; \
@failed=(); \
for component in $(COMPONENTS_RUNNERS); do\
echo "==========================================================="; \
echo "Running integration tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; pytest --capture=no --verbose $(PYTEST_OPTS) $$component/tests/integration || ((failed+=1)); \
. $(VIRTUALENV_DIR)/bin/activate; \
pytest --capture=no --verbose $(PYTEST_OPTS) $$component/tests/integration || failed+=($$component); \
done; \
echo pytest runs failed=$$failed; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi

.PHONY: .runners-itests-coverage-html
.runners-itests-coverage-html:
@echo
@echo "============== runners-itests-coverage-html =============="
@echo
@echo "The tests assume st2 is running on 127.0.0.1."
@failed=0; \
@failed=(); \
for component in $(COMPONENTS_RUNNERS); do\
echo "==========================================================="; \
echo "Running integration tests in" $$component; \
echo "==========================================================="; \
. $(VIRTUALENV_DIR)/bin/activate; pytest --capture=no --verbose $(PYTEST_OPTS) \
--cov=$$component --cov-report=html $$component/tests/integration || ((failed+=1)); \
--cov=$$component --cov-report=html $$component/tests/integration || failed+=($$component); \
done; \
echo pytest runs failed=$$failed; \
if [ $$failed -gt 0 ]; then exit 1; fi
echo "pytest runs failed=$${failed[@]}"; \
if [ $${#failed[@]} -gt 0 ]; then exit 1; fi

.PHONY: cli
cli:
Expand Down
3 changes: 3 additions & 0 deletions conf/st2.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ protocol = udp
[system]
# Base path to all st2 artifacts.
base_path = /opt/stackstorm
# Green thread concurrency library to use ('eventlet' or 'gevent'). NOTE: This is read directly from this config file at process startup, before oslo_config is available, so it cannot be overridden via CLI args or environment variables.
# Valid values: eventlet, gevent
concurrency_library = gevent
# Enable debug mode.
debug = False
# True to validate action and runner output against schema.
Expand Down
1 change: 1 addition & 0 deletions conf/st2.tests.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ api_url = http://127.0.0.1:9101/
[system]
# This way integration tests can write to this directory
base_path = /tmp
concurrency_library = gevent

[garbagecollector]
logging = st2reactor/conf/logging.garbagecollector.conf
Expand Down
10 changes: 10 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
import hashlib
from typing import Iterable, List, Sequence

# NOTE: This must happen before any test module imports anything that pulls in tooz/eventlet
# (e.g. st2common.services.coordination). Tooz's Heart binds threading.Thread/Event as default
# args at import time, so if it's imported before monkey patching, it permanently uses the
# unpatched primitives -- causing gevent.exceptions.LoopExit or hangs later. Pytest always loads
# this file before any test module, in both whole-directory and single-file (Pants) runs, so this
# is the one place that reliably wins the race regardless of which test file happens to run first.
from st2common.util.monkey_patch import monkey_patch

monkey_patch()

from _pytest import nodes
from _pytest.config import create_terminal_writer

Expand Down
4 changes: 2 additions & 2 deletions contrib/examples/actions/python-mock-create-vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import eventlet
import random

from st2common.runners.base_action import Action
from st2common.util import concurrency


class MockCreateVMAction(Action):
def run(self, cpu_cores, memory_mb, vm_name, ip):
eventlet.sleep(5)
concurrency.sleep(5)

data = {
"vm_id": "vm" + str(random.randint(0, 10000)),
Expand Down
5 changes: 2 additions & 3 deletions contrib/hello_st2/sensors/sensor1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import eventlet

from st2common.util import concurrency
from st2reactor.sensor.base import Sensor


Expand All @@ -34,7 +33,7 @@ def run(self):
payload = {"greeting": "Yo, StackStorm!", "count": int(count) + 1}
self.sensor_service.dispatch(trigger="hello_st2.event1", payload=payload)
self.sensor_service.set_value("hello_st2.count", payload["count"])
eventlet.sleep(60)
concurrency.sleep(60)

def cleanup(self):
self._stop = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from __future__ import absolute_import

import eventlet
import traceback
import uuid
import datetime
Expand All @@ -24,6 +23,7 @@
from jsonschema import exceptions as json_schema_exc
from oslo_config import cfg

from st2common.util import concurrency
from st2common.runners.base import ActionRunner
from st2common.runners.base import get_metadata as get_runner_metadata
from st2common import log as logging
Expand Down Expand Up @@ -879,7 +879,7 @@ def _run_action(self, liveaction, wait_for_completion=True, sleep_delay=1.0):
action_constants.LIVEACTION_STATUS_PENDING,
]
):
eventlet.sleep(sleep_delay)
concurrency.sleep(sleep_delay)
liveaction = action_db_util.get_liveaction_by_id(liveaction.id)

return liveaction
Expand All @@ -901,7 +901,7 @@ def _resume_action(self, liveaction, wait_for_completion=True, sleep_delay=1.0):
action_constants.LIVEACTION_COMPLETED_STATES
+ [action_constants.LIVEACTION_STATUS_PAUSED]
):
eventlet.sleep(sleep_delay)
concurrency.sleep(sleep_delay)
liveaction = action_db_util.get_liveaction_by_id(liveaction.id)

return liveaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_chain_runner_bad_default(self, request):
runnerexceptions.ActionRunnerPreRunError, expected_msg, chain_runner.pre_run
)

@mock.patch("eventlet.sleep", mock.MagicMock())
@mock.patch("st2common.util.concurrency.sleep", mock.MagicMock())
@mock.patch.object(
action_db_util,
"get_liveaction_by_id",
Expand Down
Loading
Loading