Don't use duplicate stack names in DB unit tests
Ensure that stacks we create in the DB during unit testing have unique names. Change-Id: I31e007c4a99d467ed6e512a3b785aaa8f3a61b41 Task: 29865
This commit is contained in:
parent
6e89926921
commit
27ceeb0835
@ -30,6 +30,7 @@ from sqlalchemy.orm import session
|
|||||||
|
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.common import short_id
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.db.sqlalchemy import api as db_api
|
from heat.db.sqlalchemy import api as db_api
|
||||||
from heat.db.sqlalchemy import models
|
from heat.db.sqlalchemy import models
|
||||||
@ -95,6 +96,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
stack_user_project_id=stack_user_project_id)
|
stack_user_project_id=stack_user_project_id)
|
||||||
with utils.UUIDStub(stack_id):
|
with utils.UUIDStub(stack_id):
|
||||||
stack.store(backup=backup)
|
stack.store(backup=backup)
|
||||||
|
|
||||||
return (template, stack)
|
return (template, stack)
|
||||||
|
|
||||||
def _mock_create(self):
|
def _mock_create(self):
|
||||||
@ -310,7 +312,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_resource_data_delete(self):
|
def test_resource_data_delete(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('res_data_delete', UUID1)[1]
|
||||||
self._mock_create()
|
self._mock_create()
|
||||||
|
|
||||||
stack.create()
|
stack.create()
|
||||||
@ -335,73 +337,74 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_stack_get_by_name(self):
|
def test_stack_get_by_name(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1,
|
name = 'stack_get_by_name'
|
||||||
|
stack = self._setup_test_stack(name, UUID1,
|
||||||
stack_user_project_id=UUID2)[1]
|
stack_user_project_id=UUID2)[1]
|
||||||
|
|
||||||
st = db_api.stack_get_by_name(self.ctx, 'stack')
|
st = db_api.stack_get_by_name(self.ctx, name)
|
||||||
self.assertEqual(UUID1, st.id)
|
self.assertEqual(UUID1, st.id)
|
||||||
|
|
||||||
self.ctx.tenant = UUID3
|
self.ctx.tenant = UUID3
|
||||||
st = db_api.stack_get_by_name(self.ctx, 'stack')
|
st = db_api.stack_get_by_name(self.ctx, name)
|
||||||
self.assertIsNone(st)
|
self.assertIsNone(st)
|
||||||
|
|
||||||
self.ctx.tenant = UUID2
|
self.ctx.tenant = UUID2
|
||||||
st = db_api.stack_get_by_name(self.ctx, 'stack')
|
st = db_api.stack_get_by_name(self.ctx, name)
|
||||||
self.assertEqual(UUID1, st.id)
|
self.assertEqual(UUID1, st.id)
|
||||||
|
|
||||||
stack.delete()
|
stack.delete()
|
||||||
|
|
||||||
st = db_api.stack_get_by_name(self.ctx, 'stack')
|
st = db_api.stack_get_by_name(self.ctx, name)
|
||||||
self.assertIsNone(st)
|
self.assertIsNone(st)
|
||||||
|
|
||||||
def test_nested_stack_get_by_name(self):
|
def test_nested_stack_get_by_name(self):
|
||||||
stack1 = self._setup_test_stack('stack1', UUID1)[1]
|
stack1 = self._setup_test_stack('neststack1', UUID1)[1]
|
||||||
stack2 = self._setup_test_stack('stack2', UUID2,
|
stack2 = self._setup_test_stack('neststack2', UUID2,
|
||||||
owner_id=stack1.id)[1]
|
owner_id=stack1.id)[1]
|
||||||
|
|
||||||
result = db_api.stack_get_by_name(self.ctx, 'stack2')
|
result = db_api.stack_get_by_name(self.ctx, 'neststack2')
|
||||||
self.assertEqual(UUID2, result.id)
|
self.assertEqual(UUID2, result.id)
|
||||||
|
|
||||||
stack2.delete()
|
stack2.delete()
|
||||||
|
|
||||||
result = db_api.stack_get_by_name(self.ctx, 'stack2')
|
result = db_api.stack_get_by_name(self.ctx, 'neststack2')
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_stack_get_by_name_and_owner_id(self):
|
def test_stack_get_by_name_and_owner_id(self):
|
||||||
stack1 = self._setup_test_stack('stack1', UUID1,
|
stack1 = self._setup_test_stack('ownstack1', UUID1,
|
||||||
stack_user_project_id=UUID3)[1]
|
stack_user_project_id=UUID3)[1]
|
||||||
stack2 = self._setup_test_stack('stack2', UUID2,
|
stack2 = self._setup_test_stack('ownstack2', UUID2,
|
||||||
owner_id=stack1.id,
|
owner_id=stack1.id,
|
||||||
stack_user_project_id=UUID3)[1]
|
stack_user_project_id=UUID3)[1]
|
||||||
|
|
||||||
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'stack2',
|
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
|
||||||
None)
|
None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'stack2',
|
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
|
||||||
stack1.id)
|
stack1.id)
|
||||||
|
|
||||||
self.assertEqual(UUID2, result.id)
|
self.assertEqual(UUID2, result.id)
|
||||||
|
|
||||||
self.ctx.tenant = str(uuid.uuid4())
|
self.ctx.tenant = str(uuid.uuid4())
|
||||||
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'stack2',
|
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
|
||||||
None)
|
None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
self.ctx.tenant = UUID3
|
self.ctx.tenant = UUID3
|
||||||
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'stack2',
|
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
|
||||||
stack1.id)
|
stack1.id)
|
||||||
|
|
||||||
self.assertEqual(UUID2, result.id)
|
self.assertEqual(UUID2, result.id)
|
||||||
|
|
||||||
stack2.delete()
|
stack2.delete()
|
||||||
|
|
||||||
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'stack2',
|
result = db_api.stack_get_by_name_and_owner_id(self.ctx, 'ownstack2',
|
||||||
stack1.id)
|
stack1.id)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_stack_get(self):
|
def test_stack_get(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('stack_get', UUID1)[1]
|
||||||
|
|
||||||
st = db_api.stack_get(self.ctx, UUID1, show_deleted=False)
|
st = db_api.stack_get(self.ctx, UUID1, show_deleted=False)
|
||||||
self.assertEqual(UUID1, st.id)
|
self.assertEqual(UUID1, st.id)
|
||||||
@ -414,7 +417,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(UUID1, st.id)
|
self.assertEqual(UUID1, st.id)
|
||||||
|
|
||||||
def test_stack_get_status(self):
|
def test_stack_get_status(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('stack_get_status', UUID1)[1]
|
||||||
|
|
||||||
st = db_api.stack_get_status(self.ctx, UUID1)
|
st = db_api.stack_get_status(self.ctx, UUID1)
|
||||||
self.assertEqual(('CREATE', 'IN_PROGRESS', '', None), st)
|
self.assertEqual(('CREATE', 'IN_PROGRESS', '', None), st)
|
||||||
@ -430,7 +433,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
db_api.stack_get_status, self.ctx, UUID2)
|
db_api.stack_get_status, self.ctx, UUID2)
|
||||||
|
|
||||||
def test_stack_get_show_deleted_context(self):
|
def test_stack_get_show_deleted_context(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('stack_get_deleted', UUID1)[1]
|
||||||
|
|
||||||
self.assertFalse(self.ctx.show_deleted)
|
self.assertFalse(self.ctx.show_deleted)
|
||||||
st = db_api.stack_get(self.ctx, UUID1)
|
st = db_api.stack_get(self.ctx, UUID1)
|
||||||
@ -445,7 +448,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(UUID1, st.id)
|
self.assertEqual(UUID1, st.id)
|
||||||
|
|
||||||
def test_stack_get_all(self):
|
def test_stack_get_all(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stack_get_all_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx)
|
st_db = db_api.stack_get_all(self.ctx)
|
||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
@ -459,7 +463,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(1, len(st_db))
|
self.assertEqual(1, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_show_deleted(self):
|
def test_stack_get_all_show_deleted(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stack_get_all_deleted_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx)
|
st_db = db_api.stack_get_all(self.ctx)
|
||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
@ -472,11 +477,11 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_show_nested(self):
|
def test_stack_get_all_show_nested(self):
|
||||||
stack1 = self._setup_test_stack('stack1', UUID1)[1]
|
stack1 = self._setup_test_stack('neststack_get_all_1', UUID1)[1]
|
||||||
stack2 = self._setup_test_stack('stack2', UUID2,
|
stack2 = self._setup_test_stack('neststack_get_all_2', UUID2,
|
||||||
owner_id=stack1.id)[1]
|
owner_id=stack1.id)[1]
|
||||||
# Backup stack should not be returned
|
# Backup stack should not be returned
|
||||||
stack3 = self._setup_test_stack('stack1*', UUID3,
|
stack3 = self._setup_test_stack('neststack_get_all_1*', UUID3,
|
||||||
owner_id=stack1.id,
|
owner_id=stack1.id,
|
||||||
backup=True)[1]
|
backup=True)[1]
|
||||||
|
|
||||||
@ -493,7 +498,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
|
|
||||||
def test_stack_get_all_with_filters(self):
|
def test_stack_get_all_with_filters(self):
|
||||||
self._setup_test_stack('foo', UUID1)
|
self._setup_test_stack('foo', UUID1)
|
||||||
self._setup_test_stack('bar', UUID2)
|
self._setup_test_stack('baz', UUID2)
|
||||||
|
|
||||||
filters = {'name': 'foo'}
|
filters = {'name': 'foo'}
|
||||||
results = db_api.stack_get_all(self.ctx,
|
results = db_api.stack_get_all(self.ctx,
|
||||||
@ -503,7 +508,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual('foo', results[0]['name'])
|
self.assertEqual('foo', results[0]['name'])
|
||||||
|
|
||||||
def test_stack_get_all_filter_matches_in_list(self):
|
def test_stack_get_all_filter_matches_in_list(self):
|
||||||
self._setup_test_stack('foo', UUID1)
|
self._setup_test_stack('wibble', UUID1)
|
||||||
self._setup_test_stack('bar', UUID2)
|
self._setup_test_stack('bar', UUID2)
|
||||||
|
|
||||||
filters = {'name': ['bar', 'quux']}
|
filters = {'name': ['bar', 'quux']}
|
||||||
@ -514,8 +519,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual('bar', results[0]['name'])
|
self.assertEqual('bar', results[0]['name'])
|
||||||
|
|
||||||
def test_stack_get_all_returns_all_if_no_filters(self):
|
def test_stack_get_all_returns_all_if_no_filters(self):
|
||||||
self._setup_test_stack('foo', UUID1)
|
self._setup_test_stack('stack_get_all_no_filter1', UUID1)
|
||||||
self._setup_test_stack('bar', UUID2)
|
self._setup_test_stack('stack_get_all_no_filter2', UUID2)
|
||||||
|
|
||||||
filters = None
|
filters = None
|
||||||
results = db_api.stack_get_all(self.ctx,
|
results = db_api.stack_get_all(self.ctx,
|
||||||
@ -524,7 +529,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(2, len(results))
|
self.assertEqual(2, len(results))
|
||||||
|
|
||||||
def test_stack_get_all_default_sort_keys_and_dir(self):
|
def test_stack_get_all_default_sort_keys_and_dir(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_def_sort_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx)
|
st_db = db_api.stack_get_all(self.ctx)
|
||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
@ -533,7 +539,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(stacks[0].id, st_db[2].id)
|
self.assertEqual(stacks[0].id, st_db[2].id)
|
||||||
|
|
||||||
def test_stack_get_all_default_sort_dir(self):
|
def test_stack_get_all_default_sort_dir(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_def_sort_dir_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx, sort_dir='asc')
|
st_db = db_api.stack_get_all(self.ctx, sort_dir='asc')
|
||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
@ -542,7 +549,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(stacks[2].id, st_db[2].id)
|
self.assertEqual(stacks[2].id, st_db[2].id)
|
||||||
|
|
||||||
def test_stack_get_all_str_sort_keys(self):
|
def test_stack_get_all_str_sort_keys(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_str_sort_keys_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx,
|
st_db = db_api.stack_get_all(self.ctx,
|
||||||
sort_keys='creation_time')
|
sort_keys='creation_time')
|
||||||
@ -564,21 +572,24 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(expected_keys, used_sort_keys)
|
self.assertEqual(expected_keys, used_sort_keys)
|
||||||
|
|
||||||
def test_stack_get_all_marker(self):
|
def test_stack_get_all_marker(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_marker_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_get_all(self.ctx, marker=stacks[1].id)
|
st_db = db_api.stack_get_all(self.ctx, marker=stacks[1].id)
|
||||||
self.assertEqual(1, len(st_db))
|
self.assertEqual(1, len(st_db))
|
||||||
self.assertEqual(stacks[0].id, st_db[0].id)
|
self.assertEqual(stacks[0].id, st_db[0].id)
|
||||||
|
|
||||||
def test_stack_get_all_non_existing_marker(self):
|
def test_stack_get_all_non_existing_marker(self):
|
||||||
[self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
[self._setup_test_stack('stacks_nonex_marker_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
uuid = 'this stack doesn\'t exist'
|
uuid = 'this stack doesn\'t exist'
|
||||||
st_db = db_api.stack_get_all(self.ctx, marker=uuid)
|
st_db = db_api.stack_get_all(self.ctx, marker=uuid)
|
||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_doesnt_mutate_sort_keys(self):
|
def test_stack_get_all_doesnt_mutate_sort_keys(self):
|
||||||
[self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
[self._setup_test_stack('stacks_sort_nomutate_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
sort_keys = ['id']
|
sort_keys = ['id']
|
||||||
|
|
||||||
db_api.stack_get_all(self.ctx, sort_keys=sort_keys)
|
db_api.stack_get_all(self.ctx, sort_keys=sort_keys)
|
||||||
@ -587,7 +598,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
def test_stack_get_all_hidden_tags(self):
|
def test_stack_get_all_hidden_tags(self):
|
||||||
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
||||||
|
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_hidden_tags_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['hidden']
|
stacks[0].tags = ['hidden']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['random']
|
stacks[1].tags = ['random']
|
||||||
@ -605,7 +617,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertNotEqual(stacks[0].id, stack.id)
|
self.assertNotEqual(stacks[0].id, stack.id)
|
||||||
|
|
||||||
def test_stack_get_all_by_tags(self):
|
def test_stack_get_all_by_tags(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_tags_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag1', 'tag2']
|
stacks[1].tags = ['tag1', 'tag2']
|
||||||
@ -623,7 +636,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(1, len(st_db))
|
self.assertEqual(1, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_by_tags_any(self):
|
def test_stack_get_all_by_tags_any(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_tags_any_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag2']
|
stacks[0].tags = ['tag2']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag1', 'tag2']
|
stacks[1].tags = ['tag1', 'tag2']
|
||||||
@ -639,7 +653,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(3, len(st_db))
|
self.assertEqual(3, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_by_not_tags(self):
|
def test_stack_get_all_by_not_tags(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_not_tags_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag1', 'tag2']
|
stacks[1].tags = ['tag1', 'tag2']
|
||||||
@ -658,7 +673,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(2, len(st_db))
|
self.assertEqual(2, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_by_not_tags_any(self):
|
def test_stack_get_all_by_not_tags_any(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_not_tags_any_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag2']
|
stacks[0].tags = ['tag2']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag1', 'tag2']
|
stacks[1].tags = ['tag1', 'tag2']
|
||||||
@ -674,7 +690,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(0, len(st_db))
|
self.assertEqual(0, len(st_db))
|
||||||
|
|
||||||
def test_stack_get_all_by_tag_with_pagination(self):
|
def test_stack_get_all_by_tag_with_pagination(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_tag_page_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag2']
|
stacks[1].tags = ['tag2']
|
||||||
@ -697,7 +714,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
def test_stack_get_all_by_tag_with_show_hidden(self):
|
def test_stack_get_all_by_tag_with_show_hidden(self):
|
||||||
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
||||||
|
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_tag_hidden_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['hidden', 'tag1']
|
stacks[1].tags = ['hidden', 'tag1']
|
||||||
@ -712,7 +730,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(1, len(st_db))
|
self.assertEqual(1, len(st_db))
|
||||||
|
|
||||||
def test_stack_count_all(self):
|
def test_stack_count_all(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_count_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
|
|
||||||
st_db = db_api.stack_count_all(self.ctx)
|
st_db = db_api.stack_count_all(self.ctx)
|
||||||
self.assertEqual(3, st_db)
|
self.assertEqual(3, st_db)
|
||||||
@ -734,7 +753,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
def test_count_all_hidden_tags(self):
|
def test_count_all_hidden_tags(self):
|
||||||
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
||||||
|
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_count_hid_tag_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['hidden']
|
stacks[0].tags = ['hidden']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['random']
|
stacks[1].tags = ['random']
|
||||||
@ -747,7 +767,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(2, st_db_visible)
|
self.assertEqual(2, st_db_visible)
|
||||||
|
|
||||||
def test_count_all_by_tags(self):
|
def test_count_all_by_tags(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_count_all_tag_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['tag2']
|
stacks[1].tags = ['tag2']
|
||||||
@ -764,7 +785,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
def test_count_all_by_tag_with_show_hidden(self):
|
def test_count_all_by_tag_with_show_hidden(self):
|
||||||
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
cfg.CONF.set_override('hidden_stack_tags', ['hidden'])
|
||||||
|
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stacks_count_all_tagsh_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
stacks[0].tags = ['tag1']
|
stacks[0].tags = ['tag1']
|
||||||
stacks[0].store()
|
stacks[0].store()
|
||||||
stacks[1].tags = ['hidden', 'tag1']
|
stacks[1].tags = ['hidden', 'tag1']
|
||||||
@ -779,13 +801,12 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(1, st_db)
|
self.assertEqual(1, st_db)
|
||||||
|
|
||||||
def test_stack_count_all_with_filters(self):
|
def test_stack_count_all_with_filters(self):
|
||||||
self._setup_test_stack('foo', UUID1)
|
self._setup_test_stack('sca_foo', UUID1)
|
||||||
self._setup_test_stack('bar', UUID2)
|
self._setup_test_stack('sca_bar', UUID2)
|
||||||
self._setup_test_stack('bar', UUID3)
|
filters = {'name': 'sca_bar'}
|
||||||
filters = {'name': 'bar'}
|
|
||||||
|
|
||||||
st_db = db_api.stack_count_all(self.ctx, filters=filters)
|
st_db = db_api.stack_count_all(self.ctx, filters=filters)
|
||||||
self.assertEqual(2, st_db)
|
self.assertEqual(1, st_db)
|
||||||
|
|
||||||
def test_stack_count_all_show_nested(self):
|
def test_stack_count_all_show_nested(self):
|
||||||
stack1 = self._setup_test_stack('stack1', UUID1)[1]
|
stack1 = self._setup_test_stack('stack1', UUID1)[1]
|
||||||
@ -803,7 +824,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
self.assertEqual(2, st_db)
|
self.assertEqual(2, st_db)
|
||||||
|
|
||||||
def test_event_get_all_by_stack(self):
|
def test_event_get_all_by_stack(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('stack_events', UUID1)[1]
|
||||||
self._mock_create()
|
self._mock_create()
|
||||||
|
|
||||||
stack.create()
|
stack.create()
|
||||||
@ -900,7 +921,7 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_event_count_all_by_stack(self):
|
def test_event_count_all_by_stack(self):
|
||||||
stack = self._setup_test_stack('stack', UUID1)[1]
|
stack = self._setup_test_stack('stack_event_count', UUID1)[1]
|
||||||
self._mock_create()
|
self._mock_create()
|
||||||
|
|
||||||
stack.create()
|
stack.create()
|
||||||
@ -926,7 +947,8 @@ class SqlAlchemyTest(common.HeatTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_event_get_all_by_tenant(self):
|
def test_event_get_all_by_tenant(self):
|
||||||
stacks = [self._setup_test_stack('stack', x)[1] for x in UUIDs]
|
stacks = [self._setup_test_stack('stack_ev_ten_%d' % i, x)[1]
|
||||||
|
for i, x in enumerate(UUIDs)]
|
||||||
self._mock_create()
|
self._mock_create()
|
||||||
|
|
||||||
[s.create() for s in stacks]
|
[s.create() for s in stacks]
|
||||||
@ -1427,7 +1449,7 @@ def create_user_creds(ctx, **kwargs):
|
|||||||
|
|
||||||
def create_stack(ctx, template, user_creds, **kwargs):
|
def create_stack(ctx, template, user_creds, **kwargs):
|
||||||
values = {
|
values = {
|
||||||
'name': 'db_test_stack_name',
|
'name': short_id.generate_id(),
|
||||||
'raw_template_id': template.id,
|
'raw_template_id': template.id,
|
||||||
'username': ctx.username,
|
'username': ctx.username,
|
||||||
'tenant': ctx.tenant_id,
|
'tenant': ctx.tenant_id,
|
||||||
@ -1444,6 +1466,8 @@ def create_stack(ctx, template, user_creds, **kwargs):
|
|||||||
'prev_raw_template': None
|
'prev_raw_template': None
|
||||||
}
|
}
|
||||||
values.update(kwargs)
|
values.update(kwargs)
|
||||||
|
if 'tenant' in kwargs:
|
||||||
|
ctx.tenant_id = kwargs['tenant']
|
||||||
return db_api.stack_create(ctx, values)
|
return db_api.stack_create(ctx, values)
|
||||||
|
|
||||||
|
|
||||||
@ -1711,7 +1735,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
def test_stack_create(self):
|
def test_stack_create(self):
|
||||||
stack = create_stack(self.ctx, self.template, self.user_creds)
|
stack = create_stack(self.ctx, self.template, self.user_creds)
|
||||||
self.assertIsNotNone(stack.id)
|
self.assertIsNotNone(stack.id)
|
||||||
self.assertEqual('db_test_stack_name', stack.name)
|
self.assertEqual(12, len(stack.name))
|
||||||
self.assertEqual(self.template.id, stack.raw_template_id)
|
self.assertEqual(self.template.id, stack.raw_template_id)
|
||||||
self.assertEqual(self.ctx.username, stack.username)
|
self.assertEqual(self.ctx.username, stack.username)
|
||||||
self.assertEqual(self.ctx.tenant_id, stack.tenant)
|
self.assertEqual(self.ctx.tenant_id, stack.tenant)
|
||||||
@ -1741,7 +1765,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
ret_stack = db_api.stack_get(self.ctx, stack_id, show_deleted=True)
|
ret_stack = db_api.stack_get(self.ctx, stack_id, show_deleted=True)
|
||||||
self.assertIsNotNone(ret_stack)
|
self.assertIsNotNone(ret_stack)
|
||||||
self.assertEqual(stack_id, ret_stack.id)
|
self.assertEqual(stack_id, ret_stack.id)
|
||||||
self.assertEqual('db_test_stack_name', ret_stack.name)
|
self.assertEqual(12, len(ret_stack.name))
|
||||||
|
|
||||||
# Testing child resources deletion
|
# Testing child resources deletion
|
||||||
self.assertRaises(exception.NotFound, db_api.resource_get,
|
self.assertRaises(exception.NotFound, db_api.resource_get,
|
||||||
@ -1857,7 +1881,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
ret_stack = db_api.stack_get(self.ctx, stack.id, show_deleted=False)
|
ret_stack = db_api.stack_get(self.ctx, stack.id, show_deleted=False)
|
||||||
self.assertIsNotNone(ret_stack)
|
self.assertIsNotNone(ret_stack)
|
||||||
self.assertEqual(stack.id, ret_stack.id)
|
self.assertEqual(stack.id, ret_stack.id)
|
||||||
self.assertEqual('db_test_stack_name', ret_stack.name)
|
self.assertEqual(12, len(ret_stack.name))
|
||||||
|
|
||||||
def test_stack_get_returns_none_if_stack_does_not_exist(self):
|
def test_stack_get_returns_none_if_stack_does_not_exist(self):
|
||||||
stack = db_api.stack_get(self.ctx, UUID1, show_deleted=False)
|
stack = db_api.stack_get(self.ctx, UUID1, show_deleted=False)
|
||||||
@ -1876,7 +1900,7 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
ret_stack = db_api.stack_get(self.ctx, stack.id, show_deleted=False)
|
ret_stack = db_api.stack_get(self.ctx, stack.id, show_deleted=False)
|
||||||
self.assertIsNotNone(ret_stack)
|
self.assertIsNotNone(ret_stack)
|
||||||
self.assertEqual(stack.id, ret_stack.id)
|
self.assertEqual(stack.id, ret_stack.id)
|
||||||
self.assertEqual('db_test_stack_name', ret_stack.name)
|
self.assertEqual(12, len(ret_stack.name))
|
||||||
|
|
||||||
def test_stack_get_can_return_a_stack_from_different_tenant(self):
|
def test_stack_get_can_return_a_stack_from_different_tenant(self):
|
||||||
# create a stack with the common tenant
|
# create a stack with the common tenant
|
||||||
@ -1888,14 +1912,14 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
ret_stack = db_api.stack_get(admin_ctx, stack.id,
|
ret_stack = db_api.stack_get(admin_ctx, stack.id,
|
||||||
show_deleted=False)
|
show_deleted=False)
|
||||||
self.assertEqual(stack.id, ret_stack.id)
|
self.assertEqual(stack.id, ret_stack.id)
|
||||||
self.assertEqual('db_test_stack_name', ret_stack.name)
|
self.assertEqual(12, len(ret_stack.name))
|
||||||
|
|
||||||
def test_stack_get_by_name(self):
|
def test_stack_get_by_name(self):
|
||||||
stack = create_stack(self.ctx, self.template, self.user_creds)
|
stack = create_stack(self.ctx, self.template, self.user_creds)
|
||||||
ret_stack = db_api.stack_get_by_name(self.ctx, stack.name)
|
ret_stack = db_api.stack_get_by_name(self.ctx, stack.name)
|
||||||
self.assertIsNotNone(ret_stack)
|
self.assertIsNotNone(ret_stack)
|
||||||
self.assertEqual(stack.id, ret_stack.id)
|
self.assertEqual(stack.id, ret_stack.id)
|
||||||
self.assertEqual('db_test_stack_name', ret_stack.name)
|
self.assertEqual(12, len(ret_stack.name))
|
||||||
|
|
||||||
self.assertIsNone(db_api.stack_get_by_name(self.ctx, 'abc'))
|
self.assertIsNone(db_api.stack_get_by_name(self.ctx, 'abc'))
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ class SnapshotServiceTest(common.HeatTestCase):
|
|||||||
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)
|
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)
|
||||||
mock_load.reset_mock()
|
mock_load.reset_mock()
|
||||||
|
|
||||||
stk2 = self._create_stack('stack_snapshot_restore_other_stack_1')
|
stk2 = self._create_stack('stack_snapshot_restore_other_stack_2')
|
||||||
mock_load.return_value = stk2
|
mock_load.return_value = stk2
|
||||||
|
|
||||||
ex = self.assertRaises(dispatcher.ExpectedException,
|
ex = self.assertRaises(dispatcher.ExpectedException,
|
||||||
|
@ -15,6 +15,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.common import short_id
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import stack as parser
|
from heat.engine import stack as parser
|
||||||
@ -55,7 +56,7 @@ outputs:
|
|||||||
return (template_strict, template_loose)
|
return (template_strict, template_loose)
|
||||||
|
|
||||||
def parse_stack(self, templ_obj):
|
def parse_stack(self, templ_obj):
|
||||||
stack_name = 'test_value_stack'
|
stack_name = 'test_value_stack_%s' % short_id.generate_id()
|
||||||
stack = parser.Stack(utils.dummy_context(), stack_name, templ_obj)
|
stack = parser.Stack(utils.dummy_context(), stack_name, templ_obj)
|
||||||
stack.validate()
|
stack.validate()
|
||||||
stack.store()
|
stack.store()
|
||||||
|
@ -302,7 +302,7 @@ Resources:
|
|||||||
nested_t = template_format.parse(self.nested_template)
|
nested_t = template_format.parse(self.nested_template)
|
||||||
nested_t['Parameters']['KeyName']['Default'] = 'Key'
|
nested_t['Parameters']['KeyName']['Default'] = 'Key'
|
||||||
|
|
||||||
nested_stack = parser.Stack(ctx, 'test',
|
nested_stack = parser.Stack(ctx, 'test_nested',
|
||||||
template.Template(nested_t))
|
template.Template(nested_t))
|
||||||
nested_stack.store()
|
nested_stack.store()
|
||||||
|
|
||||||
|
@ -505,9 +505,10 @@ class StackTest(common.HeatTestCase):
|
|||||||
"resource_id": null, "action": "INIT", "type": "GenericResourceType",
|
"resource_id": null, "action": "INIT", "type": "GenericResourceType",
|
||||||
"metadata": {}}}'''
|
"metadata": {}}}'''
|
||||||
env = environment.Environment({'parameters': {'param1': 'test'}})
|
env = environment.Environment({'parameters': {'param1': 'test'}})
|
||||||
|
self.ctx.tenant_id = '123'
|
||||||
self.stack = stack.Stack(self.ctx, 'stack_details_test',
|
self.stack = stack.Stack(self.ctx, 'stack_details_test',
|
||||||
template.Template(tpl, env=env),
|
template.Template(tpl, env=env),
|
||||||
tenant_id='123',
|
tenant_id=self.ctx.tenant_id,
|
||||||
stack_user_project_id='234',
|
stack_user_project_id='234',
|
||||||
tags=['tag1', 'tag2'])
|
tags=['tag1', 'tag2'])
|
||||||
self.stack.store()
|
self.stack.store()
|
||||||
@ -1439,7 +1440,7 @@ class StackTest(common.HeatTestCase):
|
|||||||
self.stack.id)
|
self.stack.id)
|
||||||
self.assertIsNone(db_tags)
|
self.assertIsNone(db_tags)
|
||||||
|
|
||||||
self.stack = stack.Stack(self.ctx, 'tags_stack', self.tmpl,
|
self.stack = stack.Stack(self.ctx, 'tags_stack2', self.tmpl,
|
||||||
tags=['tag1', 'tag2'])
|
tags=['tag1', 'tag2'])
|
||||||
self.stack.store()
|
self.stack.store()
|
||||||
db_tags = stack_tag_object.StackTagList.get(self.stack.context,
|
db_tags = stack_tag_object.StackTagList.get(self.stack.context,
|
||||||
|
Loading…
Reference in New Issue
Block a user