2021-01-08 13:41:50 +01:00
|
|
|
From 5db9ccdb4f557cdbff670b18c45e55124e29c57c Mon Sep 17 00:00:00 2001
|
2020-04-07 14:14:01 +02:00
|
|
|
From: Jochen Breuer <jbreuer@suse.de>
|
|
|
|
Date: Tue, 10 Mar 2020 14:02:17 +0100
|
|
|
|
Subject: [PATCH] Changed imports to vendored Tornado
|
|
|
|
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/cli/batch_async.py | 25 ++++++++++++-----------
|
2020-04-07 14:14:01 +02:00
|
|
|
salt/master.py | 2 +-
|
|
|
|
tests/unit/cli/test_batch_async.py | 32 +++++++++++++++---------------
|
2021-01-08 13:41:50 +01:00
|
|
|
3 files changed, 30 insertions(+), 29 deletions(-)
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
diff --git a/salt/cli/batch_async.py b/salt/cli/batch_async.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 3dc04826d1..09aa85258b 100644
|
2020-04-07 14:14:01 +02:00
|
|
|
--- a/salt/cli/batch_async.py
|
|
|
|
+++ b/salt/cli/batch_async.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -8,6 +8,7 @@ import gc
|
|
|
|
import logging
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
import salt.client
|
2021-01-08 13:41:50 +01:00
|
|
|
+import salt.ext.tornado
|
|
|
|
import tornado
|
|
|
|
from salt.cli.batch import batch_get_eauth, batch_get_opts, get_bnum
|
|
|
|
|
|
|
|
@@ -46,7 +47,7 @@ class BatchAsync:
|
|
|
|
"""
|
|
|
|
|
2020-04-07 14:14:01 +02:00
|
|
|
def __init__(self, parent_opts, jid_gen, clear_load):
|
|
|
|
- ioloop = tornado.ioloop.IOLoop.current()
|
|
|
|
+ ioloop = salt.ext.tornado.ioloop.IOLoop.current()
|
2021-01-08 13:41:50 +01:00
|
|
|
self.local = salt.client.get_local_client(
|
|
|
|
parent_opts["conf_file"], io_loop=ioloop
|
|
|
|
)
|
|
|
|
@@ -161,7 +162,7 @@ class BatchAsync:
|
2020-04-07 14:14:01 +02:00
|
|
|
self.find_job_returned = self.find_job_returned.difference(running)
|
|
|
|
self.event.io_loop.spawn_callback(self.find_job, running)
|
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def find_job(self, minions):
|
|
|
|
if self.event:
|
2021-01-08 13:41:50 +01:00
|
|
|
not_done = minions.difference(self.done_minions).difference(
|
|
|
|
@@ -182,7 +183,7 @@ class BatchAsync:
|
2020-04-07 14:14:01 +02:00
|
|
|
jid=jid,
|
2021-01-08 13:41:50 +01:00
|
|
|
**self.eauth
|
|
|
|
)
|
|
|
|
- yield tornado.gen.sleep(self.opts["gather_job_timeout"])
|
|
|
|
+ yield salt.ext.tornado.gen.sleep(self.opts["gather_job_timeout"])
|
2020-04-07 14:14:01 +02:00
|
|
|
if self.event:
|
|
|
|
self.event.io_loop.spawn_callback(
|
2021-01-08 13:41:50 +01:00
|
|
|
self.check_find_job, not_done, jid
|
|
|
|
@@ -195,7 +196,7 @@ class BatchAsync:
|
|
|
|
)
|
2020-04-07 14:14:01 +02:00
|
|
|
self.close_safe()
|
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def start(self):
|
|
|
|
if self.event:
|
|
|
|
self.__set_event_handler()
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -213,13 +214,13 @@ class BatchAsync:
|
|
|
|
)
|
|
|
|
self.targeted_minions = set(ping_return["minions"])
|
|
|
|
# start batching even if not all minions respond to ping
|
|
|
|
- yield tornado.gen.sleep(
|
|
|
|
+ yield salt.ext.tornado.gen.sleep(
|
|
|
|
self.batch_presence_ping_timeout or self.opts["gather_job_timeout"]
|
|
|
|
)
|
2020-04-07 14:14:01 +02:00
|
|
|
if self.event:
|
|
|
|
self.event.io_loop.spawn_callback(self.start_batch)
|
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def start_batch(self):
|
|
|
|
if not self.initialized:
|
|
|
|
self.batch_size = get_bnum(self.opts, self.minions, True)
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -235,7 +236,7 @@ class BatchAsync:
|
2020-04-07 14:14:01 +02:00
|
|
|
if self.event:
|
|
|
|
self.event.io_loop.spawn_callback(self.run_next)
|
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def end_batch(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
left = self.minions.symmetric_difference(
|
|
|
|
self.done_minions.union(self.timedout_minions)
|
|
|
|
@@ -253,7 +254,7 @@ class BatchAsync:
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
# release to the IOLoop to allow the event to be published
|
|
|
|
# before closing batch async execution
|
|
|
|
- yield tornado.gen.sleep(1)
|
|
|
|
+ yield salt.ext.tornado.gen.sleep(1)
|
|
|
|
self.close_safe()
|
|
|
|
|
|
|
|
def close_safe(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -266,16 +267,16 @@ class BatchAsync:
|
|
|
|
del self
|
|
|
|
gc.collect()
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def schedule_next(self):
|
|
|
|
if not self.scheduled:
|
|
|
|
self.scheduled = True
|
|
|
|
# call later so that we maybe gather more returns
|
|
|
|
- yield tornado.gen.sleep(self.batch_delay)
|
|
|
|
+ yield salt.ext.tornado.gen.sleep(self.batch_delay)
|
|
|
|
if self.event:
|
|
|
|
self.event.io_loop.spawn_callback(self.run_next)
|
|
|
|
|
|
|
|
- @tornado.gen.coroutine
|
|
|
|
+ @salt.ext.tornado.gen.coroutine
|
|
|
|
def run_next(self):
|
|
|
|
self.scheduled = False
|
|
|
|
next_batch = self._get_next()
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -294,7 +295,7 @@ class BatchAsync:
|
|
|
|
metadata=self.metadata,
|
|
|
|
)
|
2020-04-07 14:14:01 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
- yield tornado.gen.sleep(self.opts["timeout"])
|
|
|
|
+ yield salt.ext.tornado.gen.sleep(self.opts["timeout"])
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
# The batch can be done already at this point, which means no self.event
|
|
|
|
if self.event:
|
|
|
|
diff --git a/salt/master.py b/salt/master.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 7a99af357a..ab85c7f5c6 100644
|
2020-04-07 14:14:01 +02:00
|
|
|
--- a/salt/master.py
|
|
|
|
+++ b/salt/master.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -2237,7 +2237,7 @@ class ClearFuncs(TransportMethods):
|
2020-04-07 14:14:01 +02:00
|
|
|
functools.partial(self._prep_jid, clear_load, {}),
|
2021-01-08 13:41:50 +01:00
|
|
|
batch_load,
|
2020-04-07 14:14:01 +02:00
|
|
|
)
|
|
|
|
- ioloop = tornado.ioloop.IOLoop.current()
|
|
|
|
+ ioloop = salt.ext.tornado.ioloop.IOLoop.current()
|
|
|
|
ioloop.add_callback(batch.start)
|
|
|
|
|
|
|
|
return {
|
|
|
|
diff --git a/tests/unit/cli/test_batch_async.py b/tests/unit/cli/test_batch_async.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index dcee9a87bd..82a712b15b 100644
|
2020-04-07 14:14:01 +02:00
|
|
|
--- a/tests/unit/cli/test_batch_async.py
|
|
|
|
+++ b/tests/unit/cli/test_batch_async.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1,8 +1,8 @@
|
2020-04-07 14:14:01 +02:00
|
|
|
-import tornado
|
|
|
|
+import salt.ext.tornado
|
2021-01-08 13:41:50 +01:00
|
|
|
from salt.cli.batch_async import BatchAsync
|
2020-04-07 14:14:01 +02:00
|
|
|
+from salt.ext.tornado.testing import AsyncTestCase
|
2021-01-08 13:41:50 +01:00
|
|
|
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
|
|
|
from tests.support.unit import TestCase, skipIf
|
|
|
|
-from tornado.testing import AsyncTestCase
|
|
|
|
|
2020-04-07 14:14:01 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
|
|
@@ -52,10 +52,10 @@ class AsyncBatchTestCase(AsyncTestCase, TestCase):
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.start_batch()
|
|
|
|
self.assertEqual(self.batch.batch_size, 2)
|
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_start_on_batch_presence_ping_timeout(self):
|
|
|
|
self.batch.event = MagicMock()
|
|
|
|
- future = tornado.gen.Future()
|
|
|
|
+ future = salt.ext.tornado.gen.Future()
|
2021-01-08 13:41:50 +01:00
|
|
|
future.set_result({"minions": ["foo", "bar"]})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.local.run_job_async.return_value = future
|
|
|
|
ret = self.batch.start()
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -71,10 +71,10 @@ class AsyncBatchTestCase(AsyncTestCase, TestCase):
|
2020-04-07 14:14:01 +02:00
|
|
|
# assert targeted_minions == all minions matched by tgt
|
2021-01-08 13:41:50 +01:00
|
|
|
self.assertEqual(self.batch.targeted_minions, {"foo", "bar"})
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_start_on_gather_job_timeout(self):
|
|
|
|
self.batch.event = MagicMock()
|
|
|
|
- future = tornado.gen.Future()
|
|
|
|
+ future = salt.ext.tornado.gen.Future()
|
2021-01-08 13:41:50 +01:00
|
|
|
future.set_result({"minions": ["foo", "bar"]})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.local.run_job_async.return_value = future
|
|
|
|
self.batch.batch_presence_ping_timeout = None
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -103,7 +103,7 @@ class AsyncBatchTestCase(AsyncTestCase, TestCase):
|
|
|
|
),
|
2020-04-07 14:14:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_start_batch_calls_next(self):
|
|
|
|
self.batch.run_next = MagicMock(return_value=MagicMock())
|
|
|
|
self.batch.event = MagicMock()
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -160,14 +160,14 @@ class AsyncBatchTestCase(AsyncTestCase, TestCase):
|
|
|
|
self.assertEqual(len(event.unsubscribe.mock_calls), 2)
|
|
|
|
self.assertEqual(len(event.remove_event_handler.mock_calls), 1)
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_next(self):
|
|
|
|
self.batch.event = MagicMock()
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.opts["fun"] = "my.fun"
|
|
|
|
self.batch.opts["arg"] = []
|
|
|
|
self.batch._get_next = MagicMock(return_value={"foo", "bar"})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.batch_size = 2
|
|
|
|
- future = tornado.gen.Future()
|
|
|
|
+ future = salt.ext.tornado.gen.Future()
|
2021-01-08 13:41:50 +01:00
|
|
|
future.set_result({"minions": ["foo", "bar"]})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.local.run_job_async.return_value = future
|
|
|
|
self.batch.run_next()
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -290,38 +290,38 @@ class AsyncBatchTestCase(AsyncTestCase, TestCase):
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch._BatchAsync__event_handler(MagicMock())
|
2021-01-08 13:41:50 +01:00
|
|
|
self.assertEqual(self.batch.find_job_returned, {"foo"})
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_run_next_end_batch_when_no_next(self):
|
|
|
|
self.batch.end_batch = MagicMock()
|
|
|
|
self.batch._get_next = MagicMock(return_value={})
|
|
|
|
self.batch.run_next()
|
|
|
|
self.assertEqual(len(self.batch.end_batch.mock_calls), 1)
|
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_find_job(self):
|
|
|
|
self.batch.event = MagicMock()
|
|
|
|
- future = tornado.gen.Future()
|
|
|
|
+ future = salt.ext.tornado.gen.Future()
|
|
|
|
future.set_result({})
|
|
|
|
self.batch.local.run_job_async.return_value = future
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.minions = {"foo", "bar"}
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.jid_gen = MagicMock(return_value="1234")
|
|
|
|
- tornado.gen.sleep = MagicMock(return_value=future)
|
|
|
|
+ salt.ext.tornado.gen.sleep = MagicMock(return_value=future)
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.find_job({"foo", "bar"})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.batch.event.io_loop.spawn_callback.call_args[0],
|
2021-01-08 13:41:50 +01:00
|
|
|
(self.batch.check_find_job, {"foo", "bar"}, "1234"),
|
2020-04-07 14:14:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
- @tornado.testing.gen_test
|
|
|
|
+ @salt.ext.tornado.testing.gen_test
|
|
|
|
def test_batch_find_job_with_done_minions(self):
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.done_minions = {"bar"}
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.event = MagicMock()
|
|
|
|
- future = tornado.gen.Future()
|
|
|
|
+ future = salt.ext.tornado.gen.Future()
|
|
|
|
future.set_result({})
|
|
|
|
self.batch.local.run_job_async.return_value = future
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.minions = {"foo", "bar"}
|
2020-04-07 14:14:01 +02:00
|
|
|
self.batch.jid_gen = MagicMock(return_value="1234")
|
|
|
|
- tornado.gen.sleep = MagicMock(return_value=future)
|
|
|
|
+ salt.ext.tornado.gen.sleep = MagicMock(return_value=future)
|
2021-01-08 13:41:50 +01:00
|
|
|
self.batch.find_job({"foo", "bar"})
|
2020-04-07 14:14:01 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.batch.event.io_loop.spawn_callback.call_args[0],
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-04-07 14:14:01 +02:00
|
|
|
|
|
|
|
|