diff options
| author | Eoghan Glynn <eglynn@redhat.com> | 2012-06-29 17:30:52 +0000 |
|---|---|---|
| committer | Eoghan Glynn <eglynn@redhat.com> | 2012-06-30 08:30:16 +0100 |
| commit | ea711b229789d9db54b7e10fe4c67ee1bf1db8c6 (patch) | |
| tree | df134fa7a50c5d1e26847ba7ca7eb1cea246ca64 | |
| parent | 019d953ef5b4bed7c53401375bfd7aa890fc0c1d (diff) | |
Create instance in DB before block device mapping
Fixes lp 1019334
A recently added foreign key constraint on the the block_device_mapping
table causes boot-from-volume to fail, as the bdm is populated before the
instance DB entry is created.
This fix simply transposes the ordering to avoid breaking the constraint.
Change-Id: Ic62ea3ba000a2cdf58d2bd5bb17dde2b8cf340e4
| -rw-r--r-- | nova/compute/api.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 557dbb930..3fbaf12df 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -587,7 +587,6 @@ class API(base.Base): instance_uuid = instance['uuid'] mappings = image['properties'].get('mappings', []) if mappings: - instance['shutdown_terminate'] = False self._update_image_block_device_mapping(elevated, instance_type, instance_uuid, mappings) @@ -595,10 +594,17 @@ class API(base.Base): for mapping in (image_bdm, block_device_mapping): if not mapping: continue - instance['shutdown_terminate'] = False self._update_block_device_mapping(elevated, instance_type, instance_uuid, mapping) + def _populate_instance_shutdown_terminate(self, instance, image, + block_device_mapping): + """Populate instance shutdown_terminate information.""" + if (block_device_mapping or + image['properties'].get('mappings') or + image['properties'].get('block_device_mapping')): + instance['shutdown_terminate'] = False + def _populate_instance_names(self, instance): """Populate instance display_name and hostname.""" display_name = instance.get('display_name') @@ -662,11 +668,14 @@ class API(base.Base): self._populate_instance_names(instance) - self._populate_instance_for_bdm(context, instance, - instance_type, image, block_device_mapping) + self._populate_instance_shutdown_terminate(instance, image, + block_device_mapping) instance = self.db.instance_create(context, instance) + self._populate_instance_for_bdm(context, instance, + instance_type, image, block_device_mapping) + # send a state update notification for the initial create to # show it going from non-existent to BUILDING notifications.send_update_with_states(context, instance, None, |
