diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-11-11 19:06:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-11-11 19:06:18 +0000 |
| commit | 314539cce77846a7fe9ff7dc52d6291fcc34814e (patch) | |
| tree | cd565c0122bbfed8cedffbd2d6b4918bdc10a1a8 /nova | |
| parent | ed3635f40fa31b896bb700610b93fe288a90e692 (diff) | |
| parent | d29f9e34555c2af2d996cd96e084af4be513a33b (diff) | |
| download | nova-314539cce77846a7fe9ff7dc52d6291fcc34814e.tar.gz nova-314539cce77846a7fe9ff7dc52d6291fcc34814e.tar.xz nova-314539cce77846a7fe9ff7dc52d6291fcc34814e.zip | |
Merge "Converting snapshot/backup to use instance objects"
Diffstat (limited to 'nova')
| -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 b913a2bb5..b3c4fbce9 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -567,8 +567,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 6549031e2..6dcf7bd1d 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1111,41 +1111,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 @@ -1154,8 +1154,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 20a8e3d5b..2bf726697 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1190,32 +1190,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) |
