Stop copying UUIDStub, put it into tests.utils
Change-Id: Ice52f4294df5575579795eecfcbae9748f252e2e
This commit is contained in:
@@ -13,15 +13,13 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from heat.tests import generic_resource
|
||||
from heat.tests import fakes
|
||||
from heat.tests.common import HeatTestCase
|
||||
from heat.tests.utils import stack_delete_after
|
||||
from heat.tests.utils import setup_dummy_db
|
||||
from heat.tests import utils
|
||||
|
||||
from heat.common import context
|
||||
from heat.common import exception
|
||||
@@ -48,24 +46,11 @@ test_template_signal = '''
|
||||
'''
|
||||
|
||||
|
||||
class UUIDStub(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __enter__(self):
|
||||
self.uuid4 = uuid.uuid4
|
||||
uuid_stub = lambda: self.value
|
||||
uuid.uuid4 = uuid_stub
|
||||
|
||||
def __exit__(self, *exc_info):
|
||||
uuid.uuid4 = self.uuid4
|
||||
|
||||
|
||||
class SignalTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SignalTest, self).setUp()
|
||||
setup_dummy_db()
|
||||
utils.setup_dummy_db()
|
||||
|
||||
resource._register_class('SignalResourceType',
|
||||
generic_resource.SignalResource)
|
||||
@@ -89,7 +74,7 @@ class SignalTest(HeatTestCase):
|
||||
disable_rollback=True)
|
||||
|
||||
# Stub out the stack ID so we have a known value
|
||||
with UUIDStub(self.stack_id):
|
||||
with utils.UUIDStub(self.stack_id):
|
||||
stack.store()
|
||||
|
||||
if stub:
|
||||
@@ -98,7 +83,7 @@ class SignalTest(HeatTestCase):
|
||||
self.fc)
|
||||
return stack
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_FnGetAtt_Alarm_Url(self):
|
||||
self.stack = self.create_stack()
|
||||
|
||||
@@ -125,7 +110,7 @@ class SignalTest(HeatTestCase):
|
||||
self.assertEqual(expected_url, rsrc.FnGetAtt('AlarmUrl'))
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_signal(self):
|
||||
test_d = {'Data': 'foo', 'Reason': 'bar',
|
||||
'Status': 'SUCCESS', 'UniqueId': '123'}
|
||||
@@ -147,7 +132,7 @@ class SignalTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_signal_wrong_resource(self):
|
||||
# assert that we get the correct exception when calling a
|
||||
# resource.signal() that does not have a handle_signal()
|
||||
@@ -165,7 +150,7 @@ class SignalTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_signal_reception_wrong_state(self):
|
||||
# assert that we get the correct exception when calling a
|
||||
# resource.signal() that is in having a destructive action.
|
||||
@@ -185,7 +170,7 @@ class SignalTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_signal_reception_failed_call(self):
|
||||
# assert that we get the correct exception from resource.signal()
|
||||
# when resource.handle_signal() raises an exception.
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
import datetime
|
||||
import time
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from heat.tests.common import HeatTestCase
|
||||
from heat.tests import fakes
|
||||
from heat.tests.utils import dummy_context
|
||||
from heat.tests.utils import setup_dummy_db
|
||||
from heat.tests.utils import stack_delete_after
|
||||
from heat.tests import utils
|
||||
|
||||
import heat.db.api as db_api
|
||||
from heat.common import template_format
|
||||
@@ -76,24 +73,11 @@ test_template_wc_count = '''
|
||||
'''
|
||||
|
||||
|
||||
class UUIDStub(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __enter__(self):
|
||||
self.uuid4 = uuid.uuid4
|
||||
uuid_stub = lambda: self.value
|
||||
uuid.uuid4 = uuid_stub
|
||||
|
||||
def __exit__(self, *exc_info):
|
||||
uuid.uuid4 = self.uuid4
|
||||
|
||||
|
||||
class WaitConditionTest(HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(WaitConditionTest, self).setUp()
|
||||
setup_dummy_db()
|
||||
utils.setup_dummy_db()
|
||||
self.m.StubOutWithMock(wc.WaitConditionHandle,
|
||||
'get_status')
|
||||
|
||||
@@ -110,13 +94,13 @@ class WaitConditionTest(HeatTestCase):
|
||||
stub=True):
|
||||
temp = template_format.parse(template)
|
||||
template = parser.Template(temp)
|
||||
ctx = dummy_context(tenant_id='test_tenant')
|
||||
ctx = utils.dummy_context(tenant_id='test_tenant')
|
||||
stack = parser.Stack(ctx, stack_name, template,
|
||||
environment.Environment(params),
|
||||
disable_rollback=True)
|
||||
|
||||
# Stub out the stack ID so we have a known value
|
||||
with UUIDStub(self.stack_id):
|
||||
with utils.UUIDStub(self.stack_id):
|
||||
stack.store()
|
||||
|
||||
if stub:
|
||||
@@ -131,7 +115,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
|
||||
return stack
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_post_success_to_handle(self):
|
||||
self.stack = self.create_stack()
|
||||
wc.WaitConditionHandle.get_status().AndReturn([])
|
||||
@@ -151,7 +135,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(r.name, 'WaitHandle')
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_post_failure_to_handle(self):
|
||||
self.stack = self.create_stack()
|
||||
wc.WaitConditionHandle.get_status().AndReturn([])
|
||||
@@ -172,7 +156,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(r.name, 'WaitHandle')
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_post_success_to_handle_count(self):
|
||||
self.stack = self.create_stack(template=test_template_wc_count)
|
||||
wc.WaitConditionHandle.get_status().AndReturn([])
|
||||
@@ -194,7 +178,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(r.name, 'WaitHandle')
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_post_failure_to_handle_count(self):
|
||||
self.stack = self.create_stack(template=test_template_wc_count)
|
||||
wc.WaitConditionHandle.get_status().AndReturn([])
|
||||
@@ -215,7 +199,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(r.name, 'WaitHandle')
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_timeout(self):
|
||||
st = time.time()
|
||||
|
||||
@@ -249,7 +233,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
rsrc.handle_update, {}, {}, {})
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_FnGetAtt(self):
|
||||
self.stack = self.create_stack()
|
||||
wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])
|
||||
@@ -279,7 +263,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
self.assertEqual(wc_att, u'{"123": "foo", "456": "dog"}')
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_validate_handle_url_bad_stackid(self):
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -298,7 +282,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_validate_handle_url_bad_stackname(self):
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -315,7 +299,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_validate_handle_url_bad_tenant(self):
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -332,7 +316,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_validate_handle_url_bad_resource(self):
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -349,7 +333,7 @@ class WaitConditionTest(HeatTestCase):
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_validate_handle_url_bad_resource_type(self):
|
||||
self.m.ReplayAll()
|
||||
|
||||
@@ -374,18 +358,18 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
'http://127.0.0.1:8000/v1/waitcondition')
|
||||
|
||||
self.fc = fakes.FakeKeystoneClient()
|
||||
setup_dummy_db()
|
||||
utils.setup_dummy_db()
|
||||
self.stack = self.create_stack()
|
||||
|
||||
def create_stack(self, stack_name='test_stack2', params={}):
|
||||
temp = template_format.parse(test_template_waitcondition)
|
||||
template = parser.Template(temp)
|
||||
ctx = dummy_context(tenant_id='test_tenant')
|
||||
ctx = utils.dummy_context(tenant_id='test_tenant')
|
||||
stack = parser.Stack(ctx, stack_name, template,
|
||||
environment.Environment(params),
|
||||
disable_rollback=True)
|
||||
# Stub out the UUID for this test, so we can get an expected signature
|
||||
with UUIDStub('STACKABCD1234'):
|
||||
with utils.UUIDStub('STACKABCD1234'):
|
||||
stack.store()
|
||||
|
||||
# Stub waitcondition status so all goes CREATE_COMPLETE
|
||||
@@ -406,7 +390,7 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
|
||||
return stack
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_handle(self):
|
||||
created_time = datetime.datetime(2012, 11, 29, 13, 49, 37)
|
||||
|
||||
@@ -432,7 +416,7 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
rsrc.handle_update, {}, {}, {})
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_metadata_update(self):
|
||||
rsrc = self.stack.resources['WaitHandle']
|
||||
self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
|
||||
@@ -446,7 +430,7 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
self.assertEqual(rsrc.metadata, handle_metadata)
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_metadata_update_invalid(self):
|
||||
rsrc = self.stack.resources['WaitHandle']
|
||||
self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
|
||||
@@ -489,7 +473,7 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
new_metadata=err_metadata)
|
||||
self.m.VerifyAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_get_status(self):
|
||||
rsrc = self.stack.resources['WaitHandle']
|
||||
self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
|
||||
@@ -515,7 +499,7 @@ class WaitConditionHandleTest(HeatTestCase):
|
||||
wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)
|
||||
self.m.ReplayAll()
|
||||
|
||||
@stack_delete_after
|
||||
@utils.stack_delete_after
|
||||
def test_get_status_reason(self):
|
||||
rsrc = self.stack.resources['WaitHandle']
|
||||
self.assertEqual(rsrc.state, (rsrc.CREATE, rsrc.COMPLETE))
|
||||
|
||||
@@ -16,6 +16,7 @@ import functools
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from heat.common import context
|
||||
from heat.common import exception
|
||||
@@ -26,6 +27,19 @@ from heat.db.sqlalchemy.session import get_engine
|
||||
from heat.db import migration
|
||||
|
||||
|
||||
class UUIDStub(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __enter__(self):
|
||||
self.uuid4 = uuid.uuid4
|
||||
uuid_stub = lambda: self.value
|
||||
uuid.uuid4 = uuid_stub
|
||||
|
||||
def __exit__(self, *exc_info):
|
||||
uuid.uuid4 = self.uuid4
|
||||
|
||||
|
||||
def random_name():
|
||||
return ''.join(random.choice(string.ascii_uppercase)
|
||||
for x in range(10))
|
||||
|
||||
Reference in New Issue
Block a user