Merge "Find root stack ID with database operations"
This commit is contained in:
commit
bf669cbf13
@ -198,6 +198,10 @@ def stack_lock_release(stack_id, engine_id):
|
|||||||
return IMPL.stack_lock_release(stack_id, engine_id)
|
return IMPL.stack_lock_release(stack_id, engine_id)
|
||||||
|
|
||||||
|
|
||||||
|
def stack_get_root_id(context, stack_id):
|
||||||
|
return IMPL.stack_get_root_id(context, stack_id)
|
||||||
|
|
||||||
|
|
||||||
def user_creds_create(context):
|
def user_creds_create(context):
|
||||||
return IMPL.user_creds_create(context)
|
return IMPL.user_creds_create(context)
|
||||||
|
|
||||||
|
@ -576,6 +576,13 @@ def stack_lock_release(stack_id, engine_id):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def stack_get_root_id(context, stack_id):
|
||||||
|
s = stack_get(context, stack_id)
|
||||||
|
while s.owner_id:
|
||||||
|
s = stack_get(context, s.owner_id)
|
||||||
|
return s.id
|
||||||
|
|
||||||
|
|
||||||
def user_creds_create(context):
|
def user_creds_create(context):
|
||||||
values = context.to_dict()
|
values = context.to_dict()
|
||||||
user_creds_ref = models.UserCreds()
|
user_creds_ref = models.UserCreds()
|
||||||
|
@ -528,7 +528,7 @@ class Instance(resource.Resource):
|
|||||||
if cfg.CONF.stack_scheduler_hints:
|
if cfg.CONF.stack_scheduler_hints:
|
||||||
if scheduler_hints is None:
|
if scheduler_hints is None:
|
||||||
scheduler_hints = {}
|
scheduler_hints = {}
|
||||||
scheduler_hints['heat_root_stack_id'] = self.stack.root_stack.id
|
scheduler_hints['heat_root_stack_id'] = self.stack.root_stack_id()
|
||||||
scheduler_hints['heat_stack_id'] = self.stack.id
|
scheduler_hints['heat_stack_id'] = self.stack.id
|
||||||
scheduler_hints['heat_stack_name'] = self.stack.name
|
scheduler_hints['heat_stack_name'] = self.stack.name
|
||||||
scheduler_hints['heat_path_in_stack'] = self.stack.path_in_stack()
|
scheduler_hints['heat_path_in_stack'] = self.stack.path_in_stack()
|
||||||
|
@ -670,7 +670,7 @@ class Server(stack_user.StackUser):
|
|||||||
if cfg.CONF.stack_scheduler_hints:
|
if cfg.CONF.stack_scheduler_hints:
|
||||||
if scheduler_hints is None:
|
if scheduler_hints is None:
|
||||||
scheduler_hints = {}
|
scheduler_hints = {}
|
||||||
scheduler_hints['heat_root_stack_id'] = self.stack.root_stack.id
|
scheduler_hints['heat_root_stack_id'] = self.stack.root_stack_id()
|
||||||
scheduler_hints['heat_stack_id'] = self.stack.id
|
scheduler_hints['heat_stack_id'] = self.stack.id
|
||||||
scheduler_hints['heat_stack_name'] = self.stack.name
|
scheduler_hints['heat_stack_name'] = self.stack.name
|
||||||
scheduler_hints['heat_path_in_stack'] = self.stack.path_in_stack()
|
scheduler_hints['heat_path_in_stack'] = self.stack.path_in_stack()
|
||||||
|
@ -257,6 +257,11 @@ class Stack(collections.Mapping):
|
|||||||
def reset_dependencies(self):
|
def reset_dependencies(self):
|
||||||
self._dependencies = None
|
self._dependencies = None
|
||||||
|
|
||||||
|
def root_stack_id(self):
|
||||||
|
if not self.owner_id:
|
||||||
|
return self.id
|
||||||
|
return stack_object.Stack.get_root_id(self.context, self.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def root_stack(self):
|
def root_stack(self):
|
||||||
'''
|
'''
|
||||||
|
@ -80,6 +80,10 @@ class Stack(
|
|||||||
stack.obj_reset_changes()
|
stack.obj_reset_changes()
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_root_id(cls, context, stack_id):
|
||||||
|
return db_api.stack_get_root_id(context, stack_id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_id(cls, context, stack_id, **kwargs):
|
def get_by_id(cls, context, stack_id, **kwargs):
|
||||||
db_stack = db_api.stack_get(context, stack_id, **kwargs)
|
db_stack = db_api.stack_get(context, stack_id, **kwargs)
|
||||||
|
@ -550,7 +550,7 @@ class InstancesTest(common.HeatTestCase):
|
|||||||
limit=instance.physical_resource_name_limit),
|
limit=instance.physical_resource_name_limit),
|
||||||
security_groups=None,
|
security_groups=None,
|
||||||
userdata=mox.IgnoreArg(),
|
userdata=mox.IgnoreArg(),
|
||||||
scheduler_hints={'heat_root_stack_id': stack.root_stack.id,
|
scheduler_hints={'heat_root_stack_id': stack.root_stack_id(),
|
||||||
'heat_stack_id': stack.id,
|
'heat_stack_id': stack.id,
|
||||||
'heat_stack_name': stack.name,
|
'heat_stack_name': stack.name,
|
||||||
'heat_path_in_stack': [(None, stack.name)],
|
'heat_path_in_stack': [(None, stack.name)],
|
||||||
|
@ -1801,6 +1801,25 @@ class DBAPIStackTest(common.HeatTestCase):
|
|||||||
self.assertIsNone(db_api.stack_get(ctx, stacks[s].id,
|
self.assertIsNone(db_api.stack_get(ctx, stacks[s].id,
|
||||||
show_deleted=True))
|
show_deleted=True))
|
||||||
|
|
||||||
|
def test_stack_get_root_id(self):
|
||||||
|
root = create_stack(self.ctx, self.template, self.user_creds,
|
||||||
|
name='root stack')
|
||||||
|
child_1 = create_stack(self.ctx, self.template, self.user_creds,
|
||||||
|
name='child 1 stack', owner_id=root.id)
|
||||||
|
child_2 = create_stack(self.ctx, self.template, self.user_creds,
|
||||||
|
name='child 2 stack', owner_id=child_1.id)
|
||||||
|
child_3 = create_stack(self.ctx, self.template, self.user_creds,
|
||||||
|
name='child 3 stack', owner_id=child_2.id)
|
||||||
|
|
||||||
|
self.assertEqual(root.id, db_api.stack_get_root_id(
|
||||||
|
self.ctx, child_3.id))
|
||||||
|
self.assertEqual(root.id, db_api.stack_get_root_id(
|
||||||
|
self.ctx, child_2.id))
|
||||||
|
self.assertEqual(root.id, db_api.stack_get_root_id(
|
||||||
|
self.ctx, root.id))
|
||||||
|
self.assertEqual(root.id, db_api.stack_get_root_id(
|
||||||
|
self.ctx, child_1.id))
|
||||||
|
|
||||||
|
|
||||||
class DBAPIResourceTest(common.HeatTestCase):
|
class DBAPIResourceTest(common.HeatTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -905,7 +905,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
name=server_name,
|
name=server_name,
|
||||||
security_groups=[],
|
security_groups=[],
|
||||||
userdata=mox.IgnoreArg(),
|
userdata=mox.IgnoreArg(),
|
||||||
scheduler_hints={'heat_root_stack_id': stack.root_stack.id,
|
scheduler_hints={'heat_root_stack_id': stack.root_stack_id(),
|
||||||
'heat_stack_id': stack.id,
|
'heat_stack_id': stack.id,
|
||||||
'heat_stack_name': stack.name,
|
'heat_stack_name': stack.name,
|
||||||
'heat_path_in_stack': [(None, stack.name)],
|
'heat_path_in_stack': [(None, stack.name)],
|
||||||
|
Loading…
Reference in New Issue
Block a user