diff options
| author | Brian Waldon <brian.waldon@rackspace.com> | 2011-11-10 21:54:14 -0500 |
|---|---|---|
| committer | Brian Waldon <brian.waldon@rackspace.com> | 2011-11-10 21:54:14 -0500 |
| commit | d29f9e34555c2af2d996cd96e084af4be513a33b (patch) | |
| tree | 278e0f0c5ba4f660f3238fb33b233574a56dd2be | |
| parent | 59dfaf9e02ff0064a6844c9c986737267317776f (diff) | |
| download | nova-d29f9e34555c2af2d996cd96e084af4be513a33b.tar.gz nova-d29f9e34555c2af2d996cd96e084af4be513a33b.tar.xz nova-d29f9e34555c2af2d996cd96e084af4be513a33b.zip | |
Converting snapshot/backup to use instance objects
Related to blueprint internal-uuids
Change-Id: I8d9768524d36f7066cc1550bba01326dc5167a8d
| -rw-r--r-- | nova/api/openstack/servers.py | 8 | ||||
| -rw-r--r-- | nova/compute/api.py | 18 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 24 |
3 files changed, 35 insertions, 15 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index ba9dd4ec3..dd784043a 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -568,8 +568,10 @@ class Controller(object): msg = _("Invalid metadata") raise exc.HTTPBadRequest(explanation=msg) + instance = self._get_server(context, instance_id) + image = self.compute_api.backup(context, - instance_id, + instance, image_name, backup_type, rotation, @@ -846,9 +848,11 @@ class Controller(object): msg = _("Invalid metadata") raise exc.HTTPBadRequest(explanation=msg) + instance = self._get_server(context, instance_id) + try: image = self.compute_api.snapshot(context, - instance_id, + instance, image_name, extra_properties=props) except exception.InstanceBusy: diff --git a/nova/compute/api.py b/nova/compute/api.py index 820a7b9b6..8511305ac 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1110,41 +1110,41 @@ class API(base.Base): % instance_id) @scheduler_api.reroute_compute("backup") - def backup(self, context, instance_id, name, backup_type, rotation, + def backup(self, context, instance, name, backup_type, rotation, extra_properties=None): """Backup the given instance - :param instance_id: nova.db.sqlalchemy.models.Instance.Id + :param instance: nova.db.sqlalchemy.models.Instance :param name: name of the backup or snapshot name = backup_type # daily backups are called 'daily' :param rotation: int representing how many backups to keep around; None if rotation shouldn't be used (as in the case of snapshots) :param extra_properties: dict of extra image properties to include """ - recv_meta = self._create_image(context, instance_id, name, 'backup', + recv_meta = self._create_image(context, instance, name, 'backup', backup_type=backup_type, rotation=rotation, extra_properties=extra_properties) return recv_meta @scheduler_api.reroute_compute("snapshot") - def snapshot(self, context, instance_id, name, extra_properties=None): + def snapshot(self, context, instance, name, extra_properties=None): """Snapshot the given instance. - :param instance_id: nova.db.sqlalchemy.models.Instance.Id + :param instance: nova.db.sqlalchemy.models.Instance :param name: name of the backup or snapshot :param extra_properties: dict of extra image properties to include :returns: A dict containing image metadata """ - return self._create_image(context, instance_id, name, 'snapshot', + return self._create_image(context, instance, name, 'snapshot', extra_properties=extra_properties) - def _create_image(self, context, instance_id, name, image_type, + def _create_image(self, context, instance, name, image_type, backup_type=None, rotation=None, extra_properties=None): """Create snapshot or backup for an instance on this host. :param context: security context - :param instance_id: nova.db.sqlalchemy.models.Instance.Id + :param instance: nova.db.sqlalchemy.models.Instance :param name: string for name of the snapshot :param image_type: snapshot | backup :param backup_type: daily | weekly @@ -1153,8 +1153,8 @@ class API(base.Base): :param extra_properties: dict of extra image properties to include """ - instance = self.db.instance_get(context, instance_id) task_state = instance["task_state"] + instance_id = instance['id'] if task_state == task_states.IMAGE_BACKUP: raise exception.InstanceBackingUp(instance_id=instance_id) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 0e8d53751..666782105 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1188,32 +1188,48 @@ class ComputeAPITestCase(BaseTestCase): self.compute.terminate_instance(self.context, instance_id) - def test_snapshot_conflict_backup(self): + 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) + self.compute_api.snapshot(self.context, instance, None, None) + 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) + self.compute_api.backup(self.context, instance, None, None, None) + 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_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) self.assertRaises(exception.InstanceBackingUp, self.compute_api.backup, self.context, - instance_id, + instance, None, None, None) db.instance_destroy(self.context, instance_id) - def test_snapshot_conflict_snapshot(self): + def test_snapshot_conflict(self): """Can't snapshot an instance which is already being snapshotted.""" instance_id = self._create_instance() 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) self.assertRaises(exception.InstanceSnapshotting, self.compute_api.snapshot, self.context, - instance_id, + instance, None) db.instance_destroy(self.context, instance_id) |
