summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-02-23 21:57:04 +0000
committerGerrit Code Review <review@openstack.org>2015-02-23 21:57:04 +0000
commit134ae48845398d52ec1913b4b534ff8e84094da6 (patch)
tree450e8fc9ddc482c42da5c77a55a77b259fb8fcb0
parent8f777029daf92205e6c9d00be9022ce4f6f59bc0 (diff)
parent3ea6c6a89080510e88882c21c0a4f654a44c787c (diff)
downloadheat-134ae48845398d52ec1913b4b534ff8e84094da6.tar.gz
Merge "Stop patching oslo.messaging private bits" into stable/juno
-rw-r--r--heat/tests/test_stack_lock.py56
1 files changed, 29 insertions, 27 deletions
diff --git a/heat/tests/test_stack_lock.py b/heat/tests/test_stack_lock.py
index 22b36cfa5..94bfc94ce 100644
--- a/heat/tests/test_stack_lock.py
+++ b/heat/tests/test_stack_lock.py
@@ -12,7 +12,6 @@
# under the License.
import mock
-
from oslo import messaging
from heat.common import exception
@@ -62,10 +61,6 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- self.m.StubOutWithMock(messaging.rpc.client._CallContext, "call")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
self.m.StubOutWithMock(db_api, "stack_lock_steal")
db_api.stack_lock_steal(self.stack.id, "fake-engine-id",
self.engine_id).AndReturn(None)
@@ -73,6 +68,7 @@ class StackLockTest(HeatTestCase):
self.m.ReplayAll()
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ self.patchobject(slock, 'engine_alive', return_value=False)
slock.acquire()
self.m.VerifyAll()
@@ -81,13 +77,10 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- self.m.StubOutWithMock(messaging.rpc.client._CallContext, "call")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndReturn(True)
-
self.m.ReplayAll()
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ self.patchobject(slock, 'engine_alive', return_value=True)
self.assertRaises(exception.ActionInProgress, slock.acquire)
self.m.VerifyAll()
@@ -96,10 +89,6 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- self.m.StubOutWithMock(messaging.rpc.client._CallContext, "call")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
self.m.StubOutWithMock(db_api, "stack_lock_steal")
db_api.stack_lock_steal(
self.stack.id, "fake-engine-id",
@@ -108,6 +97,7 @@ class StackLockTest(HeatTestCase):
self.m.ReplayAll()
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ self.patchobject(slock, 'engine_alive', return_value=False)
self.assertRaises(exception.ActionInProgress, slock.acquire)
self.m.VerifyAll()
@@ -116,10 +106,6 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- self.m.StubOutWithMock(messaging.rpc.client._CallContext, "call")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
self.m.StubOutWithMock(db_api, "stack_lock_steal")
db_api.stack_lock_steal(
self.stack.id, "fake-engine-id", self.engine_id).AndReturn(True)
@@ -127,15 +113,13 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
db_api.stack_lock_steal(
self.stack.id, "fake-engine-id", self.engine_id).AndReturn(None)
self.m.ReplayAll()
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ self.patchobject(slock, 'engine_alive', return_value=False)
slock.acquire()
self.m.VerifyAll()
@@ -144,10 +128,6 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- self.m.StubOutWithMock(messaging.rpc.client._CallContext, "call")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
self.m.StubOutWithMock(db_api, "stack_lock_steal")
db_api.stack_lock_steal(
self.stack.id, "fake-engine-id", self.engine_id).AndReturn(True)
@@ -155,15 +135,13 @@ class StackLockTest(HeatTestCase):
db_api.stack_lock_create(
self.stack.id, self.engine_id).AndReturn("fake-engine-id")
- messaging.rpc.client._CallContext.call(
- self.context, "listening").AndRaise(messaging.MessagingTimeout)
-
db_api.stack_lock_steal(
self.stack.id, "fake-engine-id", self.engine_id).AndReturn(True)
self.m.ReplayAll()
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ self.patchobject(slock, 'engine_alive', return_value=False)
self.assertRaises(exception.ActionInProgress, slock.acquire)
self.m.VerifyAll()
@@ -218,3 +196,27 @@ class StackLockTest(HeatTestCase):
raise self.TestThreadLockException
self.assertRaises(self.TestThreadLockException, check_thread_lock)
assert not db_api.stack_lock_release.called
+
+ def test_engine_alive_ok(self):
+ slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ mget_client = self.patchobject(stack_lock.rpc_messaging,
+ 'get_rpc_client')
+ mclient = mget_client.return_value
+ mclient_ctx = mclient.prepare.return_value
+ mclient_ctx.call.return_value = True
+ ret = slock.engine_alive(self.context, self.engine_id)
+ self.assertTrue(ret)
+ mclient.prepare.assert_called_once_with(timeout=2)
+ mclient_ctx.call.assert_called_once_with(self.context, 'listening')
+
+ def test_engine_alive_timeout(self):
+ slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
+ mget_client = self.patchobject(stack_lock.rpc_messaging,
+ 'get_rpc_client')
+ mclient = mget_client.return_value
+ mclient_ctx = mclient.prepare.return_value
+ mclient_ctx.call.side_effect = messaging.MessagingTimeout('too slow')
+ ret = slock.engine_alive(self.context, self.engine_id)
+ self.assertIs(False, ret)
+ mclient.prepare.assert_called_once_with(timeout=2)
+ mclient_ctx.call.assert_called_once_with(self.context, 'listening')