summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Olof Gunnar Andersson <eandersson@blizzard.com>2018-07-28 20:37:09 -0700
committerErik Olof Gunnar Andersson <eandersson@blizzard.com>2018-07-30 00:27:11 +0000
commit44b64c317c1e3f9ac67bfbd1c85d25d8abbdd677 (patch)
treed5d612d58fc55009dd3b536adefe9188618964c8
parentc929ec2dc5c603ea038e5c5ff37fd71a2c89ea24 (diff)
downloaddesignate-44b64c317c1e3f9ac67bfbd1c85d25d8abbdd677.tar.gz
Change Bad Action from a traceback into a warning
* Added new exception BadAction. * Cleaned up processing code. Partial-Bug: #1768618 Change-Id: I1255b87209a94ab25519aaa83648b7abfd49f067
-rw-r--r--designate/exceptions.py4
-rw-r--r--designate/tests/test_workers/test_processing.py27
-rw-r--r--designate/tests/test_workers/test_zone_tasks.py3
-rw-r--r--designate/worker/processing.py19
-rw-r--r--designate/worker/tasks/zone.py2
5 files changed, 40 insertions, 15 deletions
diff --git a/designate/exceptions.py b/designate/exceptions.py
index 7462c141..fdcd75b5 100644
--- a/designate/exceptions.py
+++ b/designate/exceptions.py
@@ -127,6 +127,10 @@ class InvalidObject(Base):
expected = True
+class BadAction(Base):
+ error_type = 'bad_action'
+
+
class BadRequest(Base):
error_code = 400
error_type = 'bad_request'
diff --git a/designate/tests/test_workers/test_processing.py b/designate/tests/test_workers/test_processing.py
index 1918bf9f..4f55cf4c 100644
--- a/designate/tests/test_workers/test_processing.py
+++ b/designate/tests/test_workers/test_processing.py
@@ -13,12 +13,17 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.mport threading
-from unittest import TestCase
-
+from designate import exceptions
+from designate.tests import TestCase
+from designate.tests import fixtures
from designate.worker import processing
class TestProcessingExecutor(TestCase):
+ def setUp(self):
+ super(TestProcessingExecutor, self).setUp()
+ self.stdlog = fixtures.StandardLogging()
+ self.useFixture(self.stdlog)
def test_execute_multiple_tasks(self):
def t1():
@@ -31,16 +36,24 @@ class TestProcessingExecutor(TestCase):
exe = processing.Executor()
results = exe.run(tasks)
- assert results == [1, 2, 1, 2, 1]
+ self.assertEqual(results, [1, 2, 1, 2, 1])
def test_execute_single_task(self):
def t1():
return 1
- def t2():
- return 2
-
exe = processing.Executor()
results = exe.run(t1)
- assert results == [1]
+ self.assertEqual(results[0], 1)
+
+ def test_execute_bad_task(self):
+ def failed_task():
+ raise exceptions.BadAction('Not Great')
+
+ exe = processing.Executor()
+
+ results = exe.run(failed_task)
+ self.assertEqual(results[0], None)
+
+ self.assertIn('Not Great', self.stdlog.logger.output)
diff --git a/designate/tests/test_workers/test_zone_tasks.py b/designate/tests/test_workers/test_zone_tasks.py
index 83eaa7d7..6116e302 100644
--- a/designate/tests/test_workers/test_zone_tasks.py
+++ b/designate/tests/test_workers/test_zone_tasks.py
@@ -98,7 +98,8 @@ class TestZoneActor(TestCase):
)
def test_invalid_action(self):
- with testtools.ExpectedException(Exception, "Bad Action"):
+ with testtools.ExpectedException(exceptions.BadAction,
+ 'Unexpected action: BAD'):
self.actor._validate_action('BAD')
def test_threshold_from_config(self):
diff --git a/designate/worker/processing.py b/designate/worker/processing.py
index 1bef590d..cf43383a 100644
--- a/designate/worker/processing.py
+++ b/designate/worker/processing.py
@@ -19,6 +19,8 @@ from concurrent import futures
from oslo_log import log as logging
from oslo_config import cfg
+from designate import exceptions
+
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
@@ -39,14 +41,19 @@ class Executor(object):
executor that can map multiple tasks across a configurable number of
threads
"""
+
def __init__(self, executor=None):
self._executor = executor or default_executor()
@staticmethod
def do(task):
- return task()
+ try:
+ return task()
+ except exceptions.BadAction as e:
+ LOG.warning(e)
- def task_name(self, task):
+ @staticmethod
+ def task_name(task):
if hasattr(task, 'task_name'):
return str(task.task_name)
if hasattr(task, 'func_name'):
@@ -63,17 +70,17 @@ class Executor(object):
If a single task is pass
"""
- self.start_time = time.time()
+ start_time = time.time()
if callable(tasks):
tasks = [tasks]
results = [r for r in self._executor.map(self.do, tasks)]
- self.end_time = time.time()
- self.task_time = self.end_time - self.start_time
+ end_time = time.time()
+ task_time = end_time - start_time
task_names = [self.task_name(t) for t in tasks]
LOG.debug("Finished Tasks %(tasks)s in %(time)fs",
- {'tasks': task_names, 'time': self.task_time})
+ {'tasks': task_names, 'time': task_time})
return results
diff --git a/designate/worker/tasks/zone.py b/designate/worker/tasks/zone.py
index 5b40a8a9..71eb7dec 100644
--- a/designate/worker/tasks/zone.py
+++ b/designate/worker/tasks/zone.py
@@ -162,7 +162,7 @@ class ZoneActor(base.Task, ThresholdMixin):
def _validate_action(self, action):
if action not in ['CREATE', 'UPDATE', 'DELETE']:
- raise Exception('Bad Action')
+ raise exceptions.BadAction('Unexpected action: %s' % action)
def _execute(self):
results = self.executor.run([