diff options
| author | Alex Meade <alex.meade@rackspace.com> | 2011-11-17 16:08:10 -0500 |
|---|---|---|
| committer | Alex Meade <alex.meade@rackspace.com> | 2011-11-18 10:35:20 -0500 |
| commit | 265d77e16774f37775c6befbf34837d165ca844e (patch) | |
| tree | ce03311371baf25ef2be46e3b2e643b3c53226c6 | |
| parent | 15937a41609a0216020aa23a8debbd10c1f74de6 (diff) | |
| download | nova-265d77e16774f37775c6befbf34837d165ca844e.tar.gz nova-265d77e16774f37775c6befbf34837d165ca844e.tar.xz nova-265d77e16774f37775c6befbf34837d165ca844e.zip | |
snapshot/backup in compute manager to use uuids
Related to blueprint internal-uuids. Changes shapshot in the computer manager to
expect uuids instead of ids. Also updates some compute api fakes.
Change-Id: I525754ea065c7df9dfe1d093e4c94c02bebf4c02
| -rw-r--r-- | nova/compute/api.py | 20 | ||||
| -rw-r--r-- | nova/compute/manager.py | 15 | ||||
| -rw-r--r-- | nova/exception.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/openstack/fakes.py | 13 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 22 |
5 files changed, 40 insertions, 34 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 5c7ed9ba3..9384ed26f 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1053,7 +1053,10 @@ class API(base.Base): instance = self.get(context, instance_id) host = instance['host'] queue = self.db.queue_get_for(context, FLAGS.compute_topic, host) - params['instance_id'] = instance_id + if utils.is_uuid_like(instance_id): + params['instance_uuid'] = instance_id + else: + params['instance_id'] = instance_id kwargs = {'method': method, 'args': params} rpc.cast(context, queue, kwargs) @@ -1072,7 +1075,10 @@ class API(base.Base): instance = self.get(context, instance_id) host = instance['host'] queue = self.db.queue_get_for(context, FLAGS.compute_topic, host) - params['instance_id'] = instance_id + if utils.is_uuid_like(instance_id): + params['instance_uuid'] = instance_id + else: + params['instance_id'] = instance_id kwargs = {'method': method, 'args': params} return rpc.call(context, queue, kwargs) @@ -1136,15 +1142,15 @@ class API(base.Base): """ task_state = instance["task_state"] - instance_id = instance['id'] + instance_uuid = instance['uuid'] if task_state == task_states.IMAGE_BACKUP: - raise exception.InstanceBackingUp(instance_id=instance_id) + raise exception.InstanceBackingUp(instance_uuid=instance_uuid) if task_state == task_states.IMAGE_SNAPSHOT: - raise exception.InstanceSnapshotting(instance_id=instance_id) + raise exception.InstanceSnapshotting(instance_uuid=instance_uuid) - properties = {'instance_uuid': instance['uuid'], + properties = {'instance_uuid': instance_uuid, 'user_id': str(context.user_id), 'image_state': 'creating', 'image_type': image_type, @@ -1155,7 +1161,7 @@ class API(base.Base): recv_meta = self.image_service.create(context, sent_meta) params = {'image_id': recv_meta['id'], 'image_type': image_type, 'backup_type': backup_type, 'rotation': rotation} - self._cast_compute_message('snapshot_instance', context, instance_id, + self._cast_compute_message('snapshot_instance', context, instance_uuid, params=params) return recv_meta diff --git a/nova/compute/manager.py b/nova/compute/manager.py index dd3ab74af..0e9893854 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -715,13 +715,13 @@ class ComputeManager(manager.SchedulerDependentManager): task_state=None) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - def snapshot_instance(self, context, instance_id, image_id, + def snapshot_instance(self, context, instance_uuid, image_id, image_type='snapshot', backup_type=None, rotation=None): """Snapshot an instance on this host. :param context: security context - :param instance_id: nova.db.sqlalchemy.models.Instance.Id + :param instance_uuid: nova.db.sqlalchemy.models.Instance.Uuid :param image_id: glance.db.sqlalchemy.models.Image.Id :param image_type: snapshot | backup :param backup_type: daily | weekly @@ -736,33 +736,32 @@ class ComputeManager(manager.SchedulerDependentManager): raise Exception(_('Image type not recognized %s') % image_type) context = context.elevated() - instance_ref = self.db.instance_get(context, instance_id) + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) current_power_state = self._get_power_state(context, instance_ref) self._instance_update(context, - instance_id, + instance_ref['id'], power_state=current_power_state, vm_state=vm_states.ACTIVE, task_state=task_state) - LOG.audit(_('instance %s: snapshotting'), instance_id, + LOG.audit(_('instance %s: snapshotting'), instance_uuid, context=context) if instance_ref['power_state'] != power_state.RUNNING: state = instance_ref['power_state'] running = power_state.RUNNING LOG.warn(_('trying to snapshot a non-running ' - 'instance: %(instance_id)s (state: %(state)s ' + 'instance: %(instance_uuid)s (state: %(state)s ' 'expected: %(running)s)') % locals()) self.driver.snapshot(context, instance_ref, image_id) - self._instance_update(context, instance_id, task_state=None) + self._instance_update(context, instance_ref['id'], task_state=None) if image_type == 'snapshot' and rotation: raise exception.ImageRotationNotAllowed() elif image_type == 'backup' and rotation: - instance_uuid = instance_ref['uuid'] self.rotate_backups(context, instance_uuid, backup_type, rotation) elif image_type == 'backup': diff --git a/nova/exception.py b/nova/exception.py index bf277f53a..78a888faa 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -197,11 +197,11 @@ class InstanceBusy(NovaException): class InstanceSnapshotting(InstanceBusy): - message = _("Instance %(instance_id)s is currently snapshotting.") + message = _("Instance %(instance_uuid)s is currently snapshotting.") class InstanceBackingUp(InstanceBusy): - message = _("Instance %(instance_id)s is currently being backed up.") + message = _("Instance %(instance_uuid)s is currently being backed up.") class Invalid(NovaException): diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index c12ae5eab..9f5383944 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -168,11 +168,10 @@ class stub_out_compute_api_snapshot(object): self.extra_props_last_call = None stubs.Set(nova.compute.API, 'snapshot', self.snapshot) - def snapshot(self, context, instance_id, name, extra_properties=None): + def snapshot(self, context, instance, name, extra_properties=None): self.extra_props_last_call = extra_properties - props = dict(instance_id=instance_id, instance_ref=instance_id) - props.update(extra_properties or {}) - return dict(id='123', status='ACTIVE', name=name, properties=props) + return dict(id='123', status='ACTIVE', name=name, + properties=extra_properties) class stub_out_compute_api_backup(object): @@ -182,11 +181,11 @@ class stub_out_compute_api_backup(object): self.extra_props_last_call = None stubs.Set(nova.compute.API, 'backup', self.backup) - def backup(self, context, instance_id, name, backup_type, rotation, + def backup(self, context, instance, name, backup_type, rotation, extra_properties=None): self.extra_props_last_call = extra_properties - props = dict(instance_id=instance_id, instance_ref=instance_id, - backup_type=backup_type, rotation=rotation) + props = dict(backup_type=backup_type, + rotation=rotation) props.update(extra_properties or {}) return dict(id='123', status='ACTIVE', name=name, properties=props) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 397b5e268..93cf1a935 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -333,10 +333,12 @@ class ComputeTestCase(BaseTestCase): def test_snapshot(self): """Ensure instance can be snapshotted""" - instance_id = self._create_instance() + instance = self._create_fake_instance() + instance_id = instance['id'] + instance_uuid = instance['uuid'] name = "myfakesnapshot" self.compute.run_instance(self.context, instance_id) - self.compute.snapshot_instance(self.context, instance_id, name) + self.compute.snapshot_instance(self.context, instance_uuid, name) self.compute.terminate_instance(self.context, instance_id) def test_console_output(self): @@ -1316,21 +1318,20 @@ class ComputeAPITestCase(BaseTestCase): def test_snapshot(self): """Can't backup an instance which is already being backed up.""" - instance_id = self._create_instance() - instance = self.compute_api.get(self.context, instance_id) + instance = self._create_fake_instance() self.compute_api.snapshot(self.context, instance, None, None) - db.instance_destroy(self.context, instance_id) + db.instance_destroy(self.context, instance['id']) def test_backup(self): """Can't backup an instance which is already being backed up.""" - instance_id = self._create_instance() - instance = self.compute_api.get(self.context, instance_id) + instance = self._create_fake_instance() self.compute_api.backup(self.context, instance, None, None, None) - db.instance_destroy(self.context, instance_id) + db.instance_destroy(self.context, instance['id']) def test_backup_conflict(self): """Can't backup an instance which is already being backed up.""" - instance_id = self._create_instance() + instance = self._create_fake_instance() + instance_id = instance['id'] instance_values = {'task_state': task_states.IMAGE_BACKUP} db.instance_update(self.context, instance_id, instance_values) instance = self.compute_api.get(self.context, instance_id) @@ -1347,7 +1348,8 @@ class ComputeAPITestCase(BaseTestCase): def test_snapshot_conflict(self): """Can't snapshot an instance which is already being snapshotted.""" - instance_id = self._create_instance() + instance = self._create_fake_instance() + instance_id = instance['id'] instance_values = {'task_state': task_states.IMAGE_SNAPSHOT} db.instance_update(self.context, instance_id, instance_values) instance = self.compute_api.get(self.context, instance_id) |
