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
This commit is contained in:
@@ -1053,7 +1053,10 @@ class API(base.Base):
|
|||||||
instance = self.get(context, instance_id)
|
instance = self.get(context, instance_id)
|
||||||
host = instance['host']
|
host = instance['host']
|
||||||
queue = self.db.queue_get_for(context, FLAGS.compute_topic, 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}
|
kwargs = {'method': method, 'args': params}
|
||||||
rpc.cast(context, queue, kwargs)
|
rpc.cast(context, queue, kwargs)
|
||||||
|
|
||||||
@@ -1072,7 +1075,10 @@ class API(base.Base):
|
|||||||
instance = self.get(context, instance_id)
|
instance = self.get(context, instance_id)
|
||||||
host = instance['host']
|
host = instance['host']
|
||||||
queue = self.db.queue_get_for(context, FLAGS.compute_topic, 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}
|
kwargs = {'method': method, 'args': params}
|
||||||
return rpc.call(context, queue, kwargs)
|
return rpc.call(context, queue, kwargs)
|
||||||
|
|
||||||
@@ -1136,15 +1142,15 @@ class API(base.Base):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
task_state = instance["task_state"]
|
task_state = instance["task_state"]
|
||||||
instance_id = instance['id']
|
instance_uuid = instance['uuid']
|
||||||
|
|
||||||
if task_state == task_states.IMAGE_BACKUP:
|
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:
|
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),
|
'user_id': str(context.user_id),
|
||||||
'image_state': 'creating',
|
'image_state': 'creating',
|
||||||
'image_type': image_type,
|
'image_type': image_type,
|
||||||
@@ -1155,7 +1161,7 @@ class API(base.Base):
|
|||||||
recv_meta = self.image_service.create(context, sent_meta)
|
recv_meta = self.image_service.create(context, sent_meta)
|
||||||
params = {'image_id': recv_meta['id'], 'image_type': image_type,
|
params = {'image_id': recv_meta['id'], 'image_type': image_type,
|
||||||
'backup_type': backup_type, 'rotation': rotation}
|
'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)
|
params=params)
|
||||||
return recv_meta
|
return recv_meta
|
||||||
|
|
||||||
|
|||||||
@@ -715,13 +715,13 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||||||
task_state=None)
|
task_state=None)
|
||||||
|
|
||||||
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
|
@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,
|
image_type='snapshot', backup_type=None,
|
||||||
rotation=None):
|
rotation=None):
|
||||||
"""Snapshot an instance on this host.
|
"""Snapshot an instance on this host.
|
||||||
|
|
||||||
:param context: security context
|
: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_id: glance.db.sqlalchemy.models.Image.Id
|
||||||
:param image_type: snapshot | backup
|
:param image_type: snapshot | backup
|
||||||
:param backup_type: daily | weekly
|
:param backup_type: daily | weekly
|
||||||
@@ -736,33 +736,32 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||||||
raise Exception(_('Image type not recognized %s') % image_type)
|
raise Exception(_('Image type not recognized %s') % image_type)
|
||||||
|
|
||||||
context = context.elevated()
|
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)
|
current_power_state = self._get_power_state(context, instance_ref)
|
||||||
self._instance_update(context,
|
self._instance_update(context,
|
||||||
instance_id,
|
instance_ref['id'],
|
||||||
power_state=current_power_state,
|
power_state=current_power_state,
|
||||||
vm_state=vm_states.ACTIVE,
|
vm_state=vm_states.ACTIVE,
|
||||||
task_state=task_state)
|
task_state=task_state)
|
||||||
|
|
||||||
LOG.audit(_('instance %s: snapshotting'), instance_id,
|
LOG.audit(_('instance %s: snapshotting'), instance_uuid,
|
||||||
context=context)
|
context=context)
|
||||||
|
|
||||||
if instance_ref['power_state'] != power_state.RUNNING:
|
if instance_ref['power_state'] != power_state.RUNNING:
|
||||||
state = instance_ref['power_state']
|
state = instance_ref['power_state']
|
||||||
running = power_state.RUNNING
|
running = power_state.RUNNING
|
||||||
LOG.warn(_('trying to snapshot a non-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())
|
'expected: %(running)s)') % locals())
|
||||||
|
|
||||||
self.driver.snapshot(context, instance_ref, image_id)
|
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:
|
if image_type == 'snapshot' and rotation:
|
||||||
raise exception.ImageRotationNotAllowed()
|
raise exception.ImageRotationNotAllowed()
|
||||||
|
|
||||||
elif image_type == 'backup' and rotation:
|
elif image_type == 'backup' and rotation:
|
||||||
instance_uuid = instance_ref['uuid']
|
|
||||||
self.rotate_backups(context, instance_uuid, backup_type, rotation)
|
self.rotate_backups(context, instance_uuid, backup_type, rotation)
|
||||||
|
|
||||||
elif image_type == 'backup':
|
elif image_type == 'backup':
|
||||||
|
|||||||
@@ -197,11 +197,11 @@ class InstanceBusy(NovaException):
|
|||||||
|
|
||||||
|
|
||||||
class InstanceSnapshotting(InstanceBusy):
|
class InstanceSnapshotting(InstanceBusy):
|
||||||
message = _("Instance %(instance_id)s is currently snapshotting.")
|
message = _("Instance %(instance_uuid)s is currently snapshotting.")
|
||||||
|
|
||||||
|
|
||||||
class InstanceBackingUp(InstanceBusy):
|
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):
|
class Invalid(NovaException):
|
||||||
|
|||||||
@@ -168,11 +168,10 @@ class stub_out_compute_api_snapshot(object):
|
|||||||
self.extra_props_last_call = None
|
self.extra_props_last_call = None
|
||||||
stubs.Set(nova.compute.API, 'snapshot', self.snapshot)
|
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
|
self.extra_props_last_call = extra_properties
|
||||||
props = dict(instance_id=instance_id, instance_ref=instance_id)
|
return dict(id='123', status='ACTIVE', name=name,
|
||||||
props.update(extra_properties or {})
|
properties=extra_properties)
|
||||||
return dict(id='123', status='ACTIVE', name=name, properties=props)
|
|
||||||
|
|
||||||
|
|
||||||
class stub_out_compute_api_backup(object):
|
class stub_out_compute_api_backup(object):
|
||||||
@@ -182,11 +181,11 @@ class stub_out_compute_api_backup(object):
|
|||||||
self.extra_props_last_call = None
|
self.extra_props_last_call = None
|
||||||
stubs.Set(nova.compute.API, 'backup', self.backup)
|
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):
|
extra_properties=None):
|
||||||
self.extra_props_last_call = extra_properties
|
self.extra_props_last_call = extra_properties
|
||||||
props = dict(instance_id=instance_id, instance_ref=instance_id,
|
props = dict(backup_type=backup_type,
|
||||||
backup_type=backup_type, rotation=rotation)
|
rotation=rotation)
|
||||||
props.update(extra_properties or {})
|
props.update(extra_properties or {})
|
||||||
return dict(id='123', status='ACTIVE', name=name, properties=props)
|
return dict(id='123', status='ACTIVE', name=name, properties=props)
|
||||||
|
|
||||||
|
|||||||
@@ -333,10 +333,12 @@ class ComputeTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_snapshot(self):
|
def test_snapshot(self):
|
||||||
"""Ensure instance can be snapshotted"""
|
"""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"
|
name = "myfakesnapshot"
|
||||||
self.compute.run_instance(self.context, instance_id)
|
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)
|
self.compute.terminate_instance(self.context, instance_id)
|
||||||
|
|
||||||
def test_console_output(self):
|
def test_console_output(self):
|
||||||
@@ -1316,21 +1318,20 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_snapshot(self):
|
def test_snapshot(self):
|
||||||
"""Can't backup an instance which is already being backed up."""
|
"""Can't backup an instance which is already being backed up."""
|
||||||
instance_id = self._create_instance()
|
instance = self._create_fake_instance()
|
||||||
instance = self.compute_api.get(self.context, instance_id)
|
|
||||||
self.compute_api.snapshot(self.context, instance, None, None)
|
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):
|
def test_backup(self):
|
||||||
"""Can't backup an instance which is already being backed up."""
|
"""Can't backup an instance which is already being backed up."""
|
||||||
instance_id = self._create_instance()
|
instance = self._create_fake_instance()
|
||||||
instance = self.compute_api.get(self.context, instance_id)
|
|
||||||
self.compute_api.backup(self.context, instance, None, None, None)
|
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):
|
def test_backup_conflict(self):
|
||||||
"""Can't backup an instance which is already being backed up."""
|
"""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}
|
instance_values = {'task_state': task_states.IMAGE_BACKUP}
|
||||||
db.instance_update(self.context, instance_id, instance_values)
|
db.instance_update(self.context, instance_id, instance_values)
|
||||||
instance = self.compute_api.get(self.context, instance_id)
|
instance = self.compute_api.get(self.context, instance_id)
|
||||||
@@ -1347,7 +1348,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_snapshot_conflict(self):
|
def test_snapshot_conflict(self):
|
||||||
"""Can't snapshot an instance which is already being snapshotted."""
|
"""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}
|
instance_values = {'task_state': task_states.IMAGE_SNAPSHOT}
|
||||||
db.instance_update(self.context, instance_id, instance_values)
|
db.instance_update(self.context, instance_id, instance_values)
|
||||||
instance = self.compute_api.get(self.context, instance_id)
|
instance = self.compute_api.get(self.context, instance_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user