From eec3d75c4447ec81e889dcf421ca37e70bc90891 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 11:42:13 +0200 Subject: [PATCH 01/16] Update various dependencies. --- fixed-requirements.txt | 10 +++++----- requirements.txt | 10 +++++----- st2client/requirements.txt | 2 +- st2common/requirements.txt | 6 +++--- test-requirements.txt | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fixed-requirements.txt b/fixed-requirements.txt index 097253fea8..bde5e566ac 100644 --- a/fixed-requirements.txt +++ b/fixed-requirements.txt @@ -1,6 +1,6 @@ # Packages versions fixed for the whole st2 stack # Note: greenlet is used by eventlet -greenlet==0.4.14 +greenlet==0.4.15 # Note: 0.20.0 removed select.poll() on which some of our code and libraries we # depend on rely eventlet==0.24.1 @@ -19,15 +19,15 @@ requests[security]<2.15,>=2.14.1 apscheduler==3.5.3 gitpython==2.1.11 jsonschema==2.6.0 -pymongo==3.7.1 +pymongo==3.7.2 passlib==1.7.1 lockfile==0.12.2 python-gnupg==0.4.3 jsonpath-rw==1.4.0 pyinotify==0.9.6 semver==2.8.1 -pytz==2018.5 -stevedore==1.29.0 +pytz==2018.6 +stevedore==1.30.0 paramiko==2.4.2 networkx==1.11 python-keyczar==0.716 @@ -38,7 +38,7 @@ virtualenv==15.1.0 sseclient==0.0.19 python-editor==1.0.3 prompt-toolkit==1.0.15 -tooz==1.62.0 +tooz==1.63.1 zake==0.2.2 routes==2.4.1 flex==6.13.2 diff --git a/requirements.txt b/requirements.txt index 5ef56a7883..82b9b4b982 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ git+/~https://github.com/StackStorm/orquesta.git@142a19ddabbeea6a8d9d10341ba705851 git+/~https://github.com/StackStorm/python-mistralclient.git#egg=python-mistralclient git+/~https://github.com/StackStorm/st2-auth-backend-flat-file.git@master#egg=st2-auth-backend-flat-file gitpython==2.1.11 -greenlet==0.4.14 +greenlet==0.4.15 gunicorn==19.9.0 ipaddr jinja2 @@ -34,14 +34,14 @@ prometheus_client==0.1.1 prompt-toolkit==1.0.15 psutil==5.4.7 pyinotify==0.9.6 -pymongo==3.7.1 +pymongo==3.7.2 pyrabbit python-dateutil python-editor==1.0.3 python-gnupg==0.4.3 python-json-logger python-statsd==2.1.0 -pytz==2018.5 +pytz==2018.6 pywinrm==0.3.0 pyyaml==3.13 rednose @@ -51,8 +51,8 @@ routes==2.4.1 semver==2.8.1 six==1.11.0 sseclient==0.0.19 -stevedore==1.29.0 -tooz==1.62.0 +stevedore==1.30.0 +tooz==1.63.1 ujson==1.35 unittest2 webob==1.8.2 diff --git a/st2client/requirements.txt b/st2client/requirements.txt index fec0a83097..9121403ec4 100644 --- a/st2client/requirements.txt +++ b/st2client/requirements.txt @@ -6,7 +6,7 @@ prettytable prompt-toolkit==1.0.15 python-dateutil python-editor==1.0.3 -pytz==2018.5 +pytz==2018.6 pyyaml==3.13 requests[security]<2.15,>=2.14.1 six==1.11.0 diff --git a/st2common/requirements.txt b/st2common/requirements.txt index a53cbfe431..196956eb1a 100644 --- a/st2common/requirements.txt +++ b/st2common/requirements.txt @@ -5,7 +5,7 @@ eventlet==0.24.1 flex==6.13.2 git+/~https://github.com/StackStorm/mongoengine.git@stackstorm_patched#egg=mongoengine git+/~https://github.com/StackStorm/orquesta.git@142a19ddabbeea6a8d9d10341ba70585114dc3b7#egg=orquesta -greenlet==0.4.14 +greenlet==0.4.15 ipaddr jinja2 jsonpath-rw==1.4.0 @@ -15,7 +15,7 @@ networkx==1.11 oslo.config<1.13,>=1.12.1 paramiko==2.4.2 prometheus_client==0.1.1 -pymongo==3.7.1 +pymongo==3.7.2 python-dateutil python-statsd==2.1.0 pyyaml==3.13 @@ -24,7 +24,7 @@ retrying==1.3.3 routes==2.4.1 semver==2.8.1 six==1.11.0 -tooz==1.62.0 +tooz==1.63.1 ujson==1.35 webob==1.8.2 zake==0.2.2 diff --git a/test-requirements.txt b/test-requirements.txt index 2e0513ea41..4c71d0e380 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,16 +1,16 @@ coverage pep8==1.7.1 -flake8==3.5.0 -astroid==1.6.4 +flake8==3.6.0 +astroid==2.0.4 pylint==1.9.3 pylint-plugin-utils>=0.4 -bandit==1.4.0 +bandit==1.5.1 ipython<6.0.0 mock==2.0.0 nose>=1.3.7 tabulate unittest2 -sphinx==1.7.5 +sphinx==1.8.1 sphinx-autobuild # nosetests enhancements rednose From af6eda1a55560d13f75db262c43c6737825ac0ab Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 15:07:24 +0200 Subject: [PATCH 02/16] Try a workaround for for intermediate test failures. --- st2actions/tests/unit/policies/test_concurrency.py | 10 ++++++++++ .../tests/unit/policies/test_concurrency_by_attr.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/st2actions/tests/unit/policies/test_concurrency.py b/st2actions/tests/unit/policies/test_concurrency.py index 350624807b..1abfc16908 100644 --- a/st2actions/tests/unit/policies/test_concurrency.py +++ b/st2actions/tests/unit/policies/test_concurrency.py @@ -85,6 +85,12 @@ def setUpClass(cls): loader.save_fixtures_to_db(fixtures_pack=PACK, fixtures_dict=TEST_FIXTURES) + def setUp(self): + super(ConcurrencyPolicyTestCase, self).setUp() + + # Wait for all threads to finish processing so there is no cross test polution + MockLiveActionPublisherNonBlocking.wait_all() + def tearDown(self): for liveaction in LiveAction.get_all(): action_service.update_status( @@ -259,12 +265,16 @@ def test_on_cancellation(self): # Since states are being processed asynchronously, wait for the # liveactions to go into scheduled states. + MockLiveActionPublisherNonBlocking.wait_all() + for i in range(0, 100): eventlet.sleep(1) scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] if len(scheduled) == policy_db.parameters['threshold']: break + MockLiveActionPublisherNonBlocking.wait_all() + scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] self.assertEqual(len(scheduled), policy_db.parameters['threshold']) diff --git a/st2actions/tests/unit/policies/test_concurrency_by_attr.py b/st2actions/tests/unit/policies/test_concurrency_by_attr.py index 62f37f3ba4..517bdf9fc8 100644 --- a/st2actions/tests/unit/policies/test_concurrency_by_attr.py +++ b/st2actions/tests/unit/policies/test_concurrency_by_attr.py @@ -85,6 +85,11 @@ def setUpClass(cls): loader.save_fixtures_to_db(fixtures_pack=PACK, fixtures_dict=TEST_FIXTURES) + def setUp(self): + super(ConcurrencyByAttributePolicyTestCase, self).setUp() + + MockLiveActionPublisherNonBlocking.wait_all() + def tearDown(self): for liveaction in LiveAction.get_all(): action_service.update_status( @@ -109,6 +114,8 @@ def test_over_threshold_delay_executions(self): liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'}) action_service.request(liveaction) + MockLiveActionPublisherNonBlocking.wait_all() + # Since states are being processed asynchronously, wait for the # liveactions to go into scheduled states. for i in range(0, 100): @@ -117,6 +124,8 @@ def test_over_threshold_delay_executions(self): if len(scheduled) == policy_db.parameters['threshold']: break + MockLiveActionPublisherNonBlocking.wait_all() + scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] self.assertEqual(len(scheduled), policy_db.parameters['threshold']) @@ -282,12 +291,16 @@ def test_on_cancellation(self): # Since states are being processed asynchronously, wait for the # liveactions to go into scheduled states. + MockLiveActionPublisherNonBlocking.wait_all() + for i in range(0, 100): eventlet.sleep(1) scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] if len(scheduled) == policy_db.parameters['threshold']: break + MockLiveActionPublisherNonBlocking.wait_all() + scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] self.assertEqual(len(scheduled), policy_db.parameters['threshold']) From a18be9138fa56387a52b2bcef04a2b30a8378f58 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 15:09:37 +0200 Subject: [PATCH 03/16] Update more deps. --- fixed-requirements.txt | 1 + requirements.txt | 2 +- scripts/travis/install-requirements.sh | 2 +- st2client/requirements.txt | 2 +- st2common/requirements.txt | 2 +- test-requirements.txt | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fixed-requirements.txt b/fixed-requirements.txt index bde5e566ac..bb90511aae 100644 --- a/fixed-requirements.txt +++ b/fixed-requirements.txt @@ -53,3 +53,4 @@ python-statsd==2.1.0 prometheus_client==0.1.1 mock==2.0.0 ujson==1.35 +python-dateutil==2.7.4 diff --git a/requirements.txt b/requirements.txt index 82b9b4b982..9c34f63579 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,7 +36,7 @@ psutil==5.4.7 pyinotify==0.9.6 pymongo==3.7.2 pyrabbit -python-dateutil +python-dateutil==2.7.4 python-editor==1.0.3 python-gnupg==0.4.3 python-json-logger diff --git a/scripts/travis/install-requirements.sh b/scripts/travis/install-requirements.sh index 85450bcc0c..4b5d6d2f9e 100755 --- a/scripts/travis/install-requirements.sh +++ b/scripts/travis/install-requirements.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if [ "${TASK}" = 'compilepy3 ci-py3-unit' ] || [ "${TASK}" = 'ci-py3-integration' ]; then - pip install "tox==3.1.3" + pip install "tox==3.5.2" # Install runners . virtualenv/bin/activate diff --git a/st2client/requirements.txt b/st2client/requirements.txt index 9121403ec4..23fb755f5f 100644 --- a/st2client/requirements.txt +++ b/st2client/requirements.txt @@ -4,7 +4,7 @@ jsonpath-rw==1.4.0 jsonschema==2.6.0 prettytable prompt-toolkit==1.0.15 -python-dateutil +python-dateutil==2.7.4 python-editor==1.0.3 pytz==2018.6 pyyaml==3.13 diff --git a/st2common/requirements.txt b/st2common/requirements.txt index 196956eb1a..c61b6afe0b 100644 --- a/st2common/requirements.txt +++ b/st2common/requirements.txt @@ -16,7 +16,7 @@ oslo.config<1.13,>=1.12.1 paramiko==2.4.2 prometheus_client==0.1.1 pymongo==3.7.2 -python-dateutil +python-dateutil==2.7.4 python-statsd==2.1.0 pyyaml==3.13 requests[security]<2.15,>=2.14.1 diff --git a/test-requirements.txt b/test-requirements.txt index 4c71d0e380..0efc46de1a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ coverage pep8==1.7.1 flake8==3.6.0 astroid==2.0.4 -pylint==1.9.3 +pylint==2.1.1 pylint-plugin-utils>=0.4 bandit==1.5.1 ipython<6.0.0 From a80094f6c31931113f1fef32d0014084d906ed78 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 15:09:43 +0200 Subject: [PATCH 04/16] Add workaround for travis / pip issue. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 1d625e880f..f50efc4d51 100644 --- a/Makefile +++ b/Makefile @@ -383,6 +383,7 @@ requirements: virtualenv .sdist-requirements install-runners # Fix for Travis CI caching issue $(VIRTUALENV_DIR)/bin/pip uninstall -y "pytz" + $(VIRTUALENV_DIR)/bin/pip uninstall -y "python-dateutil" # Install requirements # From 3ee45016dc89de89c52718f17271e49313d90c5f Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 17:44:39 +0200 Subject: [PATCH 05/16] Add in wait_all. --- st2actions/tests/unit/policies/test_concurrency.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/st2actions/tests/unit/policies/test_concurrency.py b/st2actions/tests/unit/policies/test_concurrency.py index 1abfc16908..538b2e64ac 100644 --- a/st2actions/tests/unit/policies/test_concurrency.py +++ b/st2actions/tests/unit/policies/test_concurrency.py @@ -114,6 +114,8 @@ def test_over_threshold_delay_executions(self): liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'}) action_service.request(liveaction) + MockLiveActionPublisherNonBlocking.wait_all() + # Since states are being processed asynchronously, wait for the # liveactions to go into scheduled states. for i in range(0, 100): @@ -122,6 +124,8 @@ def test_over_threshold_delay_executions(self): if len(scheduled) == policy_db.parameters['threshold']: break + MockLiveActionPublisherNonBlocking.wait_all() + scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES] self.assertEqual(len(scheduled), policy_db.parameters['threshold']) From 4b930f65840faba8757ac64e485b3e6d4f6df2e3 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Fri, 26 Oct 2018 21:58:53 +0200 Subject: [PATCH 06/16] Update dependencies. --- test-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 0efc46de1a..bc9f39c592 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,8 @@ coverage pep8==1.7.1 flake8==3.6.0 -astroid==2.0.4 -pylint==2.1.1 +astroid==1.6.5 +pylint==1.9.2 pylint-plugin-utils>=0.4 bandit==1.5.1 ipython<6.0.0 From b45b9576ae6b88542ab94f2eb81bcc7a30e0525d Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 11:55:40 +0100 Subject: [PATCH 07/16] Also add wait_all to tearDown. --- st2actions/tests/unit/policies/test_concurrency.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/st2actions/tests/unit/policies/test_concurrency.py b/st2actions/tests/unit/policies/test_concurrency.py index 538b2e64ac..1de1db005e 100644 --- a/st2actions/tests/unit/policies/test_concurrency.py +++ b/st2actions/tests/unit/policies/test_concurrency.py @@ -92,6 +92,8 @@ def setUp(self): MockLiveActionPublisherNonBlocking.wait_all() def tearDown(self): + MockLiveActionPublisherNonBlocking.wait_all() + for liveaction in LiveAction.get_all(): action_service.update_status( liveaction, action_constants.LIVEACTION_STATUS_CANCELED) From 5239eaa45cf10ad6d6118e841f542e9714ce8872 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 11:55:40 +0100 Subject: [PATCH 08/16] Also add wait_all to tearDown. --- st2actions/tests/unit/policies/test_concurrency.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/st2actions/tests/unit/policies/test_concurrency.py b/st2actions/tests/unit/policies/test_concurrency.py index 538b2e64ac..1de1db005e 100644 --- a/st2actions/tests/unit/policies/test_concurrency.py +++ b/st2actions/tests/unit/policies/test_concurrency.py @@ -92,6 +92,8 @@ def setUp(self): MockLiveActionPublisherNonBlocking.wait_all() def tearDown(self): + MockLiveActionPublisherNonBlocking.wait_all() + for liveaction in LiveAction.get_all(): action_service.update_status( liveaction, action_constants.LIVEACTION_STATUS_CANCELED) From 6a4391a4f78eeb8503ed8c68fab73494f51f5118 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 12:03:54 +0100 Subject: [PATCH 09/16] Add wait_all to tearDown. --- st2actions/tests/unit/policies/test_concurrency_by_attr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/st2actions/tests/unit/policies/test_concurrency_by_attr.py b/st2actions/tests/unit/policies/test_concurrency_by_attr.py index 517bdf9fc8..ca5b00b476 100644 --- a/st2actions/tests/unit/policies/test_concurrency_by_attr.py +++ b/st2actions/tests/unit/policies/test_concurrency_by_attr.py @@ -91,6 +91,8 @@ def setUp(self): MockLiveActionPublisherNonBlocking.wait_all() def tearDown(self): + MockLiveActionPublisherNonBlocking.wait_all() + for liveaction in LiveAction.get_all(): action_service.update_status( liveaction, action_constants.LIVEACTION_STATUS_CANCELED) From fcf575a2b368e39d9232828a947eacbb3d79bcc9 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 12:04:01 +0100 Subject: [PATCH 10/16] Upgrade pylint. --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index bc9f39c592..c9ed9f268b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ coverage pep8==1.7.1 flake8==3.6.0 astroid==1.6.5 -pylint==1.9.2 +pylint==1.9.3 pylint-plugin-utils>=0.4 bandit==1.5.1 ipython<6.0.0 From 246e3447c4a5482c33cf4d6a487795d1a4700733 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 14:57:22 +0100 Subject: [PATCH 11/16] Ignore errors if a dependency is not installed (creating a new virtualenv from scratch). --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9a8b9923f6..d3bdd52567 100644 --- a/Makefile +++ b/Makefile @@ -383,8 +383,8 @@ requirements: virtualenv .sdist-requirements install-runners $(VIRTUALENV_DIR)/bin/pip install "six==1.11.0" # Fix for Travis CI caching issue - $(VIRTUALENV_DIR)/bin/pip uninstall -y "pytz" - $(VIRTUALENV_DIR)/bin/pip uninstall -y "python-dateutil" + $(VIRTUALENV_DIR)/bin/pip uninstall -y "pytz" || echo "not installed" + $(VIRTUALENV_DIR)/bin/pip uninstall -y "python-dateutil" || echo "not installed" # Install requirements # From 1839143d4c18aad5ab8d78202fa0a98ad88c05b4 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 15:18:41 +0100 Subject: [PATCH 12/16] Fix flake8 lint violations which are detected by new version of flake8. All the regular expression strings now need to be prefixed with r so they are correctly treated as raw strings. --- .../tests/unit/test_actionchain.py | 4 ++-- .../runners/local_runner/local_runner/base.py | 4 ++-- .../tests/unit/test_error_handling.py | 8 ++++---- .../tests/unit/test_pythonrunner.py | 16 ++++++++-------- .../tests/unit/test_windows_runners.py | 4 ++-- .../windows_runner/windows_runner/base.py | 4 ++-- .../windows_runner/windows_script_runner.py | 2 +- lint-configs/python/.flake8 | 2 +- .../tests/unit/test_actions_registrar.py | 8 ++++---- st2actions/tests/unit/test_notifier.py | 8 ++++---- st2api/st2api/controllers/resource.py | 2 +- .../controllers/v1/test_workflow_inspection.py | 8 ++++---- st2client/st2client/utils/jsutil.py | 2 +- st2common/st2common/models/api/action.py | 10 +++++----- st2common/st2common/models/api/execution.py | 2 +- st2common/st2common/models/api/pack.py | 2 +- st2common/st2common/models/api/policy.py | 4 ++-- .../st2common/models/system/actionchain.py | 4 ++-- st2common/st2common/runners/parallel_ssh.py | 6 +++--- st2common/st2common/util/ip_utils.py | 4 ++-- st2common/st2common/util/isotime.py | 2 +- st2common/st2common/util/workflow/mistral.py | 18 +++++++++--------- st2common/tests/unit/test_casts.py | 2 +- st2common/tests/unit/test_content_utils.py | 12 ++++++------ st2common/tests/unit/test_executions_util.py | 2 +- .../test_jinja_render_json_escape_filters.py | 2 +- .../unit/test_jinja_render_regex_filters.py | 8 ++++---- st2common/tests/unit/test_logger.py | 2 +- st2common/tests/unit/test_queue_utils.py | 2 +- .../tests/unit/test_resource_reference.py | 2 +- .../tests/unit/test_resource_registrar.py | 2 +- st2debug/st2debug/cmd/submit_debug_info.py | 4 ++-- st2debug/st2debug/utils/system_info.py | 2 +- .../orquesta/test_wiring_error_handling.py | 18 +++++++++--------- tools/log_watcher.py | 2 +- 35 files changed, 92 insertions(+), 92 deletions(-) diff --git a/contrib/runners/action_chain_runner/tests/unit/test_actionchain.py b/contrib/runners/action_chain_runner/tests/unit/test_actionchain.py index d392fb178d..89878fb7e9 100644 --- a/contrib/runners/action_chain_runner/tests/unit/test_actionchain.py +++ b/contrib/runners/action_chain_runner/tests/unit/test_actionchain.py @@ -702,8 +702,8 @@ def test_chain_task_passes_invalid_parameter_type_to_action(self, mock_request): chain_runner.pre_run() action_parameters = {} - expected_msg = ('Failed to cast value "stringnotanarray" \(type: str\) for parameter ' - '"arrtype" of type "array"') + expected_msg = (r'Failed to cast value "stringnotanarray" \(type: str\) for parameter ' + r'"arrtype" of type "array"') self.assertRaisesRegexp(ValueError, expected_msg, chain_runner.run, action_parameters=action_parameters) diff --git a/contrib/runners/local_runner/local_runner/base.py b/contrib/runners/local_runner/local_runner/base.py index 51b4143c3c..184aacee5a 100644 --- a/contrib/runners/local_runner/local_runner/base.py +++ b/contrib/runners/local_runner/local_runner/base.py @@ -182,8 +182,8 @@ def _run(self, action): # Detect if user provided an invalid sudo password or sudo is not configured for that user if self._sudo_password: - if re.search('sudo: \d+ incorrect password attempts', stderr): - match = re.search('\[sudo\] password for (.+?)\:', stderr) + if re.search(r'sudo: \d+ incorrect password attempts', stderr): + match = re.search(r'\[sudo\] password for (.+?)\:', stderr) if match: username = match.groups()[0] diff --git a/contrib/runners/orquesta_runner/tests/unit/test_error_handling.py b/contrib/runners/orquesta_runner/tests/unit/test_error_handling.py index 553c326272..f28bc0e9cf 100644 --- a/contrib/runners/orquesta_runner/tests/unit/test_error_handling.py +++ b/contrib/runners/orquesta_runner/tests/unit/test_error_handling.py @@ -111,7 +111,7 @@ def test_fail_inspection(self): { 'type': 'content', 'message': 'The action "std.noop" is not registered in the database.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.action', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.action', 'spec_path': 'tasks.task3.action' }, { @@ -119,7 +119,7 @@ def test_fail_inspection(self): 'language': 'yaql', 'expression': '<% ctx().foobar %>', 'message': 'Variable "foobar" is referenced before assignment.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input', 'spec_path': 'tasks.task1.input', }, { @@ -131,7 +131,7 @@ def test_fail_inspection(self): 'position 0 of expression \'<% succeeded()\'' ), 'schema_path': ( - 'properties.tasks.patternProperties.^\w+$.' + r'properties.tasks.patternProperties.^\w+$.' 'properties.next.items.properties.when' ), 'spec_path': 'tasks.task2.next[0].when' @@ -142,7 +142,7 @@ def test_fail_inspection(self): '[{\'cmd\': \'echo <% ctx().macro %>\'}] is ' 'not valid under any of the given schemas' ), - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', 'spec_path': 'tasks.task2.input' } ] diff --git a/contrib/runners/python_runner/tests/unit/test_pythonrunner.py b/contrib/runners/python_runner/tests/unit/test_pythonrunner.py index ff445dfc10..a5bb8054d5 100644 --- a/contrib/runners/python_runner/tests/unit/test_pythonrunner.py +++ b/contrib/runners/python_runner/tests/unit/test_pythonrunner.py @@ -104,10 +104,10 @@ def test_action_returns_non_serializable_result(self): if six.PY2: expected_result_re = (r"\[{'a': '1'}, {'h': 3, 'c': 2}, {'e': " - "}\]") + r"}\]") else: expected_result_re = (r"\[{'a': '1'}, {'c': 2, 'h': 3}, {'e': " - "}\]") + r"}\]") match = re.match(expected_result_re, output['result']) self.assertTrue(match) @@ -624,17 +624,17 @@ def test_python_action_wrapper_action_script_file_doesnt_exist_friendly_error(se wrapper = PythonActionWrapper(pack='dummy_pack_5', file_path=ACTION_1_PATH, user='joe') - expected_msg = ('Failed to load action class from file ".*?list_repos_doesnt_exist.py" ' - '\(action file most likely doesn\'t exist or contains invalid syntax\): ' - '\[Errno 2\] No such file or directory') + expected_msg = (r'Failed to load action class from file ".*?list_repos_doesnt_exist.py" ' + r'\(action file most likely doesn\'t exist or contains invalid syntax\): ' + r'\[Errno 2\] No such file or directory') self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance) def test_python_action_wrapper_action_script_file_contains_invalid_syntax_friendly_error(self): wrapper = PythonActionWrapper(pack='dummy_pack_5', file_path=ACTION_2_PATH, user='joe') - expected_msg = ('Failed to load action class from file ".*?invalid_syntax.py" ' - '\(action file most likely doesn\'t exist or contains invalid syntax\): ' - 'No module named \'?invalid\'?') + expected_msg = (r'Failed to load action class from file ".*?invalid_syntax.py" ' + r'\(action file most likely doesn\'t exist or contains invalid syntax\): ' + r'No module named \'?invalid\'?') self.assertRaisesRegexp(Exception, expected_msg, wrapper._get_action_instance) def test_simple_action_log_messages_and_log_level_runner_param(self): diff --git a/contrib/runners/windows_runner/tests/unit/test_windows_runners.py b/contrib/runners/windows_runner/tests/unit/test_windows_runners.py index 2025f3ebc6..8844c722ef 100644 --- a/contrib/runners/windows_runner/tests/unit/test_windows_runners.py +++ b/contrib/runners/windows_runner/tests/unit/test_windows_runners.py @@ -72,7 +72,7 @@ def test_get_winexe_command_args(self): [ 'winexe', '--interactive', '0', - '-U', 'MyDomain\Administrator3%bar3', + '-U', r'MyDomain\Administrator3%bar3', '//localhost', 'dir' ] @@ -123,7 +123,7 @@ def test_get_smbclient_command_args(self): ], [ 'smbclient', - '-U', 'MyDomain\Administrator3%bar3', + '-U', r'MyDomain\Administrator3%bar3', '//localhost/E$', '-c', 'dir' ], diff --git a/contrib/runners/windows_runner/windows_runner/base.py b/contrib/runners/windows_runner/windows_runner/base.py index e12089ff67..496f9412a0 100644 --- a/contrib/runners/windows_runner/windows_runner/base.py +++ b/contrib/runners/windows_runner/windows_runner/base.py @@ -62,7 +62,7 @@ def _get_winexe_command_args(self, host, username, password, command, domain=Non args += ['--interactive', '0'] if domain: - args += ['-U', '%s\%s%%%s' % (domain, username, password)] + args += ['-U', r'%s\%s%%%s' % (domain, username, password)] else: args += ['-U', '%s%%%s' % (username, password)] @@ -84,7 +84,7 @@ def _get_smbclient_command_args(self, host, username, password, command, share=' values = {'domain': domain, 'username': username, 'password': password} if domain: - auth_string = '%(domain)s\%(username)s%%%(password)s' % values + auth_string = r'%(domain)s\%(username)s%%%(password)s' % values else: auth_string = '%(username)s%%%(password)s' % values diff --git a/contrib/runners/windows_runner/windows_runner/windows_script_runner.py b/contrib/runners/windows_runner/windows_runner/windows_script_runner.py index a88e6a2f79..66c8b74117 100644 --- a/contrib/runners/windows_runner/windows_runner/windows_script_runner.py +++ b/contrib/runners/windows_runner/windows_runner/windows_script_runner.py @@ -314,7 +314,7 @@ def _parse_share_information(self, stdout): for line in lines: line = line.strip() - split = re.split('\s{3,}', line) + split = re.split(r'\s{3,}', line) if len(split) not in [1, 2]: # Invalid line, skip it diff --git a/lint-configs/python/.flake8 b/lint-configs/python/.flake8 index 38ab49ffb6..d9ea56c6ea 100644 --- a/lint-configs/python/.flake8 +++ b/lint-configs/python/.flake8 @@ -1,4 +1,4 @@ [flake8] max-line-length = 100 -ignore = E128,E402,E722 +ignore = E128,E402,E722,W504 exclude=*.egg/* diff --git a/st2actions/tests/unit/test_actions_registrar.py b/st2actions/tests/unit/test_actions_registrar.py index f2928dc665..4a0f365984 100644 --- a/st2actions/tests/unit/test_actions_registrar.py +++ b/st2actions/tests/unit/test_actions_registrar.py @@ -66,8 +66,8 @@ def test_pack_name_missing(self): content = yaml.safe_load(fd) action_name = str(content['name']) action_db = Action.get_by_name(action_name) - self.assertEqual(action_db.pack, 'dummy', 'Content pack must be ' + - 'set to dummy') + expected_msg = 'Content pack must be set to dummy' + self.assertEqual(action_db.pack, 'dummy', expected_msg) Action.delete(action_db) @mock.patch.object(action_validator, '_is_valid_pack', mock.MagicMock(return_value=True)) @@ -138,6 +138,6 @@ def test_action_update(self): content = yaml.safe_load(fd) action_name = str(content['name']) action_db = Action.get_by_name(action_name) - self.assertEqual(action_db.pack, 'wolfpack', 'Content pack must be ' + - 'set to wolfpack') + expected_msg = 'Content pack must be set to wolfpack' + self.assertEqual(action_db.pack, 'wolfpack', expected_msg) Action.delete(action_db) diff --git a/st2actions/tests/unit/test_notifier.py b/st2actions/tests/unit/test_notifier.py index f9f222f6a4..f82ecd0bf2 100644 --- a/st2actions/tests/unit/test_notifier.py +++ b/st2actions/tests/unit/test_notifier.py @@ -110,8 +110,8 @@ def test_notify_triggers(self): liveaction_db.notify = NotificationSchema(on_success=on_success, on_failure=on_failure) liveaction_db.start_timestamp = date_utils.get_datetime_utc_now() - liveaction_db.end_timestamp = (liveaction_db.start_timestamp + - datetime.timedelta(seconds=50)) + liveaction_db.end_timestamp = \ + (liveaction_db.start_timestamp + datetime.timedelta(seconds=50)) LiveAction.add_or_update(liveaction_db) execution = MOCK_EXECUTION @@ -181,8 +181,8 @@ def test_notify_triggers_jinja_patterns(self, dispatch): data={'stdout': '{{action_results.stdout}}'}) liveaction_db.notify = NotificationSchema(on_success=on_success) liveaction_db.start_timestamp = date_utils.get_datetime_utc_now() - liveaction_db.end_timestamp = (liveaction_db.start_timestamp + - datetime.timedelta(seconds=50)) + liveaction_db.end_timestamp = \ + (liveaction_db.start_timestamp + datetime.timedelta(seconds=50)) LiveAction.add_or_update(liveaction_db) diff --git a/st2api/st2api/controllers/resource.py b/st2api/st2api/controllers/resource.py index deed7f192b..3db751b64e 100644 --- a/st2api/st2api/controllers/resource.py +++ b/st2api/st2api/controllers/resource.py @@ -66,7 +66,7 @@ def parameter_validation(validator, properties, instance, schema): "description": "Input parameters for the action.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_parameters_schema() + r"^\w+$": util_schema.get_action_parameters_schema() }, 'additionalProperties': False, "default": {} diff --git a/st2api/tests/unit/controllers/v1/test_workflow_inspection.py b/st2api/tests/unit/controllers/v1/test_workflow_inspection.py index 06faf48414..8bc558824e 100644 --- a/st2api/tests/unit/controllers/v1/test_workflow_inspection.py +++ b/st2api/tests/unit/controllers/v1/test_workflow_inspection.py @@ -73,7 +73,7 @@ def test_inspection_return_errors(self): { 'type': 'content', 'message': 'The action "std.noop" is not registered in the database.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.action', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.action', 'spec_path': 'tasks.task3.action' }, { @@ -81,7 +81,7 @@ def test_inspection_return_errors(self): 'language': 'yaql', 'expression': '<% ctx().foobar %>', 'message': 'Variable "foobar" is referenced before assignment.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input', 'spec_path': 'tasks.task1.input', }, { @@ -93,7 +93,7 @@ def test_inspection_return_errors(self): 'position 0 of expression \'<% succeeded()\'' ), 'schema_path': ( - 'properties.tasks.patternProperties.^\w+$.' + r'properties.tasks.patternProperties.^\w+$.' 'properties.next.items.properties.when' ), 'spec_path': 'tasks.task2.next[0].when' @@ -104,7 +104,7 @@ def test_inspection_return_errors(self): '[{\'cmd\': \'echo <% ctx().macro %>\'}] is ' 'not valid under any of the given schemas' ), - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', 'spec_path': 'tasks.task2.input' } ] diff --git a/st2client/st2client/utils/jsutil.py b/st2client/st2client/utils/jsutil.py index bc56714510..e1a8602d21 100644 --- a/st2client/st2client/utils/jsutil.py +++ b/st2client/st2client/utils/jsutil.py @@ -33,7 +33,7 @@ # a..b # abc. # a(* -SIMPLE_EXPRESSION_REGEX = "^([a-zA-Z0-9\-_]+\.)*([a-zA-Z0-9\-_]+)$" +SIMPLE_EXPRESSION_REGEX = r"^([a-zA-Z0-9\-_]+\.)*([a-zA-Z0-9\-_]+)$" SIMPLE_EXPRESSION_REGEX_CMPL = re.compile(SIMPLE_EXPRESSION_REGEX) diff --git a/st2common/st2common/models/api/action.py b/st2common/st2common/models/api/action.py index 2c523a5070..658a602ca3 100644 --- a/st2common/st2common/models/api/action.py +++ b/st2common/st2common/models/api/action.py @@ -106,7 +106,7 @@ class RunnerTypeAPI(BaseAPI): "description": "Input parameters for the action runner.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_parameters_schema() + r"^\w+$": util_schema.get_action_parameters_schema() }, 'additionalProperties': False }, @@ -119,7 +119,7 @@ class RunnerTypeAPI(BaseAPI): "description": "Schema for the runner's output.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_output_schema() + r"^\w+$": util_schema.get_action_output_schema() }, 'additionalProperties': False, "default": {} @@ -217,7 +217,7 @@ class ActionAPI(BaseAPI, APIUIDMixin): "description": "Input parameters for the action.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_parameters_schema() + r"^\w+$": util_schema.get_action_parameters_schema() }, 'additionalProperties': False, "default": {} @@ -226,7 +226,7 @@ class ActionAPI(BaseAPI, APIUIDMixin): "description": "Schema for the action's output.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_output_schema() + r"^\w+$": util_schema.get_action_output_schema() }, 'additionalProperties': False, "default": {} @@ -375,7 +375,7 @@ class LiveActionAPI(BaseAPI): "description": "Input parameters for the action.", "type": "object", "patternProperties": { - "^\w+$": { + r"^\w+$": { "anyOf": [ {"type": "array"}, {"type": "boolean"}, diff --git a/st2common/st2common/models/api/execution.py b/st2common/st2common/models/api/execution.py index 8a6a94f9d3..7d181b5f65 100644 --- a/st2common/st2common/models/api/execution.py +++ b/st2common/st2common/models/api/execution.py @@ -94,7 +94,7 @@ class ActionExecutionAPI(BaseAPI): "description": "Input parameters for the action.", "type": "object", "patternProperties": { - "^\w+$": { + r"^\w+$": { "anyOf": [ {"type": "array"}, {"type": "boolean"}, diff --git a/st2common/st2common/models/api/pack.py b/st2common/st2common/models/api/pack.py index 7d9c56b821..a9e8619695 100644 --- a/st2common/st2common/models/api/pack.py +++ b/st2common/st2common/models/api/pack.py @@ -223,7 +223,7 @@ class ConfigSchemaAPI(BaseAPI): "description": "Config schema attributes.", "type": "object", "patternProperties": { - "^\w+$": util_schema.get_action_parameters_schema() + r"^\w+$": util_schema.get_action_parameters_schema() }, 'additionalProperties': False, "default": {} diff --git a/st2common/st2common/models/api/policy.py b/st2common/st2common/models/api/policy.py index 352dcc6b2a..ddbdc77779 100644 --- a/st2common/st2common/models/api/policy.py +++ b/st2common/st2common/models/api/policy.py @@ -65,7 +65,7 @@ class PolicyTypeAPI(BaseAPI, APIUIDMixin): "parameters": { "type": "object", "patternProperties": { - "^\w+$": util_schema.get_draft_schema() + r"^\w+$": util_schema.get_draft_schema() }, 'additionalProperties': False } @@ -125,7 +125,7 @@ class PolicyAPI(BaseAPI, APIUIDMixin): "parameters": { "type": "object", "patternProperties": { - "^\w+$": { + r"^\w+$": { "anyOf": [ {"type": "array"}, {"type": "boolean"}, diff --git a/st2common/st2common/models/system/actionchain.py b/st2common/st2common/models/system/actionchain.py index f4f766d0fd..5f16f281d7 100644 --- a/st2common/st2common/models/system/actionchain.py +++ b/st2common/st2common/models/system/actionchain.py @@ -68,7 +68,7 @@ class Node(object): " remainder of the chain as a global variable.", "type": "object", "patternProperties": { - "^\w+$": {} + r"^\w+$": {} } }, "notify": { @@ -137,7 +137,7 @@ class ActionChain(object): "description": "", "type": "object", "patternProperties": { - "^\w+$": {} + r"^\w+$": {} } } }, diff --git a/st2common/st2common/runners/parallel_ssh.py b/st2common/st2common/runners/parallel_ssh.py index 0a58beadd8..15d757b4bd 100644 --- a/st2common/st2common/runners/parallel_ssh.py +++ b/st2common/st2common/runners/parallel_ssh.py @@ -348,8 +348,8 @@ def _get_host_port_info(self, host_str): def _handle_command_result(self, stdout, stderr, exit_code): # Detect if user provided an invalid sudo password or sudo is not configured for that user if self._sudo_password: - if re.search('sudo: \d+ incorrect password attempts', stderr): - match = re.search('\[sudo\] password for (.+?)\:', stderr) + if re.search(r'sudo: \d+ incorrect password attempts', stderr): + match = re.search(r'\[sudo\] password for (.+?)\:', stderr) if match: username = match.groups()[0] @@ -376,7 +376,7 @@ def _sanitize_command_string(cmd): if not cmd: return cmd - result = re.sub('ST2_ACTION_AUTH_TOKEN=(.+?)\s+?', 'ST2_ACTION_AUTH_TOKEN=%s ' % + result = re.sub(r'ST2_ACTION_AUTH_TOKEN=(.+?)\s+?', 'ST2_ACTION_AUTH_TOKEN=%s ' % (MASKED_ATTRIBUTE_VALUE), cmd) return result diff --git a/st2common/st2common/util/ip_utils.py b/st2common/st2common/util/ip_utils.py index cf70f4724f..0b11719af7 100644 --- a/st2common/st2common/util/ip_utils.py +++ b/st2common/st2common/util/ip_utils.py @@ -27,10 +27,10 @@ 'split_host_port' ] -BRACKET_PATTERN = "^\[.*\]" # IPv6 bracket pattern to specify port +BRACKET_PATTERN = r"^\[.*\]" # IPv6 bracket pattern to specify port COMPILED_BRACKET_PATTERN = re.compile(BRACKET_PATTERN) -HOST_ONLY_IN_BRACKET = "^\[.*\]$" +HOST_ONLY_IN_BRACKET = r"^\[.*\]$" COMPILED_HOST_ONLY_IN_BRACKET_PATTERN = re.compile(HOST_ONLY_IN_BRACKET) diff --git a/st2common/st2common/util/isotime.py b/st2common/st2common/util/isotime.py index 60e488d6f1..0b8b13e99b 100644 --- a/st2common/st2common/util/isotime.py +++ b/st2common/st2common/util/isotime.py @@ -34,7 +34,7 @@ ISO8601_FORMAT = '%Y-%m-%dT%H:%M:%S' ISO8601_FORMAT_MICROSECOND = '%Y-%m-%dT%H:%M:%S.%f' ISO8601_UTC_REGEX = \ - '^\d{4}\-\d{2}\-\d{2}(\s|T)\d{2}:\d{2}:\d{2}(\.\d{3,6})?(Z|\+00|\+0000|\+00:00)$' + r'^\d{4}\-\d{2}\-\d{2}(\s|T)\d{2}:\d{2}:\d{2}(\.\d{3,6})?(Z|\+00|\+0000|\+00:00)$' def format(dt, usec=True, offset=True): diff --git a/st2common/st2common/util/workflow/mistral.py b/st2common/st2common/util/workflow/mistral.py index 0057b95074..08e12d9c91 100644 --- a/st2common/st2common/util/workflow/mistral.py +++ b/st2common/st2common/util/workflow/mistral.py @@ -33,13 +33,13 @@ LOG = logging.getLogger(__name__) -CMD_PTRN = re.compile("^[\w\.]+[^=\s\"]*") +CMD_PTRN = re.compile(r"^[\w\.]+[^=\s\"]*") -INLINE_YAQL = '<%.*?%>' -_ALL_IN_BRACKETS = "\[.*\]\s*" -_ALL_IN_QUOTES = "\"[^\"]*\"\s*" -_ALL_IN_APOSTROPHES = "'[^']*'\s*" -_DIGITS = "\d+" +INLINE_YAQL = r'<%.*?%>' +_ALL_IN_BRACKETS = r"\[.*\]\s*" +_ALL_IN_QUOTES = r"\"[^\"]*\"\s*" +_ALL_IN_APOSTROPHES = r"'[^']*'\s*" +_DIGITS = r"\d+" _TRUE = "true" _FALSE = "false" _NULL = "null" @@ -49,7 +49,7 @@ _ALL_IN_BRACKETS, _TRUE, _FALSE, _NULL, _DIGITS ) -PARAMS_PTRN = re.compile("([\w]+)=(%s)" % "|".join(ALL)) +PARAMS_PTRN = re.compile(r"([\w]+)=(%s)" % "|".join(ALL)) SPEC_TYPES = { 'adhoc': { @@ -62,9 +62,9 @@ } } -JINJA_REGEX_WITH_ST2KV = '{{st2kv\..*?|.*?\sst2kv\..*?}}' +JINJA_REGEX_WITH_ST2KV = r'{{st2kv\..*?|.*?\sst2kv\..*?}}' JINJA_REGEX_WITH_ST2KV_PTRN = re.compile(JINJA_REGEX_WITH_ST2KV) -JINJA_REGEX_WITH_LOCAL_CTX = '{{.*?_\..*?}}' +JINJA_REGEX_WITH_LOCAL_CTX = r'{{.*?_\..*?}}' JINJA_REGEX_WITH_LOCAL_CTX_PTRN = re.compile(JINJA_REGEX_WITH_LOCAL_CTX) diff --git a/st2common/tests/unit/test_casts.py b/st2common/tests/unit/test_casts.py index f2b166eaa1..e29bf68bdb 100644 --- a/st2common/tests/unit/test_casts.py +++ b/st2common/tests/unit/test_casts.py @@ -44,7 +44,7 @@ def test_cast_string(self): # Non string or non, should throw a friendly exception value = [] - expected_msg = 'Value "\[\]" must either be a string or None. Got "list"' + expected_msg = r'Value "\[\]" must either be a string or None. Got "list"' self.assertRaisesRegexp(ValueError, expected_msg, cast_func, value) def test_cast_array(self): diff --git a/st2common/tests/unit/test_content_utils.py b/st2common/tests/unit/test_content_utils.py index c80f2795eb..751787cd97 100644 --- a/st2common/tests/unit/test_content_utils.py +++ b/st2common/tests/unit/test_content_utils.py @@ -119,8 +119,8 @@ def test_get_pack_resource_file_abs_path(self): '../../foo.py'] for file_path in file_paths: # action resource_type - expected_msg = ('Invalid file path: ".*%s"\. File path needs to be relative to the ' - 'pack actions directory (.*). For example "my_action.py"\.' % + expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the ' + r'pack actions directory (.*). For example "my_action.py"\.' % (file_path)) self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path, pack_ref='dummy_pack_1', @@ -128,8 +128,8 @@ def test_get_pack_resource_file_abs_path(self): file_path=file_path) # sensor resource_type - expected_msg = ('Invalid file path: ".*%s"\. File path needs to be relative to the ' - 'pack sensors directory (.*). For example "my_sensor.py"\.' % + expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the ' + r'pack sensors directory (.*). For example "my_sensor.py"\.' % (file_path)) self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path, pack_ref='dummy_pack_1', @@ -137,8 +137,8 @@ def test_get_pack_resource_file_abs_path(self): file_path=file_path) # no resource type - expected_msg = ('Invalid file path: ".*%s"\. File path needs to be relative to the ' - 'pack directory (.*). For example "my_action.py"\.' % + expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the ' + r'pack directory (.*). For example "my_action.py"\.' % (file_path)) self.assertRaisesRegexp(ValueError, expected_msg, get_pack_file_abs_path, pack_ref='dummy_pack_1', diff --git a/st2common/tests/unit/test_executions_util.py b/st2common/tests/unit/test_executions_util.py index 489ddb42bc..26096aa8a1 100644 --- a/st2common/tests/unit/test_executions_util.py +++ b/st2common/tests/unit/test_executions_util.py @@ -169,7 +169,7 @@ def test_abandon_executions(self): def test_abandon_executions_on_complete(self): liveaction_db = self.MODELS['liveactions']['successful_liveaction.yaml'] executions_util.create_execution_object(liveaction_db) - expected_msg = 'LiveAction %s already in a completed state %s\.' % \ + expected_msg = r'LiveAction %s already in a completed state %s\.' % \ (str(liveaction_db.id), liveaction_db.status) self.assertRaisesRegexp(ValueError, expected_msg, diff --git a/st2common/tests/unit/test_jinja_render_json_escape_filters.py b/st2common/tests/unit/test_jinja_render_json_escape_filters.py index fa4928c6ec..bfca3da01c 100644 --- a/st2common/tests/unit/test_jinja_render_json_escape_filters.py +++ b/st2common/tests/unit/test_jinja_render_json_escape_filters.py @@ -32,7 +32,7 @@ def test_doublequotes(self): def test_backslashes(self): env = jinja_utils.get_jinja_environment() template = '{{ test_str | json_escape }}' - actual = env.from_string(template).render({'test_str': 'foo \ bar'}) + actual = env.from_string(template).render({'test_str': r'foo \ bar'}) expected = 'foo \\\\ bar' self.assertEqual(actual, expected) diff --git a/st2common/tests/unit/test_jinja_render_regex_filters.py b/st2common/tests/unit/test_jinja_render_regex_filters.py index 2b2c06b970..2e94a02033 100644 --- a/st2common/tests/unit/test_jinja_render_regex_filters.py +++ b/st2common/tests/unit/test_jinja_render_regex_filters.py @@ -74,7 +74,7 @@ def test_filters_regex_substring(self): env = jinja_utils.get_jinja_environment() # Normal (match) - template = '{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))")}}' + template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))")}}' actual = env.from_string(template).render( {'input_str': 'My address is 123 Somewhere Ave. See you soon!'} ) @@ -82,7 +82,7 @@ def test_filters_regex_substring(self): self.assertEqual(actual, expected) # Selecting second match explicitly - template = '{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' + template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' actual = env.from_string(template).render( {'input_str': 'Your address is 567 Elsewhere Dr. My address is 123 Somewhere Ave.'} ) @@ -90,14 +90,14 @@ def test_filters_regex_substring(self): self.assertEqual(actual, expected) # Selecting second match explicitly, but doesn't exist - template = '{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' + template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {'input_str': 'Your address is 567 Elsewhere Dr.'} ) # No match - template = '{{input_str | regex_substring("([0-3]{3} \w+ (?:Ave|St|Dr))")}}' + template = r'{{input_str | regex_substring("([0-3]{3} \w+ (?:Ave|St|Dr))")}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {'input_str': 'My address is 986 Somewhere Ave. See you soon!'} diff --git a/st2common/tests/unit/test_logger.py b/st2common/tests/unit/test_logger.py index a255c7e6ce..fb40472edf 100644 --- a/st2common/tests/unit/test_logger.py +++ b/st2common/tests/unit/test_logger.py @@ -250,7 +250,7 @@ def test_format_secret_action_parameters_are_masked(self): record._action_execution_db = mock_action_execution_db expected_msg_part = (r"'parameters': {u?'parameter1': u?'value1', " - "u?'parameter2': u?'\*\*\*\*\*\*\*\*'}") + r"u?'parameter2': u?'\*\*\*\*\*\*\*\*'}") message = formatter.format(record=record) self.assertTrue('test message 1' in message) diff --git a/st2common/tests/unit/test_queue_utils.py b/st2common/tests/unit/test_queue_utils.py index ae1a423b81..737b9fe0bf 100644 --- a/st2common/tests/unit/test_queue_utils.py +++ b/st2common/tests/unit/test_queue_utils.py @@ -41,7 +41,7 @@ def test_get_queue_name(self): queue_name_suffix='foo', add_random_uuid_to_suffix=True ) - pattern = re.compile('st2.test.watch.foo-\w') + pattern = re.compile(r'st2.test.watch.foo-\w') self.assertTrue(re.match(pattern, queue_name)) queue_name = queue_utils.get_queue_name( diff --git a/st2common/tests/unit/test_resource_reference.py b/st2common/tests/unit/test_resource_reference.py index 3f6484fc35..be7a28471f 100644 --- a/st2common/tests/unit/test_resource_reference.py +++ b/st2common/tests/unit/test_resource_reference.py @@ -48,7 +48,7 @@ def test_to_string_reference(self): ref = ResourceReference.to_string_reference(pack='mapack', name='moname') self.assertEqual(ref, 'mapack.moname') - expected_msg = 'Pack name should not contain "\."' + expected_msg = r'Pack name should not contain "\."' self.assertRaisesRegexp(ValueError, expected_msg, ResourceReference.to_string_reference, pack='pack.invalid', name='bar') diff --git a/st2common/tests/unit/test_resource_registrar.py b/st2common/tests/unit/test_resource_registrar.py index b6682e74ea..91bf3ec3b0 100644 --- a/st2common/tests/unit/test_resource_registrar.py +++ b/st2common/tests/unit/test_resource_registrar.py @@ -189,6 +189,6 @@ def test_register_pack_invalid_config_schema_invalid_attribute(self): registrar._pack_loader.get_packs.return_value = {'dummy_pack_18': PACK_PATH_18} packs_base_paths = content_utils.get_packs_base_paths() - expected_msg = 'Additional properties are not allowed \(\'invalid\' was unexpected\)' + expected_msg = r'Additional properties are not allowed \(\'invalid\' was unexpected\)' self.assertRaisesRegexp(ValueError, expected_msg, registrar.register_packs, base_dirs=packs_base_paths) diff --git a/st2debug/st2debug/cmd/submit_debug_info.py b/st2debug/st2debug/cmd/submit_debug_info.py index 4fe6c60a5d..b0aa21e8ac 100644 --- a/st2debug/st2debug/cmd/submit_debug_info.py +++ b/st2debug/st2debug/cmd/submit_debug_info.py @@ -490,9 +490,9 @@ def format_output_filename(cmd): :rtype: ``str`` """ if six.PY3: - cmd = cmd.translate(cmd.maketrans('', '', """ !@#$%^&*()[]{};:,./<>?\|`~=+"'""")) + cmd = cmd.translate(cmd.maketrans('', '', r""" !@#$%^&*()[]{};:,./<>?\|`~=+"'""")) else: - cmd = cmd.translate(None, """ !@#$%^&*()[]{};:,./<>?\|`~=+"'""") + cmd = cmd.translate(None, r""" !@#$%^&*()[]{};:,./<>?\|`~=+"'""") return cmd diff --git a/st2debug/st2debug/utils/system_info.py b/st2debug/st2debug/utils/system_info.py index 6a482a2429..99bf703cdd 100644 --- a/st2debug/st2debug/utils/system_info.py +++ b/st2debug/st2debug/utils/system_info.py @@ -145,7 +145,7 @@ def get_deb_package_list(name_startswith): if not line: continue - split = re.split('\s+', line) + split = re.split(r'\s+', line) name = split[1] version = split[2] diff --git a/st2tests/integration/orquesta/test_wiring_error_handling.py b/st2tests/integration/orquesta/test_wiring_error_handling.py index 82bbac4d67..a4a053d13e 100644 --- a/st2tests/integration/orquesta/test_wiring_error_handling.py +++ b/st2tests/integration/orquesta/test_wiring_error_handling.py @@ -27,7 +27,7 @@ def test_inspection_error(self): { 'type': 'content', 'message': 'The action "std.noop" is not registered in the database.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.action', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.action', 'spec_path': 'tasks.task3.action' }, { @@ -35,7 +35,7 @@ def test_inspection_error(self): 'language': 'yaql', 'expression': '<% ctx().foobar %>', 'message': 'Variable "foobar" is referenced before assignment.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input', 'spec_path': 'tasks.task1.input', }, { @@ -47,7 +47,7 @@ def test_inspection_error(self): 'position 0 of expression \'<% succeeded()\'' ), 'schema_path': ( - 'properties.tasks.patternProperties.^\w+$.' + r'properties.tasks.patternProperties.^\w+$.' 'properties.next.items.properties.when' ), 'spec_path': 'tasks.task2.next[0].when' @@ -58,7 +58,7 @@ def test_inspection_error(self): '[{\'cmd\': \'echo <% ctx().macro %>\'}] is ' 'not valid under any of the given schemas' ), - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input.oneOf', 'spec_path': 'tasks.task2.input' } ] @@ -135,27 +135,27 @@ def test_task_content_errors(self): { 'type': 'content', 'message': 'The action reference "echo" is not formatted correctly.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.action', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.action', 'spec_path': 'tasks.task1.action' }, { 'type': 'content', 'message': 'The action "core.echoz" is not registered in the database.', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.action', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.action', 'spec_path': 'tasks.task2.action' }, { 'type': 'content', 'message': 'Action "core.echo" is missing required input "message".', - 'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input', + 'schema_path': r'properties.tasks.patternProperties.^\w+$.properties.input', 'spec_path': 'tasks.task3.input' }, { 'type': 'content', 'message': 'Action "core.echo" has unexpected input "messages".', 'schema_path': ( - 'properties.tasks.patternProperties.^\w+$.properties.input.' - 'patternProperties.^\w+$' + r'properties.tasks.patternProperties.^\w+$.properties.input.' + r'patternProperties.^\w+$' ), 'spec_path': 'tasks.task3.input.messages' } diff --git a/tools/log_watcher.py b/tools/log_watcher.py index d65dd751c5..7d2b5cf1a9 100755 --- a/tools/log_watcher.py +++ b/tools/log_watcher.py @@ -84,7 +84,7 @@ def _build_regex(): regex_strings = {} regexes = {} for level in EVILS: - regex_string = '|'.join(['\.'.join([log, level]) for log in LOG_VARS]) + regex_string = '|'.join([r'\.'.join([log, level]) for log in LOG_VARS]) regex_strings[level] = regex_string # print('Level: %s, regex_string: %s' % (level, regex_strings[level])) regexes[level] = re.compile(regex_strings[level]) From 1922120a9bbc68fa1f42f2ba7c42063df398dec7 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 29 Oct 2018 15:45:23 +0100 Subject: [PATCH 13/16] New version of sphinx breaks rstcheck. --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index c9ed9f268b..18b562a691 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,7 +10,7 @@ mock==2.0.0 nose>=1.3.7 tabulate unittest2 -sphinx==1.8.1 +sphinx==1.7.9 sphinx-autobuild # nosetests enhancements rednose From 2ea60a41d9c7f73db13120fdab94290796e4bb74 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 30 Oct 2018 10:49:47 +0100 Subject: [PATCH 14/16] Add changelog entry. --- CHANGELOG.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 333ba956ab..1e805fafc9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -48,6 +48,8 @@ Changed If user wants to retrieve and view all the attributes, they can use ``--attr all`` CLI command argument (same as before). (improvement) #4396 +* Update various internal dependencies to latest stable versions (greenlet, pymongo, pytz, + stevedore, tooz). #4410 Fixed ~~~~~ From 94c02fb9ddb0055ce774f260793b8223ea9891ca Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 30 Oct 2018 14:02:43 +0100 Subject: [PATCH 15/16] Use longer token expiry time. Depending on when module is imported, token could already expire by the time tests actually run. --- st2api/tests/unit/controllers/v1/test_executions_auth.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/st2api/tests/unit/controllers/v1/test_executions_auth.py b/st2api/tests/unit/controllers/v1/test_executions_auth.py index 679773999d..12c4a50d1d 100644 --- a/st2api/tests/unit/controllers/v1/test_executions_auth.py +++ b/st2api/tests/unit/controllers/v1/test_executions_auth.py @@ -73,8 +73,13 @@ } } +# NOTE: We use a longer expiry time because this variable is initialized on +# module import (aka when nosetests or similar imports this module before +# running the tests). +# Depending on when the import happens, token could expire already and tests +# fail. NOW = date_utils.get_datetime_utc_now() -EXPIRY = NOW + datetime.timedelta(seconds=300) +EXPIRY = NOW + datetime.timedelta(seconds=1000) SYS_TOKEN = TokenDB(id=bson.ObjectId(), user='system', token=uuid.uuid4().hex, expiry=EXPIRY) USR_TOKEN = TokenDB(id=bson.ObjectId(), user='tokenuser', token=uuid.uuid4().hex, expiry=EXPIRY) From eab6c6df7b7c2404574e8de5b9d37c590852ac89 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 30 Oct 2018 14:10:47 +0100 Subject: [PATCH 16/16] Update the comment. --- st2api/tests/unit/controllers/v1/test_executions_auth.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/st2api/tests/unit/controllers/v1/test_executions_auth.py b/st2api/tests/unit/controllers/v1/test_executions_auth.py index 12c4a50d1d..dc987e01eb 100644 --- a/st2api/tests/unit/controllers/v1/test_executions_auth.py +++ b/st2api/tests/unit/controllers/v1/test_executions_auth.py @@ -73,11 +73,10 @@ } } -# NOTE: We use a longer expiry time because this variable is initialized on -# module import (aka when nosetests or similar imports this module before -# running the tests). -# Depending on when the import happens, token could expire already and tests -# fail. +# NOTE: We use a longer expiry time because this variable is initialized on module import (aka +# when nosetests or similar imports this module before running the tests. +# Depending on when the import happens and when the tests actually run, token could already expire +# by that time and the tests would fail. NOW = date_utils.get_datetime_utc_now() EXPIRY = NOW + datetime.timedelta(seconds=1000) SYS_TOKEN = TokenDB(id=bson.ObjectId(), user='system', token=uuid.uuid4().hex, expiry=EXPIRY)