From 5d46d3fb74452a7a1c8ddd8d1a8b643712a0f801 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Fri, 14 Sep 2012 14:12:55 -0400 Subject: make ensure_default_security_group() call sgh This change makes sure that sgh is called when default security group is created. Fixes bug 1050982 Change-Id: I483e33d8977b2bfbd7456a7c7c0d1fe7803708f8 --- nova/db/api.py | 7 ++++++- nova/db/sqlalchemy/api.py | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index de393287a..cb651793e 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -1288,7 +1288,12 @@ def security_group_create(context, values): def security_group_ensure_default(context): - """Ensure default security group exists for a project_id.""" + """Ensure default security group exists for a project_id. + + Returns a tuple with the first element being a bool indicating + if the default security group previously existed. Second + element is the dict used to create the default security group. + """ return IMPL.security_group_ensure_default(context) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 533298bee..ad013b877 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1423,8 +1423,8 @@ def instance_create(context, values): def _get_sec_group_models(session, security_groups): models = [] - default_group = security_group_ensure_default(context, - session=session) + _existed, default_group = security_group_ensure_default(context, + session=session) if 'default' in security_groups: models.append(default_group) # Generate a new list, so we don't modify the original @@ -3527,11 +3527,17 @@ def security_group_create(context, values, session=None): def security_group_ensure_default(context, session=None): - """Ensure default security group exists for a project_id.""" + """Ensure default security group exists for a project_id. + + Returns a tuple with the first element being a bool indicating + if the default security group previously existed. Second + element is the dict used to create the default security group. + """ try: default_group = security_group_get_by_name(context, context.project_id, 'default', columns_to_join=[], session=session) + return (True, default_group) except exception.NotFound: values = {'name': 'default', 'description': 'default', @@ -3539,7 +3545,7 @@ def security_group_ensure_default(context, session=None): 'project_id': context.project_id} default_group = security_group_create(context, values, session=session) - return default_group + return (False, default_group) @require_context -- cgit