summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-04 00:40:44 +0000
committerGerrit Code Review <review@openstack.org>2018-07-04 00:40:44 +0000
commitdff11337f55b7a9a28d7c30658df51b7b0b443eb (patch)
tree35fe57ee6ef57f17e013b3092874038c76998724
parentc49c96ff74190b9f1b1504eaa8a7ef66b8ae333f (diff)
parentdf6bf3401266f42271627c1e408f87c71a06cef7 (diff)
Merge "Rename enginefacade.async to enginefacade.async_"4.40.0
-rw-r--r--oslo_db/sqlalchemy/enginefacade.py14
-rw-r--r--oslo_db/tests/sqlalchemy/test_enginefacade.py31
2 files changed, 39 insertions, 6 deletions
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py
index 2b9f81e..481e166 100644
--- a/oslo_db/sqlalchemy/enginefacade.py
+++ b/oslo_db/sqlalchemy/enginefacade.py
@@ -17,6 +17,7 @@ import operator
17import threading 17import threading
18import warnings 18import warnings
19 19
20import debtcollector.moves
20import debtcollector.removals 21import debtcollector.removals
21import debtcollector.renames 22import debtcollector.renames
22from oslo_config import cfg 23from oslo_config import cfg
@@ -965,7 +966,7 @@ class _TransactionContextManager(object):
965 return self._clone(connection=True) 966 return self._clone(connection=True)
966 967
967 @property 968 @property
968 def async(self): 969 def async_(self):
969 """Modifier to set a READER operation to ASYNC_READER.""" 970 """Modifier to set a READER operation to ASYNC_READER."""
970 971
971 if self._mode is _WRITER: 972 if self._mode is _WRITER:
@@ -1049,6 +1050,17 @@ class _TransactionContextManager(object):
1049 transaction_contexts_by_thread.current = restore 1050 transaction_contexts_by_thread.current = restore
1050 1051
1051 1052
1053@property
1054@debtcollector.moves.moved_property("async_")
1055def async_compat(self):
1056 return self.async_
1057
1058setattr(
1059 _TransactionContextManager,
1060 "async", async_compat
1061)
1062
1063
1052def _context_descriptor(attr=None): 1064def _context_descriptor(attr=None):
1053 getter = operator.attrgetter(attr) 1065 getter = operator.attrgetter(attr)
1054 1066
diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py
index ced9483..cab7547 100644
--- a/oslo_db/tests/sqlalchemy/test_enginefacade.py
+++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py
@@ -15,6 +15,7 @@ import contextlib
15import copy 15import copy
16import fixtures 16import fixtures
17import pickle 17import pickle
18import sys
18import warnings 19import warnings
19 20
20import mock 21import mock
@@ -607,7 +608,7 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
607 608
608 def test_async_on_writer_raises(self): 609 def test_async_on_writer_raises(self):
609 exc = self.assertRaises( 610 exc = self.assertRaises(
610 TypeError, getattr, enginefacade.writer, "async" 611 TypeError, getattr, enginefacade.writer, "async_"
611 ) 612 )
612 self.assertEqual( 613 self.assertEqual(
613 "Setting async on a WRITER makes no sense", 614 "Setting async on a WRITER makes no sense",
@@ -626,7 +627,7 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
626 def test_reader_nested_in_async_reader_raises(self): 627 def test_reader_nested_in_async_reader_raises(self):
627 context = oslo_context.RequestContext() 628 context = oslo_context.RequestContext()
628 629
629 @enginefacade.reader.async 630 @enginefacade.reader.async_
630 def go1(context): 631 def go1(context):
631 context.session.execute("test1") 632 context.session.execute("test1")
632 go2(context) 633 go2(context)
@@ -647,7 +648,7 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
647 def test_reader_allow_async_nested_in_async_reader(self): 648 def test_reader_allow_async_nested_in_async_reader(self):
648 context = oslo_context.RequestContext() 649 context = oslo_context.RequestContext()
649 650
650 @enginefacade.reader.async 651 @enginefacade.reader.async_
651 def go1(context): 652 def go1(context):
652 context.session.execute("test1") 653 context.session.execute("test1")
653 go2(context) 654 go2(context)
@@ -701,7 +702,7 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
701 def test_writer_nested_in_async_reader_raises(self): 702 def test_writer_nested_in_async_reader_raises(self):
702 context = oslo_context.RequestContext() 703 context = oslo_context.RequestContext()
703 704
704 @enginefacade.reader.async 705 @enginefacade.reader.async_
705 def go1(context): 706 def go1(context):
706 context.session.execute("test1") 707 context.session.execute("test1")
707 go2(context) 708 go2(context)
@@ -741,10 +742,30 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
741 with self._assert_writer_session(makers) as session: 742 with self._assert_writer_session(makers) as session:
742 session.execute("test2") 743 session.execute("test2")
743 744
745 def test_deprecated_async_reader_name(self):
746 if sys.version_info >= (3, 7):
747 self.skipTest("Test only runs on Python < 3.7")
748
749 context = oslo_context.RequestContext()
750
751 old = getattr(enginefacade.reader, "async")
752
753 @old
754 def go1(context):
755 context.session.execute("test1")
756
757 go1(context)
758
759 with self._assert_engines() as engines:
760 with self._assert_makers(engines) as makers:
761 with self._assert_async_reader_session(
762 makers, assert_calls=False) as session:
763 session.execute("test1")
764
744 def test_async_reader_then_reader_ok(self): 765 def test_async_reader_then_reader_ok(self):
745 context = oslo_context.RequestContext() 766 context = oslo_context.RequestContext()
746 767
747 @enginefacade.reader.async 768 @enginefacade.reader.async_
748 def go1(context): 769 def go1(context):
749 context.session.execute("test1") 770 context.session.execute("test1")
750 771