nova/nova
melanie witt 416290f193 Remove redundant call to get/create default security group
In the instance_create DB API method, it ensures the (legacy) default
security group gets created for the specified project_id if it does
not already exist. If the security group does not exist, it is created
in a separate transaction.

Later in the instance_create method, it reads the default security group
back that it wrote earlier (via the same ensure default security group
code). But since it was written in a separate transaction, the current
transaction will not be able to see it and will get back 0 rows. So, it
creates a duplicate default security group record if project_id=NULL
(which it will be, if running nova-manage db online_data_migrations,
which uses an anonymous RequestContext with project_id=NULL). This
succeeds despite the unique constraint on project_id because in MySQL,
unique constraints are only enforced on non-NULL values [1].

To avoid creation of a duplicate default security group for
project_id=NULL, we can use the default security group object that was
returned from the first security_group_ensure_default call earlier in
instance_create method and remove the second, redundant call.

This also breaks out the security groups setup code from a nested
method as it was causing confusion during code review and is not being
used for any particular purpose. Inspection of the original commit
where it was added in 2012 [2] did not contain any comments about the
nested method and it appeared to either be a way to organize the code
or a way to reuse the 'models' module name as a local variable name.

Closes-Bug: #1824435

[1] https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-unique
[2] https://review.opendev.org/#/c/8973/2/nova/db/sqlalchemy/api.py@1339

Change-Id: Idb205ab5b16bbf96965418cd544016fa9cc92de9
(cherry picked from commit 6ea945e3b1)
2019-10-25 17:40:05 +00:00
..
api Merge "doc: mark the max microversion for train" 2019-09-17 01:42:09 +00:00
cmd Nova object changes for forbidden aggregates request filter 2019-09-09 20:16:32 +00:00
compute Merge "Error out interrupted builds" into stable/train 2019-10-21 18:27:04 +00:00
conductor Handle get_host_availability_zone error during reschedule 2019-10-02 13:45:58 -04:00
conf Merge "libvirt: Enable driver configuring PMEM namespaces" 2019-09-21 03:40:33 +00:00
console Merge "objects: Remove ConsoleAuthToken.to_dict" 2019-09-06 18:51:31 +00:00
db Remove redundant call to get/create default security group 2019-10-25 17:40:05 +00:00
hacking Add a hacking rule for useless assertions 2019-08-21 14:42:53 +09:00
image [Trivial]Removed unused helper _extract_query_params 2019-08-29 10:12:52 +08:00
ipv6
keymgr
locale Imported Translations from Zanata 2019-10-02 07:19:10 +00:00
network Remove upgrade specific info from user facing exception text 2019-09-24 10:44:46 +02:00
notifications Update api-ref location 2019-07-22 19:17:28 +02:00
objects Reduce scope of 'path' query parameter to noVNC consoles 2019-10-01 22:16:42 +00:00
pci hacking: Resolve W605 (invalid escape sequence) 2019-06-24 14:24:06 -05:00
policies Add server sub-resource topology API 2019-08-30 10:04:56 +08:00
privsep libvirt: Support VM creation with vpmems and vpmems cleanup 2019-09-13 08:50:35 +00:00
scheduler Add support for translating CPU policy extra specs, image meta 2019-09-18 00:21:10 +01:00
servicegroup [Trivial fix]Remove unnecessary slash 2019-05-06 16:23:59 +08:00
tests Merge "Fix exception translation when creating volume" into stable/train 2019-10-21 18:50:20 +00:00
virt make virtual pmem feature compatible with python3 2019-09-30 08:50:40 -07:00
vnc xvp: Remove use of '_LI' marker 2019-06-19 10:04:45 +01:00
volume Fix exception translation when creating volume 2019-10-11 08:41:18 +00:00
__init__.py Eventlet monkey patching should be as early as possible 2019-03-22 09:27:16 +00:00
availability_zones.py Always pass HostAPI to get_availability_zones 2019-04-26 15:30:48 -04:00
baserpc.py
block_device.py hacking: Resolve W605 (invalid escape sequence) 2019-06-24 14:24:06 -05:00
cache_utils.py
config.py Rename 'nova.common.config' module to 'nova.middleware' 2019-08-16 00:53:03 +01:00
context.py Merge "Move default policy target" 2019-07-27 00:32:20 +00:00
crypto.py
debugger.py
exception.py libvirt: Support VM creation with vpmems and vpmems cleanup 2019-09-13 08:50:35 +00:00
exception_wrapper.py
filters.py filters: Stop handling cells v1 2019-06-12 16:09:46 +01:00
hooks.py
i18n.py
loadables.py
manager.py
middleware.py Rename 'nova.common.config' module to 'nova.middleware' 2019-08-16 00:53:03 +01:00
monkey_patch.py Bump to hacking 1.1.0 2019-04-12 16:23:49 +01:00
policy.py Move default policy target 2019-06-03 16:44:50 +01:00
profiler.py
quota.py Log quota legacy method warning only if counting from placement 2019-06-17 21:31:53 +00:00
rpc.py Remove unnecessary wrapper 2019-05-29 17:14:13 +01:00
safe_utils.py
service.py Remove nova-consoleauth 2019-07-05 15:04:47 +00:00
service_auth.py
test.py Tests: autospecs all the mock.patch usages 2019-08-19 09:43:10 -05:00
utils.py Allow strict_proxies for sdk Connection 2019-08-23 14:14:40 -05:00
version.py
weights.py Per aggregate scheduling weight 2019-01-21 11:48:44 +08:00
wsgi.py